apply DRY to alumno-sancio
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import SearchUser from "@/app/Components/Global/SearchUser/searchUser";
|
||||
import ShowError from "@/app/Components/Global/ShowError";
|
||||
import QuitarSancion from "@/app/Components/QuitarSancion/QuitarSancion";
|
||||
import { GetSancionByStudent } from "@/app/lib/getStudent copy";
|
||||
import { GetSancionByStudent } from "@/app/lib/getSancionByStudent";
|
||||
|
||||
export default async function Page(props: {
|
||||
searchParams?: Promise<{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import { Alumno, AlumnoSancion, Sancion } from "@/app/types/sanction";
|
||||
import { GetSancionByStudent } from "@/app/lib/getSancionByStudent";
|
||||
import TableSanction from "./TableSanction";
|
||||
import axios from "axios";
|
||||
import Swal from "sweetalert2";
|
||||
@@ -21,12 +22,11 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
|
||||
const fetchAlumnoSanciones = async () => {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${envConfig.apiUrl}/alumno-sancion/${idCuenta}`
|
||||
);
|
||||
|
||||
setAlumno(res.data.student ?? null);
|
||||
setAlumnoSanciones(res.data.alusancion ?? []);
|
||||
const res = await GetSancionByStudent(idCuenta);
|
||||
|
||||
setAlumno(res.student ?? null);
|
||||
setAlumnoSanciones(res.alusancion ?? []);
|
||||
} catch {
|
||||
} finally {
|
||||
setLoadingTable(true)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
|
||||
import TableSanction from "../BitacoraSanciones/TableSanction";
|
||||
import { Alumno, AlumnoSancion } from "@/app/types/sanction";
|
||||
import axios from "axios";
|
||||
import { GetSancionByStudent } from "@/app/lib/getSancionByStudent";
|
||||
|
||||
function QuitarSancion({ id_cuenta }: { id_cuenta: number }) {
|
||||
const [alumno, setAlumno] = useState<Alumno>();
|
||||
@@ -13,12 +14,11 @@ function QuitarSancion({ id_cuenta }: { id_cuenta: number }) {
|
||||
|
||||
const fetchAlumnoSanciones = async () => {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`
|
||||
);
|
||||
|
||||
setAlumno(res.data.student ?? null);
|
||||
setAlumnoSanciones(res.data.alusancion ?? []);
|
||||
const res = await GetSancionByStudent(id_cuenta);
|
||||
|
||||
setAlumno(res.student ?? null);
|
||||
setAlumnoSanciones(res.alusancion ?? []);
|
||||
} catch {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { envConfig } from "./config";
|
||||
|
||||
export async function GetSanciones(numAcount: number) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${envConfig.apiUrl}/alumno-sancion/${numAcount}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const msg =
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
"Error desconocido al obtener estudiante";
|
||||
return { error: msg };
|
||||
}
|
||||
}
|
||||
//IO
|
||||
Reference in New Issue
Block a user