diff --git a/app/components/forms/user-payment-info-form.js b/app/components/forms/user-payment-info-form.js new file mode 100644 index 00000000000..ad464322b6c --- /dev/null +++ b/app/components/forms/user-payment-info-form.js @@ -0,0 +1,113 @@ +import Component from '@ember/component'; +import FormMixin from 'open-event-frontend/mixins/form'; +import { validPhoneNumber } from 'open-event-frontend/utils/validators'; +import { pick, orderBy } from 'lodash-es'; +import { action, computed } from '@ember/object'; +import { countries } from 'open-event-frontend/utils/dictionary/demography'; + +export default class extends Component.extend(FormMixin) { + didInsertElement() { + super.didInsertElement(...arguments); + this.set('userBillingInfo', pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingCountry', 'billingState', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo'])); + } + + getValidationRules() { + return { + inline : true, + delay : false, + on : 'blur', + + fields: { + name: { + identifier : 'contactName', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your name') + } + ] + }, + company: { + identifier : 'company', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your company') + } + ] + }, + country: { + identifier : 'country', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your country') + } + ] + }, + address: { + identifier : 'address', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your billing address') + } + ] + }, + city: { + identifier : 'city', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your billing city') + } + ] + }, + zipCode: { + identifier : 'zip', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter the zip code') + } + ] + }, + phone: { + identifier : 'phone', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter a phone number.') + }, + { + type : 'regExp', + value : validPhoneNumber, + prompt : this.l10n.t('Please enter a valid phone number.') + } + ] + } + } + }; + } + + @computed() + get countries() { + return orderBy(countries, 'name'); + } + + @action + submit() { + this.onValid(async() => { + this.set('isLoading', true); + try { + this.authManager.currentUser.setProperties(this.userBillingInfo); + await this.authManager.currentUser.save(); + this.notify.success(this.l10n.t('Your billing details has been updated')); + } catch (error) { + this.authManager.currentUser.rollbackAttributes(); + this.notify.error(this.l10n.t('An unexpected error occurred')); + } + this.set('isLoading', false); + }); + } +} diff --git a/app/models/user.js b/app/models/user.js index ee2c6a30b86..9340fc7fb92 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -48,6 +48,21 @@ export default ModelBase.extend({ deletedAt : attr('moment'), lastAccessedAt : attr('moment', { readOnly: true }), + /** + * Billing Contact Information + */ + + billingContactName : attr('string'), + billingPhone : attr('string'), + billingCountry : attr('string'), + company : attr('string'), + billingAddress : attr('string'), + billingCity : attr('string'), + billingZipCode : attr('string'), + billingTaxInfo : attr('string'), + billingAdditionalInfo : attr('string'), + billingState : attr('string'), + status: computed('lastAccessedAt', 'deletedAt', function() { if (this.deletedAt == null) { if (this.lastAccessedAt == null) { diff --git a/app/router.js b/app/router.js index bac71b7f1a9..5fa8f170cc2 100644 --- a/app/router.js +++ b/app/router.js @@ -113,7 +113,7 @@ router.map(function() { this.route('email-preferences'); this.route('applications'); this.route('danger-zone'); - this.route('billing-info', function() { + this.route('billing', function() { this.route('payment-info'); this.route('invoices'); }); diff --git a/app/routes/account/billing-info/invoices.js b/app/routes/account/billing-info/invoices.js deleted file mode 100644 index 6c74252aa1b..00000000000 --- a/app/routes/account/billing-info/invoices.js +++ /dev/null @@ -1,4 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ -}); diff --git a/app/routes/account/billing-info/payment-info.js b/app/routes/account/billing-info/payment-info.js deleted file mode 100644 index 6c74252aa1b..00000000000 --- a/app/routes/account/billing-info/payment-info.js +++ /dev/null @@ -1,4 +0,0 @@ -import Route from '@ember/routing/route'; - -export default Route.extend({ -}); diff --git a/app/routes/account/billing-info.js b/app/routes/account/billing.js similarity index 100% rename from app/routes/account/billing-info.js rename to app/routes/account/billing.js diff --git a/app/routes/account/billing/index.js b/app/routes/account/billing/index.js new file mode 100644 index 00000000000..7e9a38db3a6 --- /dev/null +++ b/app/routes/account/billing/index.js @@ -0,0 +1,13 @@ +import Route from '@ember/routing/route'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default class extends Route.extend(AuthenticatedRouteMixin) { + titleToken() { + return this.l10n.t('Billing Info'); + } + + beforeModel() { + super.beforeModel(...arguments); + this.replaceWith('account.billing.payment-info'); + } +} diff --git a/app/routes/account/billing/invoices.js b/app/routes/account/billing/invoices.js new file mode 100644 index 00000000000..940655cb5dc --- /dev/null +++ b/app/routes/account/billing/invoices.js @@ -0,0 +1,7 @@ +import Route from '@ember/routing/route'; + +export default class extends Route { + titleToken() { + return this.l10n.t('Invoices'); + } +} diff --git a/app/routes/account/billing/payment-info.js b/app/routes/account/billing/payment-info.js new file mode 100644 index 00000000000..3248990a07c --- /dev/null +++ b/app/routes/account/billing/payment-info.js @@ -0,0 +1,8 @@ +import Route from '@ember/routing/route'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default class extends Route.extend(AuthenticatedRouteMixin) { + titleToken() { + return this.l10n.t('Payment Info'); + } +} \ No newline at end of file diff --git a/app/templates/account.hbs b/app/templates/account.hbs index e21accdee8c..798eb2ec647 100644 --- a/app/templates/account.hbs +++ b/app/templates/account.hbs @@ -4,7 +4,7 @@ {{#link-to 'account.profile' class='item'}} {{t 'Profile'}} {{/link-to}} - {{#link-to 'account.billing-info' class='item'}} + {{#link-to 'account.billing' class='item'}} {{t 'Billing Info'}} {{/link-to}} {{#link-to 'account.password' class='item'}} diff --git a/app/templates/account/billing-info/payment-info.hbs b/app/templates/account/billing-info/payment-info.hbs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/app/templates/account/billing-info.hbs b/app/templates/account/billing.hbs similarity index 75% rename from app/templates/account/billing-info.hbs rename to app/templates/account/billing.hbs index bb0065c9612..0a16e012c10 100644 --- a/app/templates/account/billing-info.hbs +++ b/app/templates/account/billing.hbs @@ -2,10 +2,10 @@