feat: refactor group detail components for improved member and pending views

This commit is contained in:
Jose Selesan
2026-09-29 16:29:38 -03:00
parent 5ef393fa64
commit 9520763ec3
12 changed files with 432 additions and 196 deletions

View File

@@ -0,0 +1,125 @@
import { Clock, Inbox, Loader2, Share2, UserCheck } from 'lucide-react'
import { Button } from '../../../components/ui'
import { cn } from '../../../lib/utils'
import { useGroupDetail } from './GroupDetailProvider'
import { PreRegistrationsTable } from './PreRegistrationsTable'
import { WaitlistTable } from './WaitlistTable'
export function PendingView() {
const {
preRegistrations,
preRegistrationsPending,
waitlistEntries,
waitlistPending,
searchFilter,
openInviteModal,
} = useGroupDetail()
const query = searchFilter.trim().toLowerCase()
const matches = (fullName: string, phone: string | null | undefined, email?: string | null) =>
!query ||
fullName.toLowerCase().includes(query) ||
(phone != null && phone.includes(query)) ||
(email != null && email.toLowerCase().includes(query))
const filteredPrereg = preRegistrations.filter((p) => matches(p.fullName, p.phone, p.email))
const filteredWaitlist = waitlistEntries.filter((w) => matches(w.fullName, w.phone))
if (preRegistrationsPending || waitlistPending) {
return (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
)
}
const hasAnyEntry = preRegistrations.length > 0 || waitlistEntries.length > 0
if (!hasAnyEntry && !query) {
return (
<div className="rounded-lg bg-primary-soft/50 px-4 py-10 text-center">
<Inbox className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">No hay pendientes</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Las pre-inscripciones que lleguen por el enlace compartido y las personas en lista de
espera aparecerán aquí para que las revises.
</p>
<div className="mt-4 flex justify-center">
<Button variant="primary" onClick={openInviteModal} className="w-full sm:w-auto">
<Share2 className="size-4" />
Compartir Enlace
</Button>
</div>
</div>
)
}
if (filteredPrereg.length === 0 && filteredWaitlist.length === 0) {
return (
<div className="py-8 text-center text-sm text-foreground/80">
No se encontraron pendientes que coincidan con la búsqueda.
</div>
)
}
const sections = [
{
key: 'preregistrations',
title: 'Pre-inscripciones',
icon: UserCheck,
attention: true,
count: filteredPrereg.length,
emptyNote: 'Sin pre-inscripciones pendientes.',
table: <PreRegistrationsTable entries={filteredPrereg} />,
},
{
key: 'waitlist',
title: 'Lista de espera',
icon: Clock,
attention: false,
count: filteredWaitlist.length,
emptyNote: 'Sin nadie en la lista de espera.',
table: <WaitlistTable entries={filteredWaitlist} />,
},
]
return (
<div className="space-y-1">
{sections.map((section) => {
const Icon = section.icon
const hasRows = section.count > 0
// Con búsqueda activa, las secciones sin coincidencias se ocultan.
if (!hasRows && query) return null
return (
<section key={section.key}>
<div className="flex items-center gap-2 border-b border-border/70 px-3 pb-2 pt-3">
<Icon className="size-4 shrink-0 text-accent" />
<h3 className="text-xs font-semibold uppercase tracking-wide text-foreground/70">
{section.title}
</h3>
{hasRows ? (
<span
className={cn(
'ml-auto inline-flex items-center justify-center rounded-full px-1.5 py-0.5 text-[10px] font-bold leading-none tabular-nums',
section.attention
? 'bg-warning-soft text-warning'
: 'bg-primary-soft text-foreground/60',
)}
>
{section.count}
</span>
) : null}
</div>
{hasRows ? (
<div className="pt-1">{section.table}</div>
) : (
<p className="px-3 py-3 text-xs text-foreground/70">{section.emptyNote}</p>
)}
</section>
)
})}
</div>
)
}