From 8f99440207c7662401dbbd0e99f121063225a5f6 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Mon, 23 Feb 2026 11:51:39 -0600 Subject: [PATCH] apply DRY principle by removing duplicated logic --- .../AsignacionEquipo/PlaticaGate.tsx | 32 +++++++++---------- app/(private)/AsignacionEquipo/page.tsx | 25 ++------------- app/(private)/AsignacionMesas/page.tsx | 16 +--------- app/(private)/Inscripcion/page.tsx | 29 ++--------------- app/Components/Receipt/Inscripcion.tsx | 7 ++-- 5 files changed, 27 insertions(+), 82 deletions(-) diff --git a/app/(private)/AsignacionEquipo/PlaticaGate.tsx b/app/(private)/AsignacionEquipo/PlaticaGate.tsx index 7e53723..78147d4 100644 --- a/app/(private)/AsignacionEquipo/PlaticaGate.tsx +++ b/app/(private)/AsignacionEquipo/PlaticaGate.tsx @@ -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 diff --git a/app/(private)/AsignacionEquipo/page.tsx b/app/(private)/AsignacionEquipo/page.tsx index 1196874..e3dfa53 100644 --- a/app/(private)/AsignacionEquipo/page.tsx +++ b/app/(private)/AsignacionEquipo/page.tsx @@ -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: ( <> - + ), }, diff --git a/app/(private)/AsignacionMesas/page.tsx b/app/(private)/AsignacionMesas/page.tsx index edf42f8..4384edb 100644 --- a/app/(private)/AsignacionMesas/page.tsx +++ b/app/(private)/AsignacionMesas/page.tsx @@ -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 { diff --git a/app/(private)/Inscripcion/page.tsx b/app/(private)/Inscripcion/page.tsx index 098d8f4..87c3caf 100644 --- a/app/(private)/Inscripcion/page.tsx +++ b/app/(private)/Inscripcion/page.tsx @@ -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 { diff --git a/app/Components/Receipt/Inscripcion.tsx b/app/Components/Receipt/Inscripcion.tsx index 64af918..97a3aac 100644 --- a/app/Components/Receipt/Inscripcion.tsx +++ b/app/Components/Receipt/Inscripcion.tsx @@ -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);