2021-02-15 18:44:13 +00:00
|
|
|
<template>
|
|
|
|
<form
|
2021-02-15 19:28:57 +00:00
|
|
|
class="flex flex-1 flex-col p-6 overflow-y-auto"
|
2021-02-15 18:44:13 +00:00
|
|
|
@submit.prevent="onSubmit"
|
|
|
|
>
|
2021-11-11 13:32:16 +00:00
|
|
|
<div
|
|
|
|
v-if="shouldShowHeaderMessage"
|
|
|
|
class="text-black-800 text-sm leading-5"
|
|
|
|
>
|
|
|
|
{{ headerMessage }}
|
2021-02-15 18:44:13 +00:00
|
|
|
</div>
|
|
|
|
<form-input
|
|
|
|
v-if="options.requireEmail"
|
|
|
|
v-model="fullName"
|
|
|
|
class="mt-5"
|
|
|
|
:label="$t('PRE_CHAT_FORM.FIELDS.FULL_NAME.LABEL')"
|
|
|
|
:placeholder="$t('PRE_CHAT_FORM.FIELDS.FULL_NAME.PLACEHOLDER')"
|
|
|
|
type="text"
|
|
|
|
:error="
|
|
|
|
$v.fullName.$error ? $t('PRE_CHAT_FORM.FIELDS.FULL_NAME.ERROR') : ''
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
<form-input
|
|
|
|
v-if="options.requireEmail"
|
|
|
|
v-model="emailAddress"
|
|
|
|
class="mt-5"
|
|
|
|
:label="$t('PRE_CHAT_FORM.FIELDS.EMAIL_ADDRESS.LABEL')"
|
|
|
|
:placeholder="$t('PRE_CHAT_FORM.FIELDS.EMAIL_ADDRESS.PLACEHOLDER')"
|
|
|
|
type="email"
|
|
|
|
:error="
|
|
|
|
$v.emailAddress.$error
|
|
|
|
? $t('PRE_CHAT_FORM.FIELDS.EMAIL_ADDRESS.ERROR')
|
|
|
|
: ''
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
<form-text-area
|
2021-11-11 13:32:16 +00:00
|
|
|
v-if="!activeCampaignExist"
|
2021-02-15 18:44:13 +00:00
|
|
|
v-model="message"
|
|
|
|
class="my-5"
|
|
|
|
:label="$t('PRE_CHAT_FORM.FIELDS.MESSAGE.LABEL')"
|
|
|
|
:placeholder="$t('PRE_CHAT_FORM.FIELDS.MESSAGE.PLACEHOLDER')"
|
|
|
|
:error="$v.message.$error ? $t('PRE_CHAT_FORM.FIELDS.MESSAGE.ERROR') : ''"
|
|
|
|
/>
|
2021-04-07 06:13:16 +00:00
|
|
|
<custom-button
|
2021-11-11 13:32:16 +00:00
|
|
|
class="font-medium my-5"
|
2021-02-15 18:44:13 +00:00
|
|
|
block
|
|
|
|
:bg-color="widgetColor"
|
|
|
|
:text-color="textColor"
|
|
|
|
:disabled="isCreating"
|
|
|
|
>
|
|
|
|
<spinner v-if="isCreating" class="p-0" />
|
|
|
|
{{ $t('START_CONVERSATION') }}
|
2021-04-07 06:13:16 +00:00
|
|
|
</custom-button>
|
2021-02-15 18:44:13 +00:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-04-07 06:13:16 +00:00
|
|
|
import CustomButton from 'shared/components/Button';
|
2021-02-15 18:44:13 +00:00
|
|
|
import FormInput from '../Form/Input';
|
|
|
|
import FormTextArea from '../Form/TextArea';
|
|
|
|
import Spinner from 'shared/components/Spinner';
|
|
|
|
import { mapGetters } from 'vuex';
|
2021-05-24 07:13:03 +00:00
|
|
|
import { getContrastingTextColor } from '@chatwoot/utils';
|
2021-02-15 18:44:13 +00:00
|
|
|
import { required, minLength, email } from 'vuelidate/lib/validators';
|
2021-11-11 13:32:16 +00:00
|
|
|
import { isEmptyObject } from 'widget/helpers/utils';
|
|
|
|
|
2021-02-15 18:44:13 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
FormInput,
|
|
|
|
FormTextArea,
|
2021-04-07 06:13:16 +00:00
|
|
|
CustomButton,
|
2021-02-15 18:44:13 +00:00
|
|
|
Spinner,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
options: {
|
|
|
|
type: Object,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
},
|
2021-02-16 09:45:37 +00:00
|
|
|
validations() {
|
|
|
|
const identityValidations = {
|
|
|
|
fullName: {
|
|
|
|
required,
|
|
|
|
},
|
|
|
|
emailAddress: {
|
|
|
|
required,
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const messageValidation = {
|
|
|
|
message: {
|
|
|
|
required,
|
2021-03-13 06:16:08 +00:00
|
|
|
minLength: minLength(1),
|
2021-02-16 09:45:37 +00:00
|
|
|
},
|
|
|
|
};
|
2021-11-11 13:32:16 +00:00
|
|
|
// For campaign, message field is not required
|
|
|
|
if (this.activeCampaignExist) {
|
|
|
|
return identityValidations;
|
|
|
|
}
|
2021-02-16 09:45:37 +00:00
|
|
|
if (this.options.requireEmail) {
|
|
|
|
return {
|
|
|
|
...identityValidations,
|
|
|
|
...messageValidation,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return messageValidation;
|
2021-02-15 18:44:13 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fullName: '',
|
|
|
|
emailAddress: '',
|
|
|
|
message: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
|
|
isCreating: 'conversation/getIsCreating',
|
2021-11-11 13:32:16 +00:00
|
|
|
activeCampaign: 'campaign/getActiveCampaign',
|
2021-02-15 18:44:13 +00:00
|
|
|
}),
|
|
|
|
textColor() {
|
|
|
|
return getContrastingTextColor(this.widgetColor);
|
|
|
|
},
|
2021-11-11 13:32:16 +00:00
|
|
|
activeCampaignExist() {
|
|
|
|
return !isEmptyObject(this.activeCampaign);
|
|
|
|
},
|
|
|
|
shouldShowHeaderMessage() {
|
|
|
|
return this.activeCampaignExist || this.options.preChatMessage;
|
|
|
|
},
|
|
|
|
headerMessage() {
|
|
|
|
if (this.activeCampaignExist) {
|
|
|
|
return this.$t('PRE_CHAT_FORM.CAMPAIGN_HEADER');
|
|
|
|
}
|
|
|
|
return this.options.preChatMessage;
|
|
|
|
},
|
2021-02-15 18:44:13 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onSubmit() {
|
|
|
|
this.$v.$touch();
|
|
|
|
if (this.$v.$invalid) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-11 13:32:16 +00:00
|
|
|
// Check any active campaign exist or not
|
|
|
|
if (this.activeCampaignExist) {
|
|
|
|
bus.$emit('execute-campaign', this.activeCampaign.id);
|
|
|
|
this.$store.dispatch('contacts/update', {
|
|
|
|
user: {
|
|
|
|
email: this.emailAddress,
|
|
|
|
name: this.fullName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('conversation/createConversation', {
|
|
|
|
fullName: this.fullName,
|
|
|
|
emailAddress: this.emailAddress,
|
|
|
|
message: this.message,
|
|
|
|
});
|
|
|
|
}
|
2021-02-15 18:44:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|