diff --git a/src/collections/Blogs.ts b/src/collections/Blogs.ts index cbfe992..f9bbd96 100644 --- a/src/collections/Blogs.ts +++ b/src/collections/Blogs.ts @@ -6,6 +6,11 @@ import type { CollectionConfig } from "payload"; export const Blogs: CollectionConfig = { slug: "blogs", labels: { plural: "Posts", singular: "Post" }, + versions: { + drafts: { + validate: true, + }, + }, fields: [ { name: "title", @@ -66,15 +71,6 @@ export const Blogs: CollectionConfig = { }, ], }, - { - name: "is_published", - label: "Published", - type: "checkbox", - defaultValue: true, - admin: { - position: "sidebar", - }, - }, { name: "createdBy", type: "relationship", diff --git a/src/collections/Pages.ts b/src/collections/Pages.ts index 869c4e7..fe7c380 100644 --- a/src/collections/Pages.ts +++ b/src/collections/Pages.ts @@ -13,6 +13,11 @@ import { CollectionConfig } from "payload"; export const Pages: CollectionConfig = { slug: "pages", + versions: { + drafts: { + validate: true, + }, + }, fields: [ { name: "title", diff --git a/src/payload-types.ts b/src/payload-types.ts index 15d164f..9987a52 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -146,11 +146,11 @@ export interface Blog { description?: string | null; canonical_url?: string | null; }; - is_published?: boolean | null; createdBy?: (number | null) | User; updatedBy?: (number | null) | User; updatedAt: string; createdAt: string; + _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -310,6 +310,7 @@ export interface Page { updatedBy?: (number | null) | User; updatedAt: string; createdAt: string; + _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -646,11 +647,11 @@ export interface BlogsSelect { description?: T; canonical_url?: T; }; - is_published?: T; createdBy?: T; updatedBy?: T; updatedAt?: T; createdAt?: T; + _status?: T; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -753,6 +754,7 @@ export interface PagesSelect { updatedBy?: T; updatedAt?: T; createdAt?: T; + _status?: T; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/src/services/payload/blog.ts b/src/services/payload/blog.ts index 410c398..9929eed 100644 --- a/src/services/payload/blog.ts +++ b/src/services/payload/blog.ts @@ -10,24 +10,11 @@ export async function fetchBlog(page: number | undefined, search: string = "") { pagination: true, limit: 6, where: !search - ? { - is_published: { - equals: true, - }, - } + ? undefined : { - and: [ - { - is_published: { - equals: true, - }, - }, - { - title: { - contains: search, - }, - }, - ], + title: { + contains: search, + }, }, }); @@ -51,9 +38,6 @@ export async function fetchBlogDetail(slug: string | undefined) { collection: "blogs", where: { slug: { equals: slug }, - is_published: { - equals: true, - }, }, limit: 1, pagination: false,