import React, { useRef, useState } from "react"; // swr import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // fetching keys import { CYCLE_ISSUES, PROJECT_ISSUES_LIST } from "constants/fetch-keys"; // services import issueServices from "lib/services/issues.service"; // hooks import useUser from "lib/hooks/useUser"; import useToast from "lib/hooks/useToast"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui import { Button } from "ui"; // types import type { IIssue, IssueResponse } from "types"; type Props = { isOpen: boolean; handleClose: () => void; data?: IIssue; }; const ConfirmIssueDeletion: React.FC = ({ isOpen, handleClose, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const { activeWorkspace, activeProject } = useUser(); const { setToastAlert } = useToast(); const cancelButtonRef = useRef(null); const onClose = () => { setIsDeleteLoading(false); handleClose(); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !activeWorkspace) return; const projectId = data.project; await issueServices .deleteIssue(activeWorkspace.slug, projectId, data.id) .then(() => { mutate( PROJECT_ISSUES_LIST(activeWorkspace.slug, projectId), (prevData) => { return { ...(prevData as IssueResponse), results: prevData?.results.filter((i) => i.id !== data.id) ?? [], count: (prevData?.count as number) - 1, }; }, false ); mutate(CYCLE_ISSUES(data.issue_cycle.id)); 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 {`"`} {activeProject?.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;