import "@/features/editor/styles/index.css"; import { useEffect, useState } from "react"; import { useParams, useSearchParams } from "react-router-dom"; import ReadonlyPageEditor from "@/features/editor/readonly-page-editor"; import { Container } from "@mantine/core"; type PdfRenderData = { pageId: string; title: string; content: any; }; export default function PdfRenderPage() { const { pageId } = useParams<{ pageId: string }>(); const [searchParams] = useSearchParams(); const token = searchParams.get("token"); const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (!pageId || !token) { setError("Missing page ID or token"); return; } fetch('/api/pdf-export/render', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ pageId, token }), }) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); }) .then((result) => setData(result.data)) .catch((err) => setError(err.message)); }, [pageId, token]); useEffect(() => { if (data?.title) { document.title = data.title; } }, [data?.title]); if (error) { return
{error}
; } if (!data) { return null; } return ( ); }