From 1ab9c10548cb85efeba49b5c720cb49569f8b069 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Sat, 12 Apr 2025 13:27:41 +1200 Subject: [PATCH] global values --- payload-types.ts | 76 +++++++++++++++++++++++++++++++++++++++++++-- payload.config.ts | 3 ++ src/globals/Home.ts | 51 ++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 src/globals/Home.ts diff --git a/payload-types.ts b/payload-types.ts index 0ce0d23..e6b0f34 100644 --- a/payload-types.ts +++ b/payload-types.ts @@ -84,8 +84,12 @@ export interface Config { db: { defaultIDType: number; }; - globals: {}; - globalsSelect: {}; + globals: { + home: Home; + }; + globalsSelect: { + home: HomeSelect | HomeSelect; + }; locale: null; user: User & { collection: 'users'; @@ -276,6 +280,74 @@ export interface PayloadMigrationsSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "home". + */ +export interface Home { + id: number; + title?: string | null; + heroTitle?: string | null; + heroDescription?: { + root: { + type: string; + children: { + type: string; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; + heroItems?: + | { + name: string; + id?: string | null; + }[] + | null; + projectsTitle?: string | null; + projectsDescription?: { + root: { + type: string; + children: { + type: string; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; + updatedAt?: string | null; + createdAt?: string | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "home_select". + */ +export interface HomeSelect { + title?: T; + heroTitle?: T; + heroDescription?: T; + heroItems?: + | T + | { + name?: T; + id?: T; + }; + projectsTitle?: T; + projectsDescription?: T; + updatedAt?: T; + createdAt?: T; + globalType?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "auth". diff --git a/payload.config.ts b/payload.config.ts index 35b18c9..d3b4c84 100644 --- a/payload.config.ts +++ b/payload.config.ts @@ -3,6 +3,7 @@ import { lexicalEditor } from '@payloadcms/richtext-lexical' import { postgresAdapter } from '@payloadcms/db-postgres' import { buildConfig } from 'payload' import { News } from './src/collections/News' +import { Home } from '@/globals/Home' export default buildConfig({ // If you'd like to use Rich Text, pass your editor here @@ -10,6 +11,8 @@ export default buildConfig({ serverURL: process.env.SERVER_URL || 'http://localhost:3000', + globals: [Home], + // Define and configure your collections in this array collections: [News], diff --git a/src/globals/Home.ts b/src/globals/Home.ts new file mode 100644 index 0000000..0bfeabe --- /dev/null +++ b/src/globals/Home.ts @@ -0,0 +1,51 @@ +import { GlobalConfig } from "payload"; + +export const Home: GlobalConfig = { + slug: 'home', + fields: [ + { + name: 'title', + label: 'Title', + type: 'text', + defaultValue: 'Analytics, research, and data visualisation that make a difference' + }, + { + name: 'heroTitle', + label: 'Hero Title', + type: 'text', + defaultValue: 'We help people tell stories with data' + }, + { + name: 'heroDescription', + label: 'Hero Description', + type: 'richText', + }, + { + name: 'heroItems', + label: 'Hero Items', + type: 'array', + fields: [ + { + name: 'name', + label: 'Name', + type: 'text', + required: true, + } + ], + defaultValue: ["Data design", "Data collection", "Data analysis", "Data visualisation", "Training", "Data sovereignty"].map((item) => ({ + name: item, + })), + }, + { + name: 'projectsTitle', + label: 'Projects Title', + type: 'text', + defaultValue: 'We do data differently' + }, + { + name: 'projectsDescription', + label: 'Projects Description', + type: 'richText' + } + ], +};