import React, { useState } from "react"; import { daysLeft, getJobStatusBadge, getNextBadgeColor, } from "../../utils/appUtils"; import { useServiceProjectJobs, useUpdateServiceProjectJob } from "../../hooks/useServiceProject"; import { ITEMS_PER_PAGE, JOBS_STATUS_IDS } from "../../utils/constants"; import EmployeeAvatarGroup from "../common/EmployeeAvatarGroup"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; import { SpinnerLoader } from "../common/Loader"; import { useParams } from "react-router-dom"; import ProjectPage from "../../pages/project/ProjectPage"; import { useServiceProjectJobContext } from "./Jobs"; import ConfirmModal from "../common/ConfirmModal"; const JobList = ({ isArchive }) => { const { setSelectedJob, setManageJob } = useServiceProjectJobContext(); const { mutate: UpdateJob,isPending } = useUpdateServiceProjectJob(() => { }); const { projectId } = useParams(); const { data, isLoading, isError, error } = useServiceProjectJobs( ITEMS_PER_PAGE, 1, true, projectId, 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: isArchiveAction, }, ]; UpdateJob({ id: archiveJobId, payload, isArchiveAction, }); setIsArchiveModalOpen(false); setArchiveJobId(null); }; const jobGrid = [ { key: "jobTicketUId", label: "Job Id", getValue: (e) => {e?.jobTicketUId || "N/A"}, align: "text-start", }, { key: "title", label: "Title", getValue: (e) => ( { if (!isArchive) { setSelectedJob({ showCanvas: true, job: e?.id }); } }} title={e?.title} > {e?.title} ), isAlwaysVisible: true, className: "text-start", }, { key: "dueDate", label: "Due On", getValue: (e) => formatUTCToLocalTime(e.startDate), isAlwaysVisible: true, className: "text-start d-none d-sm-table-cell", }, { key: "status", label: "Status", getValue: (e) => { return ( {e?.status?.displayName} ); }, isAlwaysVisible: true, className: "text-start d-none d-sm-table-cell", }, { key: "daysLeft", label: "Days Left", getValue: (e) => { const { days, color } = daysLeft(e.startDate, e.dueDate); return ( {days !== null ? `${days} days` : "N/A"} ); }, isAlwaysVisible: true, className: "text-start d-none d-sm-table-cell", }, ]; const canArchive = (statusId) => { const closedId = JOBS_STATUS_IDS.find((s) => s.label === "Closed")?.id; const reviewDoneId = JOBS_STATUS_IDS.find((s) => s.label === "Review Done")?.id; return statusId === closedId || statusId === reviewDoneId; }; return ( <> {isArchiveModalOpen && ( setIsArchiveModalOpen(false)} loading={isPending} /> )}
{jobGrid.map((col) => ( ))} {Array.isArray(data?.data) && data.data.length > 0 ? ( data.data.map((row, i) => ( {jobGrid.map((col) => ( ))} )) ) : ( )}
{col.label}
Actions
// setSelectedJob({ showCanvas: true, job: row?.id }) // } onClick={() => { if (!isArchive) { setSelectedJob({ showCanvas: true, job: e?.id }); } }} > {col.getValue(row)}
{!isArchive && ( <> )} {isArchive && ( )} {!isArchive && canArchive(row?.status?.id) && ( )}
{isLoading ? : "Not Found Jobs."}
); }; export default JobList;