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
|
||||
);
|
||||
return useMutation({
|
||||
mutationFn: (id) => {
|
||||
mutationFn: async (employeeId) => {
|
||||
setemployeeLodaing(true);
|
||||
return EmployeeRepository.deleteEmployee(id);
|
||||
return await EmployeeRepository.deleteEmployee(employeeId);
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
@ -254,14 +254,21 @@ export const useSuspendEmployee = ({
|
||||
});
|
||||
showToast("Employee deleted successfully.", "success");
|
||||
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) => {
|
||||
const message =
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
"An unexpected error occurred";
|
||||
showToast(message, "error");
|
||||
showToast(
|
||||
error.response?.data?.message || error.message || "An unexpected error occurred",
|
||||
"error"
|
||||
);
|
||||
setIsDeleteModalOpen(false);
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user