import React, { FC } from "react"; import { useRouter } from "next/router"; import { Dialog, Transition } from "@headlessui/react"; // hooks import { useApplication } from "hooks/store"; // components import { PageForm } from "./page-form"; // types import { IPage } from "@plane/types"; import { useProjectPages } from "hooks/store/use-project-page"; import { IPageStore } from "store/page.store"; type Props = { // data?: IPage | null; pageStore?: IPageStore; handleClose: () => void; isOpen: boolean; projectId: string; }; export const CreateUpdatePageModal: FC = (props) => { const { isOpen, handleClose, projectId, pageStore } = props; // router const router = useRouter(); const { workspaceSlug } = router.query; const { createPage } = useProjectPages(); // store hooks const { eventTracker: { postHogEventTracker }, } = useApplication(); const createProjectPage = async (payload: IPage) => { if (!workspaceSlug) return; await createPage(workspaceSlug.toString(), projectId, payload); }; const handleFormSubmit = async (formData: IPage) => { if (!workspaceSlug || !projectId) return; try { if (pageStore) { if (pageStore.name !== formData.name) { await pageStore.updateName(formData.name); } if (pageStore.access !== formData.access) { formData.access === 1 ? await pageStore.makePrivate() : await pageStore.makePublic(); } } else { await createProjectPage(formData); } handleClose(); } catch (error) { console.log(error); } }; return (
); };