Skip to content

Commit

Permalink
feat: Se agregan las materias a los alumnos
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasMaciel committed Sep 22, 2024
1 parent e7c007e commit cec7ee5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
23 changes: 23 additions & 0 deletions FrontAdmin/src/API/DetalleAlumno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,26 @@ export const FetchDetalleAlumno = async (dni: number) => {
throw new Error('Network error: ' + error);
}
};

export const FetchMateriasAlumno = async (dni: number) => {
try {
const token = Cookies.get('tokennn');

const response = await fetch(`http://localhost:8000/api/alumnos/materias/${dni}/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
});

if (response.ok) {
const data = await response.json();
return data;
} else {
throw new Error('Error en la respuesta del servidor');
}
} catch (error) {
throw new Error('Network error: ' + error);
}
};
64 changes: 59 additions & 5 deletions FrontAdmin/src/components/Pages/Alumnos/SubPages/FichaAlumno.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import {
import { createTheme, ThemeProvider } from '@mui/material';
import logoUser from '../../../icons/logo-user.png';
import { useNavigate } from 'react-router-dom';
import { FetchDetalleAlumno } from '../../../../API/DetalleAlumno.ts';
import {
FetchDetalleAlumno,
FetchMateriasAlumno,
} from '../../../../API/DetalleAlumno.ts';
import React, { useState, useEffect, useMemo } from 'react';
import { ArrowLeftIcon, ChevronLeftIcon } from '@chakra-ui/icons';
import { Link } from 'react-router-dom';

interface Alumno {
full_name: string;
Expand All @@ -35,9 +39,18 @@ interface Alumno {
estado: string;
}

interface Materia {
codigo_materia: number;
anio_cursada: number;
anio_plan: number;
nombre: string;
cuatrimestre: number;
}

function FichaAlumno() {
const { dni } = useParams();
const [alumno, setAlumno] = useState<Alumno | null>(null); // Define el estado con un valor inicial de null
const [materias, setMaterias] = useState<Materia[]>([]); // Define el estado con un valor inicial de null
const [loading, setLoading] = useState(true);
const [error, setError] = useState<unknown>(null);
const navigate = useNavigate();
Expand All @@ -51,8 +64,10 @@ function FichaAlumno() {
try {
if (dni) {
const dniNumber = parseInt(dni, 10); // Convierte a número
const data = await FetchDetalleAlumno(dniNumber);
setAlumno(data);
const dataDetalle = await FetchDetalleAlumno(dniNumber);
const dataMaterias = await FetchMateriasAlumno(dniNumber);
setAlumno(dataDetalle);
setMaterias(dataMaterias);
}
} catch (error) {
setError(error);
Expand Down Expand Up @@ -241,7 +256,6 @@ function FichaAlumno() {
<Table variant="simple" width="100%">
<Thead>
<Tr mt={6}>

<Th textAlign="center" p={1}>
Numero
</Th>
Expand All @@ -255,7 +269,6 @@ function FichaAlumno() {
<Tbody>
{cuotas.map((cuota, index) => (
<Tr key={index}>

<Td textAlign="center" p={1}>
{cuota.numero}
</Td>
Expand Down Expand Up @@ -293,6 +306,47 @@ function FichaAlumno() {
<Text>No hay datos disponibles</Text>
)}
</Box>

<Box
borderRadius={8}
borderColor={'gray.200'}
borderStyle={'solid'}
borderWidth={1}
p={3}
ml="30px"
mt="30px"
w="100%"
>
{materias.length > 0 ? (
<Table variant="simple" width="100%">
<Thead>
<Tr mt={6}>
<Th textAlign="center">Materia</Th>
<Th textAlign="center">Año de cursada</Th>
<Th textAlign="center">Cuatrimestre</Th>
</Tr>
</Thead>
<Tbody>
{materias?.map((materia, index) => (
<Tr
key={index}
onClick={() =>
navigate(`/admin/sysacad/`) //Aca tendriamos que ver a donde se lo redirige
}
cursor="pointer"
_hover={{ bg: "gray.50" }}
>
<Td textAlign="center">{materia.nombre}</Td>
<Td textAlign="center">{materia.anio_cursada}</Td>
<Td textAlign="center">{materia.cuatrimestre}</Td>
</Tr>
))}
</Tbody>
</Table>
) : (
<Text>No hay datos de materias disponibles</Text>
)}
</Box>
</Flex>
</Box>
</Flex>
Expand Down

0 comments on commit cec7ee5

Please sign in to comment.