import React, { useEffect, useRef, useState } from "react"; // swr import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // fetching keys import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; // services import issueServices from "lib/services/issues.services"; // 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 } = 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 ); setToastAlert({ title: "Success", type: "success", message: "Issue deleted successfully", }); handleClose(); }) .catch((error) => { console.log(error); setIsDeleteLoading(false); }); }; return (
Delete Issue

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

); }; export default ConfirmIssueDeletion;