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