import React from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; // hooks import { Pencil, Trash2 } from "lucide-react"; import { IEstimate } from "@plane/types"; import { Button, CustomMenu, TOAST_TYPE, setToast } from "@plane/ui"; import { orderArrayBy } from "@/helpers/array.helper"; import { useProject } from "@/hooks/store"; // ui //icons // helpers // types type Props = { estimate: IEstimate; editEstimate: (estimate: IEstimate) => void; deleteEstimate: (estimateId: string) => void; }; export const EstimateListItem: React.FC = observer((props) => { const { estimate, editEstimate, deleteEstimate } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { currentProjectDetails, updateProject } = useProject(); const handleUseEstimate = async () => { if (!workspaceSlug || !projectId) return; await updateProject(workspaceSlug.toString(), projectId.toString(), { estimate: estimate.id, }).catch((err) => { const error = err?.error; const errorString = Array.isArray(error) ? error[0] : error; setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: errorString ?? "Estimate points could not be used. Please try again.", }); }); }; return ( <>
{estimate.name} {currentProjectDetails?.estimate && currentProjectDetails?.estimate === estimate.id && ( In use )}

{estimate.description}

{currentProjectDetails?.estimate !== estimate?.id && estimate?.points?.length > 0 && ( )} { editEstimate(estimate); }} >
Edit estimate
{currentProjectDetails?.estimate !== estimate.id && ( { deleteEstimate(estimate.id); }} >
Delete estimate
)}
{estimate?.points?.length > 0 ? (
Estimate points ( {orderArrayBy(estimate.points, "key").map((point, index) => (
{point.value} {index !== estimate.points.length - 1 && ","}{" "}
))}
)
) : (

No estimate points

)}
); });