"use client"; import { useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import useSWR from "swr"; // document-editor import { EditorRefApi, useEditorMarkings } from "@plane/document-editor"; // types import { TPage } from "@plane/types"; // ui import { TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui"; // components import { LogoSpinner } from "@/components/common"; import { PageHead } from "@/components/core"; import { IssuePeekOverview } from "@/components/issues"; import { PageEditorBody, PageEditorHeaderRoot } from "@/components/pages"; // helpers import { cn } from "@/helpers/common.helper"; // hooks import { usePage, useProjectPages } from "@/hooks/store"; const PageDetailsPage = observer(() => { // states const [sidePeekVisible, setSidePeekVisible] = useState(window.innerWidth >= 768 ? true : false); const [editorReady, setEditorReady] = useState(false); const [readOnlyEditorReady, setReadOnlyEditorReady] = useState(false); // refs const editorRef = useRef(null); const readOnlyEditorRef = useRef(null); // router const router = useRouter(); const { workspaceSlug, projectId, pageId } = useParams(); // store hooks const { createPage, getPageById } = useProjectPages(); const page = usePage(pageId?.toString() ?? ""); const { access, description_html, id, name } = page; // editor markings hook const { markings, updateMarkings } = useEditorMarkings(); // fetch page details const { error: pageDetailsError } = useSWR( pageId ? `PAGE_DETAILS_${pageId}` : null, pageId ? () => getPageById(pageId.toString()) : null, { revalidateIfStale: false, revalidateOnFocus: false, revalidateOnReconnect: false, } ); if ((!page || !id) && !pageDetailsError) return (
); if (pageDetailsError) return (

Page not found

The page you are trying to access doesn{"'"}t exist or you don{"'"}t have permission to view it.

View other Pages
); const handleCreatePage = async (payload: Partial) => await createPage(payload); const handleDuplicatePage = async () => { const formData: Partial = { name: "Copy of " + name, description_html: description_html ?? "

", access, }; await handleCreatePage(formData) .then((res) => router.push(`/${workspaceSlug}/projects/${projectId}/pages/${res?.id}`)) .catch(() => setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Page could not be duplicated. Please try again later.", }) ); }; return ( <>
{projectId && ( setSidePeekVisible(state)} /> )} setEditorReady(val)} readOnlyEditorRef={readOnlyEditorRef} handleReadOnlyEditorReady={() => setReadOnlyEditorReady(true)} markings={markings} page={page} sidePeekVisible={sidePeekVisible} updateMarkings={updateMarkings} />
); }); export default PageDetailsPage;