Skip to content

Commit 82d221e

Browse files
authored
Clear report cache when update the inspection from the IR tab (#623)
* updated_date timestamp issue * Clear IR cache on update
1 parent ee3bdfd commit 82d221e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

compliance-web/src/components/App/Inspections/InspectionDrawer.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Box } from "@mui/material";
2222
import dayjs from "dayjs";
2323
import { useCallback, useMemo } from "react";
2424
import { FormProvider, useForm } from "react-hook-form";
25+
import { useQueryClient } from "@tanstack/react-query";
2526
import InspectionFormLeft from "./InspectionFormLeft";
2627
import InspectionFormRight from "./InspectionFormRight";
2728
import { AttendanceEnum } from "@/utils/constants";
@@ -70,6 +71,7 @@ const InspectionDrawer: React.FC<InspectionDrawerProps> = ({
7071
caseFile,
7172
}) => {
7273
const { appHeaderHeight } = useMenuStore();
74+
const queryClient = useQueryClient();
7375

7476
const { data: initiationList } = useInitiationsData();
7577
const { data: irTypeList } = useIRTypesData();
@@ -174,8 +176,14 @@ const InspectionDrawer: React.FC<InspectionDrawerProps> = ({
174176
: `Inspection File ${data.ir_number} was successfully created`
175177
);
176178
reset();
179+
// Clear inspection-reports cache for new inspection
180+
if (data.id) {
181+
queryClient.invalidateQueries({
182+
queryKey: ["inspection-reports", data.id],
183+
});
184+
}
177185
},
178-
[inspection, onSubmit, reset]
186+
[inspection, onSubmit, reset, queryClient]
179187
);
180188

181189
const { mutate: createInspection, isPending: isCreateInspectionPending } =
@@ -192,15 +200,21 @@ const InspectionDrawer: React.FC<InspectionDrawerProps> = ({
192200
id: inspection.id,
193201
inspection: inspectionUpdateData,
194202
});
203+
// Clear inspection-reports cache for updated inspection
204+
queryClient.invalidateQueries({
205+
queryKey: ["inspection-reports", inspection.id],
206+
});
195207
} else {
196208
const inspectionCreateData = formatInspectionAPIData(
197209
formData,
198210
caseFile.id
199211
);
200212
createInspection(inspectionCreateData);
213+
// Note: For new inspections, cache will be cleared in onSuccess callback
214+
// when we get the new inspection ID
201215
}
202216
},
203-
[inspection, updateInspection, caseFile, createInspection]
217+
[inspection, updateInspection, caseFile, createInspection, queryClient]
204218
);
205219

206220
return (

0 commit comments

Comments
 (0)