import { FC, Fragment, useEffect, useRef, useState } from "react"; import { Check, GripVertical, MoveRight, Pencil, Trash2, X } from "lucide-react"; import { Select } from "@headlessui/react"; import { TEstimatePointsObject } from "@plane/types"; import { Draggable } from "@plane/ui"; // constants import { EEstimateUpdateStages } from "@/constants/estimates"; // components import { InlineEdit } from "./inline-editable"; type TEstimatePointItem = { mode: EEstimateUpdateStages; item: TEstimatePointsObject; editItem: (value: string) => void; deleteItem: () => void; }; const EstimatePointItem: FC = (props) => { // props const { mode, item, editItem, deleteItem } = props; const { id, key, value } = item; // ref const inputRef = useRef(null); // states const [inputValue, setInputValue] = useState(undefined); const [isEditing, setIsEditing] = useState(false); const [showDeleteUI, setShowDeleteUI] = useState(false); useEffect(() => { if (inputValue === undefined) setInputValue(value); }, [value, inputValue]); const handleSave = () => { if (id) { // Make the api call to save the estimate point // Show a spinner setIsEditing(false); } }; const handleEdit = (value: string) => { if (id) { setIsEditing(true); setTimeout(() => { inputRef.current?.focus(); inputRef.current?.select(); }); } else { setInputValue(value); editItem(value); } }; const handleDelete = () => { if (id) { setShowDeleteUI(true); } else { deleteItem(); } }; return ( {mode === EEstimateUpdateStages.CREATE && (
handleEdit(e.target.value)} className="flex-grow border-none bg-transparent focus:ring-0 focus:border-0 focus:outline-none py-2.5" />
)} {mode === EEstimateUpdateStages.EDIT && ( <>
setInputValue(e.target.value)} className="flex-grow border-none bg-transparent focus:ring-0 focus:border-0 focus:outline-none py-2.5" />
)} {mode === EEstimateUpdateStages.SWITCH && (
setInputValue(e.target.value)} className="flex-grow border-none bg-transparent focus:ring-0 focus:border-0 focus:outline-none py-2.5" />
)} {/*
{}} className="flex-grow border-none bg-transparent focus:ring-0 focus:border-0 focus:outline-none py-2.5" />
*/} {/* {isEditing && (
{}} className="border rounded-md border-custom-border-300 p-3 flex-grow" ref={inputRef} />
setIsEditing(false)} />
)} {!isEditing && (
{!showDeleteUI ? : value} {showDeleteUI && ( setShowDeleteUI(false)} /> )}
{!showDeleteUI && }
)} */}
); }; export { EstimatePointItem };