Files
gruperly/apps/web/src/features/attendee-detail/AttendeeAttendanceSection.tsx
Jose Selesan faf949fc9b feat(attendee-detail): enhance attendee detail view with payment and notes sections
- Added payment presentation logic to display payment status and due dates.
- Introduced AttendeeNotesSection and AttendeePaymentsSection components for managing notes and payments.
- Implemented forms for editing contact information and notes with validation.
- Updated API to support attendee updates and added corresponding tests.
- Improved attendance summary logic to reflect all visible sessions.
- Enhanced UI with loading states and error handling for better user experience.
2026-10-01 18:41:55 -03:00

121 lines
3.6 KiB
TypeScript

import { useState } from 'react'
import type { AttendanceStatus } from '@gruperly/shared'
import { Check, ChevronDown, Loader2, Megaphone, Minus, X } from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import { Button } from '../../components/ui'
import { cn } from '../../lib/utils'
import {
attendanceStatusClass,
attendanceStatusLabel,
attendanceSummary,
formatSessionShortDate,
HISTORY_LIMIT,
HISTORY_PREVIEW,
visibleSessions,
type AttendanceSession,
} from './attendance'
import { Section } from './Section'
import { useAttendeeDetail } from './AttendeeDetailProvider'
const STATUS_ICONS: Record<AttendanceStatus | 'UNMARKED', LucideIcon> = {
PRESENT: Check,
ABSENT: X,
EXCUSED: Megaphone,
UNMARKED: Minus,
}
function iconFor(status: AttendanceSession['status']): LucideIcon {
return STATUS_ICONS[status ?? 'UNMARKED']
}
export function AttendeeAttendanceSection() {
const { history, historyPending, historyFailed } = useAttendeeDetail()
const [showAll, setShowAll] = useState(false)
if (historyPending) {
return (
<Section title="Asistencia" trailing="—">
<div className="flex items-center justify-center py-5">
<Loader2 className="size-5 animate-spin text-accent" />
</div>
</Section>
)
}
if (historyFailed) {
return (
<Section title="Asistencia">
<p className="py-3 text-sm text-foreground">
No pudimos cargar la asistencia de este miembro.
</p>
</Section>
)
}
const sessions = history?.sessions ?? []
if (sessions.length === 0) {
return (
<Section title="Asistencia">
<p className="py-3 text-sm text-foreground">
Todavía no hay clases registradas.
</p>
</Section>
)
}
const visible = visibleSessions(sessions, showAll)
const hasMore = sessions.length > HISTORY_PREVIEW
const isCapped = sessions.length >= HISTORY_LIMIT
const summary = attendanceSummary(visible)
return (
<Section title="Asistencia" trailing={summary.label}>
<ul className="divide-y divide-border/60">
{visible.map((session) => {
const Icon = iconFor(session.status)
return (
<li
key={session.classSessionId}
className="flex items-center justify-between gap-3 px-3 py-2"
>
<span className="truncate text-sm text-primary">
{formatSessionShortDate(session.startsAt)}
</span>
<span
className={cn(
'flex shrink-0 items-center gap-1.5 text-xs font-semibold',
attendanceStatusClass(session.status),
)}
>
<Icon className="size-3.5" aria-hidden="true" />
{attendanceStatusLabel(session.status)}
</span>
</li>
)
})}
</ul>
{showAll && isCapped ? (
<p className="px-3 pt-2 text-xs text-foreground">
El historial guarda las últimas {HISTORY_LIMIT} clases.
</p>
) : null}
{hasMore ? (
<div className="mt-1 flex justify-end">
<Button
variant="ghost"
onClick={() => setShowAll((value) => !value)}
aria-expanded={showAll}
className="h-11 gap-1 px-3 text-sm text-accent-fg hover:text-primary"
>
{showAll ? 'Ver menos' : `Ver todas (${sessions.length})`}
<ChevronDown className={cn('size-4 transition-transform', showAll && 'rotate-180')} />
</Button>
</div>
) : null}
</Section>
)
}