|
@@ -5,10 +5,13 @@
|
|
|
<b-form-group :label="labels.title"
|
|
|
label-for="distributor_title">
|
|
|
<b-form-input id="distributor_title"
|
|
|
+ :state="validations.title"
|
|
|
v-model="distributorLocal.title"
|
|
|
- required
|
|
|
:placeholder="labels.titlePlaceholder">
|
|
|
</b-form-input>
|
|
|
+ <b-form-invalid-feedback>
|
|
|
+ {{labels.required}}
|
|
|
+ </b-form-invalid-feedback>
|
|
|
</b-form-group>
|
|
|
<!-- Notes Field -->
|
|
|
<b-form-group :label="labels.notes"
|
|
@@ -33,24 +36,27 @@
|
|
|
<!-- Inline contacts form -->
|
|
|
<b-form inline v-for="(contact, key) in distributorLocal.contacts" :key="contact.id">
|
|
|
<b-container>
|
|
|
- <b-row>
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-row class="mb-3">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="contact.name"
|
|
|
+ :state="Boolean(contact.name)"
|
|
|
:placeholder="labels.name" />
|
|
|
</b-input-group>
|
|
|
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="contact.email"
|
|
|
+ :state="emailValidation(contact.email)"
|
|
|
type="email"
|
|
|
- :placeholder="labels.email" />
|
|
|
+ :placeholder="labels.email"
|
|
|
+ required/>
|
|
|
</b-input-group>
|
|
|
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="contact.phone"
|
|
|
:placeholder="labels.phone"/>
|
|
|
</b-input-group>
|
|
|
|
|
|
- <b-input-group class="col mb-3 col-sm-2">
|
|
|
+ <b-input-group class="col col-sm-2">
|
|
|
<b-button @click.stop="onDelete(key)"
|
|
|
size="sm"
|
|
|
v-b-tooltip.hover :title="labels.delete"
|
|
@@ -67,25 +73,35 @@
|
|
|
<!-- Inline New contact -->
|
|
|
<b-form inline v-if="newContact.show">
|
|
|
<b-container>
|
|
|
- <b-row>
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-row class="mb-4">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="newContact.name"
|
|
|
+ :state="newContactState.name"
|
|
|
:placeholder="labels.name" />
|
|
|
+ <b-form-invalid-feedback>
|
|
|
+ {{labels.required}}
|
|
|
+ </b-form-invalid-feedback>
|
|
|
</b-input-group>
|
|
|
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="newContact.email"
|
|
|
type="email"
|
|
|
- :placeholder="labels.email" />
|
|
|
+ :state="newContactState.email"
|
|
|
+ :placeholder="labels.email"
|
|
|
+ required/>
|
|
|
+ <b-form-invalid-feedback>
|
|
|
+ {{labels.emailInvalid}}
|
|
|
+ </b-form-invalid-feedback>
|
|
|
</b-input-group>
|
|
|
|
|
|
- <b-input-group class="col mb-3">
|
|
|
+ <b-input-group class="col">
|
|
|
<b-input v-model="newContact.phone"
|
|
|
:placeholder="labels.phone"/>
|
|
|
</b-input-group>
|
|
|
<!-- Saving new contact -->
|
|
|
- <b-input-group class="col mb-3 col-sm-2">
|
|
|
- <b-button @click.stop="onSaveContact()"
|
|
|
+ <b-input-group class="col col-sm-2">
|
|
|
+ <b-button v-if="newContactState.email && newContactState.name"
|
|
|
+ @click.stop="onSaveContact()"
|
|
|
size="sm"
|
|
|
class="mr-3"
|
|
|
v-b-tooltip.hover :title="labels.save"
|
|
@@ -103,7 +119,8 @@
|
|
|
</b-row>
|
|
|
</b-container>
|
|
|
</b-form>
|
|
|
- <b-button @click.stop="onAddContact()" class="mb-12 mr-sm-12" variant="primary">{{labels.add}}</b-button>
|
|
|
+ <!-- Adding contacts -->
|
|
|
+ <b-button @click.stop="onAddContact()" class="mt-3 mb-12 mr-sm-12" variant="primary">{{labels.add}}</b-button>
|
|
|
</b-form-group>
|
|
|
|
|
|
<b-form-group class="text-right">
|
|
@@ -119,7 +136,7 @@
|
|
|
import {mapGetters, mapActions} from 'vuex';
|
|
|
import * as types from '../store/types';
|
|
|
import {store} from '../store/store';
|
|
|
-import {cloneDeep, debounce} from 'lodash';
|
|
|
+import {cloneDeep} from 'lodash';
|
|
|
|
|
|
export default {
|
|
|
props: {
|
|
@@ -143,6 +160,8 @@ export default {
|
|
|
name: 'Name',
|
|
|
email: 'Email',
|
|
|
phone: 'Phone',
|
|
|
+ required: 'Field required',
|
|
|
+ emailInvalid: 'Email invalid or missing',
|
|
|
},
|
|
|
newContact: {
|
|
|
show: false,
|
|
@@ -150,7 +169,9 @@ export default {
|
|
|
email: '',
|
|
|
phone: '',
|
|
|
},
|
|
|
- distributorLocal: {},
|
|
|
+ distributorLocal: {
|
|
|
+ contacts:[],
|
|
|
+ },
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -161,11 +182,50 @@ export default {
|
|
|
distributor() {
|
|
|
return this.$store.getters['distributor/GET_DISTRIBUTOR'](this.id)
|
|
|
},
|
|
|
+ newContactState() {
|
|
|
+ let state = {
|
|
|
+ email: this.emailValidation(this.newContact.email),
|
|
|
+ name: this.newContact.name ? true : false,
|
|
|
+ };
|
|
|
+ return state;
|
|
|
+ },
|
|
|
+ validations() {
|
|
|
+ let validations = {
|
|
|
+ title: this.distributorLocal.title ? true : false,
|
|
|
+ contacts: this.distributorLocal.contacts.length ? this.distributorLocal.contacts.map( contact => {
|
|
|
+ return {
|
|
|
+ email: this.emailValidation(contact.email),
|
|
|
+ name: contact.name ? true : false,
|
|
|
+ }
|
|
|
+ }) : [],
|
|
|
+ };
|
|
|
+
|
|
|
+ if (validations.title && !validations.contacts ) {
|
|
|
+ validations.pass = true;
|
|
|
+ return validations;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ let contactsValid = true;
|
|
|
+ for (let element of validations.contacts) {
|
|
|
+ if (!element.email || !element.name) {
|
|
|
+ // Checks each contact validation object and return false if any are false
|
|
|
+ contactsValid = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // Returns true if the title and contact fields are valid
|
|
|
+ validations.pass = (contactsValid && validations.title) ? true : false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return validations;
|
|
|
+ },
|
|
|
},
|
|
|
watch: {
|
|
|
id(newId) {
|
|
|
if (newId) {
|
|
|
this.distributorLocal = cloneDeep(this.distributor);
|
|
|
+ } else {
|
|
|
+ this.resetDistributor();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -173,19 +233,35 @@ export default {
|
|
|
...mapActions({
|
|
|
saveDistributor: types.SET_DISTRIBUTOR,
|
|
|
}),
|
|
|
- onSubmit (ev) {
|
|
|
+ onSubmit() {
|
|
|
this.saveDistributor({
|
|
|
id: this.distributorLocal.id,
|
|
|
distributor: this.distributorLocal
|
|
|
});
|
|
|
this.$root.$emit('bv::hide::modal', 'distributor_modal_form');
|
|
|
},
|
|
|
- onAddContact () {
|
|
|
+ onAddContact() {
|
|
|
this.newContact.show = true;
|
|
|
},
|
|
|
onSaveContact() {
|
|
|
- this.distributorLocal.contacts.push(this.newContact);
|
|
|
- this.newContact.show = false;
|
|
|
+ const newContact = cloneDeep(this.newContact);
|
|
|
+ this.distributorLocal.contacts.push(newContact);
|
|
|
+ this.resetNewContact();
|
|
|
+ },
|
|
|
+ resetNewContact() {
|
|
|
+ this.newContact = {
|
|
|
+ show: false,
|
|
|
+ success: false,
|
|
|
+ name: '',
|
|
|
+ email: '',
|
|
|
+ phone: '',
|
|
|
+ }
|
|
|
+ },
|
|
|
+ resetDistributor() {
|
|
|
+ this.distributorLocal = {
|
|
|
+ title: '',
|
|
|
+ contacts:[],
|
|
|
+ };
|
|
|
},
|
|
|
onCancelSaveContact() {
|
|
|
this.newContact.show = false;
|
|
@@ -195,6 +271,14 @@ export default {
|
|
|
},
|
|
|
onCancel() {
|
|
|
this.$root.$emit('bv::hide::modal', 'distributor_modal_form');
|
|
|
+ },
|
|
|
+ emailValidation(email) {
|
|
|
+ if( /(.+)@(.+){2,}\.(.+){2,}/.test(email) ){
|
|
|
+ // valid email
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
@@ -221,8 +305,12 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
.form-inline {
|
|
|
+ .input-group > .form-control:not(:last-child){
|
|
|
+ border-radius: 0.25rem;
|
|
|
+ }
|
|
|
.input-group {
|
|
|
padding-left: 0;
|
|
|
+ height: 39px;
|
|
|
}
|
|
|
}
|
|
|
}
|