Skip to content

Commit d6658b5

Browse files
authored
chore(templates): fix: the contact page of the website template throws an error in live preview (#10785)
Fixes: #10787 The underlying problem is that there are types in the form builder plugin that are unnecessarily `any` or `unknown`. Here in the website template this was being circumvented with a function that was not really needed (buildInitialFormState), and with new unknown types (Value, Property and Data). Since create-payload-app fetches from the latest commit instead of the latest release, it is necessary to first merge #10789, and once the next release is done this PR can be merged.
1 parent 8289588 commit d6658b5

File tree

2 files changed

+3
-58
lines changed

2 files changed

+3
-58
lines changed

templates/website/src/blocks/Form/Component.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client'
2-
import type { Form as FormType } from '@payloadcms/plugin-form-builder/types'
2+
import type { FormFieldBlock, Form as FormType } from '@payloadcms/plugin-form-builder/types'
33

44
import { useRouter } from 'next/navigation'
55
import React, { useCallback, useState } from 'react'
@@ -8,20 +8,9 @@ import RichText from '@/components/RichText'
88
import { Button } from '@/components/ui/button'
99
import type { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'
1010

11-
import { buildInitialFormState } from './buildInitialFormState'
1211
import { fields } from './fields'
1312
import { getClientSideURL } from '@/utilities/getURL'
1413

15-
export type Value = unknown
16-
17-
export interface Property {
18-
[key: string]: Value
19-
}
20-
21-
export interface Data {
22-
[key: string]: Property | Property[]
23-
}
24-
2514
export type FormBlockType = {
2615
blockName?: string
2716
blockType?: 'formBlock'
@@ -43,7 +32,7 @@ export const FormBlock: React.FC<
4332
} = props
4433

4534
const formMethods = useForm({
46-
defaultValues: buildInitialFormState(formFromProps.fields),
35+
defaultValues: formFromProps.fields,
4736
})
4837
const {
4938
control,
@@ -58,7 +47,7 @@ export const FormBlock: React.FC<
5847
const router = useRouter()
5948

6049
const onSubmit = useCallback(
61-
(data: Data) => {
50+
(data: FormFieldBlock[]) => {
6251
let loadingTimerID: ReturnType<typeof setTimeout>
6352
const submitForm = async () => {
6453
setError(undefined)

templates/website/src/blocks/Form/buildInitialFormState.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)