From e34eef4981426a6ff08cd93784a79fcb6b938e0d Mon Sep 17 00:00:00 2001 From: Ricardo Gomes <230413@epvc.pt> Date: Tue, 24 Feb 2026 15:29:30 +0000 Subject: [PATCH] detalhes aluno --- app/Professor/Alunos/DetalhesAluno.tsx | 91 ++++++++++++++++---------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/app/Professor/Alunos/DetalhesAluno.tsx b/app/Professor/Alunos/DetalhesAluno.tsx index dd78220..15f5f72 100644 --- a/app/Professor/Alunos/DetalhesAluno.tsx +++ b/app/Professor/Alunos/DetalhesAluno.tsx @@ -14,48 +14,68 @@ import { supabase } from '../../lib/supabase'; const DetalhesAlunos = memo(() => { const router = useRouter(); - const { alunoId } = useLocalSearchParams(); + const params = useLocalSearchParams(); + + 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); useEffect(() => { - if (alunoId) fetchAluno(); + if (!alunoId) { + console.log('alunoId não recebido'); + setLoading(false); + //return; + } + + fetchAluno(); }, [alunoId]); const fetchAluno = async () => { - setLoading(true); + try { + console.log('A buscar aluno ID:', alunoId); + setLoading(true); - const { data: alunoData } = await supabase - .from('alunos') - .select('*') - .eq('id', alunoId) - .single(); + // 1️⃣ Buscar aluno + 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); + setAluno(null); + setLoading(false); + return; + } + + // 2️⃣ Buscar dados pessoais pelo n_escola + const { data: perfilData, error: perfilError } = await supabase + .from('profiles') + .select('email, telefone, residencia, idade') + .eq('n_escola', alunoData.n_escola) + .single(); + + if (perfilError) { + console.log('Erro perfil:', perfilError); + } + + setAluno({ + ...alunoData, + ...perfilData, + }); - if (!alunoData) { setLoading(false); - return; + } catch (err) { + console.error('Erro inesperado:', err); + setLoading(false); } - - const { data: perfil } = await supabase - .from('profile') - .select('email, telefone') - .eq('n_escola', alunoData.n_escola) - .single(); - - const { data: estagio } = await supabase - .from('estagios') - .select('estado') - .eq('aluno_id', alunoId) - .single(); - - setAluno({ - ...alunoData, - ...perfil, - estagio, - }); - - setLoading(false); }; if (loading) { @@ -92,9 +112,7 @@ const DetalhesAlunos = memo(() => { {aluno.n_escola} Turma - - {aluno.ano}º {aluno.turma_curso} - + {aluno.turma_curso} Email {aluno.email || '-'} @@ -102,8 +120,11 @@ const DetalhesAlunos = memo(() => { Telefone {aluno.telefone || '-'} - Estado Estágio - {aluno.estagio?.estado || '-'} + Residência + {aluno.residencia || '-'} + + Idade + {aluno.idade || '-'}