Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/afraid-mugs-priest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/core-typings": patch
"@rocket.chat/livechat": patch
---

Fixes issue causing the setDepartment Livechat API overriding some triggers conditions
17 changes: 17 additions & 0 deletions packages/livechat/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ const updateIframeGuestData = (data: Partial<StoreState['guest']>) => {

export type HooksWidgetAPI = typeof api;

const updateIframeData = (data: Partial<StoreState['iframe']>) => {
const { iframe } = store.state;

if (data.guest) {
throw new Error('Guest data changes not allowed. Use updateIframeGuestData instead.');
}

const iframeData = { ...iframe, ...data };

store.setState({ iframe: { ...iframeData } });
};

const api = {
pageVisited(info: { change: string; title: string; location: { href: string } }) {
const { token, room } = store.state;
Expand Down Expand Up @@ -90,6 +102,11 @@ const api = {
defaultAgent,
} = store.state;

if (!user) {
updateIframeData({ defaultDepartment: value });
return;
}

const { department: existingDepartment } = user || {};

const department = departments.find((dep) => dep._id === value || dep.name === value)?._id || '';
Expand Down
9 changes: 6 additions & 3 deletions packages/livechat/src/routes/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export const Register: FunctionalComponent<{ path: string }> = () => {
theme: { title },
customFields = [],
},
iframe: { guest: { department: guestDepartment = undefined, name: guestName = undefined, email: guestEmail = undefined } = {} },

iframe: { defaultDepartment, guest: { name: guestName = undefined, email: guestEmail = undefined } = {} },

loading = false,
token,
dispatch,
Expand Down Expand Up @@ -96,8 +98,9 @@ export const Register: FunctionalComponent<{ path: string }> = () => {
};

const getDepartmentDefault = () => {
if (departments.some((dept) => dept._id === guestDepartment)) {
return guestDepartment;
const dept = departments.find((dept) => dept._id === defaultDepartment || dept.name === defaultDepartment);
Comment thread
KevLehman marked this conversation as resolved.
if (dept?._id) {
return dept._id;
}
};

Expand Down
1 change: 1 addition & 0 deletions packages/livechat/src/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type StoreState = {
visible?: boolean;
department?: string;
language?: string;
defaultDepartment?: string;
};
gdpr: {
accepted: boolean;
Expand Down