1- import { conform , list , requestIntent , useFieldList , useForm } from "@conform-to/react" ;
2- import { parse } from "@conform-to/zod" ;
1+ import { getFormProps , getInputProps , useForm } from "@conform-to/react" ;
2+ import { parseWithZod } from "@conform-to/zod" ;
33import {
44 EnvelopeIcon ,
55 GlobeAltIcon ,
@@ -104,20 +104,21 @@ export function ConfigureErrorAlerts({
104104 existingWebhooks . length > 0 ? [ ...existingWebhooks . map ( ( w ) => w . url ) , "" ] : [ "" ]
105105 ) ;
106106
107- const [ form , { emails , webhooks , slackChannel , slackIntegrationId } ] = useForm ( {
107+ const [ form , fields ] = useForm < z . infer < typeof ErrorAlertsFormSchema > > ( {
108108 id : "configure-error-alerts" ,
109109 onValidate ( { formData } ) {
110- return parse ( formData , { schema : ErrorAlertsFormSchema } ) ;
110+ return parseWithZod ( formData , { schema : ErrorAlertsFormSchema } ) ;
111111 } ,
112112 shouldRevalidate : "onSubmit" ,
113113 defaultValue : {
114114 emails : emailFieldValues . current ,
115115 webhooks : webhookFieldValues . current ,
116116 } ,
117117 } ) ;
118+ const { emails, webhooks, slackChannel, slackIntegrationId } = fields ;
118119
119- const emailFields = useFieldList ( form . ref , emails ) ;
120- const webhookFields = useFieldList ( form . ref , webhooks ) ;
120+ const emailFields = emails . getFieldList ( ) ;
121+ const webhookFields = webhooks . getFieldList ( ) ;
121122
122123 return (
123124 < div className = "grid h-full grid-rows-[auto_1fr_auto] overflow-hidden" >
@@ -135,7 +136,12 @@ export function ConfigureErrorAlerts({
135136 />
136137 </ div >
137138
138- < fetcher . Form method = "post" action = { formAction } { ...form . props } className = "contents" >
139+ < fetcher . Form
140+ method = "post"
141+ action = { formAction }
142+ { ...getFormProps ( form ) }
143+ className = "contents"
144+ >
139145 < div className = "flex-1 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600" >
140146 < Fieldset className = "flex flex-col gap-4 p-4" >
141147 < div className = "flex flex-col" >
@@ -155,7 +161,7 @@ export function ConfigureErrorAlerts({
155161 { emailFields . map ( ( emailField , index ) => (
156162 < Fragment key = { emailField . key } >
157163 < Input
158- { ...conform . input ( emailField , { type : "email" } ) }
164+ { ...getInputProps ( emailField , { type : "email" } ) }
159165 placeholder = { index === 0 ? "Enter an email address" : "Add another email" }
160166 icon = { EnvelopeIcon }
161167 onChange = { ( e ) => {
@@ -164,11 +170,11 @@ export function ConfigureErrorAlerts({
164170 emailFields . length === emailFieldValues . current . length &&
165171 emailFieldValues . current . every ( ( v ) => v !== "" )
166172 ) {
167- requestIntent ( form . ref . current ?? undefined , list . append ( emails . name ) ) ;
173+ form . insert ( { name : emails . name } ) ;
168174 }
169175 } }
170176 />
171- < FormError id = { emailField . errorId } > { emailField . error } </ FormError >
177+ < FormError id = { emailField . errorId } > { emailField . errors } </ FormError >
172178 </ Fragment >
173179 ) ) }
174180 </ InputGroup >
@@ -315,7 +321,7 @@ export function ConfigureErrorAlerts({
315321 { webhookFields . map ( ( webhookField , index ) => (
316322 < Fragment key = { webhookField . key } >
317323 < Input
318- { ...conform . input ( webhookField , { type : "url" } ) }
324+ { ...getInputProps ( webhookField , { type : "url" } ) }
319325 placeholder = {
320326 index === 0 ? "https://example.com/webhook" : "Add another webhook URL"
321327 }
@@ -326,18 +332,18 @@ export function ConfigureErrorAlerts({
326332 webhookFields . length === webhookFieldValues . current . length &&
327333 webhookFieldValues . current . every ( ( v ) => v !== "" )
328334 ) {
329- requestIntent ( form . ref . current ?? undefined , list . append ( webhooks . name ) ) ;
335+ form . insert ( { name : webhooks . name } ) ;
330336 }
331337 } }
332338 />
333- < FormError id = { webhookField . errorId } > { webhookField . error } </ FormError >
339+ < FormError id = { webhookField . errorId } > { webhookField . errors } </ FormError >
334340 </ Fragment >
335341 ) ) }
336342 < Hint > We'll issue POST requests to these URLs with a JSON payload.</ Hint >
337343 </ InputGroup >
338344 </ div >
339345
340- < FormError > { form . error } </ FormError >
346+ < FormError > { form . errors } </ FormError >
341347 </ Fieldset >
342348 </ div >
343349
0 commit comments