Skip to content

Commit db2f6f8

Browse files
committed
Create user payment information form
1 parent 974e2f5 commit db2f6f8

File tree

6 files changed

+187
-1
lines changed

6 files changed

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

app/models/user.js

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

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

app/routes/account/billing-info.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout
44
export default Route.extend(AuthenticatedRouteMixin, {
55
titleToken() {
66
return this.l10n.t('Billing Info');
7+
},
8+
beforeModel() {
9+
this._super(...arguments);
10+
if (this.authManager.currentUser) {
11+
this.replaceWith('account.billing-info.payment-info');
12+
} else {
13+
this.replaceWith('login');
14+
}
715
}
816
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import Route from '@ember/routing/route';
2+
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
23

3-
export default Route.extend({
4+
export default Route.extend(AuthenticatedRouteMixin, {
5+
titleToken() {
6+
return this.l10n.t('Payment Info');
7+
}
48
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="ui basic {{if isLoading 'loading' ''}} segment">
2+
{{forms/user-payment-info-form}}
3+
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<form class="ui form" {{action 'submit' on='submit'}}>
2+
<h3 class="ui header">
3+
{{t 'Payment Information'}}
4+
</h3>
5+
<div class="field">
6+
<label class="required" for="contactName">{{t 'Contact Name'}}</label>
7+
{{input type='text' id='contactName' value=(mut userBillingInfo.billingContactName)}}
8+
</div>
9+
<div class="field">
10+
<label class="required" for="phone">{{t 'Phone'}}</label>
11+
{{input type='text' id='phone' value=(mut userBillingInfo.billingPhone)}}
12+
</div>
13+
<div class="field">
14+
<label class="required" for="company">{{t 'Company'}}</label>
15+
{{input type='text' id='company' value=(mut userBillingInfo.company)}}
16+
</div>
17+
<div class="field">
18+
<label for="taxID">{{t 'Tax ID or Business ID'}}</label>
19+
{{input type='text' id='taxID' value=(mut userBillingInfo.billingTaxInfo)}}
20+
</div>
21+
<div class="field">
22+
<label class="required" for="address">{{t 'Address'}}</label>
23+
{{textarea rows='2' id='address' value=(mut userBillingInfo.billingAddress)}}
24+
</div>
25+
<div class="field">
26+
<label class="required" for="city">{{t 'City'}}</label>
27+
{{input type='text' id='city' value=(mut userBillingInfo.billingCity)}}
28+
</div>
29+
<div class="field">
30+
<label class="required" for="zip">{{t 'Zip Code'}}</label>
31+
{{input type='text' id='zip' value=(mut userBillingInfo.billingZipCode)}}
32+
</div>
33+
<div class="field">
34+
<label for="additionalInfo">{{t 'Additional Information'}}</label>
35+
{{textarea rows='4' id='additionalInfo' value=(mut userBillingInfo.billingAdditionalInfo)}}
36+
</div>
37+
38+
<button type="submit" class="ui teal submit button update-changes">
39+
{{t 'Submit'}}
40+
</button>
41+
</form>

0 commit comments

Comments
 (0)