11import { useErrorsLngChange } from '@/hooks/use-errors-lng-change'
2- import { TForgotPass , useForgotPassSchema } from '@/lib/schema/forgot-pass '
2+ import { TEmail , useMailSchema } from '@/lib/schema/mail '
33import { zodResolver } from '@hookform/resolvers/zod'
44import { useForm } from 'react-hook-form'
55import { useTranslation } from 'react-i18next'
66import {
7- Button ,
87 Form ,
98 FormControl ,
109 FormField ,
@@ -15,29 +14,39 @@ import {
1514} from '../ui'
1615
1716type Props = {
18- loading ?: boolean
19- onSubmit ?: ( data : TForgotPass ) => void
17+ onSubmit ?: ( data : TEmail ) => void
18+ id ?: string
19+ defaultValues ?: TEmail
2020}
2121
22- export const ForgotPassForm = ( { loading, onSubmit } : Props ) => {
22+ export const MailForm = ( {
23+ onSubmit,
24+ id = 'mail-form' ,
25+ defaultValues,
26+ } : Props ) => {
2327 const { t } = useTranslation ( [ 'set_pass' , 'forms' ] )
2428
25- const schema = useForgotPassSchema ( )
29+ const schema = useMailSchema ( )
2630
27- const form = useForm < TForgotPass > ( {
31+ const form = useForm < TEmail > ( {
2832 resolver : zodResolver ( schema ) ,
2933 mode : 'onChange' ,
34+ defaultValues,
3035 } )
3136
32- const handleSubmit = ( data : TForgotPass ) => {
37+ const handleSubmit = ( data : TEmail ) => {
3338 onSubmit ?.( data )
3439 }
3540
3641 useErrorsLngChange ( form )
3742
3843 return (
3944 < Form { ...form } >
40- < form className = 'space-y-3' onSubmit = { form . handleSubmit ( handleSubmit ) } >
45+ < form
46+ className = 'space-y-3'
47+ onSubmit = { form . handleSubmit ( handleSubmit ) }
48+ id = { id }
49+ >
4150 < FormField
4251 control = { form . control }
4352 name = 'email'
@@ -62,14 +71,9 @@ export const ForgotPassForm = ({ loading, onSubmit }: Props) => {
6271 )
6372 } }
6473 />
65- < Button className = 'w-full' type = 'submit' loading = { loading } >
66- { t ( 'btn_submit' , {
67- ns : 'set_pass' ,
68- } ) }
69- </ Button >
7074 </ form >
7175 </ Form >
7276 )
7377}
7478
75- export default ForgotPassForm
79+ export default MailForm
0 commit comments