import { useDeletedPagesQuery, useRestorePageMutation, useDeletePageMutation } from "@/features/page/queries/page-query.ts"; import { modals } from "@mantine/modals"; import { ActionIcon, Menu, Table, Text } from "@mantine/core"; import { IconDots } from "@tabler/icons-react"; interface RecycledPagesProps { spaceId: string; readOnly?: boolean; } export default function RecycledPagesList({ spaceId, readOnly, }: RecycledPagesProps) { const { data, isLoading } = useDeletedPagesQuery(spaceId); const restorePageMutation = useRestorePageMutation(); const removePageMutation = useDeletePageMutation(); const handleRestorePage = async (pageId: string) => { await restorePageMutation.mutateAsync(pageId); }; const handleRemovePage = async (pageId: string) => { await removePageMutation.mutateAsync(pageId); }; const openRemovePageModal = (pageId: string) => modals.openConfirmModal({ title: "Delete page permanently", children: ( Are you sure you want to permanently delete this page ? ), centered: true, labels: { confirm: "Delete", cancel: "Cancel" }, confirmProps: { color: "red" }, onConfirm: () => handleRemovePage(pageId), }); const openRestorePageModal = (pageId: string) => modals.openConfirmModal({ title: "Restore page", children: ( "Restore this page ?" ), centered: true, labels: { confirm: "Restore", cancel: "Cancel" }, confirmProps: { color: "blue" }, onConfirm: () => handleRestorePage(pageId) }) return ( <> {data && data.items.length > 0 ? ( Deleted Pages {data?.items.map((page) => (
{page?.title || "Untitled"}
{!readOnly && ( openRestorePageModal(page.id) }> Restore Page openRemovePageModal(page.id) }> Delete Page permanently )}
))}
) : ( No deleted pages )} ); }