@@ -57,20 +57,18 @@ export const AdminUser = (props: { onSubmit: () => void; onError: () => void; on
5757 } ) ,
5858 } ) ;
5959
60- const formMethods = useForm < {
61- username : string ;
62- email_address : string ;
63- full_name : string ;
64- password : string ;
65- } > ( {
60+ type formSchemaType = z . infer < typeof formSchema > ;
61+
62+ const formMethods = useForm < formSchemaType > ( {
63+ mode : "onChange" ,
6664 resolver : zodResolver ( formSchema ) ,
6765 } ) ;
6866
6967 const onError = ( ) => {
7068 props . onError ( ) ;
7169 } ;
7270
73- const onSubmit = formMethods . handleSubmit ( async ( data : z . infer < typeof formSchema > ) => {
71+ const onSubmit = formMethods . handleSubmit ( async ( data ) => {
7472 props . onSubmit ( ) ;
7573 const response = await fetch ( "/api/auth/setup" , {
7674 method : "POST" ,
@@ -130,11 +128,7 @@ export const AdminUser = (props: { onSubmit: () => void; onError: () => void; on
130128 className = { classNames ( "my-0" , longWebsiteUrl && "rounded-t-none" ) }
131129 onBlur = { onBlur }
132130 name = "username"
133- onChange = { async ( e ) => {
134- onChange ( e . target . value ) ;
135- formMethods . setValue ( "username" , e . target . value ) ;
136- await formMethods . trigger ( "username" ) ;
137- } }
131+ onChange = { ( e ) => onChange ( e . target . value ) }
138132 />
139133 </ >
140134 ) }
@@ -148,11 +142,7 @@ export const AdminUser = (props: { onSubmit: () => void; onError: () => void; on
148142 < TextField
149143 value = { value || "" }
150144 onBlur = { onBlur }
151- onChange = { async ( e ) => {
152- onChange ( e . target . value ) ;
153- formMethods . setValue ( "full_name" , e . target . value ) ;
154- await formMethods . trigger ( "full_name" ) ;
155- } }
145+ onChange = { ( e ) => onChange ( e . target . value ) }
156146 color = { formMethods . formState . errors . full_name ? "warn" : "" }
157147 type = "text"
158148 name = "full_name"
@@ -172,11 +162,7 @@ export const AdminUser = (props: { onSubmit: () => void; onError: () => void; on
172162 < EmailField
173163 value = { value || "" }
174164 onBlur = { onBlur }
175- onChange = { async ( e ) => {
176- onChange ( e . target . value ) ;
177- formMethods . setValue ( "email_address" , e . target . value ) ;
178- await formMethods . trigger ( "email_address" ) ;
179- } }
165+ onChange = { ( e ) => onChange ( e . target . value ) }
180166 className = "my-0"
181167 name = "email_address"
182168 />
@@ -191,11 +177,7 @@ export const AdminUser = (props: { onSubmit: () => void; onError: () => void; on
191177 < PasswordField
192178 value = { value || "" }
193179 onBlur = { onBlur }
194- onChange = { async ( e ) => {
195- onChange ( e . target . value ) ;
196- formMethods . setValue ( "password" , e . target . value ) ;
197- await formMethods . trigger ( "password" ) ;
198- } }
180+ onChange = { ( e ) => onChange ( e . target . value ) }
199181 hintErrors = { [ "caplow" , "admin_min" , "num" ] }
200182 name = "password"
201183 className = "my-0"
0 commit comments