detalhes aluno
This commit is contained in:
@@ -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<any>(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(() => {
|
||||
<Text style={styles.valor}>{aluno.n_escola}</Text>
|
||||
|
||||
<Text style={styles.label}>Turma</Text>
|
||||
<Text style={styles.valor}>
|
||||
{aluno.ano}º {aluno.turma_curso}
|
||||
</Text>
|
||||
<Text style={styles.valor}>{aluno.turma_curso}</Text>
|
||||
|
||||
<Text style={styles.label}>Email</Text>
|
||||
<Text style={styles.valor}>{aluno.email || '-'}</Text>
|
||||
@@ -102,8 +120,11 @@ const DetalhesAlunos = memo(() => {
|
||||
<Text style={styles.label}>Telefone</Text>
|
||||
<Text style={styles.valor}>{aluno.telefone || '-'}</Text>
|
||||
|
||||
<Text style={styles.label}>Estado Estágio</Text>
|
||||
<Text style={styles.valor}>{aluno.estagio?.estado || '-'}</Text>
|
||||
<Text style={styles.label}>Residência</Text>
|
||||
<Text style={styles.valor}>{aluno.residencia || '-'}</Text>
|
||||
|
||||
<Text style={styles.label}>Idade</Text>
|
||||
<Text style={styles.valor}>{aluno.idade || '-'}</Text>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
|
||||
Reference in New Issue
Block a user