diff --git a/app/(private)/InformacionEquipo/InformacionEquipo.tsx b/app/(private)/InformacionEquipo/InformacionEquipo.tsx new file mode 100644 index 0000000..1e6882d --- /dev/null +++ b/app/(private)/InformacionEquipo/InformacionEquipo.tsx @@ -0,0 +1,54 @@ +'use client' + +import Toggle from "@/app/Components/Global/Toggle/Toggle"; +import Equipos from "@/app/Components/Equipos/equipos"; +import ProgramSelector from "@/app/Components/InformacionEquipos/ProgramSelector"; +import SelectorSala from "@/app/Components/InformacionEquipos/SelectorSala"; +import { useState } from "react"; + +import "./informacionequipo.css"; + +export default function InformacionEquipo({ + defaultKey, +}: { + defaultKey?: string; +}) { + const [id, setId] = useState(null); + + return ( +
+

INFORMACION DE EQUIPOS

+ + , + }, + { + key: "Equipo", + label: "Programa por equipo", + content: , + }, + { + key: "Sala", + label: "Programa por sala", + content: ( + <> + { + setId(sala); + }} + /> + + + ), + }, + ]} + /> +
+ ); +} +//IO diff --git a/app/(private)/InformacionEquipo/page.tsx b/app/(private)/InformacionEquipo/page.tsx index 9f2d02c..fa06736 100644 --- a/app/(private)/InformacionEquipo/page.tsx +++ b/app/(private)/InformacionEquipo/page.tsx @@ -1,6 +1,4 @@ -import Toggle from "@/app/Components/Global/Toggle/Toggle"; -import Equipos from "@/app/Components/Equipos/equipos"; -import ProgramSelector from "@/app/Components/InformacionEquipos/ProgramSelector"; +import InformacionEquipo from "./InformacionEquipo"; import "./informacionequipo.css"; @@ -11,43 +9,7 @@ export default async function Page(props: { }>; }) { const params = await props.searchParams; - const key = params?.key && params.key; - const machine = params?.machine ? params.machine : null; - return ( -
- -

INFORMACION DE EQUIPOS

- - , - }, - { - key: "Equipo", - label: "Programa por equipo", - content: ( - - ), - }, - { - key: "Sala", - label: "Programa por sala", - content: ( - - ), - }, - ]} - /> -
- ); + return } -//IO \ No newline at end of file +//IO diff --git a/app/Components/InformacionEquipos/ProgramSelector.tsx b/app/Components/InformacionEquipos/ProgramSelector.tsx index fd56aed..4ebffa3 100644 --- a/app/Components/InformacionEquipos/ProgramSelector.tsx +++ b/app/Components/InformacionEquipos/ProgramSelector.tsx @@ -3,40 +3,6 @@ import { envConfig } from "@/app/lib/config"; import axios from "axios"; import { useEffect, useState } from "react"; -const programas = [ - "3D MAX STUDIO 2014", - "ADOBE CREATIVE SUITE", - "ARCHICAD 20", - "AUDACITY -win - 2.0", - "AUTOCAD", - "CODE-BLOCKS", - "COREL DRAW", - "DEV-C++", - "EVIEWS Enterprise", - "Google Earth", - "INTERNERT", - "MAPLE", - "MATHEMATICA", - "MATLAB", - "Maxima", - "miktex", - "NETBEANS", - "OFFICE 2016", - "PSeint", - "R 3.0.1", - "R Studio", - "SPPS Statiscs", - "STATA 13", - "STATGRAOHICS Centurion XVI", -]; - -const caracteristicasPorEquipo: Record = { - "Equipo 1": ["3D MAX STUDIO 2014", "AUTOCAD", "MATLAB"], - "Equipo 2": ["ADOBE CREATIVE SUITE", "COREL DRAW", "R Studio"], - "Equipo 3": ["ARCHICAD 20", "EVIEWS Enterprise", "SPPS Statiscs"], - "Equipo 4": ["MATHEMATICA", "MAPLE", "Maxima"], -}; - interface Equipos { id_equipo: number; id_plataforma: number; @@ -47,65 +13,79 @@ interface Equipos { ip: string; } +interface Programa { + id_programa: number; + programa: string; +} + export default function ProgramSelector() { - const [equipoSeleccionado, setEquipoSeleccionado] = useState(""); - const [checkboxes, setCheckboxes] = useState>( - programas.reduce((acc, prog) => ({ ...acc, [prog]: false }), {}) - ); - const [equipo, setEquipo] = useState(); + const [equipoSeleccionado, setEquipoSeleccionado] = useState(""); + const [equipos, setEquipos] = useState([]); + const [programas, setProgramas] = useState([]); + const [checkboxes, setCheckboxes] = useState>({}); useEffect(() => { - const getEquipos = async () => { - const equipos = await axios.get(`${envConfig.apiUrl}/equipo`); - setEquipo(equipos.data); + const fetchData = async () => { + const [equiposRes, programasRes] = await Promise.all([ + axios.get(`${envConfig.apiUrl}/equipo`), + axios.get(`${envConfig.apiUrl}/programa`), + ]); + + setEquipos(equiposRes.data); + setProgramas(programasRes.data); + + const initialCheckboxes: Record = {}; + programasRes.data.forEach((p: Programa) => { + initialCheckboxes[p.id_programa] = false; + }); + setCheckboxes(initialCheckboxes); }; - getEquipos(); + + fetchData(); }, []); const handleChangeEquipo = (e: React.ChangeEvent) => { - const equipo = e.target.value; - setEquipoSeleccionado(equipo); + setEquipoSeleccionado(Number(e.target.value)); + }; - const nuevosCheckboxes: Record = {}; - programas.forEach((prog) => { - nuevosCheckboxes[prog] = - caracteristicasPorEquipo[equipo]?.includes(prog) || false; - }); - setCheckboxes(nuevosCheckboxes); + const handleTogglePrograma = (id: number) => { + setCheckboxes((prev) => ({ + ...prev, + [id]: !prev[id], + })); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); + + const programasSeleccionados = Object.keys(checkboxes) + .filter((id) => checkboxes[Number(id)]) + .map(Number); + console.log("Equipo:", equipoSeleccionado); - console.log( - "Programas seleccionados:", - Object.keys(checkboxes).filter((p) => checkboxes[p]) - ); + console.log("Programas seleccionados:", programasSeleccionados); }; return (
{programas.map((prog) => ( -
@@ -115,4 +95,4 @@ export default function ProgramSelector() {
); -} \ No newline at end of file +} diff --git a/app/Components/InformacionEquipos/SelectorSala.tsx b/app/Components/InformacionEquipos/SelectorSala.tsx new file mode 100644 index 0000000..c3ce233 --- /dev/null +++ b/app/Components/InformacionEquipos/SelectorSala.tsx @@ -0,0 +1,53 @@ +"use client"; +import { envConfig } from "@/app/lib/config"; +import axios from "axios"; +import { use, useEffect, useState } from "react"; + +interface Area { + id_area_ubicacion: number; + area: string; + extra: string; +} + +interface Props { + onSearch: (id: number) => void; +} + +export default function SelectorSala({ onSearch }: Props) { + const [sala, setSala] = useState(); + const [selected, setSelected] = useState(); + + const handleChangeEquipo = (e: React.ChangeEvent) => { + setSelected(Number(e.target.value)); + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + if (!selected) return; + onSearch(selected); + }; + + useEffect(() => { + const fetchData = async () => { + const response = await axios.get(`${envConfig.apiUrl}/area-ubicacion`); + + setSala(response.data); + }; + + fetchData(); + }, []); + + return ( +
+ +
+ ); +}