feat(api): add timezone support for group fetching and increase page size

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
This commit is contained in:
Jose Selesan
2026-09-30 17:39:13 -03:00
parent 4e86096653
commit 454f20ed25
31 changed files with 1323 additions and 250 deletions

View File

@@ -1,82 +1,93 @@
import type { GroupDto, GroupRiskLevel } from '@gruperly/shared'
import { useNavigate } from '@tanstack/react-router'
import { CalendarClock, Users } from 'lucide-react'
import { Badge, Button, Tooltip } from '../../components/ui'
import { BILLING_LABELS, formatPrice, formatSchedule } from '../../lib/format'
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 { RISK_HINT, RISK_LABELS } from './constants'
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,
riskLevel,
risk,
}: {
group: GroupDto
riskLevel: GroupRiskLevel
group: GroupListItem
risk: GroupRiskSummary | undefined
}) {
const navigate = useNavigate()
const hasSchedule = (group.days?.length ?? 0) > 0
const hasRisk = riskLevel === 'HIGH' || riskLevel === 'MEDIUM'
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 (
<article className="rounded-xl border border-border bg-surface p-5 transition-all hover:border-accent/40">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<h3 className="truncate text-base font-semibold text-primary">{group.name}</h3>
{group.description ? (
<p className="mt-0.5 truncate text-sm text-foreground/60">{group.description}</p>
) : null}
</div>
<div className="flex flex-col items-end gap-1.5">
{hasRisk ? (
// Mismo tooltip que en el detalle: el badge es corto y la
// explicación (abandono, no cobranza) la da el tooltip.
<Tooltip content={RISK_HINT} tooltipClassName="left-auto right-0">
<Badge variant={riskLevel === 'HIGH' ? 'danger' : 'warning'} className="gap-1.5">
<span
className={cn(
'size-2 rounded-full',
riskLevel === 'HIGH' ? 'bg-danger' : 'bg-warning',
)}
aria-hidden="true"
/>
{RISK_LABELS[riskLevel]}
</Badge>
</Tooltip>
) : null}
<Badge variant="success">Activo</Badge>
</div>
</div>
{hasSchedule ? (
<dl className="mt-4 space-y-2 text-sm">
<div className="flex items-center gap-2 text-foreground/70">
<CalendarClock className="size-4 shrink-0 text-accent" />
<span>{formatSchedule(group.days ?? [], group.time)}</span>
</div>
<div className="flex items-center gap-2 text-foreground/70">
<Users className="size-4 shrink-0 text-accent" />
<span>
Cupo {group.capacity ?? '—'} miembros
{group.price != null
? ` · ${formatPrice(group.price)}${group.billingType ? ` · ${BILLING_LABELS[group.billingType]}` : ''}`
: ''}
{group.dueDay != null ? ` · vence el día ${group.dueDay}` : ''}
</span>
</div>
</dl>
) : (
<p className="mt-4 text-sm text-foreground/50">Aún sin plan de cobro configurado.</p>
<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>
<div className="mt-4 flex items-center justify-end gap-2 border-t border-border pt-3">
<Button
variant="outline"
size="sm"
onClick={() => void navigate({ to: `/groups/${group.id}` })}
>
Gestionar Miembros
</Button>
{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>
</article>
</Link>
)
}
}