Skip to content

Commit 9e5b0af

Browse files
committed
use lodash for object creation
1 parent e893f16 commit 9e5b0af

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
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';
45

56
export default Component.extend(FormMixin, {
67

7-
async init() {
8+
async didInsertElement() {
89
this._super(...arguments);
910
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-
};
11+
let userBillingInfo = pick(actualUser, ['billingContactName', 'billingCity', 'billingPhone', 'company', 'billingTaxInfo', 'billingAddress', 'billingZipCode', 'billingAdditionalInfo']);
2012
this.set('userBillingInfo', userBillingInfo);
2113
this.set('actualUser', actualUser);
2214
},
@@ -94,20 +86,11 @@ export default Component.extend(FormMixin, {
9486
submit() {
9587
this.onValid(async() => {
9688
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();
89+
this.authManager.currentUser.setProperties(this.userBillingInfo);
90+
await this.authManager.currentUser.save();
10891
this.notify.success(this.l10n.t('Your billing details has been updated'));
10992
} catch (error) {
110-
this.actualUser.rollbackAttributes();
93+
this.authManager.currentUser.rollbackAttributes();
11194
this.notify.error(this.l10n.t('An unexpected error occurred'));
11295
}
11396
});

0 commit comments

Comments
 (0)