feat: add attendance risk management features
- Export attendance risk related schemas and types from shared package. - Introduce new schemas for attendance risk levels and urgent member summaries. - Implement attendance risk calculation logic in the shared library. - Create tests for attendance risk calculations and group attendance summaries. - Add a new component for visualizing attendance capacity indicators in the web app.
This commit is contained in:
@@ -1,29 +1,27 @@
|
||||
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 { Check, Square } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { AttendanceBadge } from './AttendanceBadge'
|
||||
import { CapacityIndicator } from './CapacityIndicator'
|
||||
import { attendanceAlert, billingSuffix } from './card'
|
||||
import { Badge } from '../../components/ui'
|
||||
import { AttendanceCapacityIndicator, TONE_TEXT } from './AttendanceCapacityIndicator'
|
||||
import {
|
||||
barCapacity,
|
||||
capacityLabel,
|
||||
capacityCounts,
|
||||
hasProminentRisk,
|
||||
isSegmentedCapacity,
|
||||
occupancyLabel,
|
||||
riskTone,
|
||||
statusLine,
|
||||
} 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.
|
||||
/* La tarjeta es un resumen operativo, no una ficha: nombre y cupo ubican al
|
||||
grupo; el indicador y la ocupación cuentan cómo está; la última línea dice a
|
||||
quién mirar. Precio y horario siguen en el detalle y acá se omiten para que
|
||||
capacidad y asistencia sean lo primero que se escanea.
|
||||
|
||||
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. */
|
||||
Toda la superficie sigue siendo el enlace. El bloque central hace wrap para
|
||||
que, a 360px, la espera pueda bajar sin cortar la barra ni las cifras. */
|
||||
|
||||
export function GroupCard({
|
||||
group,
|
||||
@@ -32,61 +30,81 @@ export function GroupCard({
|
||||
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'
|
||||
const counts = capacityCounts(group, risk)
|
||||
const line = statusLine(group, risk)
|
||||
const tone = riskTone(counts)
|
||||
const waiting = group.waitlistCount
|
||||
const capacity = capacityLabel(group)
|
||||
// Sin cupo declarado la barra mide a la matrícula en vez de a los lugares: no
|
||||
// inventa ningún lugar libre, solo reparte a la gente por nivel.
|
||||
const bar = barCapacity(group)
|
||||
const segmented = isSegmentedCapacity(bar)
|
||||
// La tarjeta entera se tiñe solo cuando hay alguien en riesgo alto y el
|
||||
// problema abarca a media matrícula o más: antes de eso alcanza con la línea
|
||||
// de estado, y un borde en todas las tarjetas deja de significar nada. El
|
||||
// anillo va `inset` (no agrega borde ni cambia el alto) y al 40% porque un
|
||||
// trazo fuerte rompe el tono de la lista.
|
||||
const prominent = hasProminentRisk(counts, group.attendeesCount)
|
||||
|
||||
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',
|
||||
'block rounded-xl border border-border/80 bg-surface p-4 shadow-xs transition-[border-color,background-color,transform] duration-150 ease-out hover:border-accent/35 hover:bg-primary-soft/45 focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:scale-[0.995] active:bg-primary-soft/65 sm:p-5',
|
||||
prominent && '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">
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-4">
|
||||
<h3 className="min-w-0 text-lg font-semibold tracking-tight text-balance 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 className="min-w-14 text-left text-sm leading-[1.15] tabular-nums text-secondary">
|
||||
<span className="block">{capacity.value}</span>
|
||||
<span className="block">{capacity.unit}</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 className="col-span-2 mt-5 flex min-w-0 flex-wrap items-center gap-x-4 gap-y-2">
|
||||
{bar > 0 ? (
|
||||
<AttendanceCapacityIndicator
|
||||
counts={counts}
|
||||
capacity={bar}
|
||||
segmented={segmented}
|
||||
places={group.capacity !== null}
|
||||
className="shrink-0"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<span className="shrink-0 text-base tabular-nums text-secondary">
|
||||
{occupancyLabel(group)}
|
||||
</span>
|
||||
|
||||
{waiting > 0 ? (
|
||||
<Badge
|
||||
variant="neutral"
|
||||
className="border border-border/70 bg-surface/50 text-secondary"
|
||||
title={`${waiting} ${waiting === 1 ? 'persona' : 'personas'} en lista de espera`}
|
||||
>
|
||||
{waiting} en espera
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<p
|
||||
className={cn(
|
||||
'col-span-2 mt-4 flex min-w-0 items-center gap-3 text-sm font-medium',
|
||||
TONE_TEXT[tone],
|
||||
)}
|
||||
>
|
||||
{tone !== 'ok' ? (
|
||||
<Square className="size-4 shrink-0" strokeWidth={2} aria-hidden="true" />
|
||||
) : null}
|
||||
{tone === 'ok' && risk?.asistencia != null ? (
|
||||
<Check className="size-4 shrink-0" strokeWidth={2} aria-hidden="true" />
|
||||
) : null}
|
||||
<span className="min-w-0 truncate">{line.text}</span>
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user