import React, { useState } from "react"; import { useRouter } from "next/router"; import { Dialog, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; // hooks import { useApplication, useModule } from "hooks/store"; import useToast from "hooks/use-toast"; // ui import { Button } from "@plane/ui"; // icons import { AlertTriangle } from "lucide-react"; // types import type { IModule } from "@plane/types"; type Props = { data: IModule; isOpen: boolean; onClose: () => void; }; export const DeleteModuleModal: React.FC = observer((props) => { const { data, isOpen, onClose } = props; // states const [isDeleteLoading, setIsDeleteLoading] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId, moduleId, peekModule } = router.query; // store hooks const { eventTracker: { postHogEventTracker }, } = useApplication(); const { deleteModule } = useModule(); // toast alert const { setToastAlert } = useToast(); const handleClose = () => { onClose(); setIsDeleteLoading(false); }; const handleDeletion = async () => { if (!workspaceSlug || !projectId) return; setIsDeleteLoading(true); await deleteModule(workspaceSlug.toString(), projectId.toString(), data.id) .then(() => { if (moduleId || peekModule) router.push(`/${workspaceSlug}/projects/${data.project}/modules`); handleClose(); setToastAlert({ type: "success", title: "Success!", message: "Module deleted successfully.", }); postHogEventTracker("MODULE_DELETED", { state: "SUCCESS", }); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Module could not be deleted. Please try again.", }); postHogEventTracker("MODULE_DELETED", { state: "FAILED", }); }) .finally(() => { setIsDeleteLoading(false); }); }; 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.

); });