import React, { useEffect, useRef, useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // fetching keys import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; import type { CycleIssueResponse, IIssue, IssueResponse, ModuleIssueResponse } from "types"; import { CYCLE_ISSUES, PROJECT_ISSUES_LIST, MODULE_ISSUES } from "constants/fetch-keys"; // services import issueServices from "services/issues.service"; // hooks import useToast from "hooks/use-toast"; // icons // ui import { Button } from "components/ui"; // types type Props = { isOpen: boolean; handleClose: () => void; data?: IIssue; }; const ConfirmIssueDeletion: React.FC = (props) => { const { isOpen, handleClose, data } = props; const cancelButtonRef = useRef(null); const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query; const { setToastAlert } = useToast(); useEffect(() => { setIsDeleteLoading(false); }, [isOpen]); const onClose = () => { setIsDeleteLoading(false); handleClose(); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !workspaceSlug) return; const projectId = data.project; await issueServices .deleteIssue(workspaceSlug as string, projectId, data.id) .then(() => { mutate( PROJECT_ISSUES_LIST(workspaceSlug as string, projectId), (prevData) => ({ ...(prevData as IssueResponse), results: prevData?.results.filter((i) => i.id !== data.id) ?? [], count: (prevData?.count as number) - 1, }), false ); const moduleId = data.issue_module?.module; const cycleId = data.issue_cycle?.cycle; if (moduleId) { mutate( MODULE_ISSUES(moduleId), (prevData) => prevData?.filter((i) => i.issue !== data.id), false ); } if (cycleId) { mutate( CYCLE_ISSUES(cycleId), (prevData) => prevData?.filter((i) => i.issue !== data.id), false ); } setToastAlert({ title: "Success", type: "success", message: "Issue deleted successfully", }); handleClose(); }) .catch((error) => { console.log(error); setIsDeleteLoading(false); }); }; return (
Are you sure you want to delete {`"`} {data?.project_detail.identifier}-{data?.sequence_id} - {data?.name}?{`"`}

All of the data related to the issue will be permanently removed. This action cannot be undone.

); }; export default ConfirmIssueDeletion;