import React, { Dispatch, SetStateAction, useState } from "react"; import { DraggableProvidedDragHandleProps, DraggableStateSnapshot } from "@hello-pangea/dnd"; import { useRouter } from "next/router"; import { X, Pencil } from "lucide-react"; import { IIssueLabel } from "@plane/types"; // hooks import { useLabel } from "@/hooks/store"; // types // components import { CreateUpdateLabelInline } from "./create-update-label-inline"; import { ICustomMenuItem, LabelItemBlock } from "./label-block/label-item-block"; type Props = { label: IIssueLabel; handleLabelDelete: (label: IIssueLabel) => void; draggableSnapshot: DraggableStateSnapshot; dragHandleProps: DraggableProvidedDragHandleProps; setIsUpdating: Dispatch>; isChild: boolean; }; export const ProjectSettingLabelItem: React.FC = (props) => { const { label, setIsUpdating, handleLabelDelete, draggableSnapshot, dragHandleProps, isChild } = props; const { combineTargetFor, isDragging } = draggableSnapshot; // states const [isEditLabelForm, setEditLabelForm] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // 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 (
{isEditLabelForm ? ( { setEditLabelForm(false); setIsUpdating(false); }} /> ) : ( )}
); };