From 90bdb482cd7fb2e15ec030902c90e98329235f9b Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 17 Feb 2026 15:04:16 -0600 Subject: [PATCH] added conection to api in inscritos --- app/(private)/Inscritos/Inscripciones.tsx | 153 ++++++++++++++++------ 1 file changed, 111 insertions(+), 42 deletions(-) diff --git a/app/(private)/Inscritos/Inscripciones.tsx b/app/(private)/Inscritos/Inscripciones.tsx index 02924ce..43ae4c7 100644 --- a/app/(private)/Inscritos/Inscripciones.tsx +++ b/app/(private)/Inscritos/Inscripciones.tsx @@ -1,79 +1,148 @@ -"use client" +"use client"; import { envConfig } from "@/app/lib/config"; import axios from "axios"; import { useEffect, useState } from "react"; -interface Periodo{ - semestre:string, +interface Periodo { + id_periodo: number; + semestre: string; } -export default function Inscripciones() { - const [periodo,setPeriodo]= useState([]) +interface ApiResponse { + carrera: string; + genero: string | null; + profesor: string; + total: string; +} - useEffect(()=>{ - const getPeriodo = async()=>{ - const response = await axios.get(`${envConfig.apiUrl}/periodo`) - setPeriodo(response.data) - } - getPeriodo() - },[]) +interface TablaRow { + carrera: string; + genero: string | null; + WINDOWS: number; + MACINTOSH: number; + LINUX: number; + PROFESORES: number; + TOTAL: number; +} + +type TipoConteo = "WINDOWS" | "MACINTOSH" | "LINUX" | "PROFESORES"; + +export default function Inscripciones() { + const [periodo, setPeriodo] = useState([]); + const [selectedPeriodo, setSelectedPeriodo] = useState(null); + const [tablaData, setTablaData] = useState([]); + + useEffect(() => { + const getPeriodo = async () => { + const response = await axios.get(`${envConfig.apiUrl}/periodo`); + setPeriodo(response.data); + }; + getPeriodo(); + }, []); + + const handleBuscar = async (e: React.FormEvent) => { + e.preventDefault(); + + if (!selectedPeriodo) return; + + const response = await axios.get( + `${envConfig.apiUrl}/alumno-inscrito/inscritos/${selectedPeriodo}` + ); + + const data: ApiResponse[] = response.data; + + const agrupado: Record = {}; + + data.forEach((item) => { + const generoNormalizado = + item.genero === "F" || item.genero === "Femenino" + ? "Femenino" + : item.genero === "M" || item.genero === "Masculino" + ? "Masculino" + : "-"; + + const key = `${item.carrera}_${generoNormalizado}`; + + if (!agrupado[key]) { + agrupado[key] = { + carrera: item.carrera, + genero: generoNormalizado, + WINDOWS: 0, + MACINTOSH: 0, + LINUX: 0, + PROFESORES: 0, + TOTAL: 0, + }; + } + + const tipo = item.profesor as TipoConteo; + const cantidad = Number(item.total); + + agrupado[key][tipo] += cantidad; + agrupado[key].TOTAL += cantidad; + }); + + setTablaData(Object.values(agrupado)); + + }; return (
-

INSCRITOS

+

INSCRITOS

-
+
- setSelectedPeriodo(Number(e.target.value))} + defaultValue="" + > + + + {periodo.map((p) => ( + + ))} +
-
+
+ + + - -
Carrera GeneroWINDOWSMACINTOSHLINUX Profesores Total
-
-
- - - - - - - - - - - - - - - - - + {tablaData.map((row, index) => ( + + + + + + + + + + ))}
Impresione B/NImpresiones ColorPlotteoEscanerTotal
5,00010,00010,00020,00045,000
{row.carrera}{row.genero ?? "-"}{row.WINDOWS}{row.MACINTOSH}{row.LINUX}{row.PROFESORES}{row.TOTAL}
); } -//IO