|  | 
| 1 | 1 | import Component from '@ember/component'; | 
| 2 | 2 | import FormMixin from 'open-event-frontend/mixins/form'; | 
| 3 | 3 | import { validPhoneNumber } from 'open-event-frontend/utils/validators'; | 
|  | 4 | +import { pick } from 'lodash-es'; | 
| 4 | 5 | 
 | 
| 5 | 6 | export default Component.extend(FormMixin, { | 
| 6 | 7 | 
 | 
| 7 |  | -  async init() { | 
|  | 8 | +  async didInsertElement() { | 
| 8 | 9 |     this._super(...arguments); | 
| 9 | 10 |     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']); | 
| 20 | 12 |     this.set('userBillingInfo', userBillingInfo); | 
| 21 | 13 |     this.set('actualUser', actualUser); | 
| 22 | 14 |   }, | 
| @@ -94,20 +86,11 @@ export default Component.extend(FormMixin, { | 
| 94 | 86 |     submit() { | 
| 95 | 87 |       this.onValid(async() => { | 
| 96 | 88 |         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(); | 
| 108 | 91 |           this.notify.success(this.l10n.t('Your billing details has been updated')); | 
| 109 | 92 |         } catch (error) { | 
| 110 |  | -          this.actualUser.rollbackAttributes(); | 
|  | 93 | +          this.authManager.currentUser.rollbackAttributes(); | 
| 111 | 94 |           this.notify.error(this.l10n.t('An unexpected error occurred')); | 
| 112 | 95 |         } | 
| 113 | 96 |       }); | 
|  | 
0 commit comments