import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // services import issuesService from "services/issues.service"; // hooks import useToast from "hooks/use-toast"; // ui import { DangerButton, SecondaryButton } from "components/ui"; // types import type { ICurrentUserResponse, IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; type Props = { isOpen: boolean; onClose: () => void; data: IIssueLabels | null; user: ICurrentUserResponse | undefined; }; 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 issuesService .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.

Cancel {isDeleteLoading ? "Deleting..." : "Delete"}
); };