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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
import React, { useState } from 'react';
import { View, StyleSheet, Text, KeyboardAvoidingView, Platform, Alert, ScrollView } from 'react-native';
import { Link, useRouter } from 'expo-router';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Animated, { FadeInDown, FadeInUp } from 'react-native-reanimated';
import * as LocalAuthentication from 'expo-local-authentication';
import * as SecureStore from 'expo-secure-store';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Colors, Spacing, Typography } from '@/constants/theme';
import { useAuth } from '@/contexts/AuthContext';
export default function RegisterScreen() {
const insets = useSafeAreaInsets();
const router = useRouter();
const { register } = useAuth();
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [isLoading, setIsLoading] = useState(false);
async function handleRegister() {
if (!name || !email || !password) {
Alert.alert('Erro', 'Preencha todos os campos.');
return;
}
try {
setIsLoading(true);
await register({ name: name.trim(), email: email.trim(), password });
const hasHardware = await LocalAuthentication.hasHardwareAsync();
const isEnrolled = await LocalAuthentication.isEnrolledAsync();
if (hasHardware && isEnrolled) {
router.replace('/biometrics');
} else {
router.replace('/');
}
} catch (err: any) {
Alert.alert('Erro no cadastro', err.message || 'Verifique seus dados.');
setIsLoading(false);
}
}
return (
<KeyboardAvoidingView style={styles.container} behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
<ScrollView contentContainerStyle={[styles.content, { paddingTop: insets.top + Spacing.xl }]}>
<Animated.View entering={FadeInUp.duration(600)} style={styles.header}>
<Text style={styles.title}>Criar Conta</Text>
<Text style={styles.subtitle}>Junte-se ao YABA e organize sua vida financeira.</Text>
</Animated.View>
<Animated.View entering={FadeInDown.delay(200).duration(600)} style={styles.form}>
<Input
id="register-name"
label="Nome"
placeholder="Como quer ser chamado?"
value={name}
onChangeText={setName}
/>
<Input
id="register-email"
label="E-mail"
placeholder="seu@email.com"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
autoCapitalize="none"
/>
<Input
id="register-password"
label="Senha"
placeholder="No mínimo 6 caracteres"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
<Button
id="register-button"
label="Cadastrar"
fullWidth
onPress={handleRegister}
loading={isLoading}
disabled={isLoading}
/>
<View style={styles.footer}>
<Text style={styles.footerText}>Já tem uma conta? </Text>
<Link href="/login" asChild>
<Text style={styles.linkText}>Faça login</Text>
</Link>
</View>
</Animated.View>
</ScrollView>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.background,
},
content: {
flexGrow: 1,
padding: Spacing.xl,
justifyContent: 'center',
},
header: {
alignItems: 'center',
marginBottom: Spacing.xl,
},
title: {
...Typography.h1,
color: Colors.textPrimary,
},
subtitle: {
...Typography.body,
color: Colors.textSecondary,
marginTop: Spacing.xs,
textAlign: 'center',
},
form: {
gap: Spacing.lg,
},
footer: {
flexDirection: 'row',
justifyContent: 'center',
marginTop: Spacing.xl,
},
footerText: {
...Typography.body,
color: Colors.textSecondary,
},
linkText: {
...Typography.body,
color: Colors.primaryLight,
fontFamily: 'DMSans_700Bold',
},
});
|