Skip to content

Commit

Permalink
Merge branch Implement edit profile form into development
Browse files Browse the repository at this point in the history
  • Loading branch information
zeina-idris committed Sep 21, 2018
2 parents c6bb902 + ab7c04f commit 023374d
Show file tree
Hide file tree
Showing 31 changed files with 3,036 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
jquery: true
},

'extends': [
extends: [
'plugin:vue/essential',
'@vue/airbnb'
],
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
testMatch: [
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
testURL: 'http://localhost/',
setupFiles: [
'jest-localstorage-mock',
],
Expand Down
2,966 changes: 1,676 additions & 1,290 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
"register-service-worker": "^1.0.0",
"vue": "^2.5.17",
"vue-apollo": "^3.0.0-beta.16",
"vue-cli-plugin-apollo": "^0.16.2",
"vue-cli-plugin-apollo": "^0.16.4",
"vue-i18n": "^8.0.0",
"vue-router": "^3.0.1",
"vuelidate": "^0.7.4",
"vuex": "^3.0.1"
},
"devDependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
"@vue/cli-plugin-babel": "^3.0.0",
"@vue/cli-plugin-e2e-cypress": "^3.0.0",
"@vue/cli-plugin-eslint": "^3.0.0",
"@vue/cli-plugin-pwa": "^3.0.0",
"@vue/cli-plugin-unit-jest": "^3.0.0",
"@vue/cli-service": "^3.0.0",
"@vue/eslint-config-airbnb": "^3.0.0",
"@vue/cli-plugin-babel": "^3.0.3",
"@vue/cli-plugin-e2e-cypress": "^3.0.3",
"@vue/cli-plugin-eslint": "^3.0.3",
"@vue/cli-plugin-pwa": "^3.0.3",
"@vue/cli-plugin-unit-jest": "^3.0.3",
"@vue/cli-service": "^3.0.3",
"@vue/eslint-config-airbnb": "^3.0.3",
"@vue/test-utils": "^1.0.0-beta.24",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"eslint-plugin-graphql": "^2.1.1",
"jest-junit": "^5.1.0",
"jest-localstorage-mock": "^2.2.0",
"lint-staged": "^7.2.0",
"lint-staged": "^7.2.2",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi-reporters": "^1.1.7",
Expand Down
6 changes: 3 additions & 3 deletions .postcssrc.js → postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {}
}
};
autoprefixer: {},
},
};
188 changes: 188 additions & 0 deletions src/components/EditProfileForm.vue
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>
58 changes: 29 additions & 29 deletions src/components/LoginBox.vue → src/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@
<div class="login-box-description">{{ $t('description') }}</div>
<div class="login-box-input-wrapper">
<form @submit.prevent="login">
<ServerError :error="serverError"/>
<ServerError :error="serverError">
<template slot-scope="{ graphQLError }">
{{ getErrorMessage(graphQLError) }}
</template>
</ServerError>
<div class="login-box-input">
<span>{{ $t('email') }}*</span><br>
<div v-if="$v.email.$error"
data-test="login-form-email-errors"
class="error">
<div v-if="!$v.email.required">{{ $t('main.messages.requiredField') }}</div>
<div v-if="!$v.email.email">{{ $t('main.messages.requiredEmail') }}</div>
</div>
<ValidationError :vuelidate="$v.email"/>
<input v-model.trim.lazy="$v.email.$model"
autocomplete="username"
type="email"
data-test="login-form-email" />
</div>
<div class="login-box-input">
<span>{{ $t('password') }}*</span><br>
<div v-if="$v.password.$error"
data-test="login-form-password-errors"
class="error">
<div v-if="!$v.password.required">{{ $t('main.messages.requiredField') }}</div>
<div v-if="!$v.password.minLength">{{ $t('passwordMinLength') }}</div>
</div>
<ValidationError :vuelidate="$v.password"/>
<input v-model.trim.lazy="$v.password.$model"
autocomplete="current-password"
type="password"
Expand Down Expand Up @@ -71,12 +65,12 @@
</template>

<script>
import { required, email, minLength } from 'vuelidate/lib/validators';
import { required, email } from 'vuelidate/lib/validators';
import ServerError from '@/components/ServerError.vue';
import ValidationError from '@/components/ValidationError.vue';
export default {
name: 'LoginBox',
components: { ServerError },
components: { ServerError, ValidationError },
data: () => ({
email: null,
Expand All @@ -85,17 +79,6 @@ export default {
serverError: null,
}),
validations: {
email: {
required,
email,
},
password: {
required,
minLength: minLength(5),
},
},
computed: {
credentials() {
return {
Expand All @@ -120,6 +103,23 @@ export default {
this.loading = false;
}
},
getErrorMessage({ code }) {
if (code === 'InvalidCredentials') {
return this.$t('invalidCredentials');
}
return null;
},
},
validations: {
email: {
required,
email,
},
password: {
required,
},
},
};
</script>
Expand All @@ -136,7 +136,7 @@ export default {
"rememberMe": "Remember Me",
"forgotPassword": "Forgot Password",
"signIn": "Sign In",
"passwordMinLength": "Password should contain at least 5 characters"
"invalidCredentials": "Invalid credentials"
},
"de": {
"title": "Kundenanmeldung",
Expand All @@ -147,7 +147,7 @@ export default {
"rememberMe": "Angemeldet bleiben",
"forgotPassword": "Passwort vergessen",
"signIn": "Anmelden",
"passwordMinLength": "Das Passwort sollte mindestens 5 Zeichen enthalten"
"invalidCredentials": "Ungültige Anmeldeinformationen"
}
}
</i18n>
File renamed without changes.
Loading

0 comments on commit 023374d

Please sign in to comment.