import React, { useEffect, useRef, useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import modulesService from "services/modules.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 { IModule } from "types"; // fetch-keys import { MODULE_LIST } from "constants/fetch-keys"; type Props = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: IModule; }; const ConfirmModuleDeletion: React.FC = ({ isOpen, setIsOpen, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { query: { workspaceSlug }, } = router; const { setToastAlert } = useToast(); const cancelButtonRef = useRef(null); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!workspaceSlug || !data) return; await modulesService .deleteModule(workspaceSlug as string, data.project, data.id) .then(() => { mutate(MODULE_LIST(data.project)); router.push(`/${workspaceSlug}/projects/${data.project}/modules`); handleClose(); setToastAlert({ title: "Success", type: "success", message: "Module deleted successfully", }); }) .catch((error) => { console.log(error); setIsDeleteLoading(false); }); }; useEffect(() => { data && setIsOpen(true); }, [data, setIsOpen]); return (
Delete Module

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

); }; export default ConfirmModuleDeletion;