diff --git a/demo/collections/AllFields.ts b/demo/collections/AllFields.ts index 0029593e0c..31acdbcd54 100644 --- a/demo/collections/AllFields.ts +++ b/demo/collections/AllFields.ts @@ -13,13 +13,13 @@ const AllFields: PayloadCollectionConfig = { // }, admin: { useAsTitle: 'text', - }, - preview: (doc, token) => { - if (doc && doc.text) { - return `http://localhost:3000/previewable-posts/${doc.text.value}?preview=true&token=${token}`; - } + preview: (doc, token) => { + if (doc && doc.text) { + return `http://localhost:3000/previewable-posts/${doc.text.value}?preview=true&token=${token}`; + } - return null; + return null; + }, }, access: { read: () => true, diff --git a/demo/collections/DefaultValues.ts b/demo/collections/DefaultValues.ts index cf0bc0d1d4..2274fc5b62 100644 --- a/demo/collections/DefaultValues.ts +++ b/demo/collections/DefaultValues.ts @@ -14,12 +14,6 @@ const DefaultValues: PayloadCollectionConfig = { admin: { useAsTitle: 'text', }, - preview: (doc, token) => { - if (doc && doc.text) { - return `http://localhost:3000/previewable-posts/${doc.text.value}?preview=true&token=${token}`; - } - return null; - }, access: { read: () => true, }, diff --git a/demo/collections/Localized.ts b/demo/collections/Localized.ts index b27aaa315a..fb48fa953a 100644 --- a/demo/collections/Localized.ts +++ b/demo/collections/Localized.ts @@ -18,13 +18,6 @@ const LocalizedPosts: PayloadCollectionConfig = { access: { read: () => true, }, - preview: (doc, token) => { - if (doc && doc.title) { - return `http://localhost:3000/posts/${doc.title.value}?preview=true&token=${token}`; - } - - return null; - }, fields: [ { name: 'title', diff --git a/demo/collections/Preview.ts b/demo/collections/Preview.ts index 0f93981ae2..e5c6d6396b 100644 --- a/demo/collections/Preview.ts +++ b/demo/collections/Preview.ts @@ -8,13 +8,13 @@ const Preview: PayloadCollectionConfig = { }, admin: { useAsTitle: 'title', - }, - preview: (doc, token) => { - if (doc.title) { - return `http://localhost:3000/previewable-posts/${doc.title.value}?preview=true&token=${token}`; - } + preview: (doc, token) => { + if (doc.title) { + return `http://localhost:3000/previewable-posts/${doc.title.value}?preview=true&token=${token}`; + } - return null; + return null; + }, }, fields: [ { diff --git a/src/admin/components/views/collections/Edit/Default.tsx b/src/admin/components/views/collections/Edit/Default.tsx index 141009de38..23d0731966 100644 --- a/src/admin/components/views/collections/Edit/Default.tsx +++ b/src/admin/components/views/collections/Edit/Default.tsx @@ -46,9 +46,9 @@ const DefaultEditView: React.FC = (props) => { admin: { useAsTitle, disableDuplicate, + preview, }, timestamps, - preview, auth, upload, } = collection; diff --git a/src/collections/config/schema.ts b/src/collections/config/schema.ts index 5898351367..c2b6366b23 100644 --- a/src/collections/config/schema.ts +++ b/src/collections/config/schema.ts @@ -12,7 +12,6 @@ const collectionSchema = joi.object().keys({ singular: joi.string(), plural: joi.string(), }), - preview: joi.func(), access: joi.object({ create: joi.func(), read: joi.func(), @@ -32,6 +31,7 @@ const collectionSchema = joi.object().keys({ Edit: component, }), }), + preview: joi.func(), }), fields: joi.array() .items(fieldSchema), diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index c931727d4d..85df104628 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -108,8 +108,8 @@ export type PayloadCollectionConfig = { } }; enableRichTextRelationship?: boolean + preview?: (doc: Document, token: string) => string }; - preview?: (doc: Document, token: string) => string hooks?: { beforeOperation?: BeforeOperationHook[]; beforeValidate?: BeforeValidateHook[];