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 { IssueDraftService } from "services/issue"; // hooks import useIssuesView from "hooks/use-issues-view"; import useToast from "hooks/use-toast"; // icons import { AlertTriangle } from "lucide-react"; // ui import { Button } from "@plane/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; }; const issueDraftService = new IssueDraftService(); 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 issueDraftService .deleteDraftIssue(workspaceSlug as string, data.project, data.id) .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.

); };