Files
front-AT/app/(private)/Monitor/MachineTable.tsx
T

111 lines
2.9 KiB
TypeScript
Raw Normal View History

2026-01-22 12:25:07 -06:00
"use client";
import { useEffect, useState } from "react";
import styles from "./Page.module.css";
2026-01-27 16:28:34 -06:00
type AreaUbicacion = {
id_area_ubicacion: number;
area: string;
};
2026-01-22 12:25:07 -06:00
type Equipo = {
id_equipo: number;
nombre_equipo: string;
ubicacion: string;
2026-01-27 16:28:34 -06:00
activo: { data: number[] };
plataforma: { nombre: string };
areaUbicacion: { area: string };
2026-01-22 12:25:07 -06:00
};
export default function MachineTable() {
const [machines, setMachines] = useState<Equipo[]>([]);
2026-01-27 16:28:34 -06:00
const [areas, setAreas] = useState<AreaUbicacion[]>([]);
const [selectedArea, setSelectedArea] = useState("Todo");
2026-01-22 12:25:07 -06:00
const [loading, setLoading] = useState(true);
const fetchMachines = async () => {
2026-01-27 16:28:34 -06:00
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/equipo/disable`,
{ cache: "no-store" },
);
setMachines(await res.json());
setLoading(false);
};
const fetchAreas = async () => {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/area-ubicacion`,
{ cache: "no-store" },
);
setAreas(await res.json());
2026-01-22 12:25:07 -06:00
};
useEffect(() => {
fetchMachines();
2026-01-27 16:28:34 -06:00
fetchAreas();
2026-01-22 12:25:07 -06:00
}, []);
if (loading) {
return <p>Cargando equipos...</p>;
}
2026-01-27 16:28:34 -06:00
const filteredMachines =
selectedArea === "Todo"
? machines
: machines.filter(
(machine) => machine.areaUbicacion.area === selectedArea,
);
if (loading) return <p>Cargando equipos...</p>;
2026-01-22 12:25:07 -06:00
return (
<div className={styles.tableContainer}>
<table className={styles.machineTable}>
<thead>
<tr style={{ fontSize: "15px" }}>
<th>Ubicación</th>
<th>Nombre Equipo</th>
<th>Plataforma</th>
<th>Área</th>
<th>Disponible</th>
</tr>
2026-01-27 16:28:34 -06:00
<tr style={{ position: "relative", zIndex: "0" }}>
<th />
<th />
<th />
<th>
<select
style={{ minWidth: "50px" }}
value={selectedArea}
onChange={(e) => setSelectedArea(e.target.value)}
>
<option value="Todo">Todo</option>
{areas.map((area) => (
<option key={area.id_area_ubicacion} value={area.area}>
{area.area}
</option>
))}
</select>
</th>
<th />
</tr>
2026-01-22 12:25:07 -06:00
</thead>
<tbody>
2026-01-27 16:28:34 -06:00
{filteredMachines.map((machine) => (
<tr key={machine.id_equipo}>
<td>{machine.ubicacion}</td>
<td>{machine.nombre_equipo}</td>
<td className={styles[machine.plataforma.nombre]}>
{machine.plataforma.nombre}
</td>
<td>{machine.areaUbicacion.area}</td>
<td>{machine.activo.data[0] === 1 ? "Sí" : "No"}</td>
</tr>
))}
2026-01-22 12:25:07 -06:00
</tbody>
</table>
</div>
);
}