Compare commits
2 Commits
9669e725a4
...
1305ac855d
Author | SHA1 | Date | |
---|---|---|---|
1305ac855d | |||
43ed77cfc6 |
@ -176,8 +176,9 @@ export const useEmployeeProfile = (employeeId) => {
|
|||||||
export const useEmployeesName = (projectId, search) => {
|
export const useEmployeesName = (projectId, search) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["employees", projectId, search],
|
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
|
staleTime: 5 * 60 * 1000, // Optional: cache for 5 minutes
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -194,7 +195,6 @@ export const useEmployeesNameByProject = (projectId) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Mutation------------------------------------------------------------------
|
// Mutation------------------------------------------------------------------
|
||||||
|
|
||||||
export const useUpdateEmployee = () => {
|
export const useUpdateEmployee = () => {
|
||||||
@ -232,36 +232,78 @@ 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 = ({
|
export const useSuspendEmployee = ({
|
||||||
setIsDeleteModalOpen,
|
setIsDeleteModalOpen,
|
||||||
setemployeeLodaing,
|
setemployeeLodaing,
|
||||||
}) => {
|
}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const selectedProject = useSelector(
|
const selectedProjectId = useSelector(
|
||||||
(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: (_, employeeId) => {
|
||||||
// queryClient.invalidateQueries( ['allEmployee',false]);
|
showToast("Employee suspended successfully.", "success");
|
||||||
queryClient.invalidateQueries({ queryKey: ["projectEmployees"] });
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["employeeListByProject", selectedProject],
|
|
||||||
});
|
|
||||||
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 ||
|
error.message ||
|
||||||
"An unexpected error occurred";
|
"An unexpected error occurred",
|
||||||
showToast(message, "error");
|
"error"
|
||||||
|
);
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -271,8 +313,6 @@ export const useSuspendEmployee = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Manage Role
|
|
||||||
|
|
||||||
export const useUpdateEmployeeRoles = ({
|
export const useUpdateEmployeeRoles = ({
|
||||||
onClose,
|
onClose,
|
||||||
resetForm,
|
resetForm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user