fixed get alumno-sancion
This commit is contained in:
@@ -23,6 +23,7 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [tiempo, setTiempo] = useState<number>(15);
|
||||
const [bitacora, setBitacora] = useState<[] | null>([]);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
const fetchByCuenta = async (idCuenta: number) => {
|
||||
const [result, resultMesa] = await Promise.all([
|
||||
@@ -34,8 +35,8 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora([]);
|
||||
if (!result?.error) toast.error("Ya cuentas con un equipo asignado");
|
||||
if (!resultMesa?.error) toast.error("Ya cuentas con una mesa asignada");
|
||||
if (!result?.error) setError("Equipo");
|
||||
if (!resultMesa?.error) setError("Mesa");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,7 +137,11 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
};
|
||||
|
||||
if (bitacora) {
|
||||
return <></>;
|
||||
return error === "Mesa"
|
||||
? <p style={{ margin: "1rem", color: "red" }}>Ya cuentas con una mesa asignada</p>
|
||||
: error === "Equipo"
|
||||
? <p style={{ margin: "1rem", color: "red" }}>Ya cuentas con un equipo asignado</p>
|
||||
: null;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -19,6 +19,7 @@ export default function AsignacionMesas({ idCuenta, inscripcion }: Props) {
|
||||
const [mesaSeleccionada, setMesaSeleccionada] = useState<any>(null);
|
||||
const [tiempo, setTiempo] = useState<number>(15);
|
||||
const [bitacora, setBitacora] = useState<[] | null>([]);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
const fetchByCuenta = async (idCuenta: number) => {
|
||||
const [result, resultMesa] = await Promise.all([
|
||||
@@ -30,8 +31,8 @@ export default function AsignacionMesas({ idCuenta, inscripcion }: Props) {
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora([]);
|
||||
if (!result?.error) toast.error("Ya cuentas con un equipo asignado");
|
||||
if (!resultMesa?.error) toast.error("Ya cuentas con una mesa asignada");
|
||||
if (!result?.error) setError("Equipo");
|
||||
if (!resultMesa?.error) setError("Mesa");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,8 +129,13 @@ export default function AsignacionMesas({ idCuenta, inscripcion }: Props) {
|
||||
if (!puedeContinuar) return null;
|
||||
|
||||
if (bitacora) {
|
||||
return <></>;
|
||||
return error === "Mesa"
|
||||
? <p style={{ margin: "1rem", color: "red" }}>Ya cuentas con una mesa asignada</p>
|
||||
: error === "Equipo"
|
||||
? <p style={{ margin: "1rem", color: "red" }}>Ya cuentas con un equipo asignado</p>
|
||||
: null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="containerForm">
|
||||
<label style={{ marginTop: "1rem" }}>Seleccionar tiempo</label>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Alumno, AlumnoSancion, Sancion } from "@/app/types/sanction";
|
||||
import TableSanction from "./TableSanction";
|
||||
import axios from "axios";
|
||||
@@ -14,58 +13,67 @@ if (!envConfig.apiUrl) {
|
||||
|
||||
export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
const [sanciones, setSanciones] = useState<Sancion[]>([]);
|
||||
const [alumno, setAlumno] = useState<Alumno>();
|
||||
const [alumno, setAlumno] = useState<Alumno >();
|
||||
const [alumnoSanciones, setAlumnoSanciones] = useState<AlumnoSancion[]>([]);
|
||||
const [selectedSancion, setSelectedSancion] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
const fetchAlumnoSanciones = async () => {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${envConfig.apiUrl}/alumno-sancion/${idCuenta}`
|
||||
);
|
||||
|
||||
setAlumno(res.data.student ?? null);
|
||||
setAlumnoSanciones(res.data.alusancion ?? []);
|
||||
} catch {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!idCuenta) return;
|
||||
|
||||
axios
|
||||
.get(`${envConfig.apiUrl}/alumno-sancion/${idCuenta}`)
|
||||
.then((res) => {
|
||||
setAlumno(res.data.student);
|
||||
setAlumnoSanciones(
|
||||
res.data.alusancion?.length ? res.data.alusancion : [],
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
const mensaje =
|
||||
err.response?.data?.message ||
|
||||
"Error al obtener las sanciones del alumno";
|
||||
|
||||
});
|
||||
fetchAlumnoSanciones();
|
||||
|
||||
axios
|
||||
.get(`${envConfig.apiUrl}/sancion`)
|
||||
.then((res) => setSanciones(res.data))
|
||||
.catch((err) =>
|
||||
toast.error("Error al obtener el catálogo de sanciones:", err),
|
||||
.catch(() =>
|
||||
toast.error("Error al obtener el catálogo de sanciones")
|
||||
);
|
||||
}, [idCuenta]);
|
||||
|
||||
const calcularFechaFin = (fechaInicio: string, duracionSemanas: number) => {
|
||||
const fecha = new Date(fechaInicio);
|
||||
fecha.setDate(fecha.getDate() + duracionSemanas * 7);
|
||||
return fecha.toLocaleDateString();
|
||||
};
|
||||
|
||||
const handleButton = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
const handleButton = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!selectedSancion) {
|
||||
toast.error("selecciona una sancion")
|
||||
toast.error("Selecciona una sanción");
|
||||
return;
|
||||
}
|
||||
axios.post(`${envConfig.apiUrl}/alumno-sancion/`, { id_sancion: Number(selectedSancion), id_cuenta: idCuenta })
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
await axios.post(`${envConfig.apiUrl}/alumno-sancion/`, {
|
||||
id_sancion: Number(selectedSancion),
|
||||
id_cuenta: idCuenta,
|
||||
});
|
||||
|
||||
await fetchAlumnoSanciones();
|
||||
setSelectedSancion("");
|
||||
toast.success("Sanción aplicada correctamente");
|
||||
} catch {
|
||||
toast.error("Error al aplicar la sanción");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableSanction alumnoSanciones={alumnoSanciones} alumno={alumno} />
|
||||
{!(alumnoSanciones?.length > 0) &&
|
||||
|
||||
{alumnoSanciones.length === 0 && (
|
||||
<>
|
||||
<form className="containerForm">
|
||||
<div className="groupInput">
|
||||
@@ -87,11 +95,12 @@ export default function ApplySanction({ idCuenta }: { idCuenta: number }) {
|
||||
className="button buttonSearch"
|
||||
style={{ margin: "1rem 0" }}
|
||||
onClick={handleButton}
|
||||
disabled={loading}
|
||||
>
|
||||
Aplicar sanción
|
||||
{loading ? "Aplicando..." : "Aplicar sanción"}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Alumno, AlumnoSancion } from "@/app/types/sanction";
|
||||
|
||||
interface Props {
|
||||
alumnoSanciones: AlumnoSancion[],
|
||||
alumnoSanciones?: AlumnoSancion[] | null,
|
||||
alumno?: Alumno
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ export default function TableSanction({ alumnoSanciones, alumno }: Props) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{alumnoSanciones.length > 0 ? (
|
||||
alumnoSanciones.map((item) => (
|
||||
{!(alumnoSanciones?.length === 0) ? (
|
||||
alumnoSanciones?.map((item) => (
|
||||
<tr key={item.id_alumno_sancion}>
|
||||
<td>{alumno?.id_cuenta}</td>
|
||||
<td>{item.sancion.sancion}</td>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import TableSanction from "../BitacoraSanciones/TableSanction";
|
||||
import { Alumno, AlumnoSancion } from "@/app/types/sanction";
|
||||
@@ -10,32 +9,31 @@ import axios from "axios";
|
||||
function QuitarSancion({ id_cuenta }: { id_cuenta: number }) {
|
||||
const [alumno, setAlumno] = useState<Alumno>();
|
||||
const [alumnoSanciones, setAlumnoSanciones] = useState<AlumnoSancion[]>([]);
|
||||
const router = useRouter();
|
||||
|
||||
const fetchAlumnoSanciones = async () => {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`
|
||||
);
|
||||
|
||||
setAlumno(res.data.student ?? null);
|
||||
setAlumnoSanciones(res.data.alusancion ?? []);
|
||||
} catch {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!id_cuenta) return;
|
||||
|
||||
axios
|
||||
.get(`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`)
|
||||
.then((res) => {
|
||||
setAlumno(res.data.student);
|
||||
setAlumnoSanciones(
|
||||
res.data.alusancion?.length ? res.data.alusancion : [],
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
const mensaje =
|
||||
err.response?.data?.message ||
|
||||
"Error al obtener las sanciones del alumno";
|
||||
fetchAlumnoSanciones();
|
||||
|
||||
});
|
||||
}, [id_cuenta]);
|
||||
|
||||
const handleButton = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
const handleButton = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
axios.delete(`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`)
|
||||
router.refresh();
|
||||
await axios.delete(`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`)
|
||||
fetchAlumnoSanciones();
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user