forked from feliperibeiroo/atividade-testes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CadastroAtendente.js
161 lines (150 loc) · 4.8 KB
/
CadastroAtendente.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { useState } from 'react';
import { View, Text, TextInput, ScrollView, StyleSheet } from 'react-native';
import { Card, Button } from 'react-native-paper';
import { Ionicons } from '@expo/vector-icons';
import { useNavigation } from '@react-navigation/native'; // Importar useNavigation
import Header from './components/Header';
import Footer from './components/Footer';
import supabase from './database/database'; // Importe a configuração do Supabase
export default function CadastroAtendenteScreen() {
const navigation = useNavigation(); // Hook para navegação
const [nome, setNome] = useState('');
const [cpf, setCpf] = useState('');
const [email, setEmail] = useState('');
const [senha, setSenha] = useState('');
const [msg, setMsg] = useState('');
const handleCadastro = async () => {
// Limpa a mensagem anterior
setMsg('');
// Tenta inserir os dados no Supabase
const { data, error } = await supabase
.from('atendente')
.insert([{ nome, cpf, email, senha }]);
if (error) {
setMsg('Erro ao cadastrar: ' + error.message);
} else {
setMsg('Usuário cadastrado com sucesso!');
// Limpa os campos após o cadastro
setNome('');
setCpf('');
setEmail('');
setSenha('');
// Atraso antes de navegar para a tela de Login
setTimeout(() => {
navigation.navigate('Login');
}, 2000); // Atraso de 2 segundos (2000 ms)
}
};
return (
<View style={styles.container}>
{/* Barra Superior */}
<Header
name="Mariana Maia"
position="Atendente"
profileImageUrl="https://img.freepik.com/fotos-gratis/jovem-mulher-trabalhando-no-escritorio-com-laptop-e-fones-de-ouvido-na-parede-branca-atendimento-ao-cliente-e-call-center_231208-8601.jpg?w=1380&t=st=1724717085~exp=1724717685~hmac=c0df740124bfb9cd1c047f4c069f68c58dbf45ef00d76c6e66fda7765b8d3337"
/>
{/* Formulário */}
<ScrollView contentContainerStyle={styles.formContainer}>
<Card style={styles.formCard}>
<Card.Title
title="Cadastro Atendente"
titleStyle={styles.formTitle}
left={(props) => <Ionicons name="person-add" size={32} color="#FFF" />}
/>
<Card.Content>
<TextInput
style={styles.input}
placeholder="Nome Completo"
placeholderTextColor="#888"
value={nome}
onChangeText={setNome}
/>
<TextInput
style={styles.input}
placeholder="CPF"
placeholderTextColor="#888"
keyboardType="numeric"
value={cpf}
onChangeText={setCpf}
/>
<TextInput
style={styles.input}
placeholder="E-mail"
placeholderTextColor="#888"
keyboardType="email-address"
autoCapitalize="none"
value={email}
onChangeText={setEmail}
/>
<TextInput
style={styles.input}
placeholder="Senha"
placeholderTextColor="#888"
secureTextEntry
value={senha}
onChangeText={setSenha}
/>
{/* Botão de Submit */}
<Button mode="contained" style={styles.submitButton} onPress={handleCadastro}>
<Text style={styles.submitButtonText}>Cadastrar Usuário</Text>
</Button>
{/* Mensagem de feedback */}
{msg !== '' && (
<Text style={styles.message}>{msg}</Text>
)}
</Card.Content>
</Card>
</ScrollView>
{/* Footer positioned at the bottom */}
<Footer style={styles.footer}>
<Text style={styles.footerText}>Footer Content</Text>
</Footer>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#B7FAFE',
},
formContainer: {
padding: 20,
},
formCard: {
backgroundColor: '#5978E5',
borderRadius: 10,
},
formTitle: {
color: '#FFF',
},
input: {
backgroundColor: '#FFF',
color: '#888',
borderRadius: 10,
paddingHorizontal: 15,
paddingVertical: 10,
marginBottom: 15,
borderWidth: 1,
borderColor: '#5978E5',
},
submitButton: {
backgroundColor: '#2DAD2B',
marginTop: 20,
},
submitButtonText: {
color: '#FFF',
fontWeight: 'bold',
},
footer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
backgroundColor: '#5978E5',
padding: 10,
},
message: {
marginTop: 10,
color: '#FFF',
textAlign: 'center',
},
});