diff --git a/app/Components/InformacionEquipos/ProgramSelector.tsx b/app/Components/InformacionEquipos/ProgramSelector.tsx index c6f3754..46f000e 100644 --- a/app/Components/InformacionEquipos/ProgramSelector.tsx +++ b/app/Components/InformacionEquipos/ProgramSelector.tsx @@ -48,10 +48,6 @@ export default function ProgramSelector({ fetchData(); }, []); - const handleChangeEquipo = (e: React.ChangeEvent) => { - setEquipoSeleccionado(Number(e.target.value)); - }; - const handleTogglePrograma = (id: number) => { setCheckboxes((prev) => ({ ...prev, @@ -72,7 +68,7 @@ export default function ProgramSelector({ useEffect(() => { if (!programas.length) return; - if (!ubicacion && !id) return; + if (ubicacion === null && id === null) return; const buildCheckboxes = async () => { const baseCheckboxes: Record = {}; @@ -83,14 +79,16 @@ export default function ProgramSelector({ try { let res; - if (ubicacion) { + if (ubicacion && ubicacion !== "0") { res = await axios.get( `${envConfig.apiUrl}/programa-equipo/${ubicacion}`, ); } if (id) { - res = await axios.get(`${envConfig.apiUrl}/area-ubicacion/programs/${id}`); + res = await axios.get( + `${envConfig.apiUrl}/area-ubicacion/programs/${id}`, + ); } res?.data.forEach((item: any) => { @@ -135,3 +133,4 @@ export default function ProgramSelector({ ); } +//IO \ No newline at end of file diff --git a/app/Components/InformacionEquipos/SelectorEquipo.tsx b/app/Components/InformacionEquipos/SelectorEquipo.tsx index c0bc1c1..4af320e 100644 --- a/app/Components/InformacionEquipos/SelectorEquipo.tsx +++ b/app/Components/InformacionEquipos/SelectorEquipo.tsx @@ -1,7 +1,8 @@ "use client"; import { envConfig } from "@/app/lib/config"; -import axios from "axios"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; +import axios from "axios"; interface Equipos { id_equipo: number; @@ -21,21 +22,34 @@ interface Props { export default function SelectorEquipo({ onSearch }: Props) { const [sala, setSala] = useState(); - const [selected, setSelected] = useState(); + const searchParams = useSearchParams(); + const pathname = usePathname(); + const router = useRouter(); + + const paramSala = Number(searchParams.get("equipo")) || 0; + const [selected, setSelected] = useState(paramSala); const handleChangeEquipo = (e: React.ChangeEvent) => { const value = e.target.value; - setSelected(value); + const numberValue = Number(e.target.value); - if (value) { + setSelected(numberValue); + + if (numberValue === 0) { + onSearch(''); + } else { onSearch(value); } - }; - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - if (!selected) return; - onSearch(selected); + const params = new URLSearchParams(searchParams.toString()); + + if (numberValue === 0) { + params.delete("equipo"); + } else { + params.set("equipo", value); + } + + router.push(`${pathname}?${params.toString()}`); }; useEffect(() => { @@ -52,7 +66,7 @@ export default function SelectorEquipo({ onSearch }: Props) {
- - {sala && - sala.map((sala) => ( - - ))} + + {sala.map((s) => ( + + ))}
); } +//IO \ No newline at end of file