comunicacion con Api

This commit is contained in:
jls846
2025-12-04 18:49:30 -06:00
parent f465f55a68
commit 59274690b1
2 changed files with 52 additions and 36 deletions
+51 -31
View File
@@ -4,10 +4,32 @@ import Receipt from "@/app/Components/Receipt/Receipt";
import Selection from "@/app/Components/Selection/Selection";
import ShowError from "@/app/Components/Global/ShowError";
import { GetStudent } from "@/app/lib/getStudent";
import "./inscripcion.css";
import Table from "@/app/Components/Global/table";
async function getInscripcion(idCuenta: number) {
try {
const res = await fetch(`http://localhost:5000/alumno-inscrito/${idCuenta}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
// Desactiva caché si los datos pueden cambiar frecuentemente
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: {
searchParams?: Promise<{
numAcount: string;
@@ -17,35 +39,37 @@ export default async function Page(props: {
const numAcount = params?.numAcount ? params.numAcount : null;
let student: any = null;
let inscripcion: any = null;
let errorMessage = "";
if (numAcount) {
const result = await GetStudent(parseInt(numAcount));
if (result.error) {
errorMessage = `${result.error}`;
if (numAcount) {
const idCuenta = parseInt(numAcount);
const studentResult = await GetStudent(idCuenta);
if (studentResult.error) {
errorMessage = `${studentResult.error}`;
} else {
student = result;
student = studentResult;
}
const inscResult = await getInscripcion(idCuenta);
if (!inscResult.error) {
inscripcion = inscResult;
} else {
}
}
const headers = ["Inscrito", "Tiempo", "Confirmó"];
const data = [
{
Inscrito: "WINDOWS",
Tiempo: "9 minutos",
Confirmó: "si",
},
{
Inscrito: "WINDOWS",
Tiempo: "9 minutos",
Confirmó: "si/no",
},
{
Inscrito: "WINDOWS",
Tiempo: "9 minutos",
Confirmó: "si/no",
},
];
const tableData = inscripcion
? [
{
Inscrito: inscripcion.plataforma?.nombre || "—",
Tiempo: inscripcion.tiempo_disponible
? `${Math.floor(inscripcion.tiempo_disponible / 60)} minutos`
: "—",
Confirmó: inscripcion.realizo_pago === 1 ? "sí" : "no",
},
]
: [];
return (
<section className="containerSection">
@@ -68,10 +92,7 @@ export default async function Page(props: {
</>
)}
{!student && numAcount && (
<button
className="button buttonSearch"
style={{ marginTop: "1rem" }}
>
<button className="button buttonSearch" style={{ marginTop: "1rem" }}>
Registrar Estudiante
</button>
)}
@@ -79,7 +100,7 @@ export default async function Page(props: {
{student && (
<>
<Table headers={headers} data={data} />
<Table headers={headers} data={tableData} />
<button
className="button buttonSearch"
style={{ marginTop: "2rem" }}
@@ -112,5 +133,4 @@ export default async function Page(props: {
)}
</section>
);
}
//IO
}
+1 -5
View File
@@ -619,7 +619,6 @@
"integrity": "sha512-EhBeSYX0Y6ye8pNebpKrwFJq7BoQ8J5SO6NlvNwwHjSj6adXJViPQrKlsyPw7hLBLvckEMO1yxeGdR82YBBlDg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"csstype": "^3.0.2"
}
@@ -760,8 +759,7 @@
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/delayed-stream": {
"version": "1.0.0",
@@ -1144,7 +1142,6 @@
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
"integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=0.10.0"
}
@@ -1154,7 +1151,6 @@
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz",
"integrity": "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==",
"license": "MIT",
"peer": true,
"dependencies": {
"scheduler": "^0.26.0"
},