import { zodResolver } from '@hookform/resolvers/zod'
import { Button, Form } from '@zenif/react-web-components-v2'
import { passwordlessAuthSchema } from '@zenif/ts-zod'
import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
type SignInFormProps = {
id: string
onSubmit: (data: { email: string }) => void
}
export function SignInForm({ id, onSubmit }: SignInFormProps) {
const { t } = useTranslation(['common', 'errors'])
const emailLabel = 'Email' // t('email', { ns: 'common' })
const methods = useForm({
defaultValues: { email: '' },
mode: 'onChange',
resolver: zodResolver(passwordlessAuthSchema),
})
const handleSubmit = methods.handleSubmit((data) => {
onSubmit(data)
})
return (
<Form.Root methods={methods} id={id} onSubmit={handleSubmit}>
<Form.FieldControl
control={methods.control}
name="email"
render={({ field }) => (
<Form.FieldRoot>
<Form.FieldLabel>{emailLabel}</Form.FieldLabel>
<Form.FieldInput placeholder={emailLabel} type="email" {...field} />
<Form.FieldHelperText />
<Form.FieldErrorText />
</Form.FieldRoot>
)}
/>
<Form.RootErrorText />
<Button type="submit">
Sign in
</Button>
</Form.Root>
)
}
import { zodResolver } from '@hookform/resolvers/zod'
import { Button, Form } from '@zenif/react-web-components-v2'
import { passwordlessAuthSchema } from '@zenif/ts-zod'
import { useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
type SignInFormProps = {
id: string
onSubmit: (data: { email: string }) => void
}
export function SignInForm({ id, onSubmit }: SignInFormProps) {
const { t } = useTranslation(['common', 'errors'])
const emailLabel = 'Email' // t('email', { ns: 'common' })
const methods = useForm({
defaultValues: { email: '' },
mode: 'onChange',
resolver: zodResolver(passwordlessAuthSchema),
})
const handleSubmit = methods.handleSubmit((data) => {
onSubmit(data)
})
return (
<Form.Root methods={methods} id={id} onSubmit={handleSubmit}>
<Form.FieldControl
control={methods.control}
name="email"
render={({ field }) => (
<Form.FieldRoot>
<Form.FieldLabel>{emailLabel}</Form.FieldLabel>
<Form.FieldInput placeholder={emailLabel} type="email" {...field} />
<Form.FieldHelperText />
<Form.FieldErrorText />
</Form.FieldRoot>
)}
/>
<Form.RootErrorText />
<Button type="submit">
Sign in
</Button>
</Form.Root>
)
}