From a970afbd6a5500f27e60188b9c8aa105b06e4ea7 Mon Sep 17 00:00:00 2001 From: Rafael Date: Fri, 9 Apr 2021 14:53:13 -0300 Subject: [PATCH 1/5] remove contact name from room editor form. --- .../directory/chats/contextualBar/RoomEdit.js | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/client/views/omnichannel/directory/chats/contextualBar/RoomEdit.js b/client/views/omnichannel/directory/chats/contextualBar/RoomEdit.js index e67b2374c75b6..ee9c6b1de2f54 100644 --- a/client/views/omnichannel/directory/chats/contextualBar/RoomEdit.js +++ b/client/views/omnichannel/directory/chats/contextualBar/RoomEdit.js @@ -15,10 +15,6 @@ import { useForm } from '../../../../../hooks/useForm'; import { formsSubscription } from '../../../additionalForms'; import { FormSkeleton } from '../../Skeleton'; -const initialValuesUser = { - name: '', -}; - const initialValuesRoom = { topic: '', tags: '', @@ -26,18 +22,6 @@ const initialValuesRoom = { priorityId: '', }; -const getInitialValuesUser = (visitor) => { - if (!visitor) { - return initialValuesUser; - } - - const { name, fname } = visitor; - - return { - name: (name || fname) ?? '', - }; -}; - const getInitialValuesRoom = (room) => { if (!room) { return initialValuesRoom; @@ -56,9 +40,6 @@ const getInitialValuesRoom = (room) => { function RoomEdit({ room, visitor, reload, close }) { const t = useTranslation(); - const { values, handlers, hasUnsavedChanges: hasUnsavedChangesContact } = useForm( - getInitialValuesUser(visitor), - ); const { values: valuesRoom, handlers: handlersRoom, @@ -67,9 +48,6 @@ function RoomEdit({ room, visitor, reload, close }) { const canViewCustomFields = () => hasAtLeastOnePermission(['view-livechat-room-customfields', 'edit-livechat-room-customfields']); - const { handleName } = handlers; - const { name } = values; - const { handleTopic, handleTags, handlePriorityId } = handlersRoom; const { topic, tags, priorityId } = valuesRoom; @@ -131,7 +109,6 @@ function RoomEdit({ room, visitor, reload, close }) { e.preventDefault(); const userData = { _id: visitor._id, - name, }; const roomData = { @@ -153,8 +130,7 @@ function RoomEdit({ room, visitor, reload, close }) { }); const formIsValid = - (hasUnsavedChangesContact || hasUnsavedChangesRoom || hasUnsavedChangesCustomFields) && - customFieldsError.length === 0; + (hasUnsavedChangesRoom || hasUnsavedChangesCustomFields) && customFieldsError.length === 0; if ([stateCustomFields, statePriorities].includes(AsyncStatePhase.LOADING)) { return ; @@ -165,12 +141,6 @@ function RoomEdit({ room, visitor, reload, close }) { return ( <> - - {t('Name')} - - - - {canViewCustomFields() && allCustomFields && ( Date: Fri, 9 Apr 2021 17:42:45 -0300 Subject: [PATCH 2/5] update room name when contact name is updated --- app/livechat/server/api/v1/contact.js | 4 ++-- app/livechat/server/lib/Contacts.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/livechat/server/api/v1/contact.js b/app/livechat/server/api/v1/contact.js index f98b721c55fad..d28aad6b436df 100644 --- a/app/livechat/server/api/v1/contact.js +++ b/app/livechat/server/api/v1/contact.js @@ -21,9 +21,9 @@ API.v1.addRoute('omnichannel/contact', { authRequired: true }, { contactManager: Match.Maybe(Object), }); - const contact = Contacts.registerContact(this.bodyParams); + const contactId = Contacts.registerContact(this.bodyParams); - return API.v1.success({ contact }); + return API.v1.success({ contact: contactId }); } catch (e) { return API.v1.failure(e); } diff --git a/app/livechat/server/lib/Contacts.js b/app/livechat/server/lib/Contacts.js index 7e0f94e10d7c8..2c79dc86f6fb3 100644 --- a/app/livechat/server/lib/Contacts.js +++ b/app/livechat/server/lib/Contacts.js @@ -4,6 +4,10 @@ import s from 'underscore.string'; import { LivechatVisitors, LivechatCustomField, + LivechatRooms, + Rooms, + LivechatInquiry, + Subscriptions, } from '../../../models'; @@ -60,6 +64,15 @@ export const Contacts = { LivechatVisitors.updateById(contactId, updateUser); + const room = LivechatRooms.findOneByVisitorToken(token, { _id: 1 }); + + if (room) { + const { _id: rid } = room; + return Rooms.setFnameById(rid, name) + && LivechatInquiry.setNameByRoomId(rid, name) + && Subscriptions.updateDisplayNameByRoomId(rid, name); + } + return contactId; }, }; From a8a35461c43fec89deeb046c0e88834df881a241 Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 12 Apr 2021 17:44:06 -0300 Subject: [PATCH 3/5] revert refactor variable name --- app/livechat/server/api/v1/contact.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/livechat/server/api/v1/contact.js b/app/livechat/server/api/v1/contact.js index d28aad6b436df..f98b721c55fad 100644 --- a/app/livechat/server/api/v1/contact.js +++ b/app/livechat/server/api/v1/contact.js @@ -21,9 +21,9 @@ API.v1.addRoute('omnichannel/contact', { authRequired: true }, { contactManager: Match.Maybe(Object), }); - const contactId = Contacts.registerContact(this.bodyParams); + const contact = Contacts.registerContact(this.bodyParams); - return API.v1.success({ contact: contactId }); + return API.v1.success({ contact }); } catch (e) { return API.v1.failure(e); } From 544028cd1ff44452bfdf8338611c538d4ed525f9 Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 12 Apr 2021 19:29:25 -0300 Subject: [PATCH 4/5] Update all rooms associated with the same contact. --- app/livechat/server/lib/Contacts.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/livechat/server/lib/Contacts.js b/app/livechat/server/lib/Contacts.js index 2c79dc86f6fb3..379c3a04627ea 100644 --- a/app/livechat/server/lib/Contacts.js +++ b/app/livechat/server/lib/Contacts.js @@ -64,13 +64,15 @@ export const Contacts = { LivechatVisitors.updateById(contactId, updateUser); - const room = LivechatRooms.findOneByVisitorToken(token, { _id: 1 }); - - if (room) { - const { _id: rid } = room; - return Rooms.setFnameById(rid, name) - && LivechatInquiry.setNameByRoomId(rid, name) - && Subscriptions.updateDisplayNameByRoomId(rid, name); + const rooms = LivechatRooms.findByVisitorId(contactId).fetch(); + + if (rooms && rooms.length > 0) { + rooms.forEach((room) => { + const { _id: rid } = room; + Rooms.setFnameById(rid, name) + && LivechatInquiry.setNameByRoomId(rid, name) + && Subscriptions.updateDisplayNameByRoomId(rid, name); + }); } return contactId; From 52c91784318794ee95b753d87cd53a34db6d947d Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 13 Apr 2021 14:56:07 -0300 Subject: [PATCH 5/5] Change if condition to a logical and condition. --- app/livechat/server/lib/Contacts.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/livechat/server/lib/Contacts.js b/app/livechat/server/lib/Contacts.js index 379c3a04627ea..5e8b70aaf69be 100644 --- a/app/livechat/server/lib/Contacts.js +++ b/app/livechat/server/lib/Contacts.js @@ -66,14 +66,12 @@ export const Contacts = { const rooms = LivechatRooms.findByVisitorId(contactId).fetch(); - if (rooms && rooms.length > 0) { - rooms.forEach((room) => { - const { _id: rid } = room; - Rooms.setFnameById(rid, name) - && LivechatInquiry.setNameByRoomId(rid, name) - && Subscriptions.updateDisplayNameByRoomId(rid, name); - }); - } + rooms?.length && rooms.forEach((room) => { + const { _id: rid } = room; + Rooms.setFnameById(rid, name) + && LivechatInquiry.setNameByRoomId(rid, name) + && Subscriptions.updateDisplayNameByRoomId(rid, name); + }); return contactId; },