@@ -22,6 +22,7 @@ import { Box } from "@mui/material";
2222import dayjs from "dayjs" ;
2323import { useCallback , useMemo } from "react" ;
2424import { FormProvider , useForm } from "react-hook-form" ;
25+ import { useQueryClient } from "@tanstack/react-query" ;
2526import InspectionFormLeft from "./InspectionFormLeft" ;
2627import InspectionFormRight from "./InspectionFormRight" ;
2728import { 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