import React from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; // hooks import { useProject } from "hooks/store"; import useToast from "hooks/use-toast"; // ui import { Button, CustomMenu } from "@plane/ui"; //icons import { Pencil, Trash2 } from "lucide-react"; // helpers import { orderArrayBy } from "helpers/array.helper"; // types import { IEstimate } from "@plane/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(); // hooks const { setToastAlert } = useToast(); 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; setToastAlert({ 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

)}
); });