import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { Dialog, Transition } from "@headlessui/react"; import { AlertTriangle } from "lucide-react"; // ui import { Button, TOAST_TYPE, setToast } from "@plane/ui"; // constants import { PAGE_DELETED } from "constants/event-tracker"; // hooks import { useEventTracker, usePage } from "hooks/store"; import { useProjectPages } from "hooks/store/use-project-page"; // types 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.

); });