Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/livechat/server/api/v1/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Comment thread
rafaelblink marked this conversation as resolved.
Outdated
} catch (e) {
return API.v1.failure(e);
}
Expand Down
13 changes: 13 additions & 0 deletions app/livechat/server/lib/Contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import s from 'underscore.string';
import {
LivechatVisitors,
LivechatCustomField,
LivechatRooms,
Rooms,
LivechatInquiry,
Subscriptions,
} from '../../../models';


Expand Down Expand Up @@ -60,6 +64,15 @@ export const Contacts = {

LivechatVisitors.updateById(contactId, updateUser);

const room = LivechatRooms.findOneByVisitorToken(token, { _id: 1 });
Comment thread
rafaelblink marked this conversation as resolved.
Outdated

if (room) {
const { _id: rid } = room;
return Rooms.setFnameById(rid, name)
&& LivechatInquiry.setNameByRoomId(rid, name)
&& Subscriptions.updateDisplayNameByRoomId(rid, name);
}

return contactId;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@ import { useForm } from '../../../../../hooks/useForm';
import { formsSubscription } from '../../../additionalForms';
import { FormSkeleton } from '../../Skeleton';

const initialValuesUser = {
name: '',
};

const initialValuesRoom = {
topic: '',
tags: '',
livechatData: {},
priorityId: '',
};

const getInitialValuesUser = (visitor) => {
if (!visitor) {
return initialValuesUser;
}

const { name, fname } = visitor;

return {
name: (name || fname) ?? '',
};
};

const getInitialValuesRoom = (room) => {
if (!room) {
return initialValuesRoom;
Expand All @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -131,7 +109,6 @@ function RoomEdit({ room, visitor, reload, close }) {
e.preventDefault();
const userData = {
_id: visitor._id,
name,
};

const roomData = {
Expand All @@ -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 />;
Expand All @@ -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}
Expand Down