diff --git a/examples/preview/next-app/.env.example b/examples/draft-preview/next-app/.env.example similarity index 100% rename from examples/preview/next-app/.env.example rename to examples/draft-preview/next-app/.env.example diff --git a/examples/preview/next-app/.eslintrc.js b/examples/draft-preview/next-app/.eslintrc.js similarity index 100% rename from examples/preview/next-app/.eslintrc.js rename to examples/draft-preview/next-app/.eslintrc.js diff --git a/examples/preview/next-app/.gitignore b/examples/draft-preview/next-app/.gitignore similarity index 100% rename from examples/preview/next-app/.gitignore rename to examples/draft-preview/next-app/.gitignore diff --git a/examples/preview/cms/.prettierrc.js b/examples/draft-preview/next-app/.prettierrc.js similarity index 100% rename from examples/preview/cms/.prettierrc.js rename to examples/draft-preview/next-app/.prettierrc.js diff --git a/examples/preview/next-app/README.md b/examples/draft-preview/next-app/README.md similarity index 72% rename from examples/preview/next-app/README.md rename to examples/draft-preview/next-app/README.md index df0e45c294..b4d9b169e6 100644 --- a/examples/preview/next-app/README.md +++ b/examples/draft-preview/next-app/README.md @@ -1,14 +1,14 @@ -# Payload Preview Example Front-End +# Payload Draft Preview Example Front-End -This is a [Next.js](https://nextjs.org) app using the [App Router](https://nextjs.org/docs/app). It was made explicitly for Payload's [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms). +This is a [Next.js](https://nextjs.org) app using the [App Router](https://nextjs.org/docs/app). It was made explicitly for Payload's [Draft Preview Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview). -> This example uses the App Router, the latest API of Next.js. If your app is using the legacy [Pages Router](https://nextjs.org/docs/pages), check out the official [Pages Router Example](https://github.com/payloadcms/payload/tree/master/examples/preview/next-pages). +> This example uses the App Router, the latest API of Next.js. If your app is using the legacy [Pages Router](https://nextjs.org/docs/pages), check out the official [Pages Router Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/next-pages). ## Getting Started ### Payload -First you'll need a running [Payload](https://github.com/payloadcms/payload) app. If you have not done so already, open up the `cms` folder and follow the setup instructions. Take note of your `serverURL`, you'll need this in the next step. +First you'll need a running Payload app. There is one made explicitly for this example and [can be found here](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/payload). If you have not done so already, clone it down and follow the setup instructions there. This will provide all the necessary APIs that your Next.js app requires for authentication. ### Next.js @@ -18,7 +18,7 @@ First you'll need a running [Payload](https://github.com/payloadcms/payload) app 4. `yarn dev` or `npm run dev` to start the server 5. `open http://localhost:3001` to see the result -Once running you will find a couple seeded pages on your local environment with some basic instructions. You can also start editing the pages by modifying the documents within Payload. See the [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms) for full details. +Once running you will find a couple seeded pages on your local environment with some basic instructions. You can also start editing the pages by modifying the documents within Payload. See the [Draft Preview Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/payload) for full details. ## Learn More diff --git a/examples/preview/next-app/app/[slug]/index.module.scss b/examples/draft-preview/next-app/app/[slug]/index.module.scss similarity index 100% rename from examples/preview/next-app/app/[slug]/index.module.scss rename to examples/draft-preview/next-app/app/[slug]/index.module.scss diff --git a/examples/preview/next-app/app/[slug]/page.tsx b/examples/draft-preview/next-app/app/[slug]/page.tsx similarity index 91% rename from examples/preview/next-app/app/[slug]/page.tsx rename to examples/draft-preview/next-app/app/[slug]/page.tsx index deb9b700d5..9183186839 100644 --- a/examples/preview/next-app/app/[slug]/page.tsx +++ b/examples/draft-preview/next-app/app/[slug]/page.tsx @@ -2,9 +2,10 @@ import { draftMode } from 'next/headers' import { notFound } from 'next/navigation' import { Page } from '../../payload-types' +import { fetchPage } from '../_api/fetchPage' +import { fetchPages } from '../_api/fetchPages' import { Gutter } from '../_components/Gutter' import RichText from '../_components/RichText' -import { fetchPage, fetchPages } from '../cms' import classes from './index.module.scss' diff --git a/examples/preview/next-app/app/cms.ts b/examples/draft-preview/next-app/app/_api/fetchPage.ts similarity index 56% rename from examples/preview/next-app/app/cms.ts rename to examples/draft-preview/next-app/app/_api/fetchPage.ts index 02166bcf53..5e0798e81b 100644 --- a/examples/preview/next-app/app/cms.ts +++ b/examples/draft-preview/next-app/app/_api/fetchPage.ts @@ -1,12 +1,17 @@ -import { cookies } from 'next/headers' +import type { RequestCookie } from 'next/dist/compiled/@edge-runtime/cookies' -import type { Page } from '../payload-types' +import type { Page } from '../../payload-types' export const fetchPage = async ( slug: string, draft?: boolean, ): Promise => { - const payloadToken = cookies().get('payload-token') + let payloadToken: RequestCookie | undefined + + if (draft) { + const { cookies } = await import('next/headers') + payloadToken = cookies().get('payload-token') + } const pageRes: { docs: Page[] @@ -27,13 +32,3 @@ export const fetchPage = async ( return pageRes?.docs?.[0] ?? null } - -export const fetchPages = async (): Promise => { - const pageRes: { - docs: Page[] - } = await fetch(`${process.env.NEXT_PUBLIC_CMS_URL}/api/pages?depth=0&limit=100`).then(res => - res.json(), - ) // eslint-disable-line function-paren-newline - - return pageRes?.docs ?? [] -} diff --git a/examples/draft-preview/next-app/app/_api/fetchPages.ts b/examples/draft-preview/next-app/app/_api/fetchPages.ts new file mode 100644 index 0000000000..d1c4cb9e05 --- /dev/null +++ b/examples/draft-preview/next-app/app/_api/fetchPages.ts @@ -0,0 +1,11 @@ +import type { Page } from '../../payload-types' + +export const fetchPages = async (): Promise => { + const pageRes: { + docs: Page[] + } = await fetch(`${process.env.NEXT_PUBLIC_CMS_URL}/api/pages?depth=0&limit=100`).then(res => + res.json(), + ) // eslint-disable-line function-paren-newline + + return pageRes?.docs ?? [] +} diff --git a/examples/preview/next-app/app/_components/AdminBar/index.client.tsx b/examples/draft-preview/next-app/app/_components/AdminBar/index.client.tsx similarity index 100% rename from examples/preview/next-app/app/_components/AdminBar/index.client.tsx rename to examples/draft-preview/next-app/app/_components/AdminBar/index.client.tsx diff --git a/examples/preview/next-app/app/_components/AdminBar/index.module.scss b/examples/draft-preview/next-app/app/_components/AdminBar/index.module.scss similarity index 73% rename from examples/preview/next-app/app/_components/AdminBar/index.module.scss rename to examples/draft-preview/next-app/app/_components/AdminBar/index.module.scss index 5a3ea06314..ad9516097a 100644 --- a/examples/preview/next-app/app/_components/AdminBar/index.module.scss +++ b/examples/draft-preview/next-app/app/_components/AdminBar/index.module.scss @@ -1,17 +1,22 @@ .adminBar { z-index: 10; width: 100%; - background-color: rgb(var(--foreground-rgb)); + background-color: rgba(var(--foreground-rgb), 0.075); padding: calc(var(--base) * 0.5) 0; display: none; + visibility: hidden; + opacity: 0; + transition: opacity 150ms linear; } .payloadAdminBar { - color: rgb(var(--background-rgb)) !important; + color: rgb(var(--foreground-rgb)) !important; } .show { display: block; + visibility: visible; + opacity: 1; } .controls { diff --git a/examples/preview/next-app/app/_components/AdminBar/index.tsx b/examples/draft-preview/next-app/app/_components/AdminBar/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/AdminBar/index.tsx rename to examples/draft-preview/next-app/app/_components/AdminBar/index.tsx diff --git a/examples/preview/next-app/app/_components/Button/index.module.scss b/examples/draft-preview/next-app/app/_components/Button/index.module.scss similarity index 100% rename from examples/preview/next-app/app/_components/Button/index.module.scss rename to examples/draft-preview/next-app/app/_components/Button/index.module.scss diff --git a/examples/preview/next-app/app/_components/Button/index.tsx b/examples/draft-preview/next-app/app/_components/Button/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/Button/index.tsx rename to examples/draft-preview/next-app/app/_components/Button/index.tsx diff --git a/examples/preview/next-app/app/_components/CMSLink/index.tsx b/examples/draft-preview/next-app/app/_components/CMSLink/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/CMSLink/index.tsx rename to examples/draft-preview/next-app/app/_components/CMSLink/index.tsx diff --git a/examples/preview/next-app/app/_components/Gutter/index.module.scss b/examples/draft-preview/next-app/app/_components/Gutter/index.module.scss similarity index 100% rename from examples/preview/next-app/app/_components/Gutter/index.module.scss rename to examples/draft-preview/next-app/app/_components/Gutter/index.module.scss diff --git a/examples/preview/next-app/app/_components/Gutter/index.tsx b/examples/draft-preview/next-app/app/_components/Gutter/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/Gutter/index.tsx rename to examples/draft-preview/next-app/app/_components/Gutter/index.tsx diff --git a/examples/preview/next-app/app/_components/Header/index.module.scss b/examples/draft-preview/next-app/app/_components/Header/index.module.scss similarity index 100% rename from examples/preview/next-app/app/_components/Header/index.module.scss rename to examples/draft-preview/next-app/app/_components/Header/index.module.scss diff --git a/examples/preview/next-app/app/_components/Header/index.tsx b/examples/draft-preview/next-app/app/_components/Header/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/Header/index.tsx rename to examples/draft-preview/next-app/app/_components/Header/index.tsx diff --git a/examples/preview/next-app/app/_components/RichText/index.module.scss b/examples/draft-preview/next-app/app/_components/RichText/index.module.scss similarity index 100% rename from examples/preview/next-app/app/_components/RichText/index.module.scss rename to examples/draft-preview/next-app/app/_components/RichText/index.module.scss diff --git a/examples/preview/next-app/app/_components/RichText/index.tsx b/examples/draft-preview/next-app/app/_components/RichText/index.tsx similarity index 100% rename from examples/preview/next-app/app/_components/RichText/index.tsx rename to examples/draft-preview/next-app/app/_components/RichText/index.tsx diff --git a/examples/preview/next-app/app/_components/RichText/serialize.tsx b/examples/draft-preview/next-app/app/_components/RichText/serialize.tsx similarity index 100% rename from examples/preview/next-app/app/_components/RichText/serialize.tsx rename to examples/draft-preview/next-app/app/_components/RichText/serialize.tsx diff --git a/examples/preview/next-app/app/api/exit-preview/route.ts b/examples/draft-preview/next-app/app/api/exit-preview/route.ts similarity index 100% rename from examples/preview/next-app/app/api/exit-preview/route.ts rename to examples/draft-preview/next-app/app/api/exit-preview/route.ts diff --git a/examples/preview/next-app/app/api/preview/route.ts b/examples/draft-preview/next-app/app/api/preview/route.ts similarity index 100% rename from examples/preview/next-app/app/api/preview/route.ts rename to examples/draft-preview/next-app/app/api/preview/route.ts diff --git a/examples/preview/next-app/app/api/revalidate/route.ts b/examples/draft-preview/next-app/app/api/revalidate/route.ts similarity index 100% rename from examples/preview/next-app/app/api/revalidate/route.ts rename to examples/draft-preview/next-app/app/api/revalidate/route.ts diff --git a/examples/preview/next-app/app/app.scss b/examples/draft-preview/next-app/app/app.scss similarity index 100% rename from examples/preview/next-app/app/app.scss rename to examples/draft-preview/next-app/app/app.scss diff --git a/examples/preview/next-app/app/layout.tsx b/examples/draft-preview/next-app/app/layout.tsx similarity index 100% rename from examples/preview/next-app/app/layout.tsx rename to examples/draft-preview/next-app/app/layout.tsx diff --git a/examples/preview/next-app/app/page.tsx b/examples/draft-preview/next-app/app/page.tsx similarity index 100% rename from examples/preview/next-app/app/page.tsx rename to examples/draft-preview/next-app/app/page.tsx diff --git a/examples/preview/next-app/next-env.d.ts b/examples/draft-preview/next-app/next-env.d.ts similarity index 100% rename from examples/preview/next-app/next-env.d.ts rename to examples/draft-preview/next-app/next-env.d.ts diff --git a/examples/preview/next-app/next.config.js b/examples/draft-preview/next-app/next.config.js similarity index 100% rename from examples/preview/next-app/next.config.js rename to examples/draft-preview/next-app/next.config.js diff --git a/examples/preview/next-app/package.json b/examples/draft-preview/next-app/package.json similarity index 95% rename from examples/preview/next-app/package.json rename to examples/draft-preview/next-app/package.json index de15926799..6b89a38b76 100644 --- a/examples/preview/next-app/package.json +++ b/examples/draft-preview/next-app/package.json @@ -1,5 +1,5 @@ { - "name": "payload-example-nextjs-preview-app", + "name": "payload-draft-preview-next-app", "version": "0.1.0", "private": true, "scripts": { diff --git a/examples/preview/cms/src/payload-types.ts b/examples/draft-preview/next-app/payload-types.ts similarity index 100% rename from examples/preview/cms/src/payload-types.ts rename to examples/draft-preview/next-app/payload-types.ts diff --git a/examples/preview/next-app/public/favicon.ico b/examples/draft-preview/next-app/public/favicon.ico similarity index 100% rename from examples/preview/next-app/public/favicon.ico rename to examples/draft-preview/next-app/public/favicon.ico diff --git a/examples/preview/next-app/public/favicon.svg b/examples/draft-preview/next-app/public/favicon.svg similarity index 100% rename from examples/preview/next-app/public/favicon.svg rename to examples/draft-preview/next-app/public/favicon.svg diff --git a/examples/preview/next-app/tsconfig.json b/examples/draft-preview/next-app/tsconfig.json similarity index 100% rename from examples/preview/next-app/tsconfig.json rename to examples/draft-preview/next-app/tsconfig.json diff --git a/examples/preview/next-app/yarn.lock b/examples/draft-preview/next-app/yarn.lock similarity index 100% rename from examples/preview/next-app/yarn.lock rename to examples/draft-preview/next-app/yarn.lock diff --git a/examples/preview/next-pages/.editorconfig b/examples/draft-preview/next-pages/.editorconfig similarity index 100% rename from examples/preview/next-pages/.editorconfig rename to examples/draft-preview/next-pages/.editorconfig diff --git a/examples/preview/next-pages/.env.example b/examples/draft-preview/next-pages/.env.example similarity index 100% rename from examples/preview/next-pages/.env.example rename to examples/draft-preview/next-pages/.env.example diff --git a/examples/preview/next-pages/.eslintrc.js b/examples/draft-preview/next-pages/.eslintrc.js similarity index 100% rename from examples/preview/next-pages/.eslintrc.js rename to examples/draft-preview/next-pages/.eslintrc.js diff --git a/examples/preview/next-pages/.gitignore b/examples/draft-preview/next-pages/.gitignore similarity index 100% rename from examples/preview/next-pages/.gitignore rename to examples/draft-preview/next-pages/.gitignore diff --git a/examples/preview/next-app/.prettierrc.js b/examples/draft-preview/next-pages/.prettierrc.js similarity index 100% rename from examples/preview/next-app/.prettierrc.js rename to examples/draft-preview/next-pages/.prettierrc.js diff --git a/examples/preview/next-pages/README.md b/examples/draft-preview/next-pages/README.md similarity index 72% rename from examples/preview/next-pages/README.md rename to examples/draft-preview/next-pages/README.md index 0dbd80a67f..b01b952e86 100644 --- a/examples/preview/next-pages/README.md +++ b/examples/draft-preview/next-pages/README.md @@ -1,14 +1,14 @@ -# Payload Preview Example Front-End +# Payload Draft Preview Example Front-End -This is a [Next.js](https://nextjs.org) app using the [Pages Router](https://nextjs.org/docs/pages). It was made explicitly for Payload's [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms). +This is a [Next.js](https://nextjs.org) app using the [Pages Router](https://nextjs.org/docs/pages). It was made explicitly for Payload's [Draft Preview Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview). -> This example uses the Pages Router, the legacy API of Next.js. If your app is using the latest [App Router](https://nextjs.org/docs/app), check out the official [App Router Example](https://github.com/payloadcms/payload/tree/master/examples/preview/next-app). +> This example uses the Pages Router, the legacy API of Next.js. If your app is using the latest [App Router](https://nextjs.org/docs/app), check out the official [App Router Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/next-app). ## Getting Started ### Payload -First you'll need a running [Payload](https://github.com/payloadcms/payload) app. If you have not done so already, open up the `cms` folder and follow the setup instructions. Take note of your `serverURL`, you'll need this in the next step. +First you'll need a running Payload app. There is one made explicitly for this example and [can be found here](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/payload). If you have not done so already, clone it down and follow the setup instructions there. This will provide all the necessary APIs that your Next.js app requires for authentication. ### Next.js @@ -18,7 +18,7 @@ First you'll need a running [Payload](https://github.com/payloadcms/payload) app 4. `yarn dev` or `npm run dev` to start the server 5. `open http://localhost:3001` to see the result -Once running you will find a couple seeded pages on your local environment with some basic instructions. You can also start editing the pages by modifying the documents within Payload. See the [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms) for full details. +Once running you will find a couple seeded pages on your local environment with some basic instructions. You can also start editing the pages by modifying the documents within Payload. See the [Draft Preview Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview/payload) for full details. ## Learn More diff --git a/examples/preview/next-pages/next-env.d.ts b/examples/draft-preview/next-pages/next-env.d.ts similarity index 100% rename from examples/preview/next-pages/next-env.d.ts rename to examples/draft-preview/next-pages/next-env.d.ts diff --git a/examples/preview/next-pages/next.config.js b/examples/draft-preview/next-pages/next.config.js similarity index 100% rename from examples/preview/next-pages/next.config.js rename to examples/draft-preview/next-pages/next.config.js diff --git a/examples/preview/next-pages/package.json b/examples/draft-preview/next-pages/package.json similarity index 95% rename from examples/preview/next-pages/package.json rename to examples/draft-preview/next-pages/package.json index f25c75e71d..e83bc55a5d 100644 --- a/examples/preview/next-pages/package.json +++ b/examples/draft-preview/next-pages/package.json @@ -1,5 +1,5 @@ { - "name": "payload-example-nextjs-preview-pages", + "name": "payload-draft-preview-next-pages", "version": "0.1.0", "private": true, "scripts": { diff --git a/examples/preview/next-pages/public/favicon.ico b/examples/draft-preview/next-pages/public/favicon.ico similarity index 100% rename from examples/preview/next-pages/public/favicon.ico rename to examples/draft-preview/next-pages/public/favicon.ico diff --git a/examples/preview/next-pages/public/favicon.svg b/examples/draft-preview/next-pages/public/favicon.svg similarity index 100% rename from examples/preview/next-pages/public/favicon.svg rename to examples/draft-preview/next-pages/public/favicon.svg diff --git a/examples/preview/next-pages/src/components/AdminBar/index.module.scss b/examples/draft-preview/next-pages/src/components/AdminBar/index.module.scss similarity index 73% rename from examples/preview/next-pages/src/components/AdminBar/index.module.scss rename to examples/draft-preview/next-pages/src/components/AdminBar/index.module.scss index 5a3ea06314..ad9516097a 100644 --- a/examples/preview/next-pages/src/components/AdminBar/index.module.scss +++ b/examples/draft-preview/next-pages/src/components/AdminBar/index.module.scss @@ -1,17 +1,22 @@ .adminBar { z-index: 10; width: 100%; - background-color: rgb(var(--foreground-rgb)); + background-color: rgba(var(--foreground-rgb), 0.075); padding: calc(var(--base) * 0.5) 0; display: none; + visibility: hidden; + opacity: 0; + transition: opacity 150ms linear; } .payloadAdminBar { - color: rgb(var(--background-rgb)) !important; + color: rgb(var(--foreground-rgb)) !important; } .show { display: block; + visibility: visible; + opacity: 1; } .controls { diff --git a/examples/preview/next-pages/src/components/AdminBar/index.tsx b/examples/draft-preview/next-pages/src/components/AdminBar/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/AdminBar/index.tsx rename to examples/draft-preview/next-pages/src/components/AdminBar/index.tsx diff --git a/examples/preview/next-pages/src/components/Button/index.module.scss b/examples/draft-preview/next-pages/src/components/Button/index.module.scss similarity index 100% rename from examples/preview/next-pages/src/components/Button/index.module.scss rename to examples/draft-preview/next-pages/src/components/Button/index.module.scss diff --git a/examples/preview/next-pages/src/components/Button/index.tsx b/examples/draft-preview/next-pages/src/components/Button/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/Button/index.tsx rename to examples/draft-preview/next-pages/src/components/Button/index.tsx diff --git a/examples/preview/next-pages/src/components/CMSLink/index.tsx b/examples/draft-preview/next-pages/src/components/CMSLink/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/CMSLink/index.tsx rename to examples/draft-preview/next-pages/src/components/CMSLink/index.tsx diff --git a/examples/preview/next-pages/src/components/Gutter/index.module.scss b/examples/draft-preview/next-pages/src/components/Gutter/index.module.scss similarity index 100% rename from examples/preview/next-pages/src/components/Gutter/index.module.scss rename to examples/draft-preview/next-pages/src/components/Gutter/index.module.scss diff --git a/examples/preview/next-pages/src/components/Gutter/index.tsx b/examples/draft-preview/next-pages/src/components/Gutter/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/Gutter/index.tsx rename to examples/draft-preview/next-pages/src/components/Gutter/index.tsx diff --git a/examples/preview/next-pages/src/components/Header/index.module.scss b/examples/draft-preview/next-pages/src/components/Header/index.module.scss similarity index 100% rename from examples/preview/next-pages/src/components/Header/index.module.scss rename to examples/draft-preview/next-pages/src/components/Header/index.module.scss diff --git a/examples/preview/next-pages/src/components/Header/index.tsx b/examples/draft-preview/next-pages/src/components/Header/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/Header/index.tsx rename to examples/draft-preview/next-pages/src/components/Header/index.tsx diff --git a/examples/preview/next-pages/src/components/RichText/index.module.scss b/examples/draft-preview/next-pages/src/components/RichText/index.module.scss similarity index 100% rename from examples/preview/next-pages/src/components/RichText/index.module.scss rename to examples/draft-preview/next-pages/src/components/RichText/index.module.scss diff --git a/examples/preview/next-pages/src/components/RichText/index.tsx b/examples/draft-preview/next-pages/src/components/RichText/index.tsx similarity index 100% rename from examples/preview/next-pages/src/components/RichText/index.tsx rename to examples/draft-preview/next-pages/src/components/RichText/index.tsx diff --git a/examples/preview/next-pages/src/components/RichText/serialize.tsx b/examples/draft-preview/next-pages/src/components/RichText/serialize.tsx similarity index 100% rename from examples/preview/next-pages/src/components/RichText/serialize.tsx rename to examples/draft-preview/next-pages/src/components/RichText/serialize.tsx diff --git a/examples/preview/next-pages/src/pages/[slug].module.scss b/examples/draft-preview/next-pages/src/pages/[slug].module.scss similarity index 100% rename from examples/preview/next-pages/src/pages/[slug].module.scss rename to examples/draft-preview/next-pages/src/pages/[slug].module.scss diff --git a/examples/preview/next-pages/src/pages/[slug].tsx b/examples/draft-preview/next-pages/src/pages/[slug].tsx similarity index 100% rename from examples/preview/next-pages/src/pages/[slug].tsx rename to examples/draft-preview/next-pages/src/pages/[slug].tsx diff --git a/examples/preview/next-pages/src/pages/_app.tsx b/examples/draft-preview/next-pages/src/pages/_app.tsx similarity index 100% rename from examples/preview/next-pages/src/pages/_app.tsx rename to examples/draft-preview/next-pages/src/pages/_app.tsx diff --git a/examples/preview/next-pages/src/pages/api/exit-preview.ts b/examples/draft-preview/next-pages/src/pages/api/exit-preview.ts similarity index 100% rename from examples/preview/next-pages/src/pages/api/exit-preview.ts rename to examples/draft-preview/next-pages/src/pages/api/exit-preview.ts diff --git a/examples/preview/next-pages/src/pages/api/preview.ts b/examples/draft-preview/next-pages/src/pages/api/preview.ts similarity index 100% rename from examples/preview/next-pages/src/pages/api/preview.ts rename to examples/draft-preview/next-pages/src/pages/api/preview.ts diff --git a/examples/preview/next-pages/src/pages/api/revalidate.ts b/examples/draft-preview/next-pages/src/pages/api/revalidate.ts similarity index 100% rename from examples/preview/next-pages/src/pages/api/revalidate.ts rename to examples/draft-preview/next-pages/src/pages/api/revalidate.ts diff --git a/examples/preview/next-pages/src/pages/app.scss b/examples/draft-preview/next-pages/src/pages/app.scss similarity index 100% rename from examples/preview/next-pages/src/pages/app.scss rename to examples/draft-preview/next-pages/src/pages/app.scss diff --git a/examples/preview/next-pages/src/pages/index.tsx b/examples/draft-preview/next-pages/src/pages/index.tsx similarity index 100% rename from examples/preview/next-pages/src/pages/index.tsx rename to examples/draft-preview/next-pages/src/pages/index.tsx diff --git a/examples/preview/next-app/payload-types.ts b/examples/draft-preview/next-pages/src/payload-types.ts similarity index 100% rename from examples/preview/next-app/payload-types.ts rename to examples/draft-preview/next-pages/src/payload-types.ts diff --git a/examples/preview/next-pages/tsconfig.json b/examples/draft-preview/next-pages/tsconfig.json similarity index 100% rename from examples/preview/next-pages/tsconfig.json rename to examples/draft-preview/next-pages/tsconfig.json diff --git a/examples/preview/next-pages/yarn.lock b/examples/draft-preview/next-pages/yarn.lock similarity index 100% rename from examples/preview/next-pages/yarn.lock rename to examples/draft-preview/next-pages/yarn.lock diff --git a/examples/preview/cms/.env.example b/examples/draft-preview/payload/.env.example similarity index 75% rename from examples/preview/cms/.env.example rename to examples/draft-preview/payload/.env.example index 758bbbdc8c..573121d1be 100644 --- a/examples/preview/cms/.env.example +++ b/examples/draft-preview/payload/.env.example @@ -1,9 +1,9 @@ -MONGODB_URI=mongodb://127.0.0.1/payload-example-preview +MONGODB_URI=mongodb://127.0.0.1/payload-example-draft-preview PAYLOAD_SECRET=ENTER-STRING-HERE PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000 PAYLOAD_PUBLIC_SITE_URL=http://localhost:3001 PAYLOAD_PUBLIC_DRAFT_SECRET=EXAMPLE_DRAFT_SECRET COOKIE_DOMAIN=localhost REVALIDATION_KEY=EXAMPLE_REVALIDATION_KEY -PAYLOAD_SEED=true +PAYLOAD_PUBLIC_SEED=true PAYLOAD_DROP_DATABASE=true diff --git a/examples/preview/cms/.eslintrc.js b/examples/draft-preview/payload/.eslintrc.js similarity index 100% rename from examples/preview/cms/.eslintrc.js rename to examples/draft-preview/payload/.eslintrc.js diff --git a/examples/preview/cms/.gitignore b/examples/draft-preview/payload/.gitignore similarity index 100% rename from examples/preview/cms/.gitignore rename to examples/draft-preview/payload/.gitignore diff --git a/examples/preview/next-pages/.prettierrc.js b/examples/draft-preview/payload/.prettierrc.js similarity index 100% rename from examples/preview/next-pages/.prettierrc.js rename to examples/draft-preview/payload/.prettierrc.js diff --git a/examples/preview/cms/.vscode/launch.json b/examples/draft-preview/payload/.vscode/launch.json similarity index 100% rename from examples/preview/cms/.vscode/launch.json rename to examples/draft-preview/payload/.vscode/launch.json diff --git a/examples/preview/cms/README.md b/examples/draft-preview/payload/README.md similarity index 69% rename from examples/preview/cms/README.md rename to examples/draft-preview/payload/README.md index bfbd615249..f8d0c0c6c3 100644 --- a/examples/preview/cms/README.md +++ b/examples/draft-preview/payload/README.md @@ -1,8 +1,11 @@ -# Payload Preview Example +# Payload Draft Preview Example -This example demonstrates how to implement preview in [Payload](https://github.com/payloadcms/payload) using [Versions](https://payloadcms.com/docs/versions/overview) and [Drafts](https://payloadcms.com/docs/versions/drafts). Preview allows you to see draft content on your front-end before it is published. +The [Payload Draft Preview Example](https://github.com/payloadcms/payload/tree/master/examples/draft-preview) demonstrates how to implement draft preview in [Payload](https://github.com/payloadcms/payload) using [Versions](https://payloadcms.com/docs/versions/overview) and [Drafts](https://payloadcms.com/docs/versions/drafts). Draft preview allows you to see content on your front-end before it is published. There are various fully working front-ends made explicitly for this example, including: -There is a fully working Next.js app made explicitly for this example which can be found [here](../next-app). Follow the instructions there to get started. If you are setting up preview for another front-end, please consider contributing to this repo with your own example! +- [Next.js App Router](../next-app) +- [Next.js Pages Router](../next-pages) + +Follow the instructions in each respective README to get started. If you are setting up draft preview for another front-end, please consider contributing to this repo with your own example! ## Quick Start @@ -17,7 +20,7 @@ That's it! Changes made in `./src` will be reflected in your app. See the [Devel ## How it works -Preview works by sending the user to your front-end with a `secret` along with their http-only cookies. Your front-end catches the request, verifies the authenticity, then enters into it's own preview mode. Once in preview mode, your front-end can begin securely requesting draft documents from Payload. +Draft preview works by sending the user to your front-end with a `secret` along with their http-only cookies. Your front-end catches the request, verifies the authenticity, then enters into it's own preview mode. Once in preview mode, your front-end can begin securely requesting draft documents from Payload. See [Preview Mode](#preview-mode) for more details. ### Collections @@ -27,11 +30,11 @@ See the [Collections](https://payloadcms.com/docs/configuration/collections) doc The `users` collection is auth-enabled which provides access to the admin panel. When previewing documents on your front-end, the user's JWT is used to authenticate the request. See [Pages](#pages) for more details. - For additional help with authentication, see the [Authentication](https://payloadcms.com/docs/authentication/overview#authentication-overview) docs or the official [Auth Example](https://github.com/payloadcms/payload/tree/master/examples/auth/cms#readme). + For additional help with authentication, see the [Authentication](https://payloadcms.com/docs/authentication/overview#authentication-overview) docs or the official [Auth Example](https://github.com/payloadcms/payload/tree/master/examples/auth). - #### Pages - The `pages` collection is draft-enabled and has access control that restricts public users from viewing pages with a `draft` status. To fetch draft documents on your front-end, simply include the `draft=true` query param along with the `Authorization` header once you have entered [Preview Mode](#preview-mode). + The `pages` collection is draft-enabled and has access control that restricts public users from viewing pages with a `_status` of `draft`. To fetch draft documents on your front-end, simply include the `draft=true` query param along with the `Authorization` header once you have entered [Preview Mode](#preview-mode). ```ts const preview = true; // set this based on your own front-end environment (see `Preview Mode` below) @@ -52,7 +55,7 @@ See the [Collections](https://payloadcms.com/docs/configuration/collections) doc ### Preview Mode -To enter preview mode, the user first needs to have at least one draft document saved. When they click the "preview" button from the Payload admin panel, a custom [preview function](https://payloadcms.com/docs/configuration/collections#preview) routes them to your front-end with a `secret` and their http-only cookies. An API route on your front-end will verify the secret and token before entering into it's own preview mode. Once in preview mode, it can begin requesting drafts from Payload using the `Authorization` header, see [Pages](#pages) for more details. +To preview draft documents, the user first needs to have at least one draft document saved. When they click the "preview" button from the Payload admin panel, a custom [preview function](https://payloadcms.com/docs/configuration/collections#preview) routes them to your front-end with a `secret` along with their http-only cookies. An API route on your front-end will verify the secret and token before entering into it's own preview mode. Once in preview mode, it can begin requesting drafts from Payload using the `Authorization` header. See [Pages](#pages) for more details. > "Preview mode" looks differently for every front-end framework. For instance, check out the differences between Next.js [Preview Mode](https://nextjs.org/docs/pages/building-your-application/configuring/preview-mode) in the Pages Router and [Draft Mode](https://nextjs.org/docs/pages/building-your-application/configuring/draft-mode) in the App Router. In Next.js, methods are provided that set cookies in your browser, but this may not be the case for all frameworks. @@ -64,11 +67,11 @@ If your front-end is statically generated then you may also want to regenerate t ### Admin Bar -You might also want to render an admin bar on your front-end so that logged-in users can quickly navigate between the front-end and Payload as they're editing. For React apps, check out the official [Payload Admin Bar](https://github.com/payloadcms/payload-admin-bar). For other frameworks, simply hit the `/me` route with `credentials: include` and render your own admin bar if the user is logged in in order to display quick links to your CMS. +You might also want to render an admin bar on your front-end so that logged-in users can quickly navigate between the front-end and Payload as they're editing. For React apps, check out the official [Payload Admin Bar](https://github.com/payloadcms/payload-admin-bar). For other frameworks, simply hit the `/me` route with `credentials: 'include'` and render your own admin bar if the user is logged in. ### CORS -The [`cors`](https://payloadcms.com/docs/production/preventing-abuse#cross-origin-resource-sharing-cors), [`csrf`](https://payloadcms.com/docs/production/preventing-abuse#cross-site-request-forgery-csrf), and [`cookies`](https://payloadcms.com/docs/authentication/config#options) settings are configured to ensure that the admin panel and front-end can communicate with each other securely. If you are combining your front-end and admin panel into a single application that runs of a shared port and domain, you can remove these settings from your config. +The [`cors`](https://payloadcms.com/docs/production/preventing-abuse#cross-origin-resource-sharing-cors), [`csrf`](https://payloadcms.com/docs/production/preventing-abuse#cross-site-request-forgery-csrf), and [`cookies`](https://payloadcms.com/docs/authentication/config#options) settings are configured to ensure that the admin panel and front-end can communicate with each other securely. If you are combining your front-end and admin panel into a single application that runs of a shared port and domain, you can simplify your config by removing these settings. For more details on this, see the [CORS](https://payloadcms.com/docs/production/preventing-abuse#cross-origin-resource-sharing-cors) docs. @@ -76,10 +79,9 @@ For more details on this, see the [CORS](https://payloadcms.com/docs/production/ To spin up this example locally, follow the [Quick Start](#quick-start). - ### Seed -On boot, a seed script is included to scaffold a basic database for you to use as an example. This is done by setting the `PAYLOAD_DROP_DATABASE` and `PAYLOAD_SEED` environment variables which are included in the `.env.example` by default. You can remove these from your `.env` to prevent this behavior. You can also freshly seed your project at any time by running `yarn seed`. This seed creates a user with email `demo@payloadcms.com` and password `demo` along with a home page and an example page with two versions, one published and the other draft. +On boot, a seed script is included to scaffold a basic database for you to use as an example. This is done by setting the `PAYLOAD_DROP_DATABASE` and `PAYLOAD_PUBLIC_SEED` environment variables which are included in the `.env.example` by default. You can remove these from your `.env` to prevent this behavior. You can also freshly seed your project at any time by running `yarn seed`. This seed creates a user with email `demo@payloadcms.com` and password `demo` along with a home page and an example page with two versions, one published and the other draft. > NOTICE: seeding the database is destructive because it drops your current database to populate a fresh one from the seed template. Only run this command if you are starting a new project or can afford to lose your current data. diff --git a/examples/preview/cms/nodemon.json b/examples/draft-preview/payload/nodemon.json similarity index 100% rename from examples/preview/cms/nodemon.json rename to examples/draft-preview/payload/nodemon.json diff --git a/examples/preview/cms/package.json b/examples/draft-preview/payload/package.json similarity index 91% rename from examples/preview/cms/package.json rename to examples/draft-preview/payload/package.json index 8197370895..41c760340f 100644 --- a/examples/preview/cms/package.json +++ b/examples/draft-preview/payload/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon", - "seed": "rm -rf media && cross-env PAYLOAD_SEED=true PAYLOAD_DROP_DATABASE=true PAYLOAD_CONFIG_PATH=src/payload.config.ts ts-node src/server.ts", + "seed": "rm -rf media && cross-env PAYLOAD_PUBLIC_SEED=true PAYLOAD_DROP_DATABASE=true PAYLOAD_CONFIG_PATH=src/payload.config.ts ts-node src/server.ts", "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build", "build:server": "tsc", "build": "yarn copyfiles && yarn build:payload && yarn build:server", @@ -43,4 +43,4 @@ "ts-node": "^9.1.1", "typescript": "^4.8.4" } -} \ No newline at end of file +} diff --git a/examples/preview/cms/src/collections/Pages/access/loggedIn.ts b/examples/draft-preview/payload/src/collections/Pages/access/loggedIn.ts similarity index 100% rename from examples/preview/cms/src/collections/Pages/access/loggedIn.ts rename to examples/draft-preview/payload/src/collections/Pages/access/loggedIn.ts diff --git a/examples/preview/cms/src/collections/Pages/access/publishedOrLoggedIn.ts b/examples/draft-preview/payload/src/collections/Pages/access/publishedOrLoggedIn.ts similarity index 100% rename from examples/preview/cms/src/collections/Pages/access/publishedOrLoggedIn.ts rename to examples/draft-preview/payload/src/collections/Pages/access/publishedOrLoggedIn.ts diff --git a/examples/preview/cms/src/collections/Pages/hooks/formatSlug.ts b/examples/draft-preview/payload/src/collections/Pages/hooks/formatSlug.ts similarity index 100% rename from examples/preview/cms/src/collections/Pages/hooks/formatSlug.ts rename to examples/draft-preview/payload/src/collections/Pages/hooks/formatSlug.ts diff --git a/examples/draft-preview/payload/src/collections/Pages/hooks/revalidatePage.ts b/examples/draft-preview/payload/src/collections/Pages/hooks/revalidatePage.ts new file mode 100644 index 0000000000..1bafe43127 --- /dev/null +++ b/examples/draft-preview/payload/src/collections/Pages/hooks/revalidatePage.ts @@ -0,0 +1,37 @@ +import type { AfterChangeHook } from 'payload/dist/collections/config/types' + +// ensure that the home page is revalidated at '/' instead of '/home' +export const formatAppURL = ({ doc }): string => { + const pathToUse = doc.slug === 'home' ? '' : doc.slug + const { pathname } = new URL(`${process.env.PAYLOAD_PUBLIC_SITE_URL}/${pathToUse}`) + return pathname +} + +// Revalidate the page in the background, so the user doesn't have to wait +// Notice that the hook itself is not async and we are not awaiting `revalidate` +// Only revalidate existing docs that are published +export const revalidatePage: AfterChangeHook = ({ doc, req, operation }) => { + if (operation === 'update' && doc._status === 'published') { + const url = formatAppURL({ doc }) + + const revalidate = async (): Promise => { + try { + const res = await fetch( + `${process.env.PAYLOAD_PUBLIC_SITE_URL}/api/revalidate?secret=${process.env.REVALIDATION_KEY}&revalidatePath=${url}`, + ) + + if (res.ok) { + req.payload.logger.info(`Revalidated path ${url}`) + } else { + req.payload.logger.error(`Error revalidating path ${url}`) + } + } catch (err: unknown) { + req.payload.logger.error(`Error hitting revalidate route for ${url}`) + } + } + + revalidate() + } + + return doc +} diff --git a/examples/preview/cms/src/collections/Pages/index.ts b/examples/draft-preview/payload/src/collections/Pages/index.ts similarity index 100% rename from examples/preview/cms/src/collections/Pages/index.ts rename to examples/draft-preview/payload/src/collections/Pages/index.ts diff --git a/examples/preview/cms/src/collections/Users.ts b/examples/draft-preview/payload/src/collections/Users.ts similarity index 100% rename from examples/preview/cms/src/collections/Users.ts rename to examples/draft-preview/payload/src/collections/Users.ts diff --git a/examples/draft-preview/payload/src/components/BeforeLogin/index.tsx b/examples/draft-preview/payload/src/components/BeforeLogin/index.tsx new file mode 100644 index 0000000000..5108a4fef6 --- /dev/null +++ b/examples/draft-preview/payload/src/components/BeforeLogin/index.tsx @@ -0,0 +1,17 @@ +import React from 'react' + +const BeforeLogin: React.FC = () => { + if (process.env.PAYLOAD_PUBLIC_SEED === 'true') { + return ( +

+ {'Log in with the email '} + demo@payloadcms.com + {' and the password '} + demo. +

+ ) + } + return null +} + +export default BeforeLogin diff --git a/examples/preview/cms/src/fields/link.ts b/examples/draft-preview/payload/src/fields/link.ts similarity index 100% rename from examples/preview/cms/src/fields/link.ts rename to examples/draft-preview/payload/src/fields/link.ts diff --git a/examples/preview/cms/src/fields/richText/elements.ts b/examples/draft-preview/payload/src/fields/richText/elements.ts similarity index 100% rename from examples/preview/cms/src/fields/richText/elements.ts rename to examples/draft-preview/payload/src/fields/richText/elements.ts diff --git a/examples/preview/cms/src/fields/richText/index.ts b/examples/draft-preview/payload/src/fields/richText/index.ts similarity index 100% rename from examples/preview/cms/src/fields/richText/index.ts rename to examples/draft-preview/payload/src/fields/richText/index.ts diff --git a/examples/preview/cms/src/fields/richText/leaves.ts b/examples/draft-preview/payload/src/fields/richText/leaves.ts similarity index 100% rename from examples/preview/cms/src/fields/richText/leaves.ts rename to examples/draft-preview/payload/src/fields/richText/leaves.ts diff --git a/examples/preview/cms/src/globals/MainMenu.ts b/examples/draft-preview/payload/src/globals/MainMenu.ts similarity index 100% rename from examples/preview/cms/src/globals/MainMenu.ts rename to examples/draft-preview/payload/src/globals/MainMenu.ts diff --git a/examples/preview/next-pages/src/payload-types.ts b/examples/draft-preview/payload/src/payload-types.ts similarity index 100% rename from examples/preview/next-pages/src/payload-types.ts rename to examples/draft-preview/payload/src/payload-types.ts diff --git a/examples/preview/cms/src/payload.config.ts b/examples/draft-preview/payload/src/payload.config.ts similarity index 84% rename from examples/preview/cms/src/payload.config.ts rename to examples/draft-preview/payload/src/payload.config.ts index 55f4047fde..e5ac8a1fa3 100644 --- a/examples/preview/cms/src/payload.config.ts +++ b/examples/draft-preview/payload/src/payload.config.ts @@ -3,10 +3,16 @@ import { buildConfig } from 'payload/config' import { Pages } from './collections/Pages' import { Users } from './collections/Users' +import BeforeLogin from './components/BeforeLogin' import { MainMenu } from './globals/MainMenu' export default buildConfig({ collections: [Pages, Users], + admin: { + components: { + beforeLogin: [BeforeLogin], + }, + }, serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL, cors: [ process.env.PAYLOAD_PUBLIC_SERVER_URL || '', diff --git a/examples/preview/cms/src/seed/home.ts b/examples/draft-preview/payload/src/seed/home.ts similarity index 76% rename from examples/preview/cms/src/seed/home.ts rename to examples/draft-preview/payload/src/seed/home.ts index 9601b768b0..f248531aa8 100644 --- a/examples/preview/cms/src/seed/home.ts +++ b/examples/draft-preview/payload/src/seed/home.ts @@ -21,7 +21,7 @@ export const home: Partial = { { type: 'link', newTab: true, - url: 'https://github.com/payloadcms/payload/tree/master/examples/redirects/cms', + url: 'https://github.com/payloadcms/payload/tree/master/examples/redirects', children: [{ text: '' }], }, { text: '' }, @@ -29,10 +29,10 @@ export const home: Partial = { type: 'link', linkType: 'custom', newTab: true, - url: 'https://github.com/payloadcms/payload/tree/master/examples/preview/cms', - children: [{ text: 'Preview Example' }], + url: 'https://github.com/payloadcms/payload/tree/master/examples/draft-preview/payload', + children: [{ text: 'Draft Preview Example' }], }, - { text: '. This example demonstrates how to implement preview into Payload using ' }, + { text: '. This example demonstrates how to implement draft preview into Payload using ' }, { type: 'link', newTab: true, @@ -50,9 +50,9 @@ export const home: Partial = { linkType: 'custom', url: 'http://localhost:3000/admin', newTab: true, - children: [{ text: 'Log in' }], + children: [{ text: 'Log in to the admin panel' }], }, - { text: ' to the admin panel and refresh this page to see the ' }, + { text: ' and refresh this page to see the ' }, { type: 'link', linkType: 'custom', @@ -61,7 +61,7 @@ export const home: Partial = { children: [{ text: 'Payload Admin Bar' }], }, { - text: ' appear at the top of the viewport. This will allow you to seamlessly navigate between the two apps. Then, navigate to the ', + text: ' appear at the top of this site. This will allow you to seamlessly navigate between the two apps. Then, navigate to the ', }, { type: 'link', @@ -69,7 +69,7 @@ export const home: Partial = { url: 'http://localhost:3001/example-page', children: [{ text: 'example page' }], }, - { text: ' to see how access to draft content is controlled. ' }, + { text: ' to see how we control access to draft content. ' }, ], }, ], diff --git a/examples/preview/cms/src/seed/index.ts b/examples/draft-preview/payload/src/seed/index.ts similarity index 100% rename from examples/preview/cms/src/seed/index.ts rename to examples/draft-preview/payload/src/seed/index.ts diff --git a/examples/preview/cms/src/seed/page.ts b/examples/draft-preview/payload/src/seed/page.ts similarity index 71% rename from examples/preview/cms/src/seed/page.ts rename to examples/draft-preview/payload/src/seed/page.ts index ddf69df7e2..7b02abded0 100644 --- a/examples/preview/cms/src/seed/page.ts +++ b/examples/draft-preview/payload/src/seed/page.ts @@ -22,10 +22,10 @@ export const examplePage: Partial = { linkType: 'custom', url: 'http://localhost:3000/admin', newTab: true, - children: [{ text: 'Log in' }], + children: [{ text: 'Log in to the admin panel' }], }, { - text: ' to the admin panel and click "preview" to return to this page and view the latest draft content in Next.js preview mode. To make additional changes to the draft, click "save draft" before returning to the preview.', + text: ' and click "preview" to return to this page and view the latest draft content in Next.js preview mode. To make additional changes to the draft, click "save draft" before returning to the preview.', }, ], }, diff --git a/examples/preview/cms/src/seed/pageDraft.ts b/examples/draft-preview/payload/src/seed/pageDraft.ts similarity index 100% rename from examples/preview/cms/src/seed/pageDraft.ts rename to examples/draft-preview/payload/src/seed/pageDraft.ts diff --git a/examples/preview/cms/src/server.ts b/examples/draft-preview/payload/src/server.ts similarity index 92% rename from examples/preview/cms/src/server.ts rename to examples/draft-preview/payload/src/server.ts index 985169f2ed..bd78c6e1f5 100644 --- a/examples/preview/cms/src/server.ts +++ b/examples/draft-preview/payload/src/server.ts @@ -26,7 +26,7 @@ const start = async (): Promise => { }, }) - if (process.env.PAYLOAD_SEED === 'true') { + if (process.env.PAYLOAD_PUBLIC_SEED === 'true') { payload.logger.info('---- SEEDING DATABASE ----') await seed(payload) } diff --git a/examples/preview/cms/src/utilities/deepMerge.ts b/examples/draft-preview/payload/src/utilities/deepMerge.ts similarity index 100% rename from examples/preview/cms/src/utilities/deepMerge.ts rename to examples/draft-preview/payload/src/utilities/deepMerge.ts diff --git a/examples/preview/cms/tsconfig.json b/examples/draft-preview/payload/tsconfig.json similarity index 100% rename from examples/preview/cms/tsconfig.json rename to examples/draft-preview/payload/tsconfig.json diff --git a/examples/preview/cms/yarn.lock b/examples/draft-preview/payload/yarn.lock similarity index 100% rename from examples/preview/cms/yarn.lock rename to examples/draft-preview/payload/yarn.lock diff --git a/examples/preview/cms/src/collections/Pages/hooks/revalidatePage.ts b/examples/preview/cms/src/collections/Pages/hooks/revalidatePage.ts deleted file mode 100644 index 55c2be34d6..0000000000 --- a/examples/preview/cms/src/collections/Pages/hooks/revalidatePage.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { AfterChangeHook } from 'payload/dist/collections/config/types' - -// ensure that the home page is revalidated at '/' instead of '/home' -export const formatAppURL = ({ doc }): string => { - const pathToUse = doc.slug === 'home' ? '' : doc.slug - const { pathname } = new URL(`${process.env.PAYLOAD_PUBLIC_SITE_URL}/${pathToUse}`) - return pathname -} - -// Revalidate the page in the background, so the user doesn't have to wait -// Notice that the hook itself is not async and we are not awaiting `revalidate` -export const revalidatePage: AfterChangeHook = ({ doc, req }) => { - const url = formatAppURL({ doc }) - - const revalidate = async (): Promise => { - try { - const res = await fetch( - `${process.env.PAYLOAD_PUBLIC_SITE_URL}/api/revalidate?secret=${process.env.REVALIDATION_KEY}&revalidatePath=${url}`, - ) - - if (res.ok) { - req.payload.logger.info(`Revalidated path ${url}`) - } else { - req.payload.logger.error(`Error revalidating path ${url}`) - } - } catch (err: unknown) { - req.payload.logger.error(`Error hitting revalidate route for ${url}`) - } - } - - revalidate() - - return doc -}