import React, { useState } from "react"; // next import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // headless ui import { Dialog, Transition } from "@headlessui/react"; // services import pagesService from "services/pages.service"; // hooks import useToast from "hooks/use-toast"; // ui import { DangerButton, SecondaryButton } from "components/ui"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // types import type { IPage } from "types"; type TConfirmPageDeletionProps = { isOpen: boolean; setIsOpen: React.Dispatch>; data?: IPage; }; // fetch-keys import { PAGE_LIST } from "constants/fetch-keys"; export const DeletePageModal: React.FC = ({ isOpen, setIsOpen, data, }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); const router = useRouter(); const { workspaceSlug } = router.query; const { setToastAlert } = useToast(); const handleClose = () => { setIsOpen(false); setIsDeleteLoading(false); }; const handleDeletion = async () => { setIsDeleteLoading(true); if (!data || !workspaceSlug) return; await pagesService .deletePage(workspaceSlug as string, data.project, data.id) .then(() => { mutate( PAGE_LIST(data.project), (prevData) => prevData?.filter((page) => page.id !== data?.id), false ); handleClose(); setToastAlert({ title: "Success", type: "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.

Cancel {isDeleteLoading ? "Deleting..." : "Delete"}
); };