From db2f6f84f82d9bf31c013b365c45c5c2daa943c7 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Sun, 30 Jun 2019 23:24:11 +0530 Subject: [PATCH 1/6] Create user payment information form --- .../forms/user-payment-info-form.js | 116 ++++++++++++++++++ app/models/user.js | 14 +++ app/routes/account/billing-info.js | 8 ++ .../account/billing-info/payment-info.js | 6 +- .../account/billing-info/payment-info.hbs | 3 + .../forms/user-payment-info-form.hbs | 41 +++++++ 6 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 app/components/forms/user-payment-info-form.js create mode 100644 app/templates/components/forms/user-payment-info-form.hbs 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..6a1edd4ac82 --- /dev/null +++ b/app/components/forms/user-payment-info-form.js @@ -0,0 +1,116 @@ +import Component from '@ember/component'; +import FormMixin from 'open-event-frontend/mixins/form'; +import { validPhoneNumber } from 'open-event-frontend/utils/validators'; + +export default Component.extend(FormMixin, { + + async init() { + this._super(...arguments); + let actualUser = await this.authManager.currentUser; + let userBillingInfo = { + billingContactName : actualUser.billingContactName, + billingCity : actualUser.billingCity, + billingPhone : actualUser.billingPhone, + company : actualUser.company, + billingTaxInfo : actualUser.billingTaxInfo, + billingAddress : actualUser.billingAddress, + billingZipCode : actualUser.billingZipCode, + billingAdditionalInfo : actualUser.billingAdditionalInfo + }; + this.set('userBillingInfo', userBillingInfo); + this.set('actualUser', actualUser); + }, + + 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') + } + ] + }, + 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.') + } + ] + } + } + }; + }, + actions: { + submit() { + this.onValid(async() => { + try { + this.actualUser.setProperties({ + billingAdditionalInfo : this.userBillingInfo.billingAdditionalInfo, + billingZipCode : this.userBillingInfo.billingZipCode, + billingContactName : this.userBillingInfo.billingContactName, + billingPhone : this.userBillingInfo.billingPhone, + company : this.userBillingInfo.company, + billingTaxInfo : this.userBillingInfo.billingTaxInfo, + billingCity : this.userBillingInfo.billingCity, + billingAddress : this.userBillingInfo.billingAddress + }); + await this.actualUser.save(); + this.notify.success(this.l10n.t('Your billing details has been updated')); + } catch (error) { + this.actualUser.rollbackAttributes(); + this.notify.error(this.l10n.t('An unexpected error occurred')); + } + }); + } + } +}); diff --git a/app/models/user.js b/app/models/user.js index 57763e3efe6..3eda68c9ccc 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -47,6 +47,20 @@ 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'), + status: computed('lastAccessedAt', 'deletedAt', function() { if (this.deletedAt == null) { if (this.lastAccessedAt == null) { diff --git a/app/routes/account/billing-info.js b/app/routes/account/billing-info.js index b696b4ed48e..6c64268c7f8 100644 --- a/app/routes/account/billing-info.js +++ b/app/routes/account/billing-info.js @@ -4,5 +4,13 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout export default Route.extend(AuthenticatedRouteMixin, { titleToken() { return this.l10n.t('Billing Info'); + }, + beforeModel() { + this._super(...arguments); + if (this.authManager.currentUser) { + this.replaceWith('account.billing-info.payment-info'); + } else { + this.replaceWith('login'); + } } }); diff --git a/app/routes/account/billing-info/payment-info.js b/app/routes/account/billing-info/payment-info.js index 6c74252aa1b..bbf74258887 100644 --- a/app/routes/account/billing-info/payment-info.js +++ b/app/routes/account/billing-info/payment-info.js @@ -1,4 +1,8 @@ import Route from '@ember/routing/route'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Route.extend({ +export default Route.extend(AuthenticatedRouteMixin, { + titleToken() { + return this.l10n.t('Payment Info'); + } }); diff --git a/app/templates/account/billing-info/payment-info.hbs b/app/templates/account/billing-info/payment-info.hbs index e69de29bb2d..9714abc29a7 100644 --- a/app/templates/account/billing-info/payment-info.hbs +++ b/app/templates/account/billing-info/payment-info.hbs @@ -0,0 +1,3 @@ +
+ {{forms/user-payment-info-form}} +
\ No newline at end of file diff --git a/app/templates/components/forms/user-payment-info-form.hbs b/app/templates/components/forms/user-payment-info-form.hbs new file mode 100644 index 00000000000..ec5e6b43b22 --- /dev/null +++ b/app/templates/components/forms/user-payment-info-form.hbs @@ -0,0 +1,41 @@ +
+

+ {{t 'Payment Information'}} +

+
+ + {{input type='text' id='contactName' value=(mut userBillingInfo.billingContactName)}} +
+
+ + {{input type='text' id='phone' value=(mut userBillingInfo.billingPhone)}} +
+
+ + {{input type='text' id='company' value=(mut userBillingInfo.company)}} +
+
+ + {{input type='text' id='taxID' value=(mut userBillingInfo.billingTaxInfo)}} +
+
+ + {{textarea rows='2' id='address' value=(mut userBillingInfo.billingAddress)}} +
+
+ + {{input type='text' id='city' value=(mut userBillingInfo.billingCity)}} +
+
+ + {{input type='text' id='zip' value=(mut userBillingInfo.billingZipCode)}} +
+
+ + {{textarea rows='4' id='additionalInfo' value=(mut userBillingInfo.billingAdditionalInfo)}} +
+ + +
From 6d40ea71f4e9d760798fcfe40634f0d0102cbee7 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Mon, 1 Jul 2019 14:59:40 +0530 Subject: [PATCH 2/6] default reroute billing info to payment info --- .../forms/user-payment-info-form.js | 29 ++++--------------- app/routes/account/billing-info.js | 8 ----- app/routes/account/billing-info/index.js | 12 ++++++++ app/routes/account/billing-info/invoices.js | 3 ++ tests/acceptance/billing-info-test.js | 2 +- 5 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 app/routes/account/billing-info/index.js diff --git a/app/components/forms/user-payment-info-form.js b/app/components/forms/user-payment-info-form.js index 6a1edd4ac82..b5afff9df45 100644 --- a/app/components/forms/user-payment-info-form.js +++ b/app/components/forms/user-payment-info-form.js @@ -1,22 +1,14 @@ import Component from '@ember/component'; import FormMixin from 'open-event-frontend/mixins/form'; import { validPhoneNumber } from 'open-event-frontend/utils/validators'; +import { pick } from 'lodash-es'; export default Component.extend(FormMixin, { - async init() { + async didInsertElement() { this._super(...arguments); let actualUser = await this.authManager.currentUser; - let userBillingInfo = { - billingContactName : actualUser.billingContactName, - billingCity : actualUser.billingCity, - billingPhone : actualUser.billingPhone, - company : actualUser.company, - billingTaxInfo : actualUser.billingTaxInfo, - billingAddress : actualUser.billingAddress, - billingZipCode : actualUser.billingZipCode, - billingAdditionalInfo : actualUser.billingAdditionalInfo - }; + let userBillingInfo = pick(actualUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']); this.set('userBillingInfo', userBillingInfo); this.set('actualUser', actualUser); }, @@ -94,20 +86,11 @@ export default Component.extend(FormMixin, { submit() { this.onValid(async() => { try { - this.actualUser.setProperties({ - billingAdditionalInfo : this.userBillingInfo.billingAdditionalInfo, - billingZipCode : this.userBillingInfo.billingZipCode, - billingContactName : this.userBillingInfo.billingContactName, - billingPhone : this.userBillingInfo.billingPhone, - company : this.userBillingInfo.company, - billingTaxInfo : this.userBillingInfo.billingTaxInfo, - billingCity : this.userBillingInfo.billingCity, - billingAddress : this.userBillingInfo.billingAddress - }); - await this.actualUser.save(); + 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.actualUser.rollbackAttributes(); + this.authManager.currentUser.rollbackAttributes(); this.notify.error(this.l10n.t('An unexpected error occurred')); } }); diff --git a/app/routes/account/billing-info.js b/app/routes/account/billing-info.js index 6c64268c7f8..b696b4ed48e 100644 --- a/app/routes/account/billing-info.js +++ b/app/routes/account/billing-info.js @@ -4,13 +4,5 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout export default Route.extend(AuthenticatedRouteMixin, { titleToken() { return this.l10n.t('Billing Info'); - }, - beforeModel() { - this._super(...arguments); - if (this.authManager.currentUser) { - this.replaceWith('account.billing-info.payment-info'); - } else { - this.replaceWith('login'); - } } }); diff --git a/app/routes/account/billing-info/index.js b/app/routes/account/billing-info/index.js new file mode 100644 index 00000000000..575c55ee4cf --- /dev/null +++ b/app/routes/account/billing-info/index.js @@ -0,0 +1,12 @@ +import Route from '@ember/routing/route'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Route.extend(AuthenticatedRouteMixin, { + titleToken() { + return this.l10n.t('Billing Info'); + }, + beforeModel() { + this._super(...arguments); + this.replaceWith('account.billing-info.payment-info'); + } +}); diff --git a/app/routes/account/billing-info/invoices.js b/app/routes/account/billing-info/invoices.js index 6c74252aa1b..c7ab44f01ad 100644 --- a/app/routes/account/billing-info/invoices.js +++ b/app/routes/account/billing-info/invoices.js @@ -1,4 +1,7 @@ import Route from '@ember/routing/route'; export default Route.extend({ + titleToken() { + return this.l10n.t('Invoices'); + } }); diff --git a/tests/acceptance/billing-info-test.js b/tests/acceptance/billing-info-test.js index 51d3a7ecb45..5cac2bdee00 100644 --- a/tests/acceptance/billing-info-test.js +++ b/tests/acceptance/billing-info-test.js @@ -16,6 +16,6 @@ module('Acceptance | account/billing-info', function(hooks) { test('visiting account/billing-info with login', async function(assert) { await login(assert); await visit('account/billing-info'); - assert.equal(currentURL(), 'account/billing-info'); + assert.equal(currentURL(), '/account/billing-info/payment-info'); }); }); \ No newline at end of file From 3391e412e53b08384a58c4404e7d39e118935706 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Mon, 1 Jul 2019 22:38:46 +0530 Subject: [PATCH 3/6] change route name to billing --- app/components/forms/user-payment-info-form.js | 9 +++++++++ app/models/user.js | 1 + app/router.js | 2 +- app/routes/account/{billing-info.js => billing.js} | 0 .../account/{billing-info => billing}/index.js | 2 +- .../account/{billing-info => billing}/invoices.js | 0 .../{billing-info => billing}/payment-info.js | 0 app/templates/account.hbs | 2 +- .../account/{billing-info.hbs => billing.hbs} | 4 ++-- .../account/{billing-info => billing}/invoices.hbs | 0 .../{billing-info => billing}/payment-info.hbs | 0 .../components/forms/user-payment-info-form.hbs | 8 ++++++++ tests/acceptance/billing-info-test.js | 12 ++++++------ tests/acceptance/invoices-test.js | 12 ++++++------ tests/acceptance/payment-info-test.js | 12 ++++++------ 15 files changed, 41 insertions(+), 23 deletions(-) rename app/routes/account/{billing-info.js => billing.js} (100%) rename app/routes/account/{billing-info => billing}/index.js (83%) rename app/routes/account/{billing-info => billing}/invoices.js (100%) rename app/routes/account/{billing-info => billing}/payment-info.js (100%) rename app/templates/account/{billing-info.hbs => billing.hbs} (75%) rename app/templates/account/{billing-info => billing}/invoices.hbs (100%) rename app/templates/account/{billing-info => billing}/payment-info.hbs (100%) diff --git a/app/components/forms/user-payment-info-form.js b/app/components/forms/user-payment-info-form.js index b5afff9df45..c4f0d39557a 100644 --- a/app/components/forms/user-payment-info-form.js +++ b/app/components/forms/user-payment-info-form.js @@ -38,6 +38,15 @@ export default Component.extend(FormMixin, { } ] }, + country: { + identifier : 'country', + rules : [ + { + type : 'empty', + prompt : this.l10n.t('Please enter your country') + } + ] + }, address: { identifier : 'address', rules : [ diff --git a/app/models/user.js b/app/models/user.js index 3eda68c9ccc..1a3919a05f1 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -60,6 +60,7 @@ export default ModelBase.extend({ billingZipCode : attr('string'), billingTaxInfo : attr('string'), billingAdditionalInfo : attr('string'), + billingState : attr('string'), status: computed('lastAccessedAt', 'deletedAt', function() { if (this.deletedAt == null) { diff --git a/app/router.js b/app/router.js index 1be55d37470..02ff4338931 100644 --- a/app/router.js +++ b/app/router.js @@ -112,7 +112,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.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-info/index.js b/app/routes/account/billing/index.js similarity index 83% rename from app/routes/account/billing-info/index.js rename to app/routes/account/billing/index.js index 575c55ee4cf..579c50b696f 100644 --- a/app/routes/account/billing-info/index.js +++ b/app/routes/account/billing/index.js @@ -7,6 +7,6 @@ export default Route.extend(AuthenticatedRouteMixin, { }, beforeModel() { this._super(...arguments); - this.replaceWith('account.billing-info.payment-info'); + this.replaceWith('account.billing.payment-info'); } }); diff --git a/app/routes/account/billing-info/invoices.js b/app/routes/account/billing/invoices.js similarity index 100% rename from app/routes/account/billing-info/invoices.js rename to app/routes/account/billing/invoices.js diff --git a/app/routes/account/billing-info/payment-info.js b/app/routes/account/billing/payment-info.js similarity index 100% rename from app/routes/account/billing-info/payment-info.js rename to app/routes/account/billing/payment-info.js 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.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 @@
{{#tabbed-navigation isVertical=true}} - {{#link-to 'account.billing-info.payment-info' class='item'}} + {{#link-to 'account.billing.payment-info' class='item'}} {{t 'Payment Information'}} {{/link-to}} - {{#link-to 'account.billing-info.invoices' class='item'}} + {{#link-to 'account.billing.invoices' class='item'}} {{t 'Invoices'}} {{/link-to}} {{/tabbed-navigation}} diff --git a/app/templates/account/billing-info/invoices.hbs b/app/templates/account/billing/invoices.hbs similarity index 100% rename from app/templates/account/billing-info/invoices.hbs rename to app/templates/account/billing/invoices.hbs diff --git a/app/templates/account/billing-info/payment-info.hbs b/app/templates/account/billing/payment-info.hbs similarity index 100% rename from app/templates/account/billing-info/payment-info.hbs rename to app/templates/account/billing/payment-info.hbs diff --git a/app/templates/components/forms/user-payment-info-form.hbs b/app/templates/components/forms/user-payment-info-form.hbs index ec5e6b43b22..23ef5febd46 100644 --- a/app/templates/components/forms/user-payment-info-form.hbs +++ b/app/templates/components/forms/user-payment-info-form.hbs @@ -26,6 +26,14 @@ {{input type='text' id='city' value=(mut userBillingInfo.billingCity)}}
+
+ + {{input type='text' id='state' value=(mut userBillingInfo.billingState)}} +
+
+ + {{input type='text' id='country' value=(mut userBillingInfo.billingCountry)}} +
{{input type='text' id='zip' value=(mut userBillingInfo.billingZipCode)}} diff --git a/tests/acceptance/billing-info-test.js b/tests/acceptance/billing-info-test.js index 5cac2bdee00..69d57eb52fb 100644 --- a/tests/acceptance/billing-info-test.js +++ b/tests/acceptance/billing-info-test.js @@ -4,18 +4,18 @@ import { currentURL, visit } from '@ember/test-helpers'; import { login } from 'open-event-frontend/tests/helpers/custom-helpers'; -module('Acceptance | account/billing-info', function(hooks) { +module('Acceptance | account/billing', function(hooks) { setupApplicationTest(hooks); - test('visiting account/billing-info without login', async function(assert) { - await visit('account/billing-info'); + test('visiting account/billing without login', async function(assert) { + await visit('account/billing'); assert.equal(currentURL(), '/login'); }); - test('visiting account/billing-info with login', async function(assert) { + test('visiting account/billing with login', async function(assert) { await login(assert); - await visit('account/billing-info'); - assert.equal(currentURL(), '/account/billing-info/payment-info'); + await visit('account/billing'); + assert.equal(currentURL(), '/account/billing/payment-info'); }); }); \ No newline at end of file diff --git a/tests/acceptance/invoices-test.js b/tests/acceptance/invoices-test.js index 5fc236452e0..d2ff55eb155 100644 --- a/tests/acceptance/invoices-test.js +++ b/tests/acceptance/invoices-test.js @@ -4,18 +4,18 @@ import { currentURL, visit } from '@ember/test-helpers'; import { login } from 'open-event-frontend/tests/helpers/custom-helpers'; -module('Acceptance | account/billing-info/invoices', function(hooks) { +module('Acceptance | account/billing/invoices', function(hooks) { setupApplicationTest(hooks); - test('visiting account/billing-info/invoices without login', async function(assert) { - await visit('account/billing-info/invoices'); + test('visiting account/billing/invoices without login', async function(assert) { + await visit('account/billing/invoices'); assert.equal(currentURL(), '/login'); }); - test('visiting account/billing-info/invoices with login', async function(assert) { + test('visiting account/billing/invoices with login', async function(assert) { await login(assert); - await visit('/account/billing-info/invoices'); - assert.equal(currentURL(), '/account/billing-info/invoices'); + await visit('/account/billing/invoices'); + assert.equal(currentURL(), '/account/billing/invoices'); }); }); \ No newline at end of file diff --git a/tests/acceptance/payment-info-test.js b/tests/acceptance/payment-info-test.js index dca5d4b69a0..ef5820ac66c 100644 --- a/tests/acceptance/payment-info-test.js +++ b/tests/acceptance/payment-info-test.js @@ -4,18 +4,18 @@ import { currentURL, visit } from '@ember/test-helpers'; import { login } from 'open-event-frontend/tests/helpers/custom-helpers'; -module('Acceptance | account/billing-info/payment-info', function(hooks) { +module('Acceptance | account/billing/payment-info', function(hooks) { setupApplicationTest(hooks); - test('visiting account/billing-info/payment-info without login', async function(assert) { - await visit('account/billing-info/payment-info'); + test('visiting account/billing/payment-info without login', async function(assert) { + await visit('account/billing/payment-info'); assert.equal(currentURL(), '/login'); }); - test('visiting account/billing-info/payment-info with login', async function(assert) { + test('visiting account/billing/payment-info with login', async function(assert) { await login(assert); - await visit('/account/billing-info/payment-info'); - assert.equal(currentURL(), '/account/billing-info/payment-info'); + await visit('/account/billing/payment-info'); + assert.equal(currentURL(), '/account/billing/payment-info'); }); }); \ No newline at end of file From 350636f4c5f62a2b4075252078c669de9e9b9452 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Tue, 2 Jul 2019 13:34:32 +0530 Subject: [PATCH 4/6] use authManager.currentUser --- app/components/forms/user-payment-info-form.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/components/forms/user-payment-info-form.js b/app/components/forms/user-payment-info-form.js index c4f0d39557a..3889b5458ae 100644 --- a/app/components/forms/user-payment-info-form.js +++ b/app/components/forms/user-payment-info-form.js @@ -7,10 +7,8 @@ export default Component.extend(FormMixin, { async didInsertElement() { this._super(...arguments); - let actualUser = await this.authManager.currentUser; - let userBillingInfo = pick(actualUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']); + let userBillingInfo = pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']); this.set('userBillingInfo', userBillingInfo); - this.set('actualUser', actualUser); }, getValidationRules() { From 97984e8808e5e01a416ea07ccf7eafd2352c226c Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 5 Jul 2019 15:13:59 +0530 Subject: [PATCH 5/6] follow ES6 patterns and work on suggestions --- .../forms/user-payment-info-form.js | 51 ++++++++++--------- app/routes/account/billing/index.js | 9 ++-- app/routes/account/billing/payment-info.js | 4 +- .../forms/user-payment-info-form.hbs | 39 +++++++++----- 4 files changed, 61 insertions(+), 42 deletions(-) diff --git a/app/components/forms/user-payment-info-form.js b/app/components/forms/user-payment-info-form.js index 3889b5458ae..4b02da61bab 100644 --- a/app/components/forms/user-payment-info-form.js +++ b/app/components/forms/user-payment-info-form.js @@ -1,15 +1,15 @@ import Component from '@ember/component'; import FormMixin from 'open-event-frontend/mixins/form'; import { validPhoneNumber } from 'open-event-frontend/utils/validators'; -import { pick } from 'lodash-es'; +import { pick, orderBy } from 'lodash-es'; +import { action, computed } from '@ember/object'; +import { countries } from 'open-event-frontend/utils/dictionary/demography'; -export default Component.extend(FormMixin, { - - async didInsertElement() { - this._super(...arguments); - let userBillingInfo = pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']); - this.set('userBillingInfo', userBillingInfo); - }, +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 { @@ -88,19 +88,24 @@ export default Component.extend(FormMixin, { } } }; - }, - actions: { - submit() { - this.onValid(async() => { - 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')); - } - }); - } } -}); + + @computed() + get countries() { + return orderBy(countries, 'name'); + } + + @action + submit() { + this.onValid(async() => { + 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')); + } + }); + } +} diff --git a/app/routes/account/billing/index.js b/app/routes/account/billing/index.js index 579c50b696f..7e9a38db3a6 100644 --- a/app/routes/account/billing/index.js +++ b/app/routes/account/billing/index.js @@ -1,12 +1,13 @@ import Route from '@ember/routing/route'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Route.extend(AuthenticatedRouteMixin, { +export default class extends Route.extend(AuthenticatedRouteMixin) { titleToken() { return this.l10n.t('Billing Info'); - }, + } + beforeModel() { - this._super(...arguments); + super.beforeModel(...arguments); this.replaceWith('account.billing.payment-info'); } -}); +} diff --git a/app/routes/account/billing/payment-info.js b/app/routes/account/billing/payment-info.js index bbf74258887..3248990a07c 100644 --- a/app/routes/account/billing/payment-info.js +++ b/app/routes/account/billing/payment-info.js @@ -1,8 +1,8 @@ import Route from '@ember/routing/route'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Route.extend(AuthenticatedRouteMixin, { +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/components/forms/user-payment-info-form.hbs b/app/templates/components/forms/user-payment-info-form.hbs index 23ef5febd46..36653afa151 100644 --- a/app/templates/components/forms/user-payment-info-form.hbs +++ b/app/templates/components/forms/user-payment-info-form.hbs @@ -4,43 +4,56 @@
- {{input type='text' id='contactName' value=(mut userBillingInfo.billingContactName)}} + {{input type='text' id='contactName' value=userBillingInfo.billingContactName}}
- {{input type='text' id='phone' value=(mut userBillingInfo.billingPhone)}} + {{input type='text' id='phone' value=userBillingInfo.billingPhone}}
- {{input type='text' id='company' value=(mut userBillingInfo.company)}} + {{input type='text' id='company' value=userBillingInfo.company}}
- {{input type='text' id='taxID' value=(mut userBillingInfo.billingTaxInfo)}} + {{input type='text' id='taxID' value=userBillingInfo.billingTaxInfo}}
- {{textarea rows='2' id='address' value=(mut userBillingInfo.billingAddress)}} + {{textarea rows='2' id='address' value=userBillingInfo.billingAddress}}
- {{input type='text' id='city' value=(mut userBillingInfo.billingCity)}} + {{input type='text' id='city' value=userBillingInfo.billingCity}}
- {{input type='text' id='state' value=(mut userBillingInfo.billingState)}} -
-
- - {{input type='text' id='country' value=(mut userBillingInfo.billingCountry)}} + {{input type='text' id='state' value=userBillingInfo.billingState}} +
+
+ + {{#ui-dropdown class='search selection' selected=userBillingInfo.billingCountry forceSelection=false + fullTextSearch=true}} + {{input type='hidden' id='country' value=userBillingInfo.billingCountry}} + +
{{t 'Select country'}}
+ + {{/ui-dropdown}}
- {{input type='text' id='zip' value=(mut userBillingInfo.billingZipCode)}} + {{input type='text' id='zip' value=userBillingInfo.billingZipCode}}
- {{textarea rows='4' id='additionalInfo' value=(mut userBillingInfo.billingAdditionalInfo)}} + {{textarea rows='4' id='additionalInfo' value=userBillingInfo.billingAdditionalInfo}}
-