Skip to content

Commit

Permalink
#68 - fixed link to login page and removed setCustomerEmail mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
szafran89 committed Dec 19, 2018
1 parent 68c214f commit 57e06ec
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
92 changes: 92 additions & 0 deletions view/frontend/web/js/components/CustomerEmailField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<div>
<BaseInput
v-model.trim="$v.customer.email.$model"
:validation="$v.customer.email"
label="Email"
name="email"
type="email"
@input="checkIsEmailAvailable"
/>
<span
v-if="emailAvailabilityMessage"
v-html="emailAvailabilityMessage"
/>
<hr>
</div>
</template>

<script>
import BaseInput from './BaseInput.vue'
import axios from './../utils/checkout-axios.js'
import { requiredIf, email } from 'vuelidate/lib/validators'
export default {
components: {
BaseInput
},
data () {
return {
customer: {
email: '',
emailAvailable: false
}
}
},
validations: {
customer: {
email: {
required: requiredIf(function () {
return !this.isCustomerLoggedIn
}),
email
}
}
},
computed: {
ready () {
return !this.$v.customer.email.$invalid
},
emailAvailabilityMessage () {
if (this.customer.email !== '' && !this.$v.customer.email.$error) {
if (this.customer.emailAvailable) {
return `You can create an account after checkout.`
} else {
return `
You already have an account with us.
Sign in <a href="/customer/account/login/">here</a> or continue as guest.
`
}
} else {
return false
}
}
},
watch: {
ready (val) {
this.$emit('ready', val)
}
},
methods: {
touch () {
this.$v.customer.email.$touch()
},
checkIsEmailAvailable () {
const options = {
method: 'POST',
data: JSON.stringify({
'customerEmail': this.customer.email
}),
url: 'customers/isEmailAvailable'
}
axios(options)
.then(({data}) => {
this.customer.emailAvailable = data
})
.catch(error => {
console.error('Looks like there was a problem: \n', error)
})
}
}
}
</script>
4 changes: 1 addition & 3 deletions view/frontend/web/js/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const store = new Vuex.Store({
config: window.config,
baseUrl: window.baseUrl,
regions,
customer: {
email: null
},
customer: null,
step: 'shipping',
orderId: null,
shippingMethods: [],
Expand Down
3 changes: 0 additions & 3 deletions view/frontend/web/js/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ export default {
setItem (state, {item, value}) {
state[item] = value
},
setCustomerEmail (state, payload) {
state.customer.email = payload
},
setAddress (state, payload) {
const address = payload.address
const type = payload.type
Expand Down

0 comments on commit 57e06ec

Please sign in to comment.