feat(attendance): refactor attendance summary logic and update tests feat(analytics): extend GroupRiskSummary schema with absence and attendance counts feat(groups): enhance group schema with attendee and waitlist counts chore(skills): add frontend design skill with guidelines and license feat(attendee-detail): implement AttendeePhoneLine component for phone display feat(groups): create AttendanceBadge and CapacityIndicator components for group cards feat(groups): add card utility functions for attendance alerts and capacity summaries test(groups): implement tests for attendance alert and capacity summary logic
94 lines
3.9 KiB
TypeScript
94 lines
3.9 KiB
TypeScript
import type { GroupListItem, GroupRiskSummary } from '@gruperly/shared'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { CalendarClock, ChevronRight } from 'lucide-react'
|
|
import { formatPrice, formatSchedule } from '../../lib/format'
|
|
import { cn } from '../../lib/utils'
|
|
import { AttendanceBadge } from './AttendanceBadge'
|
|
import { CapacityIndicator } from './CapacityIndicator'
|
|
import { attendanceAlert, billingSuffix } from './card'
|
|
|
|
/* Toda la card es el link al grupo: nombre, horario y cupo quedan dentro, así
|
|
que el nombre accesible del enlace ya los anuncia y no hace falta un
|
|
aria-label aparte. La superficie va rellena (la misma `primary-soft` que la
|
|
ficha del grupo) porque el borde fino sobre el fondo se perdía en tema
|
|
oscuro.
|
|
|
|
El borde derecho es un riel rígido de tres pistas —`1fr · auto · 1rem`— en
|
|
vez de posiciones absolutas: el precio y la flecha comparten el mismo
|
|
track, así que su límite derecho es idéntico en todas las tarjetas sin
|
|
importar cuánto mida el nombre o el precio. El precio se alinea con la
|
|
primera línea (junto al nombre) y la flecha también, para que la fila se
|
|
lea como una sola cosa.
|
|
|
|
La fila de metadatos hace wrap: con cupo de dos dígitos, gente en espera y
|
|
la alerta, no entra en 360px y preferimos que el badge baje de línea antes
|
|
que recortar un número. El bloque de cupo va con `shrink-0` para que sea
|
|
siempre el último en caer. */
|
|
|
|
export function GroupCard({
|
|
group,
|
|
risk,
|
|
}: {
|
|
group: GroupListItem
|
|
risk: GroupRiskSummary | undefined
|
|
}) {
|
|
const days = group.days ?? []
|
|
const hasSchedule = days.length > 0
|
|
const hasPrice = group.price != null
|
|
const suffix = billingSuffix(group.billingType)
|
|
const alert = attendanceAlert(risk, group.attendeesCount)
|
|
// La misma regla que usa el badge para el color: cuando media matrícula o
|
|
// más está atrasada, la tarjeta entera se marca. El anillo va `inset` (no
|
|
// agrega borde ni cambia el alto) y al 40% porque un trazo fuerte rompe el
|
|
// tono de la lista — es refuerzo visual, el que se lee sin color es el
|
|
// badge, que ya pasa 4.5:1.
|
|
const severe = alert?.severity === 'high'
|
|
|
|
return (
|
|
<Link
|
|
to="/groups/$groupId"
|
|
params={{ groupId: group.id }}
|
|
className={cn(
|
|
'block rounded-xl bg-primary-soft p-4 transition-colors duration-150 ease-out hover:bg-accent-soft focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:bg-accent-soft/60',
|
|
severe && 'ring-1 ring-warning-strong/40 ring-inset',
|
|
)}
|
|
>
|
|
<div className="grid grid-cols-[minmax(0,1fr)_auto_1rem] items-start gap-x-2">
|
|
<h3 className="col-start-1 row-start-1 truncate text-base font-semibold text-primary">
|
|
{group.name}
|
|
</h3>
|
|
|
|
{hasPrice ? (
|
|
<p className="col-start-2 row-start-1 whitespace-nowrap text-base font-semibold tabular-nums text-primary">
|
|
{formatPrice(group.price)}
|
|
{suffix ? (
|
|
<span className="text-sm font-medium text-secondary">{suffix}</span>
|
|
) : null}
|
|
</p>
|
|
) : null}
|
|
|
|
<ChevronRight
|
|
className="col-start-3 row-start-1 mt-1 size-4 shrink-0 text-secondary/50"
|
|
aria-hidden="true"
|
|
/>
|
|
|
|
<p className="col-start-1 row-start-2 mt-1 flex min-w-0 items-center gap-2 text-sm text-secondary">
|
|
<CalendarClock className="size-4 shrink-0 text-accent-fg" aria-hidden="true" />
|
|
<span className="truncate">
|
|
{hasSchedule ? formatSchedule(days, group.time) : 'Sin horario definido'}
|
|
</span>
|
|
</p>
|
|
|
|
<div className="col-span-3 row-start-3 mt-2 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1.5">
|
|
<CapacityIndicator
|
|
attendeesCount={group.attendeesCount}
|
|
capacity={group.capacity}
|
|
waitlistCount={group.waitlistCount}
|
|
/>
|
|
{alert ? <AttendanceBadge alert={alert} /> : null}
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
)
|
|
}
|