Skip to content

Commit cbba9a3

Browse files
author
Guillermo Machado
committed
feat: adjustments to login and sign in screens
1 parent 7bbb49a commit cbba9a3

File tree

3 files changed

+81
-53
lines changed

3 files changed

+81
-53
lines changed

src/components/login-form.tsx

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import { useForm } from 'react-hook-form';
55
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';
66
import z from 'zod';
77

8+
import { translate } from '@/core';
89
import { Button, ControlledInput, Text, View } from '@/ui';
910

1011
const MIN_CHARS = 6;
1112
const schema = z.object({
1213
email: z
13-
.string({ required_error: 'Email is required' })
14-
.email('Invalid email format'),
14+
.string({
15+
required_error: translate('auth.signIn.validation.emailRequired'),
16+
})
17+
.email(translate('auth.signIn.validation.invalidEmail')),
1518
password: z
1619
.string({
17-
required_error: 'Password is required',
20+
required_error: translate('auth.signIn.validation.passwordRequired'),
1821
})
19-
.min(MIN_CHARS, 'Password must be at least 6 characters'),
22+
.min(MIN_CHARS, translate('auth.signIn.validation.passwordMinChars')),
2023
});
2124

2225
export type FormType = z.infer<typeof schema>;
@@ -39,41 +42,50 @@ export const LoginForm = ({
3942
behavior="padding"
4043
keyboardVerticalOffset={10}
4144
>
42-
<View className="flex-1 justify-center p-4">
43-
<Text testID="form-title" className="pb-6 text-center text-2xl">
44-
Sign In
45+
<View className="flex-1 justify-center gap-8 p-4">
46+
<Text testID="form-title" className="text-center text-2xl">
47+
{translate('auth.signIn.title')}
4548
</Text>
49+
<View>
50+
<ControlledInput
51+
testID="email-input"
52+
autoCapitalize="none"
53+
autoComplete="email"
54+
control={control}
55+
name="email"
56+
label={translate('auth.signIn.title')}
57+
/>
58+
<ControlledInput
59+
testID="password-input"
60+
control={control}
61+
name="password"
62+
label={translate('auth.signIn.validation.passwordRequired')}
63+
placeholder="***"
64+
secureTextEntry={true}
65+
/>
4666

47-
<ControlledInput
48-
testID="email-input"
49-
autoCapitalize="none"
50-
autoComplete="email"
51-
control={control}
52-
name="email"
53-
label="Email"
54-
/>
55-
<ControlledInput
56-
testID="password-input"
57-
control={control}
58-
name="password"
59-
label="Password"
60-
placeholder="***"
61-
secureTextEntry={true}
62-
/>
63-
64-
<Button
65-
testID="login-button"
66-
label="Login"
67-
onPress={handleSubmit(onSubmit)}
68-
loading={isLoading}
69-
/>
70-
71-
<Text>
72-
Don't have an account?{' '}
73-
<Link href="/sign-up" disabled={isLoading}>
74-
<Text className="font-bold text-black">Sign up</Text>
67+
<Button
68+
testID="login-button"
69+
label={translate('auth.signIn.buttons.login')}
70+
onPress={handleSubmit(onSubmit)}
71+
loading={isLoading}
72+
/>
73+
<Text>
74+
{translate('auth.signIn.newAccount')}{' '}
75+
<Link href="/sign-up" disabled={isLoading}>
76+
<Text className="font-bold text-black">
77+
{translate('auth.signIn.buttons.signUp')}
78+
</Text>
79+
</Link>
80+
</Text>
81+
<Link href="/forgot-password" disabled={isLoading} asChild>
82+
<Button
83+
variant="link"
84+
className="font-bold text-black"
85+
label={translate('auth.signIn.forgotPasswordButton')}
86+
/>
7587
</Link>
76-
</Text>
88+
</View>
7789
</View>
7890
</KeyboardAvoidingView>
7991
);

src/components/sign-up-form.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ import { Button, ControlledInput, Text, View } from '@/ui';
99
const MIN_PASSWORD_LENGTH = 6;
1010

1111
const passwordSchema = z
12-
.string({ required_error: translate('auth.sign_up.error.passwordRequired') })
13-
.min(MIN_PASSWORD_LENGTH, translate('auth.sign_up.error.shortPassword'));
12+
.string({ required_error: translate('auth.signUp.error.passwordRequired') })
13+
.min(MIN_PASSWORD_LENGTH, translate('auth.signUp.error.shortPassword'));
1414

1515
const schema = z
1616
.object({
1717
email: z
18-
.string({ required_error: translate('auth.sign_up.error.emailRequired') })
19-
.email(translate('auth.sign_up.error.emailInvalid')),
18+
.string({ required_error: translate('auth.signUp.error.emailRequired') })
19+
.email(translate('auth.signUp.error.emailInvalid')),
2020
name: z.string({
21-
required_error: translate('auth.sign_up.error.nameRequired'),
21+
required_error: translate('auth.signUp.error.nameRequired'),
2222
}),
2323
password: passwordSchema,
2424
passwordConfirmation: z.string({
2525
required_error: translate(
26-
'auth.sign_up.error.passwordConfirmationRequired',
26+
'auth.signUp.error.passwordConfirmationRequired',
2727
),
2828
}),
2929
})
3030
.refine((data) => data.password === data.passwordConfirmation, {
31-
message: translate('auth.sign_up.error.passwordsDoNotMatch'),
31+
message: translate('auth.signUp.error.passwordsDoNotMatch'),
3232
path: ['passwordConfirmation'],
3333
});
3434

@@ -55,7 +55,7 @@ export const SignUpForm = ({
5555
>
5656
<View className="flex-1 justify-center gap-4 p-4">
5757
<Text testID="form-title" className="text-center text-2xl">
58-
{translate('auth.sign_up.title')}
58+
{translate('auth.signUp.title')}
5959
</Text>
6060
<View>
6161
<ControlledInput
@@ -64,34 +64,34 @@ export const SignUpForm = ({
6464
autoComplete="email"
6565
control={control}
6666
name="email"
67-
label={translate('auth.sign_up.fields.email')}
67+
label={translate('auth.signUp.fields.email')}
6868
/>
6969
<ControlledInput
7070
testID="name-input"
7171
control={control}
7272
name="name"
73-
label={translate('auth.sign_up.fields.name')}
73+
label={translate('auth.signUp.fields.name')}
7474
/>
7575
<ControlledInput
7676
testID="password-input"
7777
control={control}
7878
name="password"
79-
label={translate('auth.sign_up.fields.password')}
79+
label={translate('auth.signUp.fields.password')}
8080
placeholder="***"
8181
secureTextEntry={true}
8282
/>
8383
<ControlledInput
8484
testID="password-confirmation-input"
8585
control={control}
8686
name="passwordConfirmation"
87-
label={translate('auth.sign_up.fields.password')}
87+
label={translate('auth.signUp.fields.password')}
8888
placeholder="***"
8989
secureTextEntry={true}
9090
/>
9191

9292
<Button
9393
testID="sign-up-button"
94-
label={translate('auth.sign_up.signUpButton')}
94+
label={translate('auth.signUp.signUpButton')}
9595
onPress={handleSubmit(onSubmit)}
9696
loading={isPending}
9797
disabled={isPending}

src/translations/en.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
{
22
"auth": {
3-
"sign-in": {
4-
"forgotPasswordButton": "Forgot Password"
3+
"signIn": {
4+
"buttons": {
5+
"login": "Login",
6+
"signUp": "Sign Up"
7+
},
8+
"fields": {
9+
"email": "Email",
10+
"password": "Password"
11+
},
12+
"forgotPasswordButton": "Forgot Password",
13+
"newAccount": "Doesn't have an account?",
14+
"signUp": "Already have an account?",
15+
"title": "Sign In",
16+
"validation": {
17+
"emailRequired": "Email is required",
18+
"invalidEmail": "Invalid email format",
19+
"passwordMinChars": "Password must be at least 6 characters",
20+
"passwordRequired": "Password is required"
21+
}
522
},
6-
"sign_up": {
7-
"already_have_an_account": "Already have an account? ",
23+
"signUp": {
824
"error": {
925
"emailInvalid": "Invalid email format",
1026
"emailRequired": "Email is required",

0 commit comments

Comments
 (0)