Merge branch 'Issues_Aug_1W' of https://git.marcoaiot.com/admin/marco.pms.web into Issues_Aug_1W

This commit is contained in:
Kartik Sharma 2025-08-18 10:23:03 +05:30
commit 7283140a3a

View File

@ -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,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 = ({ 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: async (employeeId) => { mutationFn: async (employeeId) => {
setemployeeLodaing(true); setemployeeLodaing(true);
return await EmployeeRepository.deleteEmployee(employeeId); 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 // Invalidate only the required employee-related queries
@ -278,8 +309,6 @@ export const useSuspendEmployee = ({
}); });
}; };
// Manage Role
export const useUpdateEmployeeRoles = ({ export const useUpdateEmployeeRoles = ({
onClose, onClose,
resetForm, resetForm,