Deleted Employee Still Visible Until Manual Refresh.
This commit is contained in:
parent
b410ec71cc
commit
43ed77cfc6
@ -211,31 +211,70 @@ export const useUpdateEmployee = () =>
|
||||
|
||||
|
||||
|
||||
export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
||||
return useMutation({
|
||||
mutationFn: (id) => {
|
||||
setemployeeLodaing(true);
|
||||
return EmployeeRepository.deleteEmployee(id);
|
||||
},
|
||||
// export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing }) => {
|
||||
// const queryClient = useQueryClient();
|
||||
// const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
||||
// return useMutation({
|
||||
// mutationFn: (id) => {
|
||||
// setemployeeLodaing(true);
|
||||
// return EmployeeRepository.deleteEmployee(id);
|
||||
// },
|
||||
|
||||
onSuccess: () => {
|
||||
// onSuccess: () => {
|
||||
|
||||
|
||||
// queryClient.invalidateQueries( ['allEmployee',false]);
|
||||
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
||||
queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
|
||||
showToast("Employee deleted successfully.", "success");
|
||||
// // queryClient.invalidateQueries( ['allEmployee',false]);
|
||||
// queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
||||
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
|
||||
// showToast("Employee deleted successfully.", "success");
|
||||
// setIsDeleteModalOpen(false);
|
||||
// },
|
||||
|
||||
// onError: (error) => {
|
||||
// const message =
|
||||
// error.response?.data?.message ||
|
||||
// error.message ||
|
||||
// "An unexpected error occurred";
|
||||
// showToast(message, "error");
|
||||
// setIsDeleteModalOpen(false);
|
||||
// },
|
||||
|
||||
// onSettled: () => {
|
||||
// setemployeeLodaing(false);
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// Manage Role
|
||||
|
||||
export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const selectedProjectId = useSelector((store) => store.localVariables.projectId);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (employeeId) => {
|
||||
setemployeeLodaing(true);
|
||||
return await EmployeeRepository.deleteEmployee(employeeId);
|
||||
},
|
||||
|
||||
onSuccess: (_, employeeId) => {
|
||||
showToast("Employee suspended 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);
|
||||
},
|
||||
|
||||
@ -245,9 +284,6 @@ export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing })
|
||||
});
|
||||
};
|
||||
|
||||
// Manage Role
|
||||
|
||||
|
||||
export const useUpdateEmployeeRoles = ({ onClose, resetForm, onSuccessCallback } = {}) => {
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
|
Loading…
x
Reference in New Issue
Block a user