@@ -11,6 +11,7 @@ import { useUpdateUserInfo } from 'data-services/hooks/auth/useUpdateUserInfo'
1111import { Button , ButtonTheme } from 'design-system/components/button/button'
1212import { IconType } from 'design-system/components/icon/icon'
1313import { InputContent } from 'design-system/components/input/input'
14+ import { useRef } from 'react'
1415import { useForm } from 'react-hook-form'
1516import { API_MAX_UPLOAD_SIZE } from 'utils/constants'
1617import { STRING , translate } from 'utils/language'
@@ -55,6 +56,7 @@ const config: FormConfig = {
5556}
5657
5758export const UserInfoForm = ( { userInfo } : { userInfo : UserInfo } ) => {
59+ const formRef = useRef < HTMLFormElement > ( null )
5860 const {
5961 control,
6062 handleSubmit,
@@ -68,29 +70,29 @@ export const UserInfoForm = ({ userInfo }: { userInfo: UserInfo }) => {
6870 const errorMessage = useFormError ( { error, setFieldError } )
6971
7072 return (
71- < form onSubmit = { handleSubmit ( ( values ) => updateUserInfo ( values ) ) } >
72- { errorMessage && (
73- < FormError
74- inDialog
75- intro = { translate ( STRING . MESSAGE_COULD_NOT_SAVE ) }
76- message = { errorMessage }
77- />
78- ) }
73+ < >
7974 < FormSection >
75+ { errorMessage && (
76+ < FormError
77+ inDialog
78+ intro = { translate ( STRING . MESSAGE_COULD_NOT_SAVE ) }
79+ message = { errorMessage }
80+ />
81+ ) }
8082 < FormRow >
8183 < UserEmailField value = { userInfo . email } />
8284 < UserPasswordField value = "************" />
83- </ FormRow >
84- < >
85- < FormRow >
85+ < form
86+ ref = { formRef }
87+ onSubmit = { handleSubmit ( ( values ) => updateUserInfo ( values ) ) }
88+ className = "grid gap-8"
89+ >
8690 < FormField
8791 name = "name"
8892 type = "text"
8993 config = { config }
9094 control = { control }
9195 />
92- </ FormRow >
93- < FormRow >
9496 < FormController
9597 name = "image"
9698 control = { control }
@@ -109,18 +111,22 @@ export const UserInfoForm = ({ userInfo }: { userInfo: UserInfo }) => {
109111 </ InputContent >
110112 ) }
111113 />
112- </ FormRow >
113- </ >
114+ </ form >
115+ </ FormRow >
114116 </ FormSection >
115117 < FormActions >
116118 < Button
117119 label = { isSuccess ? translate ( STRING . SAVED ) : translate ( STRING . SAVE ) }
118120 icon = { isSuccess ? IconType . RadixCheck : undefined }
119- type = "submit"
121+ onClick = { ( ) => {
122+ formRef . current ?. dispatchEvent (
123+ new Event ( 'submit' , { cancelable : true , bubbles : true } )
124+ )
125+ } }
120126 theme = { ButtonTheme . Success }
121127 loading = { isLoading }
122128 />
123129 </ FormActions >
124- </ form >
130+ </ >
125131 )
126132}
0 commit comments