diff --git a/app/Professor/Alunos/DetalhesAluno.tsx b/app/Professor/Alunos/DetalhesAluno.tsx index 83496e4..6cc4b64 100644 --- a/app/Professor/Alunos/DetalhesAluno.tsx +++ b/app/Professor/Alunos/DetalhesAluno.tsx @@ -2,7 +2,6 @@ import { Ionicons } from '@expo/vector-icons'; import { useLocalSearchParams, useRouter } from 'expo-router'; import { memo, useEffect, useState } from 'react'; import { - SafeAreaView, ScrollView, StatusBar, StyleSheet, @@ -10,13 +9,22 @@ import { TouchableOpacity, View, } from 'react-native'; +import { SafeAreaView } from 'react-native-safe-area-context'; +import { useTheme } from '../../../themecontext'; import { supabase } from '../../lib/supabase'; const DetalhesAlunos = memo(() => { const router = useRouter(); const params = useLocalSearchParams(); + const { isDarkMode } = useTheme(); + + const colors = { + background: isDarkMode ? '#121212' : '#f1f3f5', + card: isDarkMode ? '#1e1e1e' : '#ffffff', + text: isDarkMode ? '#ffffff' : '#000000', + label: isDarkMode ? '#aaaaaa' : '#6c757d', + }; - // alunoId é o parâmetro que vem da rota const alunoId = typeof params.alunoId === 'string' ? params.alunoId @@ -29,7 +37,6 @@ const DetalhesAlunos = memo(() => { useEffect(() => { if (!alunoId) { - console.log('alunoId não recebido'); setLoading(false); return; } @@ -38,10 +45,9 @@ const DetalhesAlunos = memo(() => { const fetchAluno = async () => { try { - console.log('Buscando aluno ID:', alunoId); setLoading(true); - // 1️⃣ Buscar aluno na tabela 'alunos' (para turma_curso e n_escola) + // 1️⃣ Buscar dados do aluno const { data: alunoData, error: alunoError } = await supabase .from('alunos') .select('id, nome, n_escola, turma_curso') @@ -55,105 +61,96 @@ const DetalhesAlunos = memo(() => { return; } - // 2️⃣ Buscar perfil na tabela 'profiles' usando n_escola - const { data: perfilData, error: perfilError } = await supabase + // 2️⃣ Buscar dados do profile como array + const { data: perfilDataArray, error: perfilError } = await supabase .from('profiles') .select('email, telefone, residencia, idade') - .eq('n_escola', alunoData.n_escola) - .maybeSingle(); // evita erro se não existir registro + .eq('n_escola', alunoData.n_escola); - if (perfilError) { - console.log('Erro ao buscar perfil:', perfilError); - } + if (perfilError) console.log('Erro ao buscar profile:', perfilError); - // 3️⃣ Combinar dados de aluno e perfil + // Pega o primeiro registro ou undefined + const perfilData = perfilDataArray?.[0]; + + // 3️⃣ Combinar dados setAluno({ - ...alunoData, + id: alunoData.id, + nome: alunoData.nome, + n_escola: alunoData.n_escola, + turma_curso: alunoData.turma_curso, email: perfilData?.email ?? '-', telefone: perfilData?.telefone ?? '-', residencia: perfilData?.residencia ?? '-', - idade: perfilData?.idade?.toString() ?? '-', // converte idade para string + idade: perfilData?.idade?.toString() ?? '-', }); setLoading(false); } catch (err) { - console.error('Erro inesperado:', err); + console.log('Erro inesperado:', err); setLoading(false); } }; if (loading) { return ( - - A carregar... + + A carregar... ); } if (!aluno) { return ( - - Aluno não encontrado + + Aluno não encontrado ); } return ( - - + + router.back()}> - + - {aluno.nome} + + {aluno.nome} + - - Número Escola - {aluno.n_escola} - - Turma - {aluno.turma_curso} - - Email - {aluno.email} - - Telefone - {aluno.telefone} - - Residência - {aluno.residencia} - - Idade - {aluno.idade} + + {renderCampo('Número Escola', aluno.n_escola, colors)} + {renderCampo('Turma', aluno.turma_curso, colors)} + {renderCampo('Email', aluno.email, colors)} + {renderCampo('Telefone', aluno.telefone, colors)} + {renderCampo('Residência', aluno.residencia, colors)} + {renderCampo('Idade', aluno.idade, colors)} ); }); +const renderCampo = (label: string, valor: string, colors: any) => ( + <> + {label} + {valor} + +); + export default DetalhesAlunos; const styles = StyleSheet.create({ - safe: { flex: 1, backgroundColor: '#f1f3f5' }, + safe: { flex: 1 }, center: { marginTop: 50, textAlign: 'center', fontSize: 16 }, - header: { - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'space-between', - padding: 16, - }, + header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 16, paddingVertical: 12 }, titulo: { fontSize: 20, fontWeight: 'bold' }, container: { padding: 16 }, - card: { - backgroundColor: '#fff', - padding: 16, - borderRadius: 12, - elevation: 2, - }, - label: { fontSize: 12, color: '#6c757d', marginTop: 10 }, + card: { padding: 16, borderRadius: 12, elevation: 2 }, + label: { fontSize: 12, marginTop: 10 }, valor: { fontSize: 16, fontWeight: '600' }, -}); +}); \ No newline at end of file