added more headers
This commit is contained in:
@@ -7,6 +7,7 @@ import { GetSancionByStudent } from "@/app/lib/getSancionByStudent";
|
||||
import TableSanction from "./TableSanction";
|
||||
import axios from "axios";
|
||||
import Swal from "sweetalert2";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
if (!envConfig.apiUrl) {
|
||||
console.error("API URL is not defined in envConfig");
|
||||
@@ -20,6 +21,9 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loadingTable, setLoadingTable] = useState(false);
|
||||
|
||||
const token = Cookies.get("token");
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
|
||||
const fetchAlumnoSanciones = async () => {
|
||||
try {
|
||||
|
||||
@@ -39,7 +43,7 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
fetchAlumnoSanciones();
|
||||
|
||||
axios
|
||||
.get(`${envConfig.apiUrl}/sancion`)
|
||||
.get(`${envConfig.apiUrl}/sancion`, { headers })
|
||||
.then((res) => setSanciones(res.data))
|
||||
.catch(() =>
|
||||
|
||||
@@ -56,7 +60,7 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!selectedSancion) {
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Selecciona una sanción!",
|
||||
icon: "error",
|
||||
@@ -71,18 +75,18 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
await axios.post(`${envConfig.apiUrl}/alumno-sancion/`, {
|
||||
id_sancion: Number(selectedSancion),
|
||||
id_cuenta: idCuenta,
|
||||
});
|
||||
}, { headers });
|
||||
|
||||
await fetchAlumnoSanciones();
|
||||
setSelectedSancion("");
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Sanción aplicada correctamente!",
|
||||
icon: "success",
|
||||
draggable: true
|
||||
});
|
||||
} catch {
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Error al aplicar la sanción!",
|
||||
icon: "error",
|
||||
|
||||
Reference in New Issue
Block a user