import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // icons import { AlertTriangle } from "lucide-react"; // services import { IssueLabelService } from "services/issue"; // hooks import useToast from "hooks/use-toast"; // ui import { Button } from "@plane/ui"; // types import type { IUser, IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; type Props = { isOpen: boolean; onClose: () => void; data: IIssueLabels | null; user: IUser | undefined; }; // services const issueLabelService = new IssueLabelService(); export const DeleteLabelModal: React.FC = ({ isOpen, onClose, data, user }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { setToastAlert } = useToast(); const handleClose = () => { onClose(); setIsDeleteLoading(false); }; const handleDeletion = async () => { if (!workspaceSlug || !projectId || !data) return; setIsDeleteLoading(true); mutate( PROJECT_ISSUE_LABELS(projectId.toString()), (prevData) => (prevData ?? []).filter((p) => p.id !== data.id), false ); await issueLabelService .deleteIssueLabel(workspaceSlug.toString(), projectId.toString(), data.id, user) .then(() => handleClose()) .catch(() => { setIsDeleteLoading(false); mutate(PROJECT_ISSUE_LABELS(projectId.toString())); setToastAlert({ type: "error", title: "Error!", message: "Label could not be deleted. Please try again.", }); }); }; return (
Delete Label

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

); };