import React, { useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Plus } from "lucide-react"; // store hooks import { useEstimate, useProject } from "hooks/store"; import useToast from "hooks/use-toast"; // components import { CreateUpdateEstimateModal, DeleteEstimateModal, EstimateListItem } from "components/estimates"; // ui import { Button, Loader } from "@plane/ui"; import { EmptyState } from "components/common"; // images import emptyEstimate from "public/empty-state/estimate.svg"; // types import { IEstimate } from "@plane/types"; export const EstimatesList: React.FC = observer(() => { // states const [estimateFormOpen, setEstimateFormOpen] = useState(false); const [estimateToDelete, setEstimateToDelete] = useState(null); const [estimateToUpdate, setEstimateToUpdate] = useState(); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { updateProject, currentProjectDetails } = useProject(); const { projectEstimates, getProjectEstimateById } = useEstimate(); // toast alert const { setToastAlert } = useToast(); const editEstimate = (estimate: IEstimate) => { setEstimateFormOpen(true); setEstimateToUpdate(estimate); }; 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; setToastAlert({ type: "error", title: "Error!", message: errorString ?? "Estimate could not be disabled. Please try again", }); }); }; return ( <> { setEstimateFormOpen(false); setEstimateToUpdate(undefined); }} /> setEstimateToDelete(null)} data={getProjectEstimateById(estimateToDelete!)} />

Estimates

{currentProjectDetails?.estimate && ( )}
{projectEstimates ? ( projectEstimates.length > 0 ? (
{projectEstimates.map((estimate) => ( editEstimate(estimate)} deleteEstimate={(estimateId) => setEstimateToDelete(estimateId)} /> ))}
) : (
, text: "Add Estimate", onClick: () => { setEstimateFormOpen(true); setEstimateToUpdate(undefined); }, }} />
) ) : ( )} ); });