Skip to content

Commit c242658

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

File tree

8 files changed

+186
-48
lines changed

8 files changed

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

app/controllers/account/password.js

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

app/controllers/account/profile.js

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

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 user.billingContactName)}}
8+
</div>
9+
<div class="field">
10+
<label class="required" for="phone">{{t 'Phone'}}</label>
11+
{{input type='text' id='phone' value=(mut user.billingPhone)}}
12+
</div>
13+
<div class="field">
14+
<label class="required" for="company">{{t 'Company'}}</label>
15+
{{input type='text' id='company' value=(mut user.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 user.billingTaxInfo)}}
20+
</div>
21+
<div class="field">
22+
<label class="required" for="address">{{t 'Address'}}</label>
23+
{{textarea rows='2' id='address' value=(mut user.billingAddress)}}
24+
</div>
25+
<div class="field">
26+
<label class="required" for="city">{{t 'City'}}</label>
27+
{{input type='text' id='city' value=(mut user.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 user.billingZipCode)}}
32+
</div>
33+
<div class="field">
34+
<label for="additionalInfo">{{t 'Additional Information'}}</label>
35+
{{textarea rows='4' id='additionalInfo' value=(mut user.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)