Implementing Restore Functionality in Jobs.
This commit is contained in:
parent
17a9f4a9b1
commit
ee4ef18594
@ -28,28 +28,26 @@ const JobList = ({ isArchive }) => {
|
||||
);
|
||||
const [isArchiveModalOpen, setIsArchiveModalOpen] = useState(false);
|
||||
const [archiveJobId, setArchiveJobId] = useState(null);
|
||||
|
||||
const [isArchiveAction, setIsArchiveAction] = useState(true);
|
||||
|
||||
const handleArchive = () => {
|
||||
const payload = [
|
||||
{
|
||||
op: "replace",
|
||||
path: "/isArchive",
|
||||
value: true,
|
||||
value: isArchiveAction,
|
||||
},
|
||||
];
|
||||
|
||||
UpdateJob({
|
||||
id: archiveJobId,
|
||||
payload,
|
||||
isArchiveAction: true,
|
||||
isArchiveAction,
|
||||
});
|
||||
|
||||
setIsArchiveModalOpen(false);
|
||||
setArchiveJobId(null);
|
||||
};
|
||||
|
||||
|
||||
const jobGrid = [
|
||||
{
|
||||
key: "jobTicketUId",
|
||||
@ -123,17 +121,21 @@ const JobList = ({ isArchive }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
{isArchiveModalOpen && (
|
||||
<ConfirmModal
|
||||
isOpen={isArchiveModalOpen}
|
||||
type="success"
|
||||
header="Archive Job"
|
||||
message="Are you sure you want to archive this job?"
|
||||
type={isArchiveAction ? "success" : "undo"}
|
||||
header={isArchiveAction ? "Archive Job" : "Restore Job"}
|
||||
message={
|
||||
isArchiveAction
|
||||
? "Are you sure you want to archive this job?"
|
||||
: "Are you sure you want to restore this job?"
|
||||
}
|
||||
onSubmit={handleArchive}
|
||||
onClose={() => setIsArchiveModalOpen(false)}
|
||||
loading={false}
|
||||
/>
|
||||
|
||||
)}
|
||||
|
||||
<div className="dataTables_wrapper dt-bootstrap5 no-footer table-responsive">
|
||||
@ -170,6 +172,7 @@ const JobList = ({ isArchive }) => {
|
||||
onClick={() =>
|
||||
setSelectedJob({ showCanvas: true, job: row?.id })
|
||||
}
|
||||
|
||||
>
|
||||
{col.getValue(row)}
|
||||
</td>
|
||||
@ -183,6 +186,9 @@ const JobList = ({ isArchive }) => {
|
||||
<i className="bx bx-dots-vertical-rounded bx-md"></i>
|
||||
</button>
|
||||
<div className="dropdown-menu dropdown-menu-end">
|
||||
|
||||
{!isArchive && (
|
||||
<>
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() =>
|
||||
@ -191,7 +197,7 @@ const JobList = ({ isArchive }) => {
|
||||
>
|
||||
<i className="bx bx-detail bx-sm"></i> View
|
||||
</button>
|
||||
<>
|
||||
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() =>
|
||||
@ -201,12 +207,27 @@ const JobList = ({ isArchive }) => {
|
||||
<i className="bx bx-edit bx-sm"></i> Edit
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{canArchive(row?.status?.id) && (
|
||||
{isArchive && (
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() => {
|
||||
setArchiveJobId(row.id);
|
||||
setIsArchiveAction(false);
|
||||
setIsArchiveModalOpen(true);
|
||||
}}
|
||||
>
|
||||
<i className="bx bx-reset bx-sm"></i> Restore
|
||||
</button>
|
||||
)}
|
||||
|
||||
{!isArchive && canArchive(row?.status?.id) && (
|
||||
<button
|
||||
className="dropdown-item py-1"
|
||||
onClick={() => {
|
||||
setArchiveJobId(row.id);
|
||||
setIsArchiveAction(true);
|
||||
setIsArchiveModalOpen(true);
|
||||
}}
|
||||
>
|
||||
@ -215,6 +236,7 @@ const JobList = ({ isArchive }) => {
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -264,7 +264,6 @@ export const useCreateServiceProjectJob = (onSuccessCallback) => {
|
||||
|
||||
export const useUpdateServiceProjectJob = (onSuccessCallback) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, payload, isArchiveAction = false }) => {
|
||||
const resp = await ServiceProjectRepository.UpdateJob(id, payload);
|
||||
@ -281,10 +280,11 @@ export const useUpdateServiceProjectJob = (onSuccessCallback) => {
|
||||
if (isArchiveAction) {
|
||||
showToast("Job archived successfully", "success");
|
||||
} else {
|
||||
showToast("Job Updated successfully", "success");
|
||||
showToast("Job restored successfully", "success");
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error?.response?.data?.message ||
|
||||
@ -336,10 +336,10 @@ export const useBranches = (
|
||||
});
|
||||
};
|
||||
|
||||
export const useBranchTypes = ()=>{
|
||||
export const useBranchTypes = () => {
|
||||
return useQuery({
|
||||
queryKey:["branch_Type"],
|
||||
queryFn:async()=> {
|
||||
queryKey: ["branch_Type"],
|
||||
queryFn: async () => {
|
||||
const resp = await ServiceProjectRepository.GetBranchTypeList();
|
||||
return resp.data;
|
||||
},
|
||||
@ -409,9 +409,9 @@ export const useDeleteBranch = () => {
|
||||
mutationFn: async ({ id, isActive }) =>
|
||||
await ServiceProjectRepository.DeleteBranch(id, isActive),
|
||||
|
||||
onSuccess: (_,variable) => {
|
||||
onSuccess: (_, variable) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["branches"] });
|
||||
showToast(`Branch ${variable.isActive ? "restored":"deleted"} successfully`, "success");
|
||||
showToast(`Branch ${variable.isActive ? "restored" : "deleted"} successfully`, "success");
|
||||
},
|
||||
|
||||
onError: (error) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user