import { FC, useState } from "react"; import useSWR from "swr"; import { IEstimate } from "@plane/types"; import { Button, Loader, TOAST_TYPE, setToast } from "@plane/ui"; // components import { EmptyState } from "@/components/empty-state"; import { EstimateEmptyScreen, EstimateLoaderScreen, CreateEstimateModal } from "@/components/estimates"; // constants import { EmptyStateType } from "@/constants/empty-state"; // ee components // hooks import { useProject, useProjectEstimates } from "@/hooks/store"; type TEstimateRoot = { workspaceSlug: string; projectId: string; }; export const EstimateRoot: FC = (props) => { const { workspaceSlug, projectId } = props; // hooks const { updateProject, currentProjectDetails } = useProject(); const { loader, projectEstimateIds, estimateById, getProjectEstimates } = useProjectEstimates(); // states const [isEstimateCreateModalOpen, setIsEstimateCreateModalOpen] = useState(false); // const [isEstimateDeleteModalOpen, setIsEstimateDeleteModalOpen] = useState(null); const [estimateToUpdate, setEstimateToUpdate] = useState(); const { isLoading: isSWRLoading } = useSWR( workspaceSlug && projectId ? `PROJECT_ESTIMATES_${workspaceSlug}_${projectId}` : null, async () => workspaceSlug && projectId && getProjectEstimates(workspaceSlug, projectId) ); // const editEstimate = (estimate: IEstimate) => { // setIsEstimateCreateModalOpen(true); // console.log("estimate", estimate); // // Order the points array by key before updating the estimate to update state // // setEstimateToUpdate({ // // ...estimate, // // points: orderArrayBy(estimate.points, "key"), // // }); // }; const disableEstimates = () => { if (!workspaceSlug || !projectId) return; updateProject(workspaceSlug.toString(), projectId.toString(), { estimate: null }).catch((err) => { const error = err?.error; const errorString = Array.isArray(error) ? error[0] : error; setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: errorString ?? "Estimate could not be disabled. Please try again", }); }); }; return (
{}} /> {loader === "init-loader" || isSWRLoading ? ( ) : ( <> {/* header section */}

Estimates

{currentProjectDetails?.estimate && ( )}
{/* listing of estimates */} {!projectEstimateIds || (projectEstimateIds && projectEstimateIds.length <= 0) ? (
) : (
{projectEstimateIds && projectEstimateIds.map((estimateId: string) => { const estimate = estimateById(estimateId); if (!estimate) return <>; return ( <> // editEstimate(estimate)} // deleteEstimate={(estimateId) => setIsEstimateDeleteModalOpen(estimateId)} // /> ); })}
)} )} {/* */} { setIsEstimateCreateModalOpen(false); setEstimateToUpdate(undefined); }} /> {/* setIsEstimateDeleteModalOpen(null)} data={} /> */}
); };