- Forms: step and checkboxGroup field types (radio, date on), server validation for them, useBuilderForm (logic) + BuilderForm (unstyled default) + RenderForm (/rsc: rich text, bound action, public part of the form only — the Emails tab never reaches the browser) - Notifications: next / back / stepOf texts - createContentHelpers: getSiteShell, getFormTexts, getLinkOptions, resolveLink, resolveNav, resolvePageRedirect, one-line route handlers (llms, llms-full, md, mcp, health, indexnow, manifest) - /rsc: SiteProviders, createPageRoute, createNotFoundPage - resolveLink / resolveNav / homeSlugFrom, buildSectionHeaderField / buildSectionSettingsField - Dev sandbox frontend built on these imports; tests (unit + real Payload) Co-Authored-By: Claude Opus 5.5 <[email protected]>
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import { devUser } from './helpers/credentials.js'
|
|
|
|
export const seed = async (payload: Payload) => {
|
|
const { totalDocs } = await payload.count({
|
|
collection: 'users',
|
|
where: {
|
|
email: {
|
|
equals: devUser.email,
|
|
},
|
|
},
|
|
})
|
|
|
|
if (!totalDocs) {
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
roles: ['admin'],
|
|
},
|
|
})
|
|
}
|
|
|
|
await seedContactPage(payload)
|
|
}
|
|
|
|
const text = (t: string) => ({
|
|
root: {
|
|
children: [{ children: [{ detail: 0, format: 0, mode: 'normal', style: '', text: t, type: 'text', version: 1 }], direction: null, format: '', indent: 0, type: 'paragraph', version: 1 }],
|
|
direction: null,
|
|
format: '',
|
|
indent: 0,
|
|
type: 'root',
|
|
version: 1,
|
|
},
|
|
})
|
|
|
|
/** A step-by-step quote form on /pl/kontakt — exercises RenderForm, steps, choice lists, dates. */
|
|
async function seedContactPage(payload: Payload) {
|
|
const { totalDocs } = await payload.count({ collection: 'pages', where: { slug: { equals: 'kontakt' } } })
|
|
if (totalDocs) {return}
|
|
const form = await payload.create({
|
|
collection: 'forms',
|
|
data: {
|
|
confirmationMessage: text('Dziękujemy! Odezwiemy się w ciągu 24 godzin.'),
|
|
confirmationType: 'message',
|
|
fields: [
|
|
{ blockType: 'step', title: 'Kontakt' },
|
|
{ name: 'name', blockType: 'text', label: 'Imię i nazwisko', required: true, width: 50 },
|
|
{ name: 'email', blockType: 'email', label: 'E-mail', required: true, width: 50 },
|
|
{ blockType: 'step', description: 'Zaznacz, czego potrzebujesz.', title: 'Projekt' },
|
|
{ name: 'services', blockType: 'checkboxGroup', label: 'Usługi', options: [{ label: 'Strona WWW', value: 'www' }, { label: 'SEO', value: 'seo' }, { label: 'Kampanie', value: 'ads' }], required: true },
|
|
{ name: 'budget', blockType: 'radio', label: 'Budżet', options: [{ label: 'do 10 tys.', value: 's' }, { label: 'powyżej 10 tys.', value: 'l' }], required: true },
|
|
{ name: 'deadline', blockType: 'date', label: 'Termin' },
|
|
{ blockType: 'message', message: text('Dane przetwarzamy wyłącznie w celu przygotowania wyceny.') },
|
|
{ name: 'consent', blockType: 'checkbox', label: 'Zgadzam się na przetwarzanie danych.', required: true },
|
|
],
|
|
submitButtonLabel: 'Wyślij zapytanie',
|
|
title: 'Wycena',
|
|
} as never,
|
|
})
|
|
const page = await payload.create({
|
|
collection: 'pages',
|
|
data: { layout: [{ blockType: 'formBlock', form: form.id }], slug: 'kontakt', title: 'Kontakt' } as never,
|
|
})
|
|
await payload.updateGlobal({ slug: 'site-settings' as never, data: { siteName: 'Sandbox' } as never })
|
|
payload.logger.info(`[seed] /pl/kontakt (page ${page.id}, form ${form.id})`)
|
|
}
|
|
|