Updation in Employee Suspend and Reactivate employee.
This commit is contained in:
parent
00b73b3d34
commit
f1bc6bd57d
@ -277,27 +277,37 @@ export const useSuspendEmployee = ({
|
||||
);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (employeeId) => {
|
||||
// Expect both employeeId and active status
|
||||
mutationFn: async ({ employeeId, active }) => {
|
||||
setemployeeLodaing(true);
|
||||
return await EmployeeRepository.deleteEmployee(employeeId);
|
||||
return await EmployeeRepository.deleteEmployee(employeeId, active);
|
||||
},
|
||||
|
||||
onSuccess: (_, employeeId) => {
|
||||
showToast("Employee suspended successfully.", "success");
|
||||
onSuccess: (_, { employeeId, active }) => {
|
||||
const message =
|
||||
active === false
|
||||
? "Employee suspended successfully."
|
||||
: "Employee reactivated successfully.";
|
||||
|
||||
showToast(message, "success");
|
||||
setIsDeleteModalOpen(false);
|
||||
|
||||
// Invalidate only the required employee-related queries
|
||||
// Invalidate relevant queries
|
||||
queryClient.invalidateQueries({ queryKey: ["employee", employeeId] });
|
||||
queryClient.invalidateQueries({ queryKey: ["allEmployees"] });
|
||||
|
||||
if (selectedProjectId) {
|
||||
queryClient.invalidateQueries({ queryKey: ["projectEmployees", selectedProjectId] });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["projectEmployees", selectedProjectId],
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error.response?.data?.message || error.message || "An unexpected error occurred",
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
"An unexpected error occurred",
|
||||
"error"
|
||||
);
|
||||
setIsDeleteModalOpen(false);
|
||||
@ -309,6 +319,7 @@ export const useSuspendEmployee = ({
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const useUpdateEmployeeRoles = ({
|
||||
onClose,
|
||||
resetForm,
|
||||
|
@ -272,12 +272,21 @@ const EmployeeList = () => {
|
||||
>
|
||||
<ConfirmModal
|
||||
type={"delete"}
|
||||
header={"Suspend Employee"}
|
||||
message={"Are you sure you want delete?"}
|
||||
onSubmit={suspendEmployee}
|
||||
header={
|
||||
selectedEmpFordelete?.isActive
|
||||
? "Suspend Employee"
|
||||
: "Reactivate Employee"
|
||||
}
|
||||
message={`Are you sure you want to ${selectedEmpFordelete?.isActive ? "suspend" : "reactivate"
|
||||
} this employee?`}
|
||||
onSubmit={() =>
|
||||
suspendEmployee({
|
||||
employeeId: selectedEmpFordelete.id,
|
||||
active: !selectedEmpFordelete.isActive,
|
||||
})
|
||||
}
|
||||
onClose={() => setIsDeleteModalOpen(false)}
|
||||
loading={employeeLodaing}
|
||||
paramData={selectedEmpFordelete}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@ -644,15 +653,17 @@ const EmployeeList = () => {
|
||||
>
|
||||
<i className="bx bx-edit bx-sm"></i> Edit
|
||||
</button>
|
||||
|
||||
|
||||
{/* Suspend only when active */}
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() => handleOpenDelete(item.id)}
|
||||
>
|
||||
<i className="bx bx-task-x bx-sm"></i> Suspend
|
||||
</button>
|
||||
|
||||
{item.isActive && (
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() => handleOpenDelete(item)}
|
||||
>
|
||||
<i className="bx bx-task-x bx-sm"></i> Suspend
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
type="button"
|
||||
@ -670,10 +681,9 @@ const EmployeeList = () => {
|
||||
{!item.isActive && showInactive && (
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() => handleOpenDelete(item.id)}
|
||||
onClick={() => handleOpenDelete(item)}
|
||||
>
|
||||
<i className="bx bx-refresh bx-sm me-1"></i>
|
||||
Re-activate
|
||||
<i className="bx bx-refresh bx-sm me-1"></i> Re-activate
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
@ -10,7 +10,7 @@ const EmployeeRepository = {
|
||||
updateEmployee: (id, data) => api.put(`/users/${id}`, data),
|
||||
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
|
||||
getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${id}`),
|
||||
deleteEmployee: (id) => api.delete(`/api/employee/${id}`),
|
||||
deleteEmployee: (id,active) => api.delete(`/api/employee/${id}?active=${active}`),
|
||||
getEmployeeName: (projectId, search) => {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user