apply DRY principle by removing duplicated logic
This commit is contained in:
@@ -55,8 +55,8 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
);
|
||||
|
||||
if (!todasAsistieron) {
|
||||
|
||||
Swal.fire({
|
||||
|
||||
Swal.fire({
|
||||
title: "El alumno no asistió a todas las pláticas!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
@@ -69,7 +69,7 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
}, [inscripcion]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!puedeContinuar || !numAcount) return;
|
||||
if (!puedeContinuar || !numAcount || error === "Equipo" || error === "Mesa") return;
|
||||
|
||||
const fetchEquipos = async () => {
|
||||
try {
|
||||
@@ -84,14 +84,14 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("No se pudieron cargar los equipos");
|
||||
|
||||
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
setEquipos(data);
|
||||
} catch (error) {
|
||||
|
||||
Swal.fire({
|
||||
|
||||
Swal.fire({
|
||||
title: "Error al cargar equipos disponibles!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
@@ -110,8 +110,8 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!equipoSeleccionado) {
|
||||
|
||||
Swal.fire({
|
||||
|
||||
Swal.fire({
|
||||
title: "Selecciona un equipo!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
@@ -140,15 +140,15 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
|
||||
}
|
||||
|
||||
setBitacora([])
|
||||
|
||||
Swal.fire({
|
||||
title: "Equipo asignado correctamente!",
|
||||
icon: "success",
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
Swal.fire({
|
||||
title: "Equipo asignado correctamente!",
|
||||
icon: "success",
|
||||
draggable: true,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Swal.fire({
|
||||
|
||||
Swal.fire({
|
||||
title: "No se pudo asignar el equipo!",
|
||||
icon: "error",
|
||||
draggable: true
|
||||
|
||||
@@ -6,31 +6,10 @@ import Information from "@/app/Components/Global/Information/information";
|
||||
import ShowError from "@/app/Components/Global/ShowError";
|
||||
import Table from "@/app/Components/Global/table";
|
||||
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import { GetRegisterStudent } from "@/app/lib/getRegisterStudent";
|
||||
import PlaticaGate from "./PlaticaGate";
|
||||
import "@/app/globals.css";
|
||||
|
||||
async function getInscripcion(idCuenta: number) {
|
||||
try {
|
||||
const res = await fetch(`${envConfig.apiUrl}/alumno-inscrito/${idCuenta}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (error: any) {
|
||||
return { error: error.message || "No se pudo cargar la inscripción" };
|
||||
}
|
||||
}
|
||||
|
||||
const headers = ["Inscrito", "Tiempo", "Confirmó"];
|
||||
|
||||
export default async function Page(props: {
|
||||
@@ -65,7 +44,7 @@ export default async function Page(props: {
|
||||
: Boolean(rawPlatica);
|
||||
}
|
||||
|
||||
const inscResult = await getInscripcion(idCuenta);
|
||||
const inscResult = await GetRegisterStudent(idCuenta);
|
||||
if (!inscResult.error && Array.isArray(inscResult)) {
|
||||
inscripcion = inscResult;
|
||||
} else {
|
||||
@@ -123,7 +102,7 @@ export default async function Page(props: {
|
||||
label: "Cancelar tiempo",
|
||||
content: (
|
||||
<>
|
||||
<CheckBoxEquipo numAcount={params?.numAcount} machine={params?.machine} />
|
||||
<CheckBoxEquipo numAcount={numAcount} machine={machine} />
|
||||
</>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -5,22 +5,8 @@ import SearchUser from "@/app/Components/Global/SearchUser/searchUser";
|
||||
import ShowError from "@/app/Components/Global/ShowError";
|
||||
import Toggle from "@/app/Components/Global/Toggle/Toggle";
|
||||
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import { GetRegisterStudent } from "@/app/lib/getRegisterStudent";
|
||||
|
||||
async function getInscripcion(idCuenta: number) {
|
||||
try {
|
||||
const res = await fetch(`${envConfig.apiUrl}/alumno-inscrito/${idCuenta}`, {
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error("Error al cargar inscripción");
|
||||
return await res.json();
|
||||
} catch (error: any) {
|
||||
return { error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
export default async function Page(props: {
|
||||
searchParams?: Promise<{
|
||||
key?: string;
|
||||
@@ -55,7 +41,7 @@ export default async function Page(props: {
|
||||
}
|
||||
|
||||
|
||||
const inscResult = await getInscripcion(idCuenta);
|
||||
const inscResult = await GetRegisterStudent(idCuenta);
|
||||
if (!inscResult.error && Array.isArray(inscResult)) {
|
||||
inscripcion = inscResult;
|
||||
} else {
|
||||
|
||||
@@ -4,35 +4,12 @@ import ShowError from "@/app/Components/Global/ShowError";
|
||||
import Table from "@/app/Components/Global/table";
|
||||
import Inscripcion from "@/app/Components/Receipt/Inscripcion";
|
||||
import { GetStudent } from "@/app/lib/getStudent";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
|
||||
import Link from "next/link";
|
||||
import { GetRegisterStudent } from "@/app/lib/getRegisterStudent";
|
||||
|
||||
import "./inscripcion.css";
|
||||
|
||||
if (!envConfig.apiUrl) {
|
||||
console.error("API URL is not defined in envConfig");
|
||||
}
|
||||
|
||||
async function getInscripcion(idCuenta: number) {
|
||||
try {
|
||||
const res = await fetch(`${envConfig.apiUrl}/alumno-inscrito/${idCuenta}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (error: any) {
|
||||
return { error: error.message || "No se pudo cargar la inscripción" };
|
||||
}
|
||||
}
|
||||
|
||||
const headers = ["Inscrito", "Tiempo", "Confirmó"];
|
||||
|
||||
export default async function Page(props: {
|
||||
@@ -63,7 +40,7 @@ export default async function Page(props: {
|
||||
student = studentResult;
|
||||
}
|
||||
|
||||
const inscResult = await getInscripcion(idCuenta);
|
||||
const inscResult = await GetRegisterStudent(idCuenta);
|
||||
if (!inscResult.error && Array.isArray(inscResult)) {
|
||||
inscripcion = inscResult;
|
||||
} else {
|
||||
|
||||
@@ -119,8 +119,11 @@ export default function Inscripcion({
|
||||
{ headers },
|
||||
);
|
||||
|
||||
|
||||
Swal.fire("Alumno inscrito con pago");
|
||||
Swal.fire({
|
||||
title: "Alumno inscrito con pago",
|
||||
icon: "success",
|
||||
draggable: true
|
||||
});
|
||||
setFolio("");
|
||||
setAmount("");
|
||||
setDate(todayISO);
|
||||
|
||||
Reference in New Issue
Block a user