diff --git a/src/hooks/useEmployees.js b/src/hooks/useEmployees.js index 40db5105..a2fae3fd 100644 --- a/src/hooks/useEmployees.js +++ b/src/hooks/useEmployees.js @@ -176,8 +176,9 @@ export const useEmployeeProfile = (employeeId) => { export const useEmployeesName = (projectId, search) => { return useQuery({ queryKey: ["employees", projectId, search], - queryFn: async() => await EmployeeRepository.getEmployeeName(projectId, search), - + queryFn: async () => + await EmployeeRepository.getEmployeeName(projectId, search), + staleTime: 5 * 60 * 1000, // Optional: cache for 5 minutes }); }; @@ -194,7 +195,6 @@ export const useEmployeesNameByProject = (projectId) => { }); }; - // Mutation------------------------------------------------------------------ export const useUpdateEmployee = () => { @@ -232,27 +232,58 @@ 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); +// }, + +// onSuccess: () => { + +// // 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 selectedProject = useSelector( + const selectedProjectId = useSelector( (store) => store.localVariables.projectId ); + return useMutation({ mutationFn: async (employeeId) => { setemployeeLodaing(true); return await EmployeeRepository.deleteEmployee(employeeId); }, - onSuccess: () => { - // queryClient.invalidateQueries( ['allEmployee',false]); - queryClient.invalidateQueries({ queryKey: ["projectEmployees"] }); - queryClient.invalidateQueries({ - queryKey: ["employeeListByProject", selectedProject], - }); - showToast("Employee deleted successfully.", "success"); + onSuccess: (_, employeeId) => { + showToast("Employee suspended successfully.", "success"); setIsDeleteModalOpen(false); // Invalidate only the required employee-related queries @@ -278,8 +309,6 @@ export const useSuspendEmployee = ({ }); }; -// Manage Role - export const useUpdateEmployeeRoles = ({ onClose, resetForm,