Display Only "Re-activate" Button for Inactive Employees in Action Column #348

Merged
pramod.mahajan merged 2 commits from Kartik_Bug#944 into Issues_Aug_1W 2025-08-23 04:37:21 +00:00
3 changed files with 44 additions and 23 deletions
Showing only changes of commit 2a2cfcb12c - Show all commits

View File

@ -277,27 +277,37 @@ export const useSuspendEmployee = ({
); );
return useMutation({ return useMutation({
mutationFn: async (employeeId) => { // Expect both employeeId and active status
mutationFn: async ({ employeeId, active }) => {
setemployeeLodaing(true); setemployeeLodaing(true);
return await EmployeeRepository.deleteEmployee(employeeId); return await EmployeeRepository.deleteEmployee(employeeId, active);
}, },
onSuccess: (_, employeeId) => { onSuccess: (_, { employeeId, active }) => {
showToast("Employee suspended successfully.", "success"); const message =
active === false
? "Employee suspended successfully."
: "Employee reactivated successfully.";
showToast(message, "success");
setIsDeleteModalOpen(false); setIsDeleteModalOpen(false);
// Invalidate only the required employee-related queries // Invalidate relevant queries
queryClient.invalidateQueries({ queryKey: ["employee", employeeId] }); queryClient.invalidateQueries({ queryKey: ["employee", employeeId] });
queryClient.invalidateQueries({ queryKey: ["allEmployees"] }); queryClient.invalidateQueries({ queryKey: ["allEmployees"] });
if (selectedProjectId) { if (selectedProjectId) {
queryClient.invalidateQueries({ queryKey: ["projectEmployees", selectedProjectId] }); queryClient.invalidateQueries({
queryKey: ["projectEmployees", selectedProjectId],
});
} }
}, },
onError: (error) => { onError: (error) => {
showToast( showToast(
error.response?.data?.message || error.message || "An unexpected error occurred", error.response?.data?.message ||
error.message ||
"An unexpected error occurred",
"error" "error"
); );
setIsDeleteModalOpen(false); setIsDeleteModalOpen(false);
@ -309,6 +319,7 @@ export const useSuspendEmployee = ({
}); });
}; };
export const useUpdateEmployeeRoles = ({ export const useUpdateEmployeeRoles = ({
onClose, onClose,
resetForm, resetForm,

View File

@ -272,12 +272,21 @@ const EmployeeList = () => {
> >
<ConfirmModal <ConfirmModal
type={"delete"} type={"delete"}
header={"Suspend Employee"} header={
message={"Are you sure you want delete?"} selectedEmpFordelete?.isActive
onSubmit={suspendEmployee} ? "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)} onClose={() => setIsDeleteModalOpen(false)}
loading={employeeLodaing} loading={employeeLodaing}
paramData={selectedEmpFordelete}
/> />
</div> </div>
)} )}
@ -644,15 +653,17 @@ const EmployeeList = () => {
> >
<i className="bx bx-edit bx-sm"></i> Edit <i className="bx bx-edit bx-sm"></i> Edit
</button> </button>
{/* Suspend only when active */} {/* Suspend only when active */}
<button {item.isActive && (
className="dropdown-item py-1" <button
onClick={() => handleOpenDelete(item.id)} className="dropdown-item py-1"
> onClick={() => handleOpenDelete(item)}
<i className="bx bx-task-x bx-sm"></i> Suspend >
</button> <i className="bx bx-task-x bx-sm"></i> Suspend
</button>
)}
<button <button
className="dropdown-item py-1" className="dropdown-item py-1"
type="button" type="button"
@ -670,10 +681,9 @@ const EmployeeList = () => {
{!item.isActive && showInactive && ( {!item.isActive && showInactive && (
<button <button
className="dropdown-item py-1" className="dropdown-item py-1"
onClick={() => handleOpenDelete(item.id)} onClick={() => handleOpenDelete(item)}
> >
<i className="bx bx-refresh bx-sm me-1"></i> <i className="bx bx-refresh bx-sm me-1"></i> Re-activate
Re-activate
</button> </button>
)} )}
</div> </div>

View File

@ -10,7 +10,7 @@ const EmployeeRepository = {
updateEmployee: (id, data) => api.put(`/users/${id}`, data), updateEmployee: (id, data) => api.put(`/users/${id}`, data),
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ), // deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${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) => { getEmployeeName: (projectId, search) => {
const params = new URLSearchParams(); const params = new URLSearchParams();