Skip to content

Commit 5b29d39

Browse files
uds5501niranjan94
authored andcommitted
feat: Create user payment information form (#3215)
* Create user payment information form * default reroute billing info to payment info * change route name to billing * use authManager.currentUser * follow ES6 patterns and work on suggestions * add loader in the form
1 parent 72748b9 commit 5b29d39

File tree

18 files changed

+243
-30
lines changed

18 files changed

+243
-30
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import Component from '@ember/component';
2+
import FormMixin from 'open-event-frontend/mixins/form';
3+
import { validPhoneNumber } from 'open-event-frontend/utils/validators';
4+
import { pick, orderBy } from 'lodash-es';
5+
import { action, computed } from '@ember/object';
6+
import { countries } from 'open-event-frontend/utils/dictionary/demography';
7+
8+
export default class extends Component.extend(FormMixin) {
9+
didInsertElement() {
10+
super.didInsertElement(...arguments);
11+
this.set('userBillingInfo', pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingCountry', 'billingState', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']));
12+
}
13+
14+
getValidationRules() {
15+
return {
16+
inline : true,
17+
delay : false,
18+
on : 'blur',
19+
20+
fields: {
21+
name: {
22+
identifier : 'contactName',
23+
rules : [
24+
{
25+
type : 'empty',
26+
prompt : this.l10n.t('Please enter your name')
27+
}
28+
]
29+
},
30+
company: {
31+
identifier : 'company',
32+
rules : [
33+
{
34+
type : 'empty',
35+
prompt : this.l10n.t('Please enter your company')
36+
}
37+
]
38+
},
39+
country: {
40+
identifier : 'country',
41+
rules : [
42+
{
43+
type : 'empty',
44+
prompt : this.l10n.t('Please enter your country')
45+
}
46+
]
47+
},
48+
address: {
49+
identifier : 'address',
50+
rules : [
51+
{
52+
type : 'empty',
53+
prompt : this.l10n.t('Please enter your billing address')
54+
}
55+
]
56+
},
57+
city: {
58+
identifier : 'city',
59+
rules : [
60+
{
61+
type : 'empty',
62+
prompt : this.l10n.t('Please enter your billing city')
63+
}
64+
]
65+
},
66+
zipCode: {
67+
identifier : 'zip',
68+
rules : [
69+
{
70+
type : 'empty',
71+
prompt : this.l10n.t('Please enter the zip code')
72+
}
73+
]
74+
},
75+
phone: {
76+
identifier : 'phone',
77+
rules : [
78+
{
79+
type : 'empty',
80+
prompt : this.l10n.t('Please enter a phone number.')
81+
},
82+
{
83+
type : 'regExp',
84+
value : validPhoneNumber,
85+
prompt : this.l10n.t('Please enter a valid phone number.')
86+
}
87+
]
88+
}
89+
}
90+
};
91+
}
92+
93+
@computed()
94+
get countries() {
95+
return orderBy(countries, 'name');
96+
}
97+
98+
@action
99+
submit() {
100+
this.onValid(async() => {
101+
this.set('isLoading', true);
102+
try {
103+
this.authManager.currentUser.setProperties(this.userBillingInfo);
104+
await this.authManager.currentUser.save();
105+
this.notify.success(this.l10n.t('Your billing details has been updated'));
106+
} catch (error) {
107+
this.authManager.currentUser.rollbackAttributes();
108+
this.notify.error(this.l10n.t('An unexpected error occurred'));
109+
}
110+
this.set('isLoading', false);
111+
});
112+
}
113+
}

app/models/user.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ export default ModelBase.extend({
4848
deletedAt : attr('moment'),
4949
lastAccessedAt : attr('moment', { readOnly: true }),
5050

51+
/**
52+
* Billing Contact Information
53+
*/
54+
55+
billingContactName : attr('string'),
56+
billingPhone : attr('string'),
57+
billingCountry : attr('string'),
58+
company : attr('string'),
59+
billingAddress : attr('string'),
60+
billingCity : attr('string'),
61+
billingZipCode : attr('string'),
62+
billingTaxInfo : attr('string'),
63+
billingAdditionalInfo : attr('string'),
64+
billingState : attr('string'),
65+
5166
status: computed('lastAccessedAt', 'deletedAt', function() {
5267
if (this.deletedAt == null) {
5368
if (this.lastAccessedAt == null) {

app/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ router.map(function() {
113113
this.route('email-preferences');
114114
this.route('applications');
115115
this.route('danger-zone');
116-
this.route('billing-info', function() {
116+
this.route('billing', function() {
117117
this.route('payment-info');
118118
this.route('invoices');
119119
});

app/routes/account/billing-info/invoices.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/routes/account/billing-info/payment-info.js

Lines changed: 0 additions & 4 deletions
This file was deleted.
File renamed without changes.

app/routes/account/billing/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Route from '@ember/routing/route';
2+
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
3+
4+
export default class extends Route.extend(AuthenticatedRouteMixin) {
5+
titleToken() {
6+
return this.l10n.t('Billing Info');
7+
}
8+
9+
beforeModel() {
10+
super.beforeModel(...arguments);
11+
this.replaceWith('account.billing.payment-info');
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default class extends Route {
4+
titleToken() {
5+
return this.l10n.t('Invoices');
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Route from '@ember/routing/route';
2+
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
3+
4+
export default class extends Route.extend(AuthenticatedRouteMixin) {
5+
titleToken() {
6+
return this.l10n.t('Payment Info');
7+
}
8+
}

app/templates/account.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{#link-to 'account.profile' class='item'}}
55
{{t 'Profile'}}
66
{{/link-to}}
7-
{{#link-to 'account.billing-info' class='item'}}
7+
{{#link-to 'account.billing' class='item'}}
88
{{t 'Billing Info'}}
99
{{/link-to}}
1010
{{#link-to 'account.password' class='item'}}

0 commit comments

Comments
 (0)