- Translated comments from Spanish to English in vite.config.ts, docker-compose.yml, attendance-risk.ts, analytics.ts, attendance.ts, attendees.ts, enums.ts, groups.ts, and onboarding.ts. - Improved descriptions for better understanding of code functionality and purpose. - Ensured uniformity in terminology and phrasing throughout the codebase.
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
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'
|
|
|
|
/* Only the exceptional is painted. "Ok" stays in the base tone and with a check
|
|
so the state reads without depending on color; overdue is the only one that
|
|
gains weight. */
|
|
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">
|
|
{/* Every dot carries its own accessible name: color is only the visual
|
|
reinforcement, not the only way to know what happened. */}
|
|
<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) is the comfortable touch floor. The whole row is the
|
|
// link, so there is no need for a chevron or a row with tabIndex: it
|
|
// inherits the role and keyboard of the <a>, and it also serves the real
|
|
// href when opened in another tab.
|
|
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[] }) {
|
|
// groupId is read once and passed down: subscribing every row to the whole
|
|
// context makes a provider state change re-render N rows for no reason.
|
|
const { groupId } = useGroupDetail()
|
|
|
|
return (
|
|
<ul>
|
|
{attendees.map((attendee) => (
|
|
<li key={attendee.id}>
|
|
<MemberRow attendee={attendee} groupId={groupId} />
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|