// react import React, { useEffect, useRef, useState } from "react"; // next import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // services import modulesService from "lib/services/modules.service"; // hooks import useUser from "lib/hooks/useUser"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // ui import { Button } from "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 { activeWorkspace } = useUser(); const router = useRouter(); const cancelButtonRef = useRef(null); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!activeWorkspace || !data) return; await modulesService .deleteModule(activeWorkspace.slug, data.project, data.id) .then(() => { mutate(MODULE_LIST(data.project)); router.push(`/projects/${data.project}/modules`); handleClose(); }) .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;