import { FC, useEffect, useRef, useState } from "react"; import { observer } from "mobx-react"; import { GripVertical, Pencil, Trash2 } from "lucide-react"; // components import { EstimatePointUpdate, EstimatePointDelete } from "@/components/estimates/points"; // hooks import { useEstimatePoint } from "@/hooks/store"; type TEstimatePointItemPreview = { workspaceSlug: string; projectId: string; estimateId: string; estimatePointId: string; }; export const EstimatePointItemPreview: FC = observer((props) => { const { workspaceSlug, projectId, estimateId, estimatePointId } = props; // hooks const { asJson: estimatePoint } = useEstimatePoint(estimateId, estimatePointId); // 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]); if (!estimatePoint?.id) return <>; return (
{!estimatePointEditToggle && !estimatePointDeleteToggle && (
{estimatePoint?.value}
setEstimatePointEditToggle(true)} >
setEstimatePointDeleteToggle(true)} >
)} {estimatePoint && estimatePointEditToggle && ( setEstimatePointEditToggle(false)} /> )} {estimatePoint && estimatePointDeleteToggle && ( setEstimatePointDeleteToggle(false)} /> )}
); });