Deleted Employee Still Visible Until Manual Refresh.
This commit is contained in:
parent
ab7de32744
commit
0722f52619
@ -241,9 +241,9 @@ export const useSuspendEmployee = ({
|
|||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
);
|
);
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (id) => {
|
mutationFn: async (employeeId) => {
|
||||||
setemployeeLodaing(true);
|
setemployeeLodaing(true);
|
||||||
return EmployeeRepository.deleteEmployee(id);
|
return await EmployeeRepository.deleteEmployee(employeeId);
|
||||||
},
|
},
|
||||||
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@ -254,14 +254,21 @@ export const useSuspendEmployee = ({
|
|||||||
});
|
});
|
||||||
showToast("Employee deleted successfully.", "success");
|
showToast("Employee deleted successfully.", "success");
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
|
|
||||||
|
// Invalidate only the required employee-related queries
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["employee", employeeId] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["allEmployees"] });
|
||||||
|
|
||||||
|
if (selectedProjectId) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["projectEmployees", selectedProjectId] });
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
const message =
|
showToast(
|
||||||
error.response?.data?.message ||
|
error.response?.data?.message || error.message || "An unexpected error occurred",
|
||||||
error.message ||
|
"error"
|
||||||
"An unexpected error occurred";
|
);
|
||||||
showToast(message, "error");
|
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user