Merge pull request 'fix: update cuestionario types to include evento details' (#22) from develop into master
Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
@@ -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<GetCuestionario[]>([]);
|
||||
const [eventos, setEventos] = React.useState<GetCuestionarioWithEvento[]>([]);
|
||||
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<GetCuestionario[]>(
|
||||
`/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<GetEvento>(
|
||||
`/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() {
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{participantes.length === 0 && (
|
||||
<div className="alert alert-warning mt-4">
|
||||
No hay participantes registrados para este evento.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Vendored
+8
-1
@@ -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;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
|
||||
Reference in New Issue
Block a user