|
| 1 | +import { zodResolver } from '@hookform/resolvers/zod'; |
| 2 | +import { View } from 'moti'; |
| 3 | +import { useForm } from 'react-hook-form'; |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { KeyboardAvoidingView } from 'react-native-keyboard-controller'; |
| 6 | +import { z } from 'zod'; |
| 7 | + |
| 8 | +import { translate } from '@/core'; |
| 9 | +import { Button, ControlledInput, Text } from '@/ui'; |
| 10 | + |
| 11 | +const schema = z.object({ |
| 12 | + email: z |
| 13 | + .string() |
| 14 | + .email(translate('forgotPassword.emailInvalidFormatFormError')), |
| 15 | +}); |
| 16 | + |
| 17 | +export type FormType = z.infer<typeof schema>; |
| 18 | + |
| 19 | +export const ForgotPasswordForm = (props: { |
| 20 | + onSubmit: (data: FormType) => void; |
| 21 | +}) => { |
| 22 | + const { t } = useTranslation(); |
| 23 | + const { handleSubmit, control } = useForm<{ |
| 24 | + email: string; |
| 25 | + }>({ |
| 26 | + resolver: zodResolver(schema), |
| 27 | + }); |
| 28 | + |
| 29 | + const onSubmit = (data: FormType) => { |
| 30 | + props.onSubmit(data); |
| 31 | + }; |
| 32 | + |
| 33 | + return ( |
| 34 | + <KeyboardAvoidingView> |
| 35 | + <View className="gap-8 p-4"> |
| 36 | + <View className="gap-2"> |
| 37 | + <Text |
| 38 | + testID="forgot-password-form-title" |
| 39 | + className="text-center text-2xl" |
| 40 | + > |
| 41 | + {t('forgotPassword.title')} |
| 42 | + </Text> |
| 43 | + <Text className="text-center text-gray-600"> |
| 44 | + {t('forgotPassword.description')} |
| 45 | + </Text> |
| 46 | + </View> |
| 47 | + <View className="gap-2"> |
| 48 | + <ControlledInput |
| 49 | + testID="email-input" |
| 50 | + autoCapitalize="none" |
| 51 | + autoComplete="email" |
| 52 | + control={control} |
| 53 | + name="email" |
| 54 | + label={t('forgotPassword.emailLabel')} |
| 55 | + placeholder={t('forgotPassword.emailPlaceholder')} |
| 56 | + /> |
| 57 | + <Text className="text-sm text-gray-500"> |
| 58 | + {t('forgotPassword.instructions')} |
| 59 | + </Text> |
| 60 | + <Button |
| 61 | + testID="send-email-button" |
| 62 | + label={t('forgotPassword.buttonLabel')} |
| 63 | + onPress={handleSubmit(onSubmit)} |
| 64 | + className="" |
| 65 | + /> |
| 66 | + </View> |
| 67 | + </View> |
| 68 | + </KeyboardAvoidingView> |
| 69 | + ); |
| 70 | +}; |
0 commit comments