import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { Dialog, Transition } from "@headlessui/react"; // hooks import { AlertTriangle } from "lucide-react"; import { Button, TOAST_TYPE, setToast } from "@plane/ui"; import { useEventTracker, useLabel } from "hooks/store"; // icons // ui // types import type { IIssueLabel } from "@plane/types"; // constants import { LABEL_DELETED, LABEL_GROUP_DELETED } from "constants/event-tracker"; type Props = { isOpen: boolean; onClose: () => void; data: IIssueLabel | null; }; export const DeleteLabelModal: React.FC = observer((props) => { const { isOpen, onClose, data } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { deleteLabel, projectLabelsTree } = useLabel(); const { captureEvent } = useEventTracker(); // states const [isDeleteLoading, setIsDeleteLoading] = useState(false); const handleClose = () => { onClose(); setIsDeleteLoading(false); }; const handleDeletion = async () => { if (!workspaceSlug || !projectId || !data) return; setIsDeleteLoading(true); await deleteLabel(workspaceSlug.toString(), projectId.toString(), data.id) .then(() => { const labelChildCount = projectLabelsTree?.find((label) => label.id === data.id)?.children?.length || 0; if (labelChildCount > 0) { captureEvent(LABEL_GROUP_DELETED, { group_id: data.id, children_count: labelChildCount, element: "Project settings labels page", state: "SUCCESS", }); } else { captureEvent(LABEL_DELETED, { label_id: data.id, element: "Project settings labels page", state: "SUCCESS", }); } handleClose(); }) .catch((err) => { setIsDeleteLoading(false); const error = err?.error || "Label could not be deleted. Please try again."; setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: error, }); }); }; return (
Delete Label

Are you sure you want to delete label-{" "} {data?.name}? The label will be removed from all the issues.

); });