refactor: remove unused attendee detail components and provider
This commit is contained in:
109
apps/web/src/features/groups/detail/MembersList.tsx
Normal file
109
apps/web/src/features/groups/detail/MembersList.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import type { AttendeeListItem, AttendanceStatus } from '@gruperly/shared'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { Check } from 'lucide-react'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { dotClass, statusLabel } from '../analytics/format'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
import {
|
||||
type PaymentState,
|
||||
paymentStateLabel,
|
||||
resolvePaymentState,
|
||||
summarizeAttendance,
|
||||
} from './member-row'
|
||||
|
||||
/* Solo lo excepcional se pinta. "Al día" queda en el tono base y con un check
|
||||
para que el estado se lea sin depender del color; vencido es el único que
|
||||
sube de peso. */
|
||||
const PAYMENT_TONE: Record<PaymentState['kind'], string> = {
|
||||
settled: 'text-foreground',
|
||||
dueSoon: 'font-medium text-warning',
|
||||
overdue: 'font-semibold text-danger',
|
||||
}
|
||||
|
||||
function PaymentLabel({ state }: { state: PaymentState }) {
|
||||
return (
|
||||
<span className={cn('flex shrink-0 items-center gap-1 text-xs', PAYMENT_TONE[state.kind])}>
|
||||
{state.kind === 'settled' ? (
|
||||
<Check className="size-3 shrink-0" aria-hidden="true" />
|
||||
) : null}
|
||||
{paymentStateLabel(state)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function AttendanceStrip({ recent }: { recent: AttendanceStatus[] }) {
|
||||
const summary = summarizeAttendance(recent)
|
||||
|
||||
if (summary.recorded === 0) {
|
||||
return <p className="mt-0.5 text-xs text-foreground">{summary.label}</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-0.5 flex items-center gap-2">
|
||||
{/* Cada punto lleva su propio nombre accesible: el color solo es el
|
||||
refuerzo visual, no la única forma de saber qué pasó. */}
|
||||
<span className="flex items-center gap-1">
|
||||
{summary.dots.map((status, index) => (
|
||||
<span
|
||||
key={index}
|
||||
role="img"
|
||||
aria-label={`Clase ${index + 1} de ${summary.recorded}: ${statusLabel(status).toLowerCase()}`}
|
||||
className={cn('size-2 rounded-full', dotClass(status))}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
<span className="text-xs text-foreground">{summary.label}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MemberRow({
|
||||
attendee,
|
||||
groupId,
|
||||
}: {
|
||||
attendee: AttendeeListItem
|
||||
groupId: string
|
||||
}) {
|
||||
const paymentState = resolvePaymentState(attendee.payment)
|
||||
|
||||
return (
|
||||
<Link
|
||||
to="/groups/$groupId/attendees/$attendeeId"
|
||||
params={{ groupId, attendeeId: attendee.id }}
|
||||
// `min-h-14` (56px) es el piso táctil cómodo. La fila entera es el link, así
|
||||
// que no hace falta chevron ni fila con tabIndex: hereda el rol y el
|
||||
// teclado del <a>, y además sirve el href real al abrir en otra pestaña.
|
||||
className={cn(
|
||||
'flex min-h-14 items-center border-b border-foreground/10 px-3 py-2.5',
|
||||
'transition-colors duration-150 hover:bg-surface/60 active:bg-surface',
|
||||
'focus-visible:bg-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent',
|
||||
)}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<span className="min-w-0 truncate font-medium text-primary" title={attendee.fullName}>
|
||||
{attendee.fullName}
|
||||
</span>
|
||||
{paymentState ? <PaymentLabel state={paymentState} /> : null}
|
||||
</div>
|
||||
<AttendanceStrip recent={attendee.recentAttendance} />
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export function MembersList({ attendees }: { attendees: AttendeeListItem[] }) {
|
||||
// El groupId se lee una vez y se pasa: suscribir cada fila al contexto entero
|
||||
// hace que un cambio de estado del provider re-renderice N filas sin motivo.
|
||||
const { groupId } = useGroupDetail()
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{attendees.map((attendee) => (
|
||||
<li key={attendee.id}>
|
||||
<MemberRow attendee={attendee} groupId={groupId} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user