import React, { useState } from "react"; import { useRouter } from "next/router"; // store import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // components import { CreateUpdateEstimateModal, DeleteEstimateModal, EstimateListItem } from "components/estimates"; //hooks import useToast from "hooks/use-toast"; // ui import { Button, Loader } from "@plane/ui"; import { EmptyState } from "components/common"; // icons import { Plus } from "lucide-react"; // images import emptyEstimate from "public/empty-state/estimate.svg"; // types import { IEstimate } from "types"; export const EstimatesList: React.FC = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store const { project: projectStore } = useMobxStore(); const { currentProjectDetails } = projectStore; // states const [estimateFormOpen, setEstimateFormOpen] = useState(false); const [estimateToDelete, setEstimateToDelete] = useState(null); const [estimateToUpdate, setEstimateToUpdate] = useState(); // hooks const { setToastAlert } = useToast(); // derived values const estimatesList = projectStore.projectEstimates; const editEstimate = (estimate: IEstimate) => { setEstimateFormOpen(true); setEstimateToUpdate(estimate); }; const disableEstimates = () => { if (!workspaceSlug || !projectId) return; projectStore.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={projectStore.getProjectEstimateById(estimateToDelete!)} />

Estimates

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