diff --git a/apps/app/components/pages/create-update-page-modal.tsx b/apps/app/components/pages/create-update-page-modal.tsx index 092e5430c..18b2c9b34 100644 --- a/apps/app/components/pages/create-update-page-modal.tsx +++ b/apps/app/components/pages/create-update-page-modal.tsx @@ -15,7 +15,12 @@ import { PageForm } from "./page-form"; // types import { IPage } from "types"; // fetch-keys -import { RECENT_PAGES_LIST } from "constants/fetch-keys"; +import { + ALL_PAGES_LIST, + FAVORITE_PAGES_LIST, + MY_PAGES_LIST, + RECENT_PAGES_LIST, +} from "constants/fetch-keys"; type Props = { isOpen: boolean; @@ -36,8 +41,18 @@ export const CreateUpdatePageModal: React.FC = ({ isOpen, handleClose, da const createPage = async (payload: IPage) => { await pagesService .createPage(workspaceSlug as string, projectId as string, payload) - .then(() => { + .then((res) => { mutate(RECENT_PAGES_LIST(projectId as string)); + mutate( + MY_PAGES_LIST(projectId as string), + (prevData) => [res, ...(prevData as IPage[])], + false + ); + mutate( + ALL_PAGES_LIST(projectId as string), + (prevData) => [res, ...(prevData as IPage[])], + false + ); onClose(); setToastAlert({ @@ -58,8 +73,38 @@ export const CreateUpdatePageModal: React.FC = ({ isOpen, handleClose, da const updatePage = async (payload: IPage) => { await pagesService .patchPage(workspaceSlug as string, projectId as string, data?.id ?? "", payload) - .then(() => { + .then((res) => { mutate(RECENT_PAGES_LIST(projectId as string)); + mutate( + FAVORITE_PAGES_LIST(projectId as string), + (prevData) => + (prevData ?? []).map((p) => { + if (p.id === res.id) return { ...p, ...res }; + + return p; + }), + false + ); + mutate( + MY_PAGES_LIST(projectId as string), + (prevData) => + (prevData ?? []).map((p) => { + if (p.id === res.id) return { ...p, ...res }; + + return p; + }), + false + ); + mutate( + ALL_PAGES_LIST(projectId as string), + (prevData) => + (prevData ?? []).map((p) => { + if (p.id === res.id) return { ...p, ...res }; + + return p; + }), + false + ); onClose(); setToastAlert({ diff --git a/apps/app/components/pages/index.ts b/apps/app/components/pages/index.ts index 99c3700e0..d2707db89 100644 --- a/apps/app/components/pages/index.ts +++ b/apps/app/components/pages/index.ts @@ -1,12 +1,8 @@ -export * from "./all-pages-list"; +export * from "./pages-list"; export * from "./create-update-page-modal"; export * from "./delete-page-modal"; -export * from "./favorite-pages-list"; -export * from "./my-pages-list"; -export * from "./other-pages-list"; export * from "./page-form"; export * from "./pages-view"; -export * from "./recent-pages-list"; export * from "./single-page-block"; export * from "./single-page-detailed-item"; export * from "./single-page-list-item"; diff --git a/apps/app/components/pages/page-form.tsx b/apps/app/components/pages/page-form.tsx index 377d35e8c..8888a861d 100644 --- a/apps/app/components/pages/page-form.tsx +++ b/apps/app/components/pages/page-form.tsx @@ -1,7 +1,11 @@ import { useEffect } from "react"; -import { useForm } from "react-hook-form"; + +import dynamic from "next/dynamic"; + +// react-hook-form +import { Controller, useForm } from "react-hook-form"; // ui -import { Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; +import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui"; // types import { IPage } from "types"; @@ -12,6 +16,16 @@ type Props = { data?: IPage | null; }; +// rich-text-editor +const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { + ssr: false, + loading: () => ( + + + + ), +}); + const defaultValues = { name: "", description: "", @@ -23,6 +37,8 @@ export const PageForm: React.FC = ({ handleFormSubmit, handleClose, statu formState: { errors, isSubmitting }, handleSubmit, reset, + control, + setValue, } = useForm({ defaultValues, }); @@ -68,16 +84,20 @@ export const PageForm: React.FC = ({ handleFormSubmit, handleClose, statu }} /> -
-