refactor: remove unused attendee detail components and provider
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
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,
|
||||
attendanceSummaryLabel,
|
||||
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
|
||||
|
||||
return (
|
||||
<Section title="Asistencia" trailing={attendanceSummaryLabel(visible)}>
|
||||
<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 py-2.5">
|
||||
<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="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-2 text-sm text-accent hover:text-accent-strong"
|
||||
>
|
||||
{showAll ? 'Ver menos' : `Ver todas (${sessions.length})`}
|
||||
<ChevronDown className={cn('size-4 transition-transform', showAll && 'rotate-180')} />
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user