import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { IEstimate } from "@plane/types"; // store hooks import { Button, Loader, TOAST_TYPE, setToast } from "@plane/ui"; import { EmptyState } from "@/components/empty-state"; import { CreateUpdateEstimateModal, DeleteEstimateModal, EstimateListItem } from "@/components/estimates"; import { EmptyStateType } from "@/constants/empty-state"; import { orderArrayBy } from "@/helpers/array.helper"; import { useEstimate, useProject } from "@/hooks/store"; // components // ui // types // helpers // constants 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(); const editEstimate = (estimate: IEstimate) => { setEstimateFormOpen(true); // 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 ( <> { 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)} /> ))}
) : (
) ) : ( )} ); });