This commit is contained in:
2026-02-25 12:00:06 +00:00
parent 814aa02413
commit c48fe23510

View File

@@ -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<any>(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(() => {
<Text style={styles.valor}>{aluno.turma_curso}</Text>
<Text style={styles.label}>Email</Text>
<Text style={styles.valor}>{aluno.email || '-'}</Text>
<Text style={styles.valor}>{aluno.email}</Text>
<Text style={styles.label}>Telefone</Text>
<Text style={styles.valor}>{aluno.telefone || '-'}</Text>
<Text style={styles.valor}>{aluno.telefone}</Text>
<Text style={styles.label}>Residência</Text>
<Text style={styles.valor}>{aluno.residencia || '-'}</Text>
<Text style={styles.valor}>{aluno.residencia}</Text>
<Text style={styles.label}>Idade</Text>
<Text style={styles.valor}>{aluno.idade || '-'}</Text>
<Text style={styles.valor}>{aluno.idade}</Text>
</View>
</ScrollView>
</SafeAreaView>
@@ -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',