Se modifico la tabla eliminando la columna de genero cambiandola por femenino y masculino
This commit is contained in:
@@ -3,8 +3,8 @@ import { envConfig } from "@/app/lib/config";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import "./inscripciones.css";
|
||||||
|
|
||||||
import "./inscripciones.css"
|
|
||||||
|
|
||||||
interface Periodo {
|
interface Periodo {
|
||||||
id_periodo: number;
|
id_periodo: number;
|
||||||
@@ -13,23 +13,26 @@ interface Periodo {
|
|||||||
|
|
||||||
interface ApiResponse {
|
interface ApiResponse {
|
||||||
carrera: string;
|
carrera: string;
|
||||||
genero: string | null;
|
profesor: string;
|
||||||
profesor: string;
|
femenino: string;
|
||||||
|
masculino: string;
|
||||||
total: string;
|
total: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type TipoConteo = "WINDOWS" | "MACINTOSH" | "LINUX" | "PROFESORES";
|
||||||
|
|
||||||
interface TablaRow {
|
interface TablaRow {
|
||||||
carrera: string;
|
carrera: string;
|
||||||
genero: string | null;
|
|
||||||
WINDOWS: number;
|
WINDOWS: number;
|
||||||
MACINTOSH: number;
|
MACINTOSH: number;
|
||||||
LINUX: number;
|
LINUX: number;
|
||||||
PROFESORES: number;
|
PROFESORES: number;
|
||||||
TOTAL: number;
|
TOTAL: number;
|
||||||
|
femenino: number;
|
||||||
|
masculino: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TipoConteo = "WINDOWS" | "MACINTOSH" | "LINUX" | "PROFESORES";
|
|
||||||
|
|
||||||
export default function Inscripciones() {
|
export default function Inscripciones() {
|
||||||
const [periodo, setPeriodo] = useState<Periodo[]>([]);
|
const [periodo, setPeriodo] = useState<Periodo[]>([]);
|
||||||
const [selectedPeriodo, setSelectedPeriodo] = useState<number | null>(null);
|
const [selectedPeriodo, setSelectedPeriodo] = useState<number | null>(null);
|
||||||
@@ -38,15 +41,16 @@ export default function Inscripciones() {
|
|||||||
const token = Cookies.get("token");
|
const token = Cookies.get("token");
|
||||||
const headers = { Authorization: `Bearer ${token}` };
|
const headers = { Authorization: `Bearer ${token}` };
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getPeriodo = async () => {
|
const getPeriodo = async () => {
|
||||||
const response = await axios.get(`${envConfig.apiUrl}/periodo`, { headers }
|
const response = await axios.get(`${envConfig.apiUrl}/periodo`, { headers });
|
||||||
);
|
|
||||||
setPeriodo(response.data);
|
setPeriodo(response.data);
|
||||||
};
|
};
|
||||||
getPeriodo();
|
getPeriodo();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const handleBuscar = async (e: React.FormEvent) => {
|
const handleBuscar = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -55,44 +59,44 @@ export default function Inscripciones() {
|
|||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`${envConfig.apiUrl}/alumno-inscrito/inscritos/${selectedPeriodo}`,
|
`${envConfig.apiUrl}/alumno-inscrito/inscritos/${selectedPeriodo}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const data: ApiResponse[] = response.data;
|
const data: ApiResponse[] = response.data;
|
||||||
|
|
||||||
|
|
||||||
const agrupado: Record<string, TablaRow> = {};
|
const agrupado: Record<string, TablaRow> = {};
|
||||||
|
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const generoNormalizado =
|
const carrera = item.carrera;
|
||||||
item.genero === "F" || item.genero === "Femenino"
|
|
||||||
? "Femenino"
|
|
||||||
: item.genero === "M" || item.genero === "Masculino"
|
|
||||||
? "Masculino"
|
|
||||||
: "-";
|
|
||||||
|
|
||||||
const key = `${item.carrera}_${generoNormalizado}`;
|
|
||||||
|
if (!agrupado[carrera]) {
|
||||||
if (!agrupado[key]) {
|
agrupado[carrera] = {
|
||||||
agrupado[key] = {
|
carrera: carrera,
|
||||||
carrera: item.carrera,
|
|
||||||
genero: generoNormalizado,
|
|
||||||
WINDOWS: 0,
|
WINDOWS: 0,
|
||||||
MACINTOSH: 0,
|
MACINTOSH: 0,
|
||||||
LINUX: 0,
|
LINUX: 0,
|
||||||
PROFESORES: 0,
|
PROFESORES: 0,
|
||||||
TOTAL: 0,
|
TOTAL: 0,
|
||||||
|
femenino: 0,
|
||||||
|
masculino: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const tipo = item.profesor as TipoConteo;
|
const fila = agrupado[carrera];
|
||||||
const cantidad = Number(item.total);
|
const tipoProfesor = item.profesor as TipoConteo;
|
||||||
|
const totalPlataforma = Number(item.total);
|
||||||
|
const fem = Number(item.femenino);
|
||||||
|
const masc = Number(item.masculino);
|
||||||
|
|
||||||
agrupado[key][tipo] += cantidad;
|
|
||||||
agrupado[key].TOTAL += cantidad;
|
fila[tipoProfesor] += totalPlataforma;
|
||||||
|
fila.TOTAL += totalPlataforma;
|
||||||
|
fila.femenino += fem;
|
||||||
|
fila.masculino += masc;
|
||||||
});
|
});
|
||||||
|
|
||||||
setTablaData(Object.values(agrupado));
|
setTablaData(Object.values(agrupado));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -109,7 +113,6 @@ export default function Inscripciones() {
|
|||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
Seleccione
|
Seleccione
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
{periodo.map((p) => (
|
{periodo.map((p) => (
|
||||||
<option key={p.id_periodo} value={p.id_periodo}>
|
<option key={p.id_periodo} value={p.id_periodo}>
|
||||||
{p.semestre}
|
{p.semestre}
|
||||||
@@ -128,7 +131,8 @@ export default function Inscripciones() {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Carrera</th>
|
<th>Carrera</th>
|
||||||
<th>Genero</th>
|
<th>Femenino</th>
|
||||||
|
<th>Masculino</th>
|
||||||
<th>WINDOWS</th>
|
<th>WINDOWS</th>
|
||||||
<th>MACINTOSH</th>
|
<th>MACINTOSH</th>
|
||||||
<th>LINUX</th>
|
<th>LINUX</th>
|
||||||
@@ -141,7 +145,8 @@ export default function Inscripciones() {
|
|||||||
{tablaData.map((row, index) => (
|
{tablaData.map((row, index) => (
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td className="textLeft">{row.carrera}</td>
|
<td className="textLeft">{row.carrera}</td>
|
||||||
<td>{row.genero ?? "-"}</td>
|
<td>{row.femenino}</td>
|
||||||
|
<td>{row.masculino}</td>
|
||||||
<td>{row.WINDOWS}</td>
|
<td>{row.WINDOWS}</td>
|
||||||
<td>{row.MACINTOSH}</td>
|
<td>{row.MACINTOSH}</td>
|
||||||
<td>{row.LINUX}</td>
|
<td>{row.LINUX}</td>
|
||||||
@@ -154,4 +159,4 @@ export default function Inscripciones() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user