Skip to content

Commit cbc9478

Browse files
committed
use intermediate user object and change route handling
1 parent 0ef8216 commit cbc9478

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Component from '@ember/component';
22
import FormMixin from 'open-event-frontend/mixins/form';
33
import { validPhoneNumber } from 'open-event-frontend/utils/validators';
44
import { computed } from '@ember/object';
5+
import EmberObject from '@ember/object';
56

67
export default Component.extend(FormMixin, {
78

@@ -74,14 +75,36 @@ export default Component.extend(FormMixin, {
7475
}
7576
};
7677
},
77-
user: computed(function() {
78-
return this.authManager.currentUser;
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;
7991
}),
8092
actions: {
8193
submit() {
8294
this.onValid(async() => {
8395
try {
84-
await this.user.save();
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();
85108
this.notify.success(this.l10n.t('Your billing details has been updated'));
86109
} catch (error) {
87110
this.notify.error(this.l10n.t('An unexpected error occurred'));

app/routes/account/billing-info.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default Route.extend(AuthenticatedRouteMixin, {
77
},
88
beforeModel() {
99
this._super(...arguments);
10-
this.replaceWith('account.billing-info.payment-info');
10+
if (this.authManager.currentUser) {
11+
this.replaceWith('account.billing-info.payment-info');
12+
} else {
13+
this.replaceWith('login');
14+
}
1115
}
1216
});

0 commit comments

Comments
 (0)