fixed checkbox equipo and mesa and delete fetch
This commit is contained in:
@@ -8,6 +8,7 @@ import { getMesaByCount } from "@/app/lib/getMesaByCount";
|
||||
|
||||
import "./asignacion.css";
|
||||
import Swal from "sweetalert2";
|
||||
import axios from "axios";
|
||||
|
||||
type Props = {
|
||||
inscripcion: any[];
|
||||
@@ -41,10 +42,9 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!numAcount) return;
|
||||
const idCuenta = numAcount;
|
||||
if (isNaN(idCuenta)) return;
|
||||
if (isNaN(numAcount)) return;
|
||||
|
||||
fetchByCuenta(idCuenta);
|
||||
fetchByCuenta(numAcount);
|
||||
}, [numAcount]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -55,11 +55,10 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
);
|
||||
|
||||
if (!todasAsistieron) {
|
||||
|
||||
Swal.fire({
|
||||
title: "El alumno no asistió a todas las pláticas!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
setPuedeContinuar(false);
|
||||
return;
|
||||
@@ -75,26 +74,16 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
try {
|
||||
setLoadingEquipos(true);
|
||||
|
||||
const res = await fetch(
|
||||
`${envConfig.apiUrl}/equipo/student/${numAcount}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
},
|
||||
const res = await axios.get(
|
||||
`${envConfig.apiUrl}/equipo/student/${numAcount}`
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("No se pudieron cargar los equipos");
|
||||
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
setEquipos(data);
|
||||
} catch (error) {
|
||||
|
||||
setEquipos(res.data);
|
||||
} catch (err) {
|
||||
Swal.fire({
|
||||
title: "Error al cargar equipos disponibles!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
} finally {
|
||||
setLoadingEquipos(false);
|
||||
@@ -110,11 +99,10 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!equipoSeleccionado) {
|
||||
|
||||
Swal.fire({
|
||||
title: "Selecciona un equipo!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -127,31 +115,20 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
id_alumno_inscrito: inscripcion[0].id_alumno_inscrito,
|
||||
};
|
||||
|
||||
const res = await fetch(`${envConfig.apiUrl}/bitacora`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
await axios.post(`${envConfig.apiUrl}/bitacora`, body);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("Error al asignar equipo");
|
||||
}
|
||||
|
||||
setBitacora([])
|
||||
setBitacora([]);
|
||||
|
||||
Swal.fire({
|
||||
title: "Equipo asignado correctamente!",
|
||||
icon: "success",
|
||||
draggable: true,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
} catch (err) {
|
||||
Swal.fire({
|
||||
title: "No se pudo asignar el equipo!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
draggable: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -190,8 +167,7 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
onClick={() => !loadingEquipos && setOpen(!open)}
|
||||
>
|
||||
{equipoSeleccionado ? (
|
||||
<span
|
||||
>
|
||||
<span>
|
||||
{equipoSeleccionado.ubicacion}{" "}
|
||||
{equipoSeleccionado.nombre_equipo}
|
||||
</span>
|
||||
@@ -240,4 +216,4 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
{ tiempo_asignado: minutos },
|
||||
);
|
||||
|
||||
|
||||
|
||||
Swal.fire({
|
||||
title: "Tiempo cancelado Correctamente!",
|
||||
icon: "success",
|
||||
@@ -153,7 +153,7 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
{modo === "Cuenta" && <SearchUser value={numAcount ?? null} />}
|
||||
{modo === "Equipo" && <SearchEquipo value={machine ?? null} />}
|
||||
|
||||
<h2 style={{marginTop:"10px"}}>{error}</h2>
|
||||
<h2 style={{ marginTop: "10px" }}>{error}</h2>
|
||||
|
||||
{bitacora && (
|
||||
<>
|
||||
@@ -167,6 +167,7 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
className="button buttonSearch"
|
||||
style={{ marginTop: "1rem" }}
|
||||
onClick={handleButton}
|
||||
disabled={minutos ? false : true}
|
||||
>
|
||||
Cancelar tiempo
|
||||
</button>
|
||||
|
||||
@@ -153,7 +153,7 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
|
||||
className="button buttonSearch"
|
||||
style={{ marginTop: "1rem" }}
|
||||
onClick={handleButton}
|
||||
disabled={loading}
|
||||
disabled={loading || minutos ? false : true}
|
||||
>
|
||||
Cancelar tiempo
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user