import React, { Dispatch, SetStateAction, useState } from "react"; import { useParams } from "next/navigation"; import { X, Pencil } from "lucide-react"; // types import { IIssueLabel } from "@plane/types"; // hooks import { useLabel } from "@/hooks/store"; // components import { CreateUpdateLabelInline } from "./create-update-label-inline"; import { ICustomMenuItem, LabelItemBlock } from "./label-block/label-item-block"; import { LabelDndHOC } from "./label-drag-n-drop-HOC"; type Props = { label: IIssueLabel; handleLabelDelete: (label: IIssueLabel) => void; setIsUpdating: Dispatch>; isParentDragging?: boolean; isChild: boolean; isLastChild: boolean; onDrop: ( draggingLabelId: string, droppedParentId: string | null, droppedLabelId: string | undefined, dropAtEndOfList: boolean ) => void; }; export const ProjectSettingLabelItem: React.FC = (props) => { const { label, setIsUpdating, handleLabelDelete, isChild, isLastChild, isParentDragging = false, onDrop } = props; // states const [isEditLabelForm, setEditLabelForm] = useState(false); // router const { workspaceSlug, projectId } = useParams(); // store hooks const { updateLabel } = useLabel(); const removeFromGroup = (label: IIssueLabel) => { if (!workspaceSlug || !projectId) return; updateLabel(workspaceSlug.toString(), projectId.toString(), label.id, { parent: null, }); }; const customMenuItems: ICustomMenuItem[] = [ { CustomIcon: X, onClick: removeFromGroup, isVisible: !!label.parent, text: "Remove from group", key: "remove_from_group", }, { CustomIcon: Pencil, onClick: () => { setEditLabelForm(true); setIsUpdating(true); }, isVisible: true, text: "Edit label", key: "edit_label", }, ]; return ( {(isDragging, isDroppingInLabel, dragHandleRef) => (
{isEditLabelForm ? ( { setEditLabelForm(false); setIsUpdating(false); }} /> ) : ( )}
)}
); };