diff --git a/app/Professor/Alunos/DetalhesAluno.tsx b/app/Professor/Alunos/DetalhesAluno.tsx index 4f0526a..83496e4 100644 --- a/app/Professor/Alunos/DetalhesAluno.tsx +++ b/app/Professor/Alunos/DetalhesAluno.tsx @@ -16,12 +16,13 @@ const DetalhesAlunos = memo(() => { const router = useRouter(); const params = useLocalSearchParams(); - const alunoId = - typeof params.alunoId === 'string' - ? params.alunoId - : Array.isArray(params.alunoId) - ? params.alunoId[0] - : null; + // alunoId é o parâmetro que vem da rota + const alunoId = + typeof params.alunoId === 'string' + ? params.alunoId + : Array.isArray(params.alunoId) + ? params.alunoId[0] + : null; const [aluno, setAluno] = useState(null); const [loading, setLoading] = useState(true); @@ -32,43 +33,46 @@ const DetalhesAlunos = memo(() => { setLoading(false); return; } - fetchAluno(); }, [alunoId]); const fetchAluno = async () => { try { - console.log('A buscar aluno ID:', alunoId); + console.log('Buscando aluno ID:', alunoId); setLoading(true); - // 1️⃣ Buscar aluno + // 1️⃣ Buscar aluno na tabela 'alunos' (para turma_curso e n_escola) const { data: alunoData, error: alunoError } = await supabase .from('alunos') .select('id, nome, n_escola, turma_curso') .eq('id', alunoId) .single(); - if (alunoError) { - console.log('Erro aluno:', alunoError); + if (alunoError || !alunoData) { + console.log('Erro ao buscar aluno:', alunoError); setAluno(null); setLoading(false); return; } - // 2️⃣ Buscar dados pessoais pelo n_escola + // 2️⃣ Buscar perfil na tabela 'profiles' usando n_escola const { data: perfilData, error: perfilError } = await supabase .from('profiles') .select('email, telefone, residencia, idade') .eq('n_escola', alunoData.n_escola) - .single(); + .maybeSingle(); // evita erro se não existir registro if (perfilError) { - console.log('Erro perfil:', perfilError); + console.log('Erro ao buscar perfil:', perfilError); } + // 3️⃣ Combinar dados de aluno e perfil setAluno({ ...alunoData, - ...perfilData, + email: perfilData?.email ?? '-', + telefone: perfilData?.telefone ?? '-', + residencia: perfilData?.residencia ?? '-', + idade: perfilData?.idade?.toString() ?? '-', // converte idade para string }); setLoading(false); @@ -115,16 +119,16 @@ const DetalhesAlunos = memo(() => { {aluno.turma_curso} Email - {aluno.email || '-'} + {aluno.email} Telefone - {aluno.telefone || '-'} + {aluno.telefone} Residência - {aluno.residencia || '-'} + {aluno.residencia} Idade - {aluno.idade || '-'} + {aluno.idade} @@ -135,7 +139,7 @@ export default DetalhesAlunos; const styles = StyleSheet.create({ safe: { flex: 1, backgroundColor: '#f1f3f5' }, - center: { marginTop: 50, textAlign: 'center' }, + center: { marginTop: 50, textAlign: 'center', fontSize: 16 }, header: { flexDirection: 'row', alignItems: 'center',