[FIX] Rename Omnichannel Rooms, Inquiries and Subscriptions when the Contact Name changes (#21513)

* remove contact name from room editor form.

* update room name when contact name is updated

* revert refactor variable name

* Update all rooms associated with the same contact.

* Change if condition to a logical and condition.

Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com>
pull/21360/head
Rafael Ferreira 5 years ago committed by GitHub
parent 11ea742f61
commit 880546bbf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/livechat/server/lib/Contacts.js
  2. 32
      client/views/omnichannel/directory/chats/contextualBar/RoomEdit.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 rooms = LivechatRooms.findByVisitorId(contactId).fetch();
rooms?.length && rooms.forEach((room) => {
const { _id: rid } = room;
Rooms.setFnameById(rid, name)
&& LivechatInquiry.setNameByRoomId(rid, name)
&& Subscriptions.updateDisplayNameByRoomId(rid, name);
});
return contactId;
},
};

@ -16,10 +16,6 @@ import { useForm } from '../../../../../hooks/useForm';
import { formsSubscription } from '../../../additionalForms';
import { FormSkeleton } from '../../Skeleton';
const initialValuesUser = {
name: '',
};
const initialValuesRoom = {
topic: '',
tags: [],
@ -27,18 +23,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;
@ -57,9 +41,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,
@ -68,9 +49,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 <FormSkeleton />;
@ -165,12 +141,6 @@ function RoomEdit({ room, visitor, reload, close }) {
return (
<>
<VerticalBar.ScrollableContent is='form'>
<Field>
<Field.Label>{t('Name')}</Field.Label>
<Field.Row>
<TextInput flexGrow={1} value={name} onChange={handleName} />
</Field.Row>
</Field>
{canViewCustomFields() && allCustomFields && (
<CustomFieldsForm
jsonCustomFields={jsonCustomField}

Loading…
Cancel
Save