2020-04-10 11:12:37 +00:00
|
|
|
<template>
|
|
|
|
<div class="form chat-bubble agent">
|
|
|
|
<form @submit.prevent="onSubmit">
|
|
|
|
<div v-for="item in items" :key="item.key" class="form-block">
|
|
|
|
<label>{{ item.label }}</label>
|
|
|
|
<input
|
|
|
|
v-if="item.type === 'email' || item.type === 'text'"
|
|
|
|
v-model="formValues[item.name]"
|
|
|
|
:type="item.type"
|
|
|
|
:name="item.name"
|
|
|
|
:placeholder="item.placeholder"
|
|
|
|
:disabled="!!submittedValues.length"
|
|
|
|
/>
|
|
|
|
<textarea
|
|
|
|
v-else-if="item.type === 'text_area'"
|
|
|
|
v-model="formValues[item.name]"
|
|
|
|
:name="item.name"
|
|
|
|
:placeholder="item.placeholder"
|
|
|
|
:disabled="!!submittedValues.length"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
v-if="!submittedValues.length"
|
2020-05-04 18:18:47 +00:00
|
|
|
class="button block"
|
2020-04-10 11:12:37 +00:00
|
|
|
type="submit"
|
|
|
|
:disabled="!isFormValid"
|
2020-05-09 16:32:43 +00:00
|
|
|
:style="{ background: widgetColor, borderColor: widgetColor }"
|
2020-04-10 11:12:37 +00:00
|
|
|
>
|
|
|
|
{{ $t('COMPONENTS.FORM_BUBBLE.SUBMIT') }}
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-05-09 16:32:43 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2020-04-10 11:12:37 +00:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
submittedValues: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
formValues: {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2020-05-09 16:32:43 +00:00
|
|
|
...mapGetters({
|
|
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
|
|
}),
|
2020-04-10 11:12:37 +00:00
|
|
|
isFormValid() {
|
|
|
|
return this.items.reduce((acc, { name }) => {
|
|
|
|
return !!this.formValues[name] && acc;
|
|
|
|
}, true);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2020-05-04 18:18:47 +00:00
|
|
|
if (this.submittedValues.length) {
|
|
|
|
this.updateFormValues();
|
|
|
|
} else {
|
|
|
|
this.setFormDefaults();
|
|
|
|
}
|
2020-04-10 11:12:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onSubmit() {
|
|
|
|
if (!this.isFormValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.$emit('submit', this.formValues);
|
|
|
|
},
|
2020-05-04 18:18:47 +00:00
|
|
|
buildFormObject(formObjectArray) {
|
|
|
|
return formObjectArray.reduce((acc, obj) => {
|
2020-04-10 11:12:37 +00:00
|
|
|
return {
|
|
|
|
...acc,
|
2020-05-04 18:18:47 +00:00
|
|
|
[obj.name]: obj.value || obj.default,
|
2020-04-10 11:12:37 +00:00
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
},
|
2020-05-04 18:18:47 +00:00
|
|
|
updateFormValues() {
|
|
|
|
this.formValues = this.buildFormObject(this.submittedValues);
|
|
|
|
},
|
|
|
|
setFormDefaults() {
|
|
|
|
this.formValues = this.buildFormObject(this.items);
|
|
|
|
},
|
2020-04-10 11:12:37 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
|
|
|
|
|
|
|
.form {
|
|
|
|
padding: $space-normal;
|
2020-05-04 18:18:47 +00:00
|
|
|
width: 80%;
|
2020-04-10 11:12:37 +00:00
|
|
|
|
|
|
|
.form-block {
|
2020-05-04 18:18:47 +00:00
|
|
|
width: 90%;
|
2020-04-10 11:12:37 +00:00
|
|
|
padding-bottom: $space-small;
|
|
|
|
}
|
|
|
|
|
|
|
|
label {
|
|
|
|
display: block;
|
2020-05-04 18:18:47 +00:00
|
|
|
font-weight: $font-weight-medium;
|
2020-04-10 11:12:37 +00:00
|
|
|
padding: $space-smaller 0;
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
input,
|
|
|
|
textarea {
|
|
|
|
border-radius: $space-smaller;
|
|
|
|
border: 1px solid $color-border;
|
|
|
|
display: block;
|
|
|
|
font-size: $font-size-default;
|
|
|
|
line-height: 1.5;
|
2020-05-04 18:18:47 +00:00
|
|
|
padding: $space-one;
|
|
|
|
width: 100%;
|
2020-04-10 11:12:37 +00:00
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
background: $color-background-light;
|
|
|
|
}
|
|
|
|
}
|
2020-05-04 18:18:47 +00:00
|
|
|
|
|
|
|
.button {
|
|
|
|
font-size: $font-size-default;
|
|
|
|
}
|
2020-04-10 11:12:37 +00:00
|
|
|
}
|
|
|
|
</style>
|