diff --git a/frontend/app/lib/api.ts b/frontend/app/lib/api.ts index 1b83d3e..c58a0d9 100644 --- a/frontend/app/lib/api.ts +++ b/frontend/app/lib/api.ts @@ -41,6 +41,13 @@ export interface Curso { nombreCurso: string; nivelCurso?: number; duracion?: number; + idPlanDeEstudios?: number; + planNombre?: string; +} +export interface Plan { + idPlanDeEstudios: number; + nombre: string; + nCursos: number; } export interface Alumno { idAlumno: string; diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index e618049..7271e2b 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -1,12 +1,13 @@ "use client"; import { useEffect, useState } from "react"; import SamShell from "./components/SamShell"; -import { apiGet, nombreCompleto, useMisCursos, type Asignacion, type Template } from "./lib/mis"; +import { apiGet, nombreCompleto, useMisCursos, type Asignacion, type Curso, type Template } from "./lib/mis"; import { useSession } from "./lib/session"; export default function Home() { const { user } = useSession(); const [templates, setTemplates] = useState([]); + const [cursosTodos, setCursosTodos] = useState([]); const [asignaciones, setAsignaciones] = useState>({}); const { cursos, loading, error } = useMisCursos(); @@ -14,6 +15,13 @@ export default function Home() { apiGet("/templates").then(setTemplates).catch(() => {}); }, []); + useEffect(() => { + if (!user) return; + apiGet(`/cursos/${user.origen === "SAM" ? "sam" : "empresa"}`) + .then(setCursosTodos) + .catch(() => {}); + }, [user]); + useEffect(() => { if (!user || cursos.length === 0) return; cursos.forEach((c) => { @@ -24,31 +32,43 @@ export default function Home() { }, [user, cursos]); const tplNombre = (id: string) => templates.find((t) => t.id === id)?.nombre ?? "Prueba"; + const planDe = (id: number) => cursosTodos.find((c) => c.idCursos === id)?.planNombre ?? "Otros"; const total = Object.values(asignaciones).reduce((s, as) => s + as.length, 0); + const grupos = new Map(); + cursos.forEach((c) => { + const p = planDe(c.idCursos); + if (!grupos.has(p)) grupos.set(p, []); + grupos.get(p)!.push(c); + }); return ( {loading &&
} {error &&
{error}
} -
- {cursos.map((c) => ( -
-
-
{c.nombreCurso}
- {(asignaciones[c.idCursos] ?? []).length === 0 ? ( -

Sin pruebas asignadas por ahora.

- ) : ( -
    - {(asignaciones[c.idCursos] ?? []).map((a) => ( -
  • {tplNombre(a.templateId)}
  • - ))} -
- )} - Rendir -
+ {[...grupos.entries()].map(([plan, cs]) => ( +
+
{plan} {cs.length}
+
+ {cs.map((c) => ( +
+
+
{c.nombreCurso}
+ {(asignaciones[c.idCursos] ?? []).length === 0 ? ( +

Sin pruebas asignadas por ahora.

+ ) : ( +
    + {(asignaciones[c.idCursos] ?? []).map((a) => ( +
  • {tplNombre(a.templateId)}
  • + ))} +
+ )} + Rendir +
+
+ ))}
- ))} -
+
+ ))} {cursos.length > 0 && (

Tienes {total} prueba(s) asignada(s) en {cursos.length} curso(s) con matrícula activa.

)}