import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; import useUser from "hooks/use-user"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import issueServices from "services/issues.service"; // hooks import useIssuesView from "hooks/use-issues-view"; import useToast from "hooks/use-toast"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui import { SecondaryButton, DangerButton } from "components/ui"; // types import type { IIssue } from "types"; // fetch-keys import { PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS } from "constants/fetch-keys"; type Props = { isOpen: boolean; handleClose: () => void; data: IIssue | null; onSubmit?: () => Promise | void; }; export const DeleteDraftIssueModal: React.FC = (props) => { const { isOpen, handleClose, data, onSubmit } = props; const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { params } = useIssuesView(); const { setToastAlert } = useToast(); const { user } = useUser(); useEffect(() => { setIsDeleteLoading(false); }, [isOpen]); const onClose = () => { setIsDeleteLoading(false); handleClose(); }; const handleDeletion = async () => { if (!workspaceSlug || !data || !user) return; setIsDeleteLoading(true); await issueServices .deleteDraftIssue(workspaceSlug as string, data.project, data.id, user) .then(() => { setIsDeleteLoading(false); handleClose(); mutate(PROJECT_DRAFT_ISSUES_LIST_WITH_PARAMS(projectId as string, params)); setToastAlert({ title: "Success", message: "Draft Issue deleted successfully", type: "success", }); }) .catch((error) => { console.log(error); handleClose(); setToastAlert({ title: "Error", message: "Something went wrong", type: "error", }); setIsDeleteLoading(false); }); if (onSubmit) await onSubmit(); }; return (

Delete Draft Issue

Are you sure you want to delete issue{" "} {data?.project_detail.identifier}-{data?.sequence_id} {""}? All of the data related to the draft issue will be permanently removed. This action cannot be undone.

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