From 11a92711da029fce5a72d79403fe815d2ae6cea9 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 27 Jan 2026 18:33:17 -0600 Subject: [PATCH] add key and add request --- .../InformacionEquipo/InformacionEquipo.tsx | 4 +- .../InformacionEquipos/ProgramSelector.tsx | 37 +++++++++++-------- .../InformacionEquipos/SelectorSala.tsx | 7 +++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/(private)/InformacionEquipo/InformacionEquipo.tsx b/app/(private)/InformacionEquipo/InformacionEquipo.tsx index a9fadce..f8cf187 100644 --- a/app/(private)/InformacionEquipo/InformacionEquipo.tsx +++ b/app/(private)/InformacionEquipo/InformacionEquipo.tsx @@ -40,7 +40,7 @@ export default function InformacionEquipo({ setUbicacion(sala); }} /> - , + , ), }, @@ -54,7 +54,7 @@ export default function InformacionEquipo({ setId(sala); }} /> - + ), }, diff --git a/app/Components/InformacionEquipos/ProgramSelector.tsx b/app/Components/InformacionEquipos/ProgramSelector.tsx index c32d804..de9dde6 100644 --- a/app/Components/InformacionEquipos/ProgramSelector.tsx +++ b/app/Components/InformacionEquipos/ProgramSelector.tsx @@ -72,6 +72,7 @@ export default function ProgramSelector({ useEffect(() => { if (!programas.length) return; + if (!ubicacion && !id) return; const buildCheckboxes = async () => { const baseCheckboxes: Record = {}; @@ -79,25 +80,31 @@ export default function ProgramSelector({ baseCheckboxes[p.id_programa] = false; }); - if (ubicacion) { - try { - const res = await axios.get( + try { + let res; + + if (ubicacion) { + res = await axios.get( `${envConfig.apiUrl}/programa-equipo/${ubicacion}`, ); + } - res.data.forEach((item: any) => { - baseCheckboxes[item.id_programa] = true; - }); - } catch (error: any) { - if (axios.isAxiosError(error)) { - if (error.response?.status === 404) { - toast.error("Equipo sin programas"); - } else { - toast.error("Error al cargar programas del equipo"); - } + if (id) { + res = await axios.get(`${envConfig.apiUrl}/programa-area/${id}`); + } + + res?.data.forEach((item: any) => { + baseCheckboxes[item.id_programa] = true; + }); + } catch (error: any) { + if (axios.isAxiosError(error)) { + if (error.response?.status === 404) { + toast.error("Sin programas asignados"); } else { - toast.error("Error inesperado"); + toast.error("Error al cargar programas"); } + } else { + toast.error("Error inesperado"); } } @@ -105,7 +112,7 @@ export default function ProgramSelector({ }; buildCheckboxes(); - }, [programas, ubicacion]); + }, [programas, ubicacion, id]); return (
diff --git a/app/Components/InformacionEquipos/SelectorSala.tsx b/app/Components/InformacionEquipos/SelectorSala.tsx index 53d0702..3874ab4 100644 --- a/app/Components/InformacionEquipos/SelectorSala.tsx +++ b/app/Components/InformacionEquipos/SelectorSala.tsx @@ -18,7 +18,12 @@ export default function SelectorSala({ onSearch }: Props) { const [selected, setSelected] = useState(); const handleChangeEquipo = (e: React.ChangeEvent) => { - setSelected(Number(e.target.value)); + const value = Number(e.target.value); + setSelected(value); + + if (value) { + onSearch(value); + } }; const handleSubmit = (e: React.FormEvent) => {