-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcadastro.tsx
More file actions
116 lines (110 loc) · 3.73 KB
/
cadastro.tsx
File metadata and controls
116 lines (110 loc) · 3.73 KB
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
import React, { useState } from 'react';
import { View, Text, TextInput, Button, StyleSheet, Alert, TouchableOpacity } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { supabase } from './services/supabase'; // Certifique-se de que o cliente Supabase está configurado corretamente
const CadastroSpulse = () => {
const [email, setEmail] = useState('');
const [name, setName] = useState('');
const [password, setPassword] = useState('');
const [cpf, setCpf] = useState('');
const navigation = useNavigation();
const handleCadastro = async () => {
if (email && password && name && cpf) {
try {
// Insere o usuário no banco de dados Spulse (tabela usersSpulse)
const { data, error } = await supabase
.from('usersSpulse')
.insert([{ name, email, senha: password, cpf }]);
if (error) {
Alert.alert('Erro', error.message || 'Falha ao salvar o cadastro.');
console.error('Erro ao salvar:', error);
} else {
Alert.alert('Sucesso', 'Cadastro realizado com sucesso!');
setName('');
setEmail('');
setPassword('');
setCpf('');
navigation.navigate('Login');
}
} catch (ex) {
console.error('Erro durante o cadastro:', ex);
Alert.alert('Erro', 'Ocorreu um erro durante o cadastro.');
}
} else {
Alert.alert('Erro', 'Por favor, preencha todos os campos.');
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Cadastro Spulse</Text>
<TextInput
style={styles.input}
placeholder="Email"
placeholderTextColor="#888888"
value={email}
onChangeText={setEmail}
/>
<TextInput
style={styles.input}
placeholder="Nome"
placeholderTextColor="#888888"
value={name}
onChangeText={setName}
/>
<TextInput
style={styles.input}
placeholder="Senha"
placeholderTextColor="#888888"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
<TextInput
style={styles.input}
placeholder="CPF"
placeholderTextColor="#888888"
value={cpf}
onChangeText={setCpf}
/>
<Button title="Cadastre-se" onPress={handleCadastro} />
<Text style={styles.registerText}>
Já tem uma conta?{' '}
<TouchableOpacity onPress={() => navigation.navigate('Login')}>
<Text style={styles.link}>Faça o Login aqui</Text>
</TouchableOpacity>
</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 16,
backgroundColor: '#f4f4f4',
},
title: {
fontSize: 24,
textAlign: 'center',
marginBottom: 20,
color: 'black',
},
input: {
height: 40,
borderColor: '#ccc',
borderWidth: 1,
borderRadius: 4,
marginBottom: 15,
paddingHorizontal: 10,
color: 'black',
},
registerText: {
textAlign: 'center',
marginTop: 20,
color: 'black',
},
link: {
color: '#007bff',
},
});
export default CadastroSpulse;