-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch Implement edit profile form into development
- Loading branch information
Showing
31 changed files
with
3,036 additions
and
1,754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ module.exports = { | |
jquery: true | ||
}, | ||
|
||
'extends': [ | ||
extends: [ | ||
'plugin:vue/essential', | ||
'@vue/airbnb' | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
plugins: { | ||
autoprefixer: {} | ||
} | ||
}; | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
<template> | ||
<div> | ||
<div class="personal-details-edit personal-details-edit-show"> | ||
<form @submit.prevent="save" | ||
id="form-edit-personal-details"> | ||
<ServerError :error="serverError"> | ||
<template slot-scope="{ graphQLError }"> | ||
{{ getErrorMessage(graphQLError) }} | ||
</template> | ||
</ServerError> | ||
<div class="row"> | ||
<div class="col-sm-6"> | ||
<div class="form-sections"> | ||
<span class="form-labels">{{ $t('firstName') }}*</span><br> | ||
<ValidationError :vuelidate="$v.firstName" /> | ||
<input v-model.trim.lazy="$v.firstName.$model" | ||
autocomplete="fname" | ||
type="text" | ||
class="form-inputs" | ||
data-test="edit-profile-form-firstname"/> | ||
</div> | ||
|
||
<div class="form-sections"> | ||
<span class="form-labels">{{ $t('email') }}*</span><br> | ||
<ValidationError :vuelidate="$v.email" /> | ||
<input v-model.trim.lazy="$v.email.$model" | ||
autocomplete="email" | ||
type="email" | ||
class="form-inputs" | ||
data-test="edit-profile-form-email"/> | ||
<br> | ||
<span class="form-notes"></span> | ||
</div> | ||
|
||
</div> | ||
<div class="col-sm-6"> | ||
<div class="form-sections"> | ||
<span class="form-labels">{{ $t('lastName') }}*</span><br> | ||
<ValidationError :vuelidate="$v.lastName" /> | ||
<input v-model.trim.lazy="$v.lastName.$model" | ||
autocomplete="lname" | ||
type="text" | ||
class="form-inputs" | ||
data-test="edit-profile-form-lastname"/> | ||
</div> | ||
</div> | ||
</div> | ||
<hr class="light-grey-hr"> | ||
<!-- <div class="personal-details-newsletter"> --> | ||
<!-- <span> --> | ||
<!-- <input name="subscribeToNewsletter" --> | ||
<!-- type="checkbox" --> | ||
<!-- {{#if personalDetails.personalDetailsForm.subscribeToNewsletter}}checked{{/if}}/> --> | ||
<!-- {{ $t('personalDetailsForm.subscribeToNewsletter') }} --> | ||
<!-- </span> --> | ||
<!-- </div> --> | ||
<div class="personal-details-edit-btn"> | ||
<span> | ||
<button :disabled="loading" | ||
type="submit" | ||
class="update-btn" | ||
data-test="edit-profile-form-submit"> | ||
<span v-if="loading"> | ||
{{ $t('main.messages.pleaseWait') }} | ||
</span> | ||
<span v-else> | ||
{{ $t('updateBtn') }} | ||
</span> | ||
</button> | ||
<button @click="$emit('close')" | ||
type="button" | ||
class="cancel-btn personal-details-edit-hide-btn" | ||
data-test="edit-profile-form-cancel"> | ||
{{ $t('cancelBtn') }} | ||
</button> | ||
</span> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { required, email } from 'vuelidate/lib/validators'; | ||
import ServerError from '@/components/ServerError.vue'; | ||
import ValidationError from '@/components/ValidationError.vue'; | ||
import { mapGetters } from 'vuex'; | ||
export default { | ||
components: { ValidationError, ServerError }, | ||
data: () => ({ | ||
firstName: null, | ||
lastName: null, | ||
email: null, | ||
loading: false, | ||
serverError: null, | ||
}), | ||
created() { | ||
this.email = this.user.email; | ||
this.firstName = this.user.firstName; | ||
this.lastName = this.user.lastName; | ||
}, | ||
computed: { | ||
...mapGetters(['user']), | ||
updateActions() { | ||
return [ | ||
{ changeEmail: { email: this.email } }, | ||
{ setFirstName: { firstName: this.firstName } }, | ||
{ setLastName: { lastName: this.lastName } }, | ||
]; | ||
}, | ||
hasFormChanged() { | ||
const hasEmailChanged = this.email !== this.user.email; | ||
const hasFirstNameChanged = this.firstName !== this.user.firstName; | ||
const hasLastNameChanged = this.lastName !== this.user.lastName; | ||
return hasEmailChanged || hasFirstNameChanged || hasLastNameChanged; | ||
}, | ||
}, | ||
methods: { | ||
async save() { | ||
this.$v.$touch(); | ||
this.serverError = null; | ||
if (!this.$v.$invalid && this.hasFormChanged) { | ||
this.loading = true; | ||
await this.$store.dispatch('updateCustomer', this.updateActions) | ||
.then(() => { | ||
this.$emit('close'); | ||
}).catch((error) => { | ||
this.serverError = error; | ||
}); | ||
this.loading = false; | ||
} | ||
}, | ||
getErrorMessage({ code, field }) { | ||
if (code === 'DuplicateField' && field === 'email') { | ||
return this.$t('duplicatedEmail'); | ||
} | ||
return null; | ||
}, | ||
}, | ||
validations: { | ||
email: { | ||
required, | ||
email, | ||
}, | ||
firstName: { | ||
required, | ||
}, | ||
lastName: { | ||
required, | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<!-- eslint-disable --> | ||
<i18n> | ||
{ | ||
"en": { | ||
"title": "Your Personal Details", | ||
"updateBtn": "Update Details", | ||
"cancelBtn": "Cancel", | ||
"firstName": "First Name", | ||
"lastName": "Last Name", | ||
"email": "Email Address", | ||
"subscribeToNewsletter": "Please add me to the Sunrise Newsletter", | ||
"duplicatedEmail": "A customer with this email already exists" | ||
}, | ||
"de": { | ||
"title": "Ihre Benutzerdaten", | ||
"updateBtn": "Details aktualisieren", | ||
"cancelBtn": "Abbrechen", | ||
"firstName": "Vorname", | ||
"lastName": "Nachname", | ||
"email": "Email Adresse", | ||
"subscribeToNewsletter": "Ich möchte den Sunrise Newsletter erhalten.", | ||
"duplicatedEmail": "Ein Kunde mit dieser E-Mail existiert bereits" | ||
} | ||
} | ||
</i18n> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.