-
PREGUNTA 3 (2/5)
- 3. Desglose la cantidad de población beneficiada por plataforma y tipo de procesador: *
+ Cantidad de población beneficiada por plataforma y tipo de procesador:
-
Presione cada pestaña para ingresar la información.
diff --git a/src/components/Perifericos/Pregunta2EP.tsx b/src/components/Perifericos/Pregunta2EP.tsx
index a85743b..599eac6 100644
--- a/src/components/Perifericos/Pregunta2EP.tsx
+++ b/src/components/Perifericos/Pregunta2EP.tsx
@@ -1,6 +1,8 @@
"use client";
-import React, { useState, useEffect } from "react";
+import { useState, useEffect } from "react";
import styles from "./pregunta2EP.module.scss";
+import axios from "axios";
+import Cookies from "js-cookie";
interface EquiposPoblacion {
alumnos: string;
@@ -13,35 +15,87 @@ interface EquiposPoblacion {
export default function Pregunta2EP() {
const [equipos, setEquipos] = useState
({
- alumnos: "35",
- profesores: "43",
+ alumnos: "0",
+ profesores: "0",
tecnicosAcademicos: "",
investigadores: "",
- administrativos: "302",
- total: "380",
+ administrativos: "0",
+ total: "0",
});
- // Listo para conectar al backend
- useEffect(() => {
- /*
- fetch("https://tu-api-backend.com/api/equipos-poblacion")
- .then((res) => res.json())
- .then((data) => setEquipos(data))
- .catch((err) => console.error("Error al obtener datos:", err));
- */
- }, []);
+ const api_url = process.env.NEXT_PUBLIC_API_URL;
- const handleChange = (e: React.ChangeEvent) => {
- const { name, value } = e.target;
- setEquipos((prev) => ({
- ...prev,
- [name]: value,
- }));
- };
+ useEffect(() => {
+ const token = Cookies.get("token");
+ const headers = { Authorization: `Bearer ${token}` };
+
+ axios
+ .get(`${api_url}/equipos/reporte/contar_periferico_tipoUso/impresoras`, {
+ headers,
+ })
+ .then((res) => {
+ const data = res.data;
+
+ // Valores por defecto
+ const valores = {
+ alumnos: "0",
+ profesores: "0",
+ tecnicosAcademicos: "0",
+ investigadores: "0",
+ administrativos: "0",
+ total: "0",
+ };
+
+ data.forEach((item: any) => {
+ const uso = item.uso.toUpperCase().trim();
+ const total = item.total ?? "0";
+
+ switch (uso) {
+ case "ALUMNO":
+ case "ALUMNOS":
+ valores.alumnos = total;
+ break;
+
+ case "PROFESOR":
+ case "PROFESORES":
+ valores.profesores = total;
+ break;
+
+ case "TÉCNICO ACADEMICO":
+ case "TÉCNICO ACADÉMICO":
+ valores.tecnicosAcademicos = total;
+ break;
+
+ case "INVESTIGADOR":
+ case "INVESTIGADORES":
+ valores.investigadores = total;
+ break;
+
+ case "ADMINISTRATIVO":
+ case "ADMINISTRATIVOS":
+ valores.administrativos = total;
+ break;
+ }
+ });
+
+ // Calcular total general
+ valores.total = String(
+ Number(valores.alumnos) +
+ Number(valores.profesores) +
+ Number(valores.tecnicosAcademicos) +
+ Number(valores.investigadores) +
+ Number(valores.administrativos)
+ );
+
+ setEquipos(valores);
+ })
+ .catch((err) => {
+ console.error("Error:", err);
+ });
+ }, []);
return (
-
Equipos de impresión de acuerdo con la población universitaria.
@@ -54,20 +108,18 @@ export default function Pregunta2EP() {
id="alumnos"
name="alumnos"
value={equipos.alumnos}
- onChange={handleChange}
+ disabled
/>
-
- Profesores
-
+ Profesores
@@ -78,33 +130,29 @@ export default function Pregunta2EP() {
id="tecnicosAcademicos"
name="tecnicosAcademicos"
value={equipos.tecnicosAcademicos}
- onChange={handleChange}
+ disabled
/>
-
- Investigadores
-
+ Investigadores
-
- Administrativos
-
+ Administrativos
@@ -115,10 +163,11 @@ export default function Pregunta2EP() {
id="total"
name="total"
value={equipos.total}
- onChange={handleChange}
+ disabled
/>