diff --git a/.changeset/many-nails-cough.md b/.changeset/many-nails-cough.md new file mode 100644 index 000000000000..3965d88ccca8 --- /dev/null +++ b/.changeset/many-nails-cough.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed edit department page showing data from the previous department diff --git a/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentItemMenu.tsx b/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentItemMenu.tsx index 639719971206..31c732803657 100644 --- a/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentItemMenu.tsx +++ b/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentItemMenu.tsx @@ -44,6 +44,7 @@ const DepartmentItemMenu = ({ department, archived }: DepartmentItemMenuProps): try { await toggleArchive(); dispatchToastMessage({ type: 'success', message: archived ? t('Department_unarchived') : t('Department_archived') }); + queryClient.removeQueries(['/v1/livechat/department/:_id', department._id]); handleReload(); } catch (error) { dispatchToastMessage({ type: 'error', message: error }); diff --git a/apps/meteor/client/views/omnichannel/departments/EditDepartment.tsx b/apps/meteor/client/views/omnichannel/departments/EditDepartment.tsx index f02ef2ed150f..6cb32e877397 100644 --- a/apps/meteor/client/views/omnichannel/departments/EditDepartment.tsx +++ b/apps/meteor/client/views/omnichannel/departments/EditDepartment.tsx @@ -14,6 +14,7 @@ import { } from '@rocket.chat/fuselage'; import { useMutableCallback, useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useToastMessageDispatch, useRoute, useMethod, useEndpoint, useTranslation } from '@rocket.chat/ui-contexts'; +import { useQueryClient } from '@tanstack/react-query'; import React, { useMemo } from 'react'; import { Controller, useForm } from 'react-hook-form'; @@ -94,6 +95,7 @@ const getInitialValues = ({ department, agents, allowedToForwardData }: InitialV function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmentProps) { const t = useTranslation(); const departmentsRoute = useRoute('omnichannel-departments'); + const queryClient = useQueryClient(); const { useEeNumberInput = () => null, @@ -197,6 +199,7 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen } else { await saveDepartmentInfo(id ?? null, payload, agentList); } + queryClient.invalidateQueries(['/v1/livechat/department/:_id', id]); dispatchToastMessage({ type: 'success', message: t('Saved') }); departmentsRoute.push({}); } catch (error) { diff --git a/apps/meteor/client/views/omnichannel/departments/EditDepartmentWithData.tsx b/apps/meteor/client/views/omnichannel/departments/EditDepartmentWithData.tsx index 47f24247997b..7f5389d0fbe7 100644 --- a/apps/meteor/client/views/omnichannel/departments/EditDepartmentWithData.tsx +++ b/apps/meteor/client/views/omnichannel/departments/EditDepartmentWithData.tsx @@ -17,7 +17,9 @@ type EditDepartmentWithDataProps = { const EditDepartmentWithData = ({ id, title }: EditDepartmentWithDataProps) => { const t = useTranslation(); const getDepartment = useEndpoint('GET', '/v1/livechat/department/:_id', { _id: id ?? '' }); - const { data, isInitialLoading, isError } = useQuery(['/v1/livechat/department/:_id'], () => getDepartment(params), { enabled: !!id }); + const { data, isInitialLoading, isError } = useQuery(['/v1/livechat/department/:_id', id], () => getDepartment(params), { + enabled: !!id, + }); if (isInitialLoading) { return ;