fix: Delete folder from cache after successful deletion (#3686)

* feat: Delete folder from cache after successful deletion

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
anovazzi1 2024-09-04 18:19:46 -03:00 committed by GitHub
commit 533d5afdc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,7 +18,8 @@ export const useDeleteFolders: useMutationFunctionType<
folder_id,
}: DeleteFoldersParams): Promise<any> => {
const res = await api.delete(`${getURL("FOLDERS")}/${folder_id}`);
return res.data;
// returning id to use it in onSuccess and delete the folder from the cache
return folder_id;
};
const mutation: UseMutationResult<
@ -30,6 +31,12 @@ export const useDeleteFolders: useMutationFunctionType<
onSettled: () => {
queryClient.refetchQueries({ queryKey: ["useGetFolders"] });
},
onSuccess: (id) => {
queryClient.removeQueries({
queryKey: ["useGetFolder", { id }],
exact: true,
});
},
});
return mutation;