Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Editing a department shows incorrect data #29468

Merged
merged 7 commits into from
Jun 13, 2023
5 changes: 5 additions & 0 deletions .changeset/many-nails-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed edit department page showing data from the previous department
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FormSkeleton />;
Expand Down