add key and add request

This commit is contained in:
2026-01-27 18:33:17 -06:00
parent 46ad510d1d
commit 11a92711da
3 changed files with 30 additions and 18 deletions
@@ -72,6 +72,7 @@ export default function ProgramSelector({
useEffect(() => {
if (!programas.length) return;
if (!ubicacion && !id) return;
const buildCheckboxes = async () => {
const baseCheckboxes: Record<number, boolean> = {};
@@ -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 (
<form className="form-container" onSubmit={handleSubmit}>