Skip to content

Commit 97984e8

Browse files
committed
follow ES6 patterns and work on suggestions
1 parent b1325ac commit 97984e8

File tree

4 files changed

+61
-42
lines changed

4 files changed

+61
-42
lines changed

app/components/forms/user-payment-info-form.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Component from '@ember/component';
22
import FormMixin from 'open-event-frontend/mixins/form';
33
import { validPhoneNumber } from 'open-event-frontend/utils/validators';
4-
import { pick } from 'lodash-es';
4+
import { pick, orderBy } from 'lodash-es';
5+
import { action, computed } from '@ember/object';
6+
import { countries } from 'open-event-frontend/utils/dictionary/demography';
57

6-
export default Component.extend(FormMixin, {
7-
8-
async didInsertElement() {
9-
this._super(...arguments);
10-
let userBillingInfo = pick(this.authManager.currentUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']);
11-
this.set('userBillingInfo', userBillingInfo);
12-
},
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+
}
1313

1414
getValidationRules() {
1515
return {
@@ -88,19 +88,24 @@ export default Component.extend(FormMixin, {
8888
}
8989
}
9090
};
91-
},
92-
actions: {
93-
submit() {
94-
this.onValid(async() => {
95-
try {
96-
this.authManager.currentUser.setProperties(this.userBillingInfo);
97-
await this.authManager.currentUser.save();
98-
this.notify.success(this.l10n.t('Your billing details has been updated'));
99-
} catch (error) {
100-
this.authManager.currentUser.rollbackAttributes();
101-
this.notify.error(this.l10n.t('An unexpected error occurred'));
102-
}
103-
});
104-
}
10591
}
106-
});
92+
93+
@computed()
94+
get countries() {
95+
return orderBy(countries, 'name');
96+
}
97+
98+
@action
99+
submit() {
100+
this.onValid(async() => {
101+
try {
102+
this.authManager.currentUser.setProperties(this.userBillingInfo);
103+
await this.authManager.currentUser.save();
104+
this.notify.success(this.l10n.t('Your billing details has been updated'));
105+
} catch (error) {
106+
this.authManager.currentUser.rollbackAttributes();
107+
this.notify.error(this.l10n.t('An unexpected error occurred'));
108+
}
109+
});
110+
}
111+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Route from '@ember/routing/route';
22
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
33

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

4-
export default Route.extend(AuthenticatedRouteMixin, {
4+
export default class extends Route.extend(AuthenticatedRouteMixin) {
55
titleToken() {
66
return this.l10n.t('Payment Info');
77
}
8-
});
8+
}

app/templates/components/forms/user-payment-info-form.hbs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,56 @@
44
</h3>
55
<div class="field">
66
<label class="required" for="contactName">{{t 'Contact Name'}}</label>
7-
{{input type='text' id='contactName' value=(mut userBillingInfo.billingContactName)}}
7+
{{input type='text' id='contactName' value=userBillingInfo.billingContactName}}
88
</div>
99
<div class="field">
1010
<label class="required" for="phone">{{t 'Phone'}}</label>
11-
{{input type='text' id='phone' value=(mut userBillingInfo.billingPhone)}}
11+
{{input type='text' id='phone' value=userBillingInfo.billingPhone}}
1212
</div>
1313
<div class="field">
1414
<label class="required" for="company">{{t 'Company'}}</label>
15-
{{input type='text' id='company' value=(mut userBillingInfo.company)}}
15+
{{input type='text' id='company' value=userBillingInfo.company}}
1616
</div>
1717
<div class="field">
1818
<label for="taxID">{{t 'Tax ID or Business ID'}}</label>
19-
{{input type='text' id='taxID' value=(mut userBillingInfo.billingTaxInfo)}}
19+
{{input type='text' id='taxID' value=userBillingInfo.billingTaxInfo}}
2020
</div>
2121
<div class="field">
2222
<label class="required" for="address">{{t 'Address'}}</label>
23-
{{textarea rows='2' id='address' value=(mut userBillingInfo.billingAddress)}}
23+
{{textarea rows='2' id='address' value=userBillingInfo.billingAddress}}
2424
</div>
2525
<div class="field">
2626
<label class="required" for="city">{{t 'City'}}</label>
27-
{{input type='text' id='city' value=(mut userBillingInfo.billingCity)}}
27+
{{input type='text' id='city' value=userBillingInfo.billingCity}}
2828
</div>
2929
<div class="field">
3030
<label for="state">{{t 'State'}}</label>
31-
{{input type='text' id='state' value=(mut userBillingInfo.billingState)}}
32-
</div>
33-
<div class="field">
34-
<label class="required" for="country">{{t 'Country'}}</label>
35-
{{input type='text' id='country' value=(mut userBillingInfo.billingCountry)}}
31+
{{input type='text' id='state' value=userBillingInfo.billingState}}
32+
</div>
33+
<div class="field">
34+
<label class="required">{{t 'Country'}}</label>
35+
{{#ui-dropdown class='search selection' selected=userBillingInfo.billingCountry forceSelection=false
36+
fullTextSearch=true}}
37+
{{input type='hidden' id='country' value=userBillingInfo.billingCountry}}
38+
<i class="dropdown icon"></i>
39+
<div class="default text">{{t 'Select country'}}</div>
40+
<div class="menu">
41+
{{#each countries as |country|}}
42+
<div class="item" data-value="{{country.name}}">
43+
<i class="{{lowercase country.code}} flag"></i>
44+
{{country.name}}
45+
</div>
46+
{{/each}}
47+
</div>
48+
{{/ui-dropdown}}
3649
</div>
3750
<div class="field">
3851
<label class="required" for="zip">{{t 'Zip Code'}}</label>
39-
{{input type='text' id='zip' value=(mut userBillingInfo.billingZipCode)}}
52+
{{input type='text' id='zip' value=userBillingInfo.billingZipCode}}
4053
</div>
4154
<div class="field">
4255
<label for="additionalInfo">{{t 'Additional Information'}}</label>
43-
{{textarea rows='4' id='additionalInfo' value=(mut userBillingInfo.billingAdditionalInfo)}}
56+
{{textarea rows='4' id='additionalInfo' value=userBillingInfo.billingAdditionalInfo}}
4457
</div>
4558

4659
<button type="submit" class="ui teal submit button update-changes">

0 commit comments

Comments
 (0)