From 28d102f526284e2973a96eaaae13f80a68f2cd02 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 3 Mar 2022 12:36:31 +0530 Subject: [PATCH] fix: Show new message screen instead of input field (#4102) --- app/javascript/widget/components/ChatFooter.vue | 15 ++++++++++----- app/javascript/widget/components/PreChat/Form.vue | 13 ++++++++++--- app/javascript/widget/mixins/routerMixin.js | 4 ++-- app/javascript/widget/views/Home.vue | 12 +----------- app/javascript/widget/views/PreChatForm.vue | 10 +++++++++- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/javascript/widget/components/ChatFooter.vue b/app/javascript/widget/components/ChatFooter.vue index 423eb2642..7ed33acbd 100755 --- a/app/javascript/widget/components/ChatFooter.vue +++ b/app/javascript/widget/components/ChatFooter.vue @@ -37,12 +37,13 @@ import CustomButton from 'shared/components/Button'; import ChatInputWrap from 'widget/components/ChatInputWrap.vue'; import { BUS_EVENTS } from 'shared/constants/busEvents'; import { sendEmailTranscript } from 'widget/api/conversation'; - +import routerMixin from 'widget/mixins/routerMixin'; export default { components: { ChatInputWrap, CustomButton, }, + mixins: [routerMixin], props: { msg: { type: String, @@ -53,7 +54,7 @@ export default { ...mapGetters({ conversationAttributes: 'conversationAttributes/getConversationParams', widgetColor: 'appConfig/getWidgetColor', - getConversationSize: 'conversation/getConversationSize', + conversationSize: 'conversation/getConversationSize', currentUser: 'contacts/getCurrentUser', isWidgetStyleFlat: 'appConfig/isWidgetStyleFlat', }), @@ -80,12 +81,11 @@ export default { 'clearConversationAttributes', ]), async handleSendMessage(content) { - const conversationSize = this.getConversationSize; await this.sendMessage({ content, }); // Update conversation attributes on new conversation - if (conversationSize === 0) { + if (this.conversationSize === 0) { this.getAttributes(); } }, @@ -95,7 +95,12 @@ export default { startNewConversation() { this.clearConversations(); this.clearConversationAttributes(); - window.bus.$emit(BUS_EVENTS.START_NEW_CONVERSATION); + + // To create a new conversation, we are redirecting + // the user to pre-chat with contact fields disabled + // Pass disableContactFields params to the route + // This would disable the contact fields in the pre-chat form + this.replaceRoute('prechat-form', { disableContactFields: true }); }, async sendTranscript() { const { email } = this.currentUser; diff --git a/app/javascript/widget/components/PreChat/Form.vue b/app/javascript/widget/components/PreChat/Form.vue index c053a58f6..7fdf33375 100644 --- a/app/javascript/widget/components/PreChat/Form.vue +++ b/app/javascript/widget/components/PreChat/Form.vue @@ -10,7 +10,7 @@ {{ headerMessage }} ({}), }, + disableContactFields: { + type: Boolean, + default: false, + }, }, validations() { const identityValidations = { @@ -99,7 +103,7 @@ export default { if (this.hasActiveCampaign) { return identityValidations; } - if (this.options.requireEmail) { + if (this.areContactFieldsVisible) { return { ...identityValidations, ...messageValidation, @@ -135,6 +139,9 @@ export default { } return this.options.preChatMessage; }, + areContactFieldsVisible() { + return this.options.requireEmail && !this.disableContactFields; + }, }, methods: { onSubmit() { diff --git a/app/javascript/widget/mixins/routerMixin.js b/app/javascript/widget/mixins/routerMixin.js index f75cc65e1..b3b37f6fd 100644 --- a/app/javascript/widget/mixins/routerMixin.js +++ b/app/javascript/widget/mixins/routerMixin.js @@ -1,8 +1,8 @@ export default { methods: { - async replaceRoute(name) { + async replaceRoute(name, params = {}) { if (this.$route.name !== name) { - return this.$router.replace({ name }); + return this.$router.replace({ name, params }); } return undefined; }, diff --git a/app/javascript/widget/views/Home.vue b/app/javascript/widget/views/Home.vue index 32aae26f1..c15fea236 100755 --- a/app/javascript/widget/views/Home.vue +++ b/app/javascript/widget/views/Home.vue @@ -15,7 +15,6 @@ import configMixin from '../mixins/configMixin'; import TeamAvailability from 'widget/components/TeamAvailability'; import { mapGetters } from 'vuex'; -import { BUS_EVENTS } from 'shared/constants/busEvents'; import routerMixin from 'widget/mixins/routerMixin'; export default { name: 'Home', @@ -34,10 +33,7 @@ export default { }, }, data() { - return { - isOnCollapsedView: false, - isOnNewConversation: false, - }; + return {}; }, computed: { ...mapGetters({ @@ -46,12 +42,6 @@ export default { conversationSize: 'conversation/getConversationSize', }), }, - mounted() { - bus.$on(BUS_EVENTS.START_NEW_CONVERSATION, () => { - this.isOnCollapsedView = true; - this.isOnNewConversation = true; - }); - }, methods: { startConversation() { if (this.preChatFormEnabled && !this.conversationSize) { diff --git a/app/javascript/widget/views/PreChatForm.vue b/app/javascript/widget/views/PreChatForm.vue index ac70e4e56..cb0b4c217 100644 --- a/app/javascript/widget/views/PreChatForm.vue +++ b/app/javascript/widget/views/PreChatForm.vue @@ -1,6 +1,10 @@