import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import { PageService } from "services/page.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Button } from "@plane/ui"; // icons import { AlertTriangle } from "lucide-react"; // types import type { IUser, IPage } from "types"; // fetch-keys import { ALL_PAGES_LIST, FAVORITE_PAGES_LIST, MY_PAGES_LIST, RECENT_PAGES_LIST } from "constants/fetch-keys"; type TConfirmPageDeletionProps = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: IPage | null; user: IUser | undefined; }; // services const pageService = new PageService(); export const DeletePageModal: React.FC = ({ isOpen, setIsOpen, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { setToastAlert } = useToast(); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !workspaceSlug || !projectId) return; await pageService .deletePage(workspaceSlug as string, data.project, data.id) .then(() => { mutate(RECENT_PAGES_LIST(projectId as string)); mutate( MY_PAGES_LIST(projectId as string), (prevData) => (prevData ?? []).filter((page) => page.id !== data?.id), false ); mutate( ALL_PAGES_LIST(projectId as string), (prevData) => (prevData ?? []).filter((page) => page.id !== data?.id), false ); mutate( FAVORITE_PAGES_LIST(projectId as string), (prevData) => (prevData ?? []).filter((page) => page.id !== data?.id), false ); 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(() => { setIsDeleteLoading(false); }); }; return (
Delete Page

Are you sure you want to delete Page-{" "} {data?.name}? All of the data related to the page will be permanently removed. This action cannot be undone.

); };