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 }) => {
|
// export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing }) => {
|
||||||
const queryClient = useQueryClient();
|
// const queryClient = useQueryClient();
|
||||||
const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
// const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
||||||
return useMutation({
|
// return useMutation({
|
||||||
mutationFn: (id) => {
|
// mutationFn: (id) => {
|
||||||
setemployeeLodaing(true);
|
// setemployeeLodaing(true);
|
||||||
return EmployeeRepository.deleteEmployee(id);
|
// return EmployeeRepository.deleteEmployee(id);
|
||||||
},
|
// },
|
||||||
|
|
||||||
onSuccess: () => {
|
// onSuccess: () => {
|
||||||
|
|
||||||
|
|
||||||
// queryClient.invalidateQueries( ['allEmployee',false]);
|
// // queryClient.invalidateQueries( ['allEmployee',false]);
|
||||||
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
// queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
||||||
queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
|
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
|
||||||
showToast("Employee deleted successfully.", "success");
|
// 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);
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -245,9 +284,6 @@ export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing })
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Manage Role
|
|
||||||
|
|
||||||
|
|
||||||
export const useUpdateEmployeeRoles = ({ onClose, resetForm, onSuccessCallback } = {}) => {
|
export const useUpdateEmployeeRoles = ({ onClose, resetForm, onSuccessCallback } = {}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user