@@ -103,13 +103,15 @@ export function ConfigureErrorAlerts({
103103 }
104104 } , [ fetcher . state , fetcher . data , closeHref , navigate , toast ] ) ;
105105
106- const [ emailFieldValues , setEmailFieldValues ] = useState < string [ ] > ( ( ) =>
106+ const [ emailDefaultValues ] = useState < string [ ] > ( ( ) =>
107107 existingEmails . length > 0 ? [ ...existingEmails . map ( ( e ) => e . email ) , "" ] : [ "" ]
108108 ) ;
109+ const emailFieldValues = useRef ( [ ...emailDefaultValues ] ) ;
109110
110- const [ webhookFieldValues , setWebhookFieldValues ] = useState < string [ ] > ( ( ) =>
111+ const [ webhookDefaultValues ] = useState < string [ ] > ( ( ) =>
111112 existingWebhooks . length > 0 ? [ ...existingWebhooks . map ( ( w ) => w . url ) , "" ] : [ "" ]
112113 ) ;
114+ const webhookFieldValues = useRef ( [ ...webhookDefaultValues ] ) ;
113115
114116 const [ form , fields ] = useForm < z . infer < typeof ErrorAlertsFormSchema > > ( {
115117 id : "configure-error-alerts" ,
@@ -118,8 +120,8 @@ export function ConfigureErrorAlerts({
118120 } ,
119121 shouldRevalidate : "onSubmit" ,
120122 defaultValue : {
121- emails : emailFieldValues ,
122- webhooks : webhookFieldValues ,
123+ emails : emailDefaultValues ,
124+ webhooks : webhookDefaultValues ,
123125 } ,
124126 } ) ;
125127 const { emails, webhooks, slackChannel, slackIntegrationId } = fields ;
@@ -167,12 +169,10 @@ export function ConfigureErrorAlerts({
167169 placeholder = { index === 0 ? "Enter an email address" : "Add another email" }
168170 icon = { EnvelopeIcon }
169171 onChange = { ( e ) => {
170- const nextValues = [ ...emailFieldValues ] ;
171- nextValues [ index ] = e . target . value ;
172- setEmailFieldValues ( nextValues ) ;
172+ emailFieldValues . current [ index ] = e . target . value ;
173173 if (
174- emailFields . length === nextValues . length &&
175- nextValues . every ( ( value ) => value !== "" )
174+ emailFields . length === emailFieldValues . current . length &&
175+ emailFieldValues . current . every ( ( value ) => value !== "" )
176176 ) {
177177 form . insert ( { name : emails . name } ) ;
178178 }
@@ -323,12 +323,10 @@ export function ConfigureErrorAlerts({
323323 }
324324 icon = { GlobeLinesIcon }
325325 onChange = { ( e ) => {
326- const nextValues = [ ...webhookFieldValues ] ;
327- nextValues [ index ] = e . target . value ;
328- setWebhookFieldValues ( nextValues ) ;
326+ webhookFieldValues . current [ index ] = e . target . value ;
329327 if (
330- webhookFields . length === nextValues . length &&
331- nextValues . every ( ( value ) => value !== "" )
328+ webhookFields . length === webhookFieldValues . current . length &&
329+ webhookFieldValues . current . every ( ( value ) => value !== "" )
332330 ) {
333331 form . insert ( { name : webhooks . name } ) ;
334332 }
0 commit comments