From 706ab872f36ffb116f2bb37eea840f6c30789ffa Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 17 Oct 2022 20:59:17 +0530 Subject: [PATCH] fix: Disable name in pre-chat form if the name is already provided in `setUser` (#5466) --- .../widget/components/PreChat/Form.vue | 20 +++++++++++++++---- .../api/v1/widget/contacts/show.json.jbuilder | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/javascript/widget/components/PreChat/Form.vue b/app/javascript/widget/components/PreChat/Form.vue index 69e543b21..1649068c6 100644 --- a/app/javascript/widget/components/PreChat/Form.vue +++ b/app/javascript/widget/components/PreChat/Form.vue @@ -117,11 +117,23 @@ export default { filteredPreChatFields() { const isUserEmailAvailable = !!this.currentUser.email; const isUserPhoneNumberAvailable = !!this.currentUser.phone_number; + const isUserIdentifierAvailable = !!this.currentUser.identifier; + const isUserNameAvailable = !!( + isUserIdentifierAvailable || + isUserEmailAvailable || + isUserPhoneNumberAvailable + ); return this.preChatFields.filter(field => { - return !( - (isUserEmailAvailable && field.name === 'emailAddress') || - (isUserPhoneNumberAvailable && field.name === 'phoneNumber') - ); + if (isUserEmailAvailable && field.name === 'emailAddress') { + return false; + } + if (isUserPhoneNumberAvailable && field.name === 'phoneNumber') { + return false; + } + if (isUserNameAvailable && field.name === 'fullName') { + return false; + } + return true; }); }, enabledPreChatFields() { diff --git a/app/views/api/v1/widget/contacts/show.json.jbuilder b/app/views/api/v1/widget/contacts/show.json.jbuilder index d6228cbfe..2e7a38277 100644 --- a/app/views/api/v1/widget/contacts/show.json.jbuilder +++ b/app/views/api/v1/widget/contacts/show.json.jbuilder @@ -2,3 +2,4 @@ json.id @contact.id json.name @contact.name json.email @contact.email json.phone_number @contact.phone_number +json.identifier @contact.identifier