import { FC, useEffect, useState } from "react"; import { observer } from "mobx-react"; import { Check, Info, X } from "lucide-react"; import { TEstimatePointsObject, TEstimateSystemKeys } from "@plane/types"; import { Tooltip } from "@plane/ui"; // constants import { EEstimateSystem } from "@/constants/estimates"; // helpers import { cn } from "@/helpers/common.helper"; type TEstimatePointItemCreateUpdate = { estimateType: TEstimateSystemKeys; estimatePoint: TEstimatePointsObject; updateEstimateValue: (value: string) => void; callback: () => void; }; export const EstimatePointItemCreateUpdate: FC = observer((props) => { const { estimateType, estimatePoint, updateEstimateValue, callback } = props; // states const [estimateInputValue, setEstimateInputValue] = useState(undefined); const [error, setError] = useState(undefined); useEffect(() => { if (estimateInputValue === undefined && estimatePoint) setEstimateInputValue(estimatePoint?.value || ""); }, [estimateInputValue, estimatePoint]); const handleClose = () => { setEstimateInputValue(""); callback(); }; const handleCreate = async () => { if (!estimatePoint) return; if (estimateInputValue) try { setError(undefined); const currentEstimateType: EEstimateSystem | undefined = estimateType; let isEstimateValid = false; if (currentEstimateType && [(EEstimateSystem.TIME, EEstimateSystem.POINTS)].includes(currentEstimateType)) { if (estimateInputValue && Number(estimateInputValue) && Number(estimateInputValue) >= 0) { isEstimateValid = true; } } else if (currentEstimateType && currentEstimateType === EEstimateSystem.CATEGORIES) { if (estimateInputValue && estimateInputValue.length > 0) { isEstimateValid = true; } } if (isEstimateValid) { updateEstimateValue(estimateInputValue); setError(undefined); handleClose(); } else { setError("please enter a valid estimate value"); } } catch { setError("something went wrong. please try again later"); } else { setError("Please fill the input field"); } }; return (
setEstimateInputValue(e.target.value)} className="border-none focus:ring-0 focus:border-0 focus:outline-none p-2.5 w-full bg-transparent" placeholder="Enter estimate point" autoFocus /> {error && ( <>
)}
); });