Skip to content

Commit

Permalink
fix: use typed functions in seed endpoint
Browse files Browse the repository at this point in the history
`JSON.parse(JSON.stringify().replace())` is easy to make mistakes with
and since we have TypeScript data objects already for the data we're
seeding it's pretty easy to just factor these as functions, making their
dependencies explicit.

Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed Jan 7, 2025
1 parent 827c75a commit d0d05e3
Show file tree
Hide file tree
Showing 7 changed files with 1,414 additions and 1,415 deletions.
3 changes: 2 additions & 1 deletion templates/website/src/endpoints/seed/contact-form.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Form } from '@/payload-types'
import { RequiredDataFromCollectionSlug } from 'payload'

export const contactForm: Partial<Form> = {
export const contactForm: RequiredDataFromCollectionSlug<'forms'> = {
confirmationMessage: {
root: {
type: 'root',
Expand Down
92 changes: 48 additions & 44 deletions templates/website/src/endpoints/seed/contact-page.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
import type { Page } from '@/payload-types'
import type { Form } from '@/payload-types'
import { RequiredDataFromCollectionSlug } from 'payload'

export const contact: Partial<Page> = {
slug: 'contact',
_status: 'published',
hero: {
type: 'none',
},
layout: [
{
blockType: 'formBlock',
enableIntro: true,
// @ts-ignore
form: '{{CONTACT_FORM_ID}}',
introContent: {
root: {
type: 'root',
children: [
{
type: 'heading',
children: [
{
type: 'text',
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Example contact form:',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
tag: 'h3',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
version: 1,
export const contact: (contactForm: Form) => RequiredDataFromCollectionSlug<'pages'> = (
contactForm: Form,
): RequiredDataFromCollectionSlug<'pages'> => {
return {
slug: 'contact',
_status: 'published',
hero: {
type: 'none',
},
layout: [
{
blockType: 'formBlock',
enableIntro: true,
form: contactForm,
introContent: {
root: {
type: 'root',
children: [
{
type: 'heading',
children: [
{
type: 'text',
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Example contact form:',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
tag: 'h3',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
version: 1,
},
},
},
},
],
title: 'Contact',
],
title: 'Contact',
}
}
Loading

0 comments on commit d0d05e3

Please sign in to comment.