From f624724521de355c734066d59ca11ebb392a0605 Mon Sep 17 00:00:00 2001 From: miguel Date: Thu, 7 Aug 2025 08:55:44 -0600 Subject: [PATCH] fix: update cuestionario types to include evento details --- src/app/(admins)/staff/lista-manual/page.tsx | 31 ++++++++++++++++---- src/types/cuestionario.d.ts | 9 +++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/app/(admins)/staff/lista-manual/page.tsx b/src/app/(admins)/staff/lista-manual/page.tsx index ec0d7eb..3160019 100644 --- a/src/app/(admins)/staff/lista-manual/page.tsx +++ b/src/app/(admins)/staff/lista-manual/page.tsx @@ -3,7 +3,11 @@ import Button from '@/components/button'; import Input from '@/components/input'; import Select from '@/components/select'; import Table, { Header } from '@/components/table'; -import { GetCuestionario } from '@/types/cuestionario'; +import { + GetCuestionario, + GetCuestionarioWithEvento, +} from '@/types/cuestionario'; +import { GetEvento } from '@/types/evento'; import { ParticipacionEvento } from '@/types/participante-evento'; import axiosInstance from '@/utils/api-config'; import React, { useEffect } from 'react'; @@ -64,7 +68,7 @@ export default function Page() { }, ]; - const [eventos, setEventos] = React.useState([]); + const [eventos, setEventos] = React.useState([]); const [participantes, setParticipantes] = React.useState< ParticipacionEvento[] >([]); @@ -76,9 +80,21 @@ export default function Page() { useEffect(() => { const getEventos = async () => { try { - const { data } = await axiosInstance.get(`/cuestionario`); + const { data } = await axiosInstance.get( + `/cuestionario` + ); if (!data) throw new Error('No se encontraron eventos'); - setEventos(data); + + const cuestionariosConEvento = await Promise.all( + data.map(async (cuestionario) => { + const { data: evento } = await axiosInstance.get( + `/evento/${cuestionario.id_evento}` + ); + return { ...cuestionario, evento }; + }) + ); + + setEventos(cuestionariosConEvento); } catch (error) { console.error('Error en getEventos:', error); } @@ -129,7 +145,7 @@ export default function Page() { label="Selecciona un evento" options={eventos.map((evento) => ({ value: evento.id_cuestionario, - label: evento.nombre_form, + label: `${evento.evento.nombre_evento} - ${evento.nombre_form}`, }))} onChange={(e) => { const id = Number(e?.target?.value ?? e); @@ -155,6 +171,11 @@ export default function Page() { )} + {participantes.length === 0 && ( +
+ No hay participantes registrados para este evento. +
+ )} ); } diff --git a/src/types/cuestionario.d.ts b/src/types/cuestionario.d.ts index 15485dc..219a761 100644 --- a/src/types/cuestionario.d.ts +++ b/src/types/cuestionario.d.ts @@ -1,10 +1,13 @@ +import { GetEvento } from './evento'; + /** * Respuesta del endpoint GET /cuestionario */ export interface GetCuestionario { id_cuestionario: number; + id_evento: number; nombre_form: string; - banner?: string; + banner?: string; descripcion: string; contador_secciones: number; cupo_maximo?: number | null; // Puede ser null si no hay lĂ­mite @@ -14,6 +17,10 @@ export interface GetCuestionario { id_tipo_cuestionario: number; } +export interface GetCuestionarioWithEvento extends GetCuestionario { + evento: GetEvento; +} + /* */ /* */ /* */