import React, { useRef, useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import viewsService from "services/views.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Button } from "components/ui"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // types import type { IView } from "types"; // fetch-keys import { VIEWS_LIST } from "constants/fetch-keys"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: IView; }; export const DeleteViewModal: React.FC = ({ isOpen, setIsOpen, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { setToastAlert } = useToast(); const cancelButtonRef = useRef(null); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!workspaceSlug || !data) return; await viewsService .deleteView(projectId as string, data.id) .then(() => { mutate(VIEWS_LIST(projectId as string)); router.push(`/${workspaceSlug}/projects/${projectId}/issues`); handleClose(); setToastAlert({ type: "success", title: "Success!", message: "View deleted successfully.", }); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "View could not be deleted. Please try again.", }); setIsDeleteLoading(false); }); }; return (
Delete View

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

); };