import React, { useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Dialog, Transition } from "@headlessui/react"; import { AlertTriangle } from "lucide-react"; // hooks import { usePage } from "hooks/store"; import useToast from "hooks/use-toast"; // ui import { Button } from "@plane/ui"; // types import { useProjectPages } from "hooks/store/use-project-page"; type TConfirmPageDeletionProps = { pageId: string; isOpen: boolean; onClose: () => void; }; export const DeletePageModal: React.FC = observer((props) => { const { pageId, isOpen, onClose } = props; // states const [isDeleting, setIsDeleting] = useState(false); // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store hooks const { deletePage } = useProjectPages(); const pageStore = usePage(pageId); // toast alert const { setToastAlert } = useToast(); if (!pageStore) return null; const { name } = pageStore; const handleClose = () => { setIsDeleting(false); onClose(); }; const handleDelete = async () => { if (!pageId || !workspaceSlug || !projectId) return; setIsDeleting(true); // Delete Page will only delete the page from the archive page map, at this point only archived pages can be deleted await deletePage(workspaceSlug.toString(), projectId as string, pageId) .then(() => { handleClose(); setToastAlert({ type: "success", title: "Success!", message: "Page deleted successfully.", }); }) .catch(() => { setToastAlert({ type: "error", title: "Error!", message: "Page could not be deleted. Please try again.", }); }) .finally(() => { setIsDeleting(false); }); }; return (
Delete Page

Are you sure you want to delete page-{" "} {name}? The Page will be deleted permanently. This action cannot be undone.

); });