diff --git a/src/blocks/Hero/Hero.ts b/src/blocks/Hero/Hero.ts new file mode 100644 index 0000000..e4b18dd --- /dev/null +++ b/src/blocks/Hero/Hero.ts @@ -0,0 +1,42 @@ +import { Block } from 'payload' + +export const Hero: Block = { + slug: 'Hero', + fields: [ + { + name: 'heading', + type: 'text', + }, + { + name: 'subheading', + type: 'text', + }, + { + name: 'brief', + type: 'textarea', + }, + { + name: 'minHeight', + type: 'select', + options: [ + { + value: '100', + label: 'Full' + }, + { + value: '80', + label: '80%' + }, + { + value: '60', + label: '60%' + }, + ] + }, + { + name: 'backgroundImage', + type: 'relationship', + relationTo: 'media', + }, + ] +} diff --git a/src/collections/Authors/Authors.ts b/src/collections/Authors/Authors.ts index 53b4b52..f9fdedf 100644 --- a/src/collections/Authors/Authors.ts +++ b/src/collections/Authors/Authors.ts @@ -46,5 +46,11 @@ export const Authors: CollectionConfig = { }, ], }, + { + name: 'books', + type: 'join', + collection: 'books', + on: 'authors', + } ], } diff --git a/src/collections/Books/Books.ts b/src/collections/Books/Books.ts index 7f42eca..33cc743 100644 --- a/src/collections/Books/Books.ts +++ b/src/collections/Books/Books.ts @@ -47,7 +47,7 @@ export const Books: CollectionConfig = { { label: 'Publication Date', name: 'date', - type: 'string', + type: 'text', }, { name: 'genre', diff --git a/src/collections/Pages/Pages.ts b/src/collections/Pages/Pages.ts new file mode 100644 index 0000000..f0d735f --- /dev/null +++ b/src/collections/Pages/Pages.ts @@ -0,0 +1,20 @@ +import { Hero } from "@/blocks/Hero/Hero"; +import { CollectionConfig } from "payload"; + +export const Pages: CollectionConfig = { + slug: 'pages', + admin: { + useAsTitle: 'title', + }, + fields: [ + { + name: 'title', + type: 'text', + }, + { + name: 'layout', + type: 'blocks', + blocks: [Hero], + }, + ] +} diff --git a/src/globals/header/config.ts b/src/globals/header/config.ts new file mode 100644 index 0000000..594c24e --- /dev/null +++ b/src/globals/header/config.ts @@ -0,0 +1,31 @@ +import { GlobalConfig } from "payload"; + + +export const Header: GlobalConfig = { + slug: 'header', + label: 'Header Nav', + fields: [ + { + name: 'headerLinks', + type: 'array', + minRows: 1, + maxRows: 5, + fields: [ + { + name: 'label', + type: 'text', + }, + { + name: 'page', + type: 'relationship', + relationTo: 'pages' + }, + { + name: 'newTab', + label: 'Open in new Tab?', + type: 'checkbox', + }, + ], + } + ] +} diff --git a/src/payload-types.ts b/src/payload-types.ts index 4c43d14..9593b9d 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -74,11 +74,16 @@ export interface Config { repositories: Repository; copies: Copy; genre: Genre; + pages: Page; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; }; - collectionsJoins: {}; + collectionsJoins: { + authors: { + books: 'books'; + }; + }; collectionsSelect: { users: UsersSelect | UsersSelect; media: MediaSelect | MediaSelect; @@ -87,6 +92,7 @@ export interface Config { repositories: RepositoriesSelect | RepositoriesSelect; copies: CopiesSelect | CopiesSelect; genre: GenreSelect | GenreSelect; + pages: PagesSelect | PagesSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; @@ -94,8 +100,12 @@ export interface Config { db: { defaultIDType: number; }; - globals: {}; - globalsSelect: {}; + globals: { + header: Header; + }; + globalsSelect: { + header: HeaderSelect | HeaderSelect; + }; locale: null; user: User & { collection: 'users'; @@ -172,6 +182,7 @@ export interface Book { pages?: number | null; lcc?: string | null; publication?: string | null; + date?: string | null; genre?: (number | Genre)[] | null; summary?: string | null; description?: { @@ -201,6 +212,11 @@ export interface Author { lf: string; fl?: string | null; role?: ('Author' | 'Translator' | 'Editor') | null; + books?: { + docs?: (number | Book)[]; + hasNextPage?: boolean; + totalDocs?: number; + }; updatedAt: string; createdAt: string; } @@ -257,6 +273,28 @@ export interface Copy { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pages". + */ +export interface Page { + id: number; + title?: string | null; + layout?: + | { + heading?: string | null; + subheading?: string | null; + brief?: string | null; + minHeight?: ('100' | '80' | '60') | null; + backgroundImage?: (number | null) | Media; + id?: string | null; + blockName?: string | null; + blockType: 'Hero'; + }[] + | null; + updatedAt: string; + createdAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-locked-documents". @@ -291,6 +329,10 @@ export interface PayloadLockedDocument { | ({ relationTo: 'genre'; value: number | Genre; + } | null) + | ({ + relationTo: 'pages'; + value: number | Page; } | null); globalSlug?: string | null; user: { @@ -394,6 +436,7 @@ export interface AuthorsSelect { lf?: T; fl?: T; role?: T; + books?: T; updatedAt?: T; createdAt?: T; } @@ -430,6 +473,30 @@ export interface GenreSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pages_select". + */ +export interface PagesSelect { + title?: T; + layout?: + | T + | { + Hero?: + | T + | { + heading?: T; + subheading?: T; + brief?: T; + minHeight?: T; + backgroundImage?: T; + id?: T; + blockName?: T; + }; + }; + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-locked-documents_select". @@ -462,6 +529,40 @@ export interface PayloadMigrationsSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "header". + */ +export interface Header { + id: number; + headerLinks?: + | { + label?: string | null; + page?: (number | null) | Page; + newTab?: boolean | null; + id?: string | null; + }[] + | null; + updatedAt?: string | null; + createdAt?: string | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "header_select". + */ +export interface HeaderSelect { + headerLinks?: + | T + | { + label?: T; + page?: T; + newTab?: T; + id?: T; + }; + updatedAt?: T; + createdAt?: T; + globalType?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "auth". diff --git a/src/payload.config.ts b/src/payload.config.ts index 76b3f2a..df5be9b 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -13,6 +13,8 @@ import { Authors } from './collections/Authors/Authors' import { Repositories } from './collections/Repositories/Repositories' import { Copies } from './collections/Copies/Copies' import { Genre } from './collections/Books/Genre' +import { Header } from './globals/header/config' +import { Pages } from './collections/Pages/Pages' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -32,7 +34,8 @@ export default buildConfig({ fileSize: 5000000, // in bytes }, }, - collections: [Users, Media, Books, Authors, Repositories, Copies, Genre], + globals: [Header], + collections: [Users, Media, Books, Authors, Repositories, Copies, Genre, Pages], editor: lexicalEditor(), secret: process.env.PAYLOAD_SECRET || '', typescript: { @@ -48,4 +51,11 @@ export default buildConfig({ //payloadCloudPlugin(), // storage-adapter-placeholder ], + hooks: { + afterError: [ + (error) => { + console.log(error) + } + ], + }, })