diff --git a/app/admin/responses/page.tsx b/app/admin/responses/page.tsx index 19734d1..86f17e1 100644 --- a/app/admin/responses/page.tsx +++ b/app/admin/responses/page.tsx @@ -1,4 +1,5 @@ import { createClient } from '@supabase/supabase-js' +import { ResponsesTable, type DisplayRow } from './responses-table' // Server Component sin auth — herramienta interna de diagnóstico (Etapa 3V-B). // Usa SUPABASE_SERVICE_ROLE_KEY: vive solo acá, server-side, nunca al cliente. @@ -28,19 +29,6 @@ interface ResponseRow { answers: AnswerRow[] } -interface FlatRow { - key: string - submissionNum: number - isFirstInGroup: boolean - submitted_at: string - qi_zone: string | null - qi_sector: string | null - code: string - prompt: string - type: string - value: unknown -} - function getSupabaseAdmin() { const url = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://placeholder.supabase.co' const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY || 'placeholder' @@ -147,7 +135,7 @@ export default async function AdminResponsesPage() { : { count: 0 } // 4. Aplanar: una fila por answer, ordenadas por position dentro de cada submission - const rows: FlatRow[] = [] + const rows: DisplayRow[] = [] responses.forEach((response, idx) => { const answers = response.answers .filter((a) => questionMap.has(a.question_id)) @@ -158,17 +146,17 @@ export default async function AdminResponsesPage() { answers.forEach((a, ai) => { const q = questionMap.get(a.question_id)! + const isFirstInGroup = ai === 0 rows.push({ key: `${response.id}-${a.question_id}`, submissionNum: idx + 1, - isFirstInGroup: ai === 0, - submitted_at: response.submitted_at, - qi_zone: response.qi_zone, - qi_sector: response.qi_sector, + isFirstInGroup, + date: isFirstInGroup ? formatDate(response.submitted_at) : '', code: q.code, - prompt: q.prompt, - type: q.type, - value: a.value, + prompt: truncate(q.prompt), + rendered: renderValue(a.value, q.type), + zone: isFirstInGroup ? (response.qi_zone ?? '—') : '', + sector: isFirstInGroup ? (response.qi_sector ?? '—') : '', }) }) }) @@ -187,46 +175,7 @@ export default async function AdminResponsesPage() {
| # | -Fecha | -Código | -Pregunta | -Tipo | -Valor | -Departamento | -Sector | -
|---|---|---|---|---|---|---|---|
| {row.submissionNum} | -{row.isFirstInGroup ? formatDate(row.submitted_at) : ''} | -{row.code} | -{truncate(row.prompt)} | -{row.type} | -- {rendered === null ? sin dato : rendered} - | -- {row.isFirstInGroup ? (row.qi_zone ?? '—') : ''} - | -- {row.isFirstInGroup ? (row.qi_sector ?? '—') : ''} - | -
Sin respuestas registradas todavía.
)} diff --git a/app/admin/responses/responses-table.tsx b/app/admin/responses/responses-table.tsx new file mode 100644 index 0000000..2bed8cf --- /dev/null +++ b/app/admin/responses/responses-table.tsx @@ -0,0 +1,98 @@ +'use client' + +import { useState } from 'react' + +export interface DisplayRow { + key: string + submissionNum: number + isFirstInGroup: boolean + date: string + code: string + prompt: string + rendered: string | null + zone: string + sector: string +} + +export function ResponsesTable({ rows }: { rows: DisplayRow[] }) { + const [expanded, setExpanded] = useState| # | +Fecha | +Código | +Pregunta | +Valor | +Departamento | +Sector | +
|---|---|---|---|---|---|---|
| + {row.isFirstInGroup && ( + + )} + {row.submissionNum} + | +{row.date} | +{row.code} | +{row.prompt} | ++ {row.rendered === null ? ( + sin dato + ) : ( + row.rendered + )} + | +{row.zone} | +{row.sector} | +