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

@@ -1,36 +1,12 @@
import { useNavigate } from '@tanstack/react-router'
import { Clock, Loader2, Plus, Search, Share2, UserCheck, Users } from 'lucide-react'
import { Button, Input } from '../../../components/ui'
import { Search } from 'lucide-react'
import { Input } from '../../../components/ui'
import { useGroupDetail } from './GroupDetailProvider'
import { MembersTable } from './MembersTable'
import { PreRegistrationsTable } from './PreRegistrationsTable'
import { MembersView } from './MembersView'
import { PendingView } from './PendingView'
import { SectionChips } from './SectionChips'
import { WaitlistTable } from './WaitlistTable'
export function MembersWaitlistSection() {
const {
groupId, attendees, attendeesPending,
waitlistEntries, waitlistPending,
preRegistrations, preRegistrationsPending,
listSection, setListSection, searchFilter, setSearchFilter, openInviteModal,
} = useGroupDetail()
const navigate = useNavigate()
const query = searchFilter.toLowerCase()
const filteredAttendees = attendees.filter(
(a) =>
a.fullName.toLowerCase().includes(query) ||
(a.phone && a.phone.includes(query)) ||
(a.email && a.email.toLowerCase().includes(query)),
)
const filteredPreRegistrations = preRegistrations.filter(
(p) =>
p.fullName.toLowerCase().includes(query) ||
p.phone.includes(query) ||
(p.email && p.email.toLowerCase().includes(query)),
)
const showSearch = listSection === 'members' || listSection === 'preregistrations'
const { listSection, searchFilter, setSearchFilter } = useGroupDetail()
return (
// Radios concéntricos: `rounded-2xl` (16px) con `p-2` (8px) deja a las
@@ -41,138 +17,27 @@ export function MembersWaitlistSection() {
<div className="flex flex-col gap-2.5 lg:flex-row lg:items-center lg:justify-between">
<SectionChips />
{showSearch ? (
<div className="relative w-full sm:w-72 lg:shrink-0">
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-foreground/70" />
<Input
placeholder="Buscar por nombre o teléfono..."
value={searchFilter}
onChange={(e) => setSearchFilter(e.target.value)}
aria-label="Buscar en el listado"
className="h-10 rounded-lg border-transparent pl-9 shadow-xs placeholder:text-foreground/80"
/>
</div>
) : null}
<div className="relative w-full sm:w-72 lg:shrink-0">
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-foreground/70" />
<Input
placeholder="Buscar por nombre o teléfono..."
value={searchFilter}
onChange={(e) => setSearchFilter(e.target.value)}
aria-label="Buscar en el listado"
className="h-10 rounded-lg border-transparent pl-9 shadow-xs placeholder:text-foreground/80"
/>
</div>
</div>
<p className="text-xs leading-relaxed text-foreground/80">
{listSection === 'members'
? 'Listado de todos los miembros incorporados al grupo.'
: listSection === 'preregistrations'
? 'Personas que se inscribieron a través del enlace compartido. Al aprobar, entran al grupo; si el grupo está lleno, pasan a la lista de espera.'
: 'Personas que esperan un cupo libre en el grupo. Al pasar a alguien al grupo, se crea automáticamente su registro como miembro.'}
: 'Pre-inscripciones que esperan tu aprobación y personas en lista de espera por un cupo libre.'}
</p>
</div>
<div className="rounded-lg bg-surface p-1 shadow-xs sm:p-2">
{listSection === 'members' ? (
<>
{attendeesPending ? (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
) : null}
{!attendeesPending && attendees.length === 0 ? (
<div className="rounded-lg bg-primary-soft/50 px-4 py-10 text-center">
<Users className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">
Todavía no hay miembros en este grupo
</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Puedes compartir el enlace de invitación único o agregar miembros de forma manual o
masiva.
</p>
<div className="mt-4 flex flex-col gap-2.5 sm:flex-row sm:items-center sm:justify-center sm:gap-3">
<Button variant="outline" onClick={openInviteModal} className="w-full sm:w-auto">
<Share2 className="size-4" />
Compartir Enlace
</Button>
<Button
variant="primary"
onClick={() =>
void navigate({ to: '/groups/$groupId/attendees/new', params: { groupId } })
}
className="w-full sm:w-auto"
>
<Plus className="size-4" />
Agregar Miembros
</Button>
</div>
</div>
) : null}
{attendees.length > 0 && filteredAttendees.length === 0 ? (
<div className="py-8 text-center text-sm text-foreground/80">
No se encontraron miembros que coincidan con la búsqueda.
</div>
) : null}
{filteredAttendees.length > 0 ? <MembersTable attendees={filteredAttendees} /> : null}
</>
) : null}
{listSection === 'preregistrations' ? (
<div className="space-y-4">
{preRegistrationsPending ? (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
) : null}
{!preRegistrationsPending && preRegistrations.length === 0 ? (
<div className="rounded-lg bg-primary-soft/50 px-4 py-10 text-center">
<UserCheck className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">
No hay pre-inscripciones pendientes
</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Cuando alguien se inscriba a través del enlace compartido, aparecerá aquí para que
revises y apruebes su lugar.
</p>
<div className="mt-4 flex justify-center">
<Button variant="outline" onClick={openInviteModal} className="w-full sm:w-auto">
<Share2 className="size-4" />
Compartir Enlace
</Button>
</div>
</div>
) : null}
{preRegistrations.length > 0 && filteredPreRegistrations.length === 0 ? (
<div className="py-8 text-center text-sm text-foreground/80">
No se encontraron pre-inscripciones que coincidan con la búsqueda.
</div>
) : null}
{filteredPreRegistrations.length > 0 ? (
<PreRegistrationsTable entries={filteredPreRegistrations} />
) : null}
</div>
) : null}
{listSection === 'waitlist' ? (
<div className="space-y-4">
{waitlistPending ? (
<div className="flex items-center justify-center py-12">
<Loader2 className="size-6 animate-spin text-accent" />
</div>
) : null}
{!waitlistPending && waitlistEntries.length === 0 ? (
<div className="rounded-lg bg-primary-soft/50 px-4 py-10 text-center">
<Clock className="mx-auto mb-2 size-10 text-foreground/40" />
<p className="text-sm font-semibold text-primary">No hay nadie en la lista de espera</p>
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
Cuando el grupo alcance su cupo, las personas podrán sumarse a la espera y podrás
pasarlas al grupo desde aquí.
</p>
</div>
) : null}
{waitlistEntries.length > 0 ? <WaitlistTable entries={waitlistEntries} /> : null}
</div>
) : null}
{listSection === 'members' ? <MembersView /> : <PendingView />}
</div>
</div>
)