diff --git a/app/(private)/Monitor/MachineTable.tsx b/app/(private)/Monitor/MachineTable.tsx new file mode 100644 index 0000000..155e73a --- /dev/null +++ b/app/(private)/Monitor/MachineTable.tsx @@ -0,0 +1,82 @@ +"use client"; + +import { useEffect, useState } from "react"; +import styles from "./Page.module.css"; + +type Equipo = { + id_equipo: number; + nombre_equipo: string; + ubicacion: string; + activo: { + data: number[]; + }; + plataforma: { + nombre: string; + }; + areaUbicacion: { + area: string; + }; +}; + +export default function MachineTable() { + const [machines, setMachines] = useState([]); + const [loading, setLoading] = useState(true); + + const fetchMachines = async () => { + try { + const res = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/equipo`, + { cache: "no-store" } + ); + const data = await res.json(); + setMachines(data); + } catch (error) { + console.error("Error al cargar equipos", error); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchMachines(); + }, []); + + if (loading) { + return

Cargando equipos...

; + } + + return ( +
+ + + + + + + + + + + + + {machines.map((machine) => { + const disponible = machine.activo.data[0] === 1; + + return ( + + + + + + + + ); + })} + +
UbicaciónNombre EquipoPlataformaÁreaDisponible
{machine.ubicacion}{machine.nombre_equipo}{machine.plataforma.nombre}{machine.areaUbicacion.area} + {disponible ? "Sí" : "No"} +
+
+ ); +} diff --git a/app/(private)/Monitor/page.tsx b/app/(private)/Monitor/page.tsx index 9700015..f81c840 100644 --- a/app/(private)/Monitor/page.tsx +++ b/app/(private)/Monitor/page.tsx @@ -1,75 +1,23 @@ +import MachineTable from "./MachineTable"; import styles from "./Page.module.css"; export default async function Page(props: { - searchParams?: Promise<{ - numAcount: string; - }>; + searchParams?: Promise<{ numAcount: string }>; }) { const params = await props.searchParams; - const numAcount = params?.numAcount ? params.numAcount : null; + const numAcount = params?.numAcount ?? null; return (
-

MONITOR DE MÁQUINAS DISPONIBLES

+

MONITOR DE MÁQUINAS DISPONIBLES

- +
-
- - - - - - - - - - - - - - - - - - - {/* {machines.map((machine, index) => ( - - - - - - - - ))} */} - -
UbicaciónNombre EquipoPlataformaÁreaDisponible
- - - - - - - - - -
{machine.ubicacion}{machine.nombre}{machine.plataforma}{machine.area} - {machine.disponible ? "si" : "no"} -
-
+
); } -//IO diff --git a/app/Components/CheckBoxMesa.tsx b/app/Components/CheckBoxMesa.tsx index b32cea7..9bcc88a 100644 --- a/app/Components/CheckBoxMesa.tsx +++ b/app/Components/CheckBoxMesa.tsx @@ -9,7 +9,7 @@ export default function CheckBoxMesa({ }: { numAcount?: string | null; }) { - const [modo, setModo] = useState<"Equipo" | "Cuenta" | null>(null); + const [modo, setModo] = useState<"Mesa" | "Cuenta" | null>(null); return ( <> @@ -18,11 +18,11 @@ export default function CheckBoxMesa({ setModo("Equipo")} + checked={modo === "Mesa"} + onChange={() => setModo("Mesa")} /> - Equipo + Mesa