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 af97260
Show file tree
Hide file tree
Showing 6 changed files with 1,394 additions and 1,414 deletions.
89 changes: 45 additions & 44 deletions templates/website/src/endpoints/seed/contact-page.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import type { Page } from '@/payload-types'
import type { Page, Form } from '@/payload-types'

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) => Partial<Page> = (contactForm: Form): Partial<Page> => {
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 af97260

Please sign in to comment.