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 { useEventTracker, usePage } from "hooks/store"; // ui import { Button, TOAST_TYPE, setToast } from "@plane/ui"; // types import { useProjectPages } from "hooks/store/use-project-page"; // constants import { PAGE_DELETED } from "constants/event-tracker"; 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 { capturePageEvent } = useEventTracker(); const pageStore = usePage(pageId); 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(() => { capturePageEvent({ eventName: PAGE_DELETED, payload: { ...pageStore, state: "SUCCESS", }, }); handleClose(); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Page deleted successfully.", }); }) .catch(() => { capturePageEvent({ eventName: PAGE_DELETED, payload: { ...pageStore, state: "FAILED", }, }); setToast({ type: TOAST_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.

); });