133 lines
4.6 KiB
TypeScript
133 lines
4.6 KiB
TypeScript
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 (
|
|
// Full-bleed and with no radius of its own: the list wrapper's
|
|
// `overflow-hidden` clips it against the rounded silhouette. `surface` over
|
|
// `primary-soft` sinks the block; with the previous wash it camouflaged.
|
|
<div className="bg-surface 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="h-11 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
|
|
const titleId = `pending-${section.title.replace(/\s+/g, '-').toLowerCase()}`
|
|
// With the search on, sections with no matches are hidden.
|
|
if (!hasRows && query) return null
|
|
|
|
return (
|
|
<section key={section.key} aria-labelledby={titleId}>
|
|
<div className="flex items-center gap-2 border-b border-foreground/10 px-3 pb-1.5 pt-2">
|
|
<Icon className="size-4 shrink-0 text-accent" aria-hidden="true" />
|
|
<h3
|
|
id={titleId}
|
|
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-surface text-foreground/70',
|
|
)}
|
|
>
|
|
{section.count}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
|
|
{hasRows ? (
|
|
<div className="pt-0.5">{section.table}</div>
|
|
) : (
|
|
<p className="px-3 py-2 text-xs text-foreground/70">{section.emptyNote}</p>
|
|
)}
|
|
</section>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
}
|