import { FC, useEffect, useRef, useState } from "react"; import { observer } from "mobx-react"; import { GripVertical, Pencil, Trash2 } from "lucide-react"; import { TEstimatePointsObject, TEstimateSystemKeys } from "@plane/types"; // components import { EstimatePointUpdate, EstimatePointDelete } from "@/components/estimates/points"; // plane web constants import { estimateCount } from "@/plane-web/constants/estimates"; type TEstimatePointItemPreview = { workspaceSlug: string; projectId: string; estimateId: string | undefined; estimateType: TEstimateSystemKeys; estimatePointId: string | undefined; estimatePoint: TEstimatePointsObject; estimatePoints: TEstimatePointsObject[]; handleEstimatePointValueUpdate?: (estimateValue: string) => void; handleEstimatePointValueRemove?: () => void; }; export const EstimatePointItemPreview: FC = observer((props) => { const { workspaceSlug, projectId, estimateId, estimateType, estimatePointId, estimatePoint, estimatePoints, handleEstimatePointValueUpdate, handleEstimatePointValueRemove, } = props; // state const [estimatePointEditToggle, setEstimatePointEditToggle] = useState(false); const [estimatePointDeleteToggle, setEstimatePointDeleteToggle] = useState(false); // ref const EstimatePointValueRef = useRef(null); useEffect(() => { if (!estimatePointEditToggle && !estimatePointDeleteToggle) EstimatePointValueRef?.current?.addEventListener("dblclick", () => setEstimatePointEditToggle(true)); }, [estimatePointDeleteToggle, estimatePointEditToggle]); return (
{!estimatePointEditToggle && !estimatePointDeleteToggle && (
{estimatePoint?.value ? ( `${estimatePoint?.value}` ) : ( Enter estimate point )}
setEstimatePointEditToggle(true)} >
{estimatePoints.length > estimateCount.min && (
estimateId && estimatePointId ? setEstimatePointDeleteToggle(true) : handleEstimatePointValueRemove && handleEstimatePointValueRemove() } >
)}
)} {estimatePoint && estimatePointEditToggle && ( handleEstimatePointValueUpdate && handleEstimatePointValueUpdate(estimatePointValue) } closeCallBack={() => setEstimatePointEditToggle(false)} /> )} {estimateId && estimatePointId && estimatePointDeleteToggle && ( estimateId && setEstimatePointDeleteToggle(false)} /> )}
); });