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 { EstimatePointItemCreateUpdate } from "@/components/estimates/points"; type TEstimatePointItemCreatePreview = { estimateType: TEstimateSystemKeys; estimatePoint: TEstimatePointsObject; handleEstimatePoint: (mode: "add" | "remove" | "update", value: TEstimatePointsObject) => void; }; export const EstimatePointItemCreatePreview: FC = observer((props) => { const { estimateType, estimatePoint, handleEstimatePoint } = props; // state const [estimatePointEditToggle, setEstimatePointEditToggle] = useState(false); // ref const EstimatePointValueRef = useRef(null); useEffect(() => { if (!estimatePointEditToggle) EstimatePointValueRef?.current?.addEventListener("dblclick", () => setEstimatePointEditToggle(true)); }, [estimatePointEditToggle]); return (
{!estimatePointEditToggle && (
{estimatePoint?.value ? ( estimatePoint?.value ) : ( Enter estimate point )}
setEstimatePointEditToggle(true)} >
handleEstimatePoint("remove", estimatePoint)} >
)} {estimatePoint && estimatePointEditToggle && ( handleEstimatePoint("update", { ...estimatePoint, value })} callback={() => setEstimatePointEditToggle(false)} /> )}
); });