|  | 
|  | 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 | +}); | 
0 commit comments