Skip to content

Commit

Permalink
fix: Editing a department shows incorrect data (RocketChat#29468)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva authored Jun 13, 2023
1 parent a52f384 commit 760c023
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
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

0 comments on commit 760c023

Please sign in to comment.