From b9a3118c841895111ca75dabb9c2172af3bb6e9d Mon Sep 17 00:00:00 2001 From: markosbenitez Date: Wed, 17 Jun 2026 09:25:18 -0300 Subject: [PATCH] Filtro en listado de respuestas admin --- .DS_Store | Bin 14340 -> 14340 bytes app/admin/responses/page.tsx | 62 ++++++++++++++++++++++++++--------- app/globals.css | 8 +++++ 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/.DS_Store b/.DS_Store index af40c5e03c16701336c1b2923cb0b849a743daad..e7d68354b301c79993a76c9740c8cf9463f8021e 100644 GIT binary patch delta 80 zcmZoEXepTB&&azmV7ELY+h!gGb9PZShFpeJh7yJhhJ1#Ul;Y%^r2PDx$@c13Ctnn> N+nlX&gAb>YH2~5!83F(R delta 40 vcmZoEXepTB&&abeV7ELY>t-GWbN0zG>K7;PVR4=OS3qcUw#E%Upuj-@C&3Q~ diff --git a/app/admin/responses/page.tsx b/app/admin/responses/page.tsx index 86f17e1..1c00a64 100644 --- a/app/admin/responses/page.tsx +++ b/app/admin/responses/page.tsx @@ -8,6 +8,13 @@ export const dynamic = 'force-dynamic' const MAX_SUBMISSIONS = 500 const PROMPT_MAX_LEN = 60 +const SURVEY_OPTIONS = [ + { label: 'Todos', id: null }, + { label: 'InQuality', id: '30000000-0000-0000-0000-000000000002' }, + { label: 'Fundación Solidaridad', id: '30000000-0000-0000-0000-000000000003' }, + { label: 'Demo', id: '30000000-0000-0000-0000-000000000001' }, +] as const + interface AllowedQuestion { id: string code: string @@ -63,7 +70,12 @@ function renderValue(value: unknown, type: string): string | null { } } -export default async function AdminResponsesPage() { +export default async function AdminResponsesPage({ + searchParams, +}: { + searchParams: Promise<{ survey_id?: string }> +}) { + const { survey_id: surveyId } = await searchParams const supabase = getSupabaseAdmin() // 1. Preguntas permitidas — text_long e is_sensitive=true se excluyen ACÁ, @@ -91,22 +103,26 @@ export default async function AdminResponsesPage() { // 2. Submissions con sus respuestas — answers!inner + .in() filtra el ARRAY // embebido a solo question_id permitidos (consulta, no post-filtro). + let responsesQuery = supabase + .from('responses') + .select( + ` + id, + submitted_at, + qi_zone, + qi_sector, + answers!inner ( value, question_id ) + ` + ) + .in('answers.question_id', allowedIds) + + if (surveyId) { + responsesQuery = responsesQuery.eq('survey_id', surveyId) + } + const { data: responsesData, error: responsesError } = allowedIds.length > 0 - ? await supabase - .from('responses') - .select( - ` - id, - submitted_at, - qi_zone, - qi_sector, - answers!inner ( value, question_id ) - ` - ) - .in('answers.question_id', allowedIds) - .order('submitted_at', { ascending: false }) - .limit(MAX_SUBMISSIONS) + ? await responsesQuery.order('submitted_at', { ascending: false }).limit(MAX_SUBMISSIONS) : { data: [] as ResponseRow[], error: null } if (responsesError) { @@ -170,6 +186,22 @@ export default async function AdminResponsesPage() { {totalSubmissions ?? 0} submissions · {totalAnswers ?? 0} respuestas individuales · actualizado {formatDate(new Date().toISOString())}

+ Actualizar diff --git a/app/globals.css b/app/globals.css index 271b605..e41aa52 100644 --- a/app/globals.css +++ b/app/globals.css @@ -758,6 +758,14 @@ body { } .admin-title { font-size: 1.375rem; font-weight: 700; color: var(--color-text); margin: 0 0 4px; } .admin-subtitle { font-size: 0.8125rem; color: var(--color-text-muted); margin: 0; } +.admin-survey-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; } +.admin-survey-link { + font-size: 0.75rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; + border: 1px solid var(--color-border); color: var(--color-text-muted); text-decoration: none; + transition: all 0.2s ease; +} +.admin-survey-link:hover { color: var(--color-text); border-color: var(--color-primary); } +.admin-survey-link-active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); } .admin-refresh { display: inline-block; padding: 8px 16px; border-radius: var(--radius); background: var(--color-primary); color: #fff; font-size: 0.8125rem;