diff --git a/src/collections/Posts.ts b/src/collections/Posts.ts new file mode 100644 index 0000000..6ac08d5 --- /dev/null +++ b/src/collections/Posts.ts @@ -0,0 +1,91 @@ +import type { CollectionConfig } from 'payload' + +export const Posts: CollectionConfig = { + slug: 'posts', + + hooks: { + beforeChange: [ + // before user presses save, this will run + + ({ data }) => { + if (data?.title) { + data.slug = data.title + .toLowerCase() + .replace(/[^a-z0-9]+/g, '-') + .replace(/^-|-$/g, '') + } + return data + }, + ], + }, + + admin: { + useAsTitle: 'title', + defaultColumns: ['title', 'slug', 'category', 'publishedDate'], + }, + fields: [ + { + name: 'title', + type: 'text', + label: 'Title', + required: true, + }, + { + name: 'slug', + type: 'text', + unique: true, + label: 'Slug', + admin: { readOnly: true }, //cant edit + }, + { + name: 'description', + type: 'richText', + required: true, + }, + { + name: 'photos', + type: 'array', + label: 'Photos', + fields: [ + { + name: 'photo', + type: 'upload', + relationTo: 'media', + // not required for now, but we can make it required later if we want to + }, + ], + }, + { + name: 'category', + type: 'select', + label: 'Category', + options: [ + { label: 'Blog', value: 'blog' }, + { label: 'Alumni Story', value: 'alumni_story' }, + { label: 'Interview', value: 'interview' }, + { label: 'Scholarships', value: 'scholarships' }, + { label: 'Newsletters', value: 'newsletters' }, + { label: 'Education', value: 'education' }, + { label: 'Audience', value: 'audience' }, + ], + }, + { + name: 'author', + type: 'text', + label: 'Author', + }, + { + name: 'publishedDate', + type: 'date', + label: 'Published Date', + //required: true, + admin: { + date: { + //theres a +1 day bug when selecting on calendar, caused by timezone offsets appaerntly + pickerAppearance: 'dayOnly', + displayFormat: 'MMM dd yyyy', // show year, month, day in the admin panel + }, + }, + }, + ], +} diff --git a/src/payload-types.ts b/src/payload-types.ts index cc849c6..e32055e 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -70,10 +70,11 @@ export interface Config { users: User; media: Media; partners: Partner; - concerts: Concert; pages: Page; passwords: Password; links: Link; + concerts: Concert; + posts: Post; 'payload-kv': PayloadKv; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; @@ -84,10 +85,11 @@ export interface Config { users: UsersSelect | UsersSelect; media: MediaSelect | MediaSelect; partners: PartnersSelect | PartnersSelect; - concerts: ConcertsSelect | ConcertsSelect; pages: PagesSelect | PagesSelect; passwords: PasswordsSelect | PasswordsSelect; links: LinksSelect | LinksSelect; + concerts: ConcertsSelect | ConcertsSelect; + posts: PostsSelect | PostsSelect; 'payload-kv': PayloadKvSelect | PayloadKvSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; @@ -185,60 +187,6 @@ export interface Partner { updatedAt: string; createdAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "concerts". - */ -export interface Concert { - id: string; - title: string; - description: { - root: { - type: string; - children: { - type: any; - version: number; - [k: string]: unknown; - }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - photo: string | Media; - pdf?: string | null; - repertoire: { - composer: string; - workTitle: string; - soloist?: string | null; - movements?: string | null; - id?: string | null; - }[]; - performances: { - dateTime: string; - venue?: string | null; - venueAddress: string; - bookingUrl: string; - price: string; - id?: string | null; - }[]; - photo_links?: - | { - link?: string | null; - id?: string | null; - }[] - | null; - video_links?: - | { - link?: string | null; - id?: string | null; - }[] - | null; - updatedAt: string; - createdAt: string; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "pages". @@ -344,6 +292,95 @@ export interface Link { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "concerts". + */ +export interface Concert { + id: string; + title: string; + description: { + root: { + type: string; + children: { + type: any; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + }; + photo: string | Media; + pdf?: string | null; + repertoire: { + composer: string; + workTitle: string; + soloist?: string | null; + movements?: string | null; + id?: string | null; + }[]; + performances: { + dateTime: string; + venue?: string | null; + venueAddress: string; + bookingUrl: string; + price: string; + id?: string | null; + }[]; + photo_links?: + | { + link?: string | null; + id?: string | null; + }[] + | null; + video_links?: + | { + link?: string | null; + id?: string | null; + }[] + | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "posts". + */ +export interface Post { + id: string; + title: string; + slug?: string | null; + description: { + root: { + type: string; + children: { + type: any; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + }; + photos?: + | { + photo?: (string | null) | Media; + id?: string | null; + }[] + | null; + category?: ('blog' | 'alumni_story' | 'interview' | 'scholarships' | 'newsletters' | 'education' | 'audience') | null; + author?: string | null; + publishedDate?: string | null; + updatedAt: string; + createdAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-kv". @@ -368,7 +405,7 @@ export interface PayloadKv { export interface PayloadLockedDocument { id: string; document?: - | ({ + | ({ relationTo: 'users'; value: string | User; } | null) @@ -380,10 +417,6 @@ export interface PayloadLockedDocument { relationTo: 'partners'; value: string | Partner; } | null) - | ({ - relationTo: 'concerts'; - value: string | Concert; - } | null) | ({ relationTo: 'pages'; value: string | Page; @@ -395,6 +428,14 @@ export interface PayloadLockedDocument { | ({ relationTo: 'links'; value: string | Link; + } | null) + | ({ + relationTo: 'concerts'; + value: string | Concert; + } | null) + | ({ + relationTo: 'posts'; + value: string | Post; } | null); globalSlug?: string | null; user: { @@ -491,49 +532,6 @@ export interface PartnersSelect { updatedAt?: T; createdAt?: T; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "concerts_select". - */ -export interface ConcertsSelect { - title?: T; - description?: T; - photo?: T; - pdf?: T; - repertoire?: - | T - | { - composer?: T; - workTitle?: T; - soloist?: T; - movements?: T; - id?: T; - }; - performances?: - | T - | { - dateTime?: T; - venue?: T; - venueAddress?: T; - bookingUrl?: T; - price?: T; - id?: T; - }; - photo_links?: - | T - | { - link?: T; - id?: T; - }; - video_links?: - | T - | { - link?: T; - id?: T; - }; - updatedAt?: T; - createdAt?: T; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "pages_select". @@ -615,6 +613,69 @@ export interface LinksSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "concerts_select". + */ +export interface ConcertsSelect { + title?: T; + description?: T; + photo?: T; + pdf?: T; + repertoire?: + | T + | { + composer?: T; + workTitle?: T; + soloist?: T; + movements?: T; + id?: T; + }; + performances?: + | T + | { + dateTime?: T; + venue?: T; + venueAddress?: T; + bookingUrl?: T; + price?: T; + id?: T; + }; + photo_links?: + | T + | { + link?: T; + id?: T; + }; + video_links?: + | T + | { + link?: T; + id?: T; + }; + updatedAt?: T; + createdAt?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "posts_select". + */ +export interface PostsSelect { + title?: T; + slug?: T; + description?: T; + photos?: + | T + | { + photo?: T; + id?: T; + }; + category?: T; + author?: T; + publishedDate?: T; + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-kv_select". diff --git a/src/payload.config.ts b/src/payload.config.ts index 788de56..cf25b76 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -10,6 +10,7 @@ import { Media } from './collections/Media' import { Partners } from './collections/Partners' import { Concerts } from './collections/Concerts' import { Pages } from './collections/Pages' +import { Posts } from './collections/Posts' import { Passwords } from './collections/Passwords' import { CalendarLink } from './collections/CalendarLink' @@ -23,7 +24,7 @@ export default buildConfig({ baseDir: path.resolve(dirname), }, }, - collections: [Users, Media, Partners, Pages, Passwords, CalendarLink, Concerts], + collections: [Users, Media, Partners, Pages, Passwords, CalendarLink, Concerts, Posts], editor: lexicalEditor(), secret: process.env.PAYLOAD_SECRET || '', typescript: {