From 2ca92ab90cdd0721a50714a78872c7582e59335a Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Tue, 20 Sep 2022 12:55:20 +0530 Subject: [PATCH] Add status after setUser --- app/javascript/widget/components/PreChat/Form.vue | 4 ++++ app/javascript/widget/store/modules/contacts.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/javascript/widget/components/PreChat/Form.vue b/app/javascript/widget/components/PreChat/Form.vue index 823440cc1..9c19f1899 100644 --- a/app/javascript/widget/components/PreChat/Form.vue +++ b/app/javascript/widget/components/PreChat/Form.vue @@ -95,6 +95,7 @@ export default { isCreating: 'conversation/getIsCreating', activeCampaign: 'campaign/getActiveCampaign', currentUser: 'contacts/getCurrentUser', + setUserTriggerStatus: 'contacts/getSetUserTriggerStatus', }), textColor() { return getContrastingTextColor(this.widgetColor); @@ -124,6 +125,9 @@ export default { ) { return false; } + if (this.setUserTriggerStatus && field.name === 'fullName') { + return false; + } return true; }); }, diff --git a/app/javascript/widget/store/modules/contacts.js b/app/javascript/widget/store/modules/contacts.js index 89af9ea34..307d86a45 100644 --- a/app/javascript/widget/store/modules/contacts.js +++ b/app/javascript/widget/store/modules/contacts.js @@ -4,9 +4,11 @@ import { SET_USER_ERROR } from '../../constants/errorTypes'; import { setHeader } from '../../helpers/axios'; const state = { currentUser: {}, + isSetUserTriggered: false, }; const SET_CURRENT_USER = 'SET_CURRENT_USER'; +const TRIGGER_SET_USER = 'TRIGGER_SET_USER'; const parseErrorData = error => error && error.response && error.response.data ? error.response.data : error; export const updateWidgetAuthToken = widgetAuthToken => { @@ -23,6 +25,9 @@ export const getters = { getCurrentUser(_state) { return _state.currentUser; }, + getSetUserTriggerStatus(_state) { + return _state.isSetUserTriggered; + }, }; export const actions = { @@ -42,7 +47,7 @@ export const actions = { // Ignore error } }, - setUser: async ({ dispatch }, { identifier, user: userObject }) => { + setUser: async ({ dispatch, commit }, { identifier, user: userObject }) => { try { const { email, @@ -75,6 +80,7 @@ export const actions = { const { data: { widget_auth_token: widgetAuthToken }, } = await ContactsAPI.setUser(identifier, user); + commit(TRIGGER_SET_USER); updateWidgetAuthToken(widgetAuthToken); dispatch('get'); if (identifierHash || widgetAuthToken) { @@ -108,6 +114,9 @@ export const mutations = { const { currentUser } = $state; $state.currentUser = { ...currentUser, ...user }; }, + [TRIGGER_SET_USER]($state) { + $state.isSetUserTriggered = true; + }, }; export default {