added new headers and added table in asignation table
This commit is contained in:
@@ -3,6 +3,7 @@ import { envConfig } from "@/app/lib/config";
|
||||
import axios from "axios";
|
||||
import { useEffect, useState } from "react";
|
||||
import Swal from "sweetalert2";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
interface Programa {
|
||||
id_programa: number;
|
||||
@@ -19,11 +20,14 @@ export default function ProgramSelector({
|
||||
const [programas, setProgramas] = useState<Programa[]>([]);
|
||||
const [checkboxes, setCheckboxes] = useState<Record<number, boolean>>({});
|
||||
|
||||
const token = Cookies.get("token");
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const [programasRes] = await Promise.all([
|
||||
axios.get(`${envConfig.apiUrl}/programa`),
|
||||
]);
|
||||
axios.get(`${envConfig.apiUrl}/programa`, { headers },
|
||||
)]);
|
||||
|
||||
setProgramas(programasRes.data);
|
||||
|
||||
@@ -58,9 +62,10 @@ export default function ProgramSelector({
|
||||
{
|
||||
programas: programasSeleccionados,
|
||||
},
|
||||
{ headers },
|
||||
);
|
||||
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Programas actualizados en la máquina!",
|
||||
icon: "success",
|
||||
@@ -70,12 +75,15 @@ export default function ProgramSelector({
|
||||
}
|
||||
|
||||
if (id) {
|
||||
await axios.patch(`${envConfig.apiUrl}/programa-equipo/sala`, {
|
||||
sala: id,
|
||||
programas: programasSeleccionados,
|
||||
});
|
||||
await axios.patch(`${envConfig.apiUrl}/programa-equipo/sala`,
|
||||
{
|
||||
sala: id,
|
||||
programas: programasSeleccionados,
|
||||
},
|
||||
{ headers },
|
||||
);
|
||||
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Programas actualizados en la sala",
|
||||
icon: "success",
|
||||
@@ -90,7 +98,7 @@ export default function ProgramSelector({
|
||||
draggable: true
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Error al guardar cambios!",
|
||||
@@ -116,12 +124,15 @@ export default function ProgramSelector({
|
||||
if (ubicacion && ubicacion !== "0") {
|
||||
res = await axios.get(
|
||||
`${envConfig.apiUrl}/programa-equipo/${ubicacion}`,
|
||||
{ headers },
|
||||
);
|
||||
}
|
||||
|
||||
if (id) {
|
||||
res = await axios.get(
|
||||
`${envConfig.apiUrl}/area-ubicacion/programs/${id}`,
|
||||
{ headers },
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -131,14 +142,14 @@ export default function ProgramSelector({
|
||||
} catch (error: any) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
if (error.response?.status === 404) {
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Sin programas asignados!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
});
|
||||
} else {
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Error al cargar programas!",
|
||||
icon: "error",
|
||||
@@ -147,7 +158,7 @@ export default function ProgramSelector({
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Error inesperado!",
|
||||
icon: "error",
|
||||
|
||||
Reference in New Issue
Block a user