feat: rediseño de Grupos y pantalla "Requiere atención"
- Grupos: subtítulo con resumen (grupos · alumnos · lugares libres), sección "Requiere atención" con los 4 alumnos más urgentes y tarjetas con avatares (punteados por lugar libre en grupos chicos, superpuestos con "+N" en grandes; con alerta primero y anillo de gravedad). - Pantalla nueva /groups/attention: filtros Todos/Asistencia/Pagos, secciones Urgente y A vigilar, Contactar / Enviar recordatorio por wa.me y "Resuelto" persistente con update optimista. - FAB "Nuevo grupo" que se pliega al scrollear (respeta reduced motion); los toasts en mobile suben para no quedar debajo. - Alertas centralizadas en computeStudentAlerts (shared). La regla de asistencia pasa a: urgente = 3 seguidas o 4 de las últimas 6; a vigilar = 2 de las últimas 4 (sin inactividad por días ni tendencia). Cuotas: 1 vencida vigilar, 2+ urgente. - Backend: GET /attention y POST /attention/:attendeeId/resolve; tabla attendee_alert_resolutions (la alerta vuelve si cambia la firma). - Tokens de gravedad para claro y oscuro; se quita el indicador de pills. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,103 +1,64 @@
|
||||
import type { GroupListItem, GroupRiskSummary } from '@gruperly/shared'
|
||||
import type { AttentionMember, GroupListItem } from '@gruperly/shared'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { TriangleAlert } from 'lucide-react'
|
||||
import { AttendanceCapacityIndicator } from './AttendanceCapacityIndicator'
|
||||
import {
|
||||
SEGMENTED_CAPACITY_MAX,
|
||||
alertTextFromMembers,
|
||||
capacityCountsFromMembers,
|
||||
membersFromGroupAndRisk,
|
||||
type GroupMember,
|
||||
} from './card'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { AvatarRow } from './AvatarRow'
|
||||
import { groupStatus, type GroupStatus } from './card'
|
||||
|
||||
const CARD_CLASS_NAME =
|
||||
'block rounded-2xl border border-border/80 bg-surface px-5 py-5 shadow-none transition-[border-color,background-color,transform] duration-150 ease-out hover:border-accent/35 hover:bg-primary-soft/35 focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:scale-[0.995] active:bg-primary-soft/55 sm:px-7'
|
||||
'block rounded-2xl border border-border/80 bg-surface px-4 py-4 transition-[border-color,background-color,transform] duration-150 ease-out hover:border-accent/35 focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none active:scale-[0.995] motion-reduce:transition-none motion-reduce:active:scale-100 sm:px-5'
|
||||
|
||||
export type GroupCardProps = {
|
||||
id?: string
|
||||
name?: string
|
||||
capacity?: number
|
||||
members?: GroupMember[]
|
||||
group?: GroupListItem
|
||||
risk?: GroupRiskSummary | undefined
|
||||
link?: boolean
|
||||
const STATUS_TONES: Record<NonNullable<GroupStatus>['tone'], string> = {
|
||||
urgente: 'text-alert-urgent-fg',
|
||||
vigilar: 'text-alert-watch-fg',
|
||||
free: 'text-free-fg',
|
||||
full: 'text-secondary',
|
||||
}
|
||||
|
||||
export function GroupCard({ link = true, ...props }: GroupCardProps) {
|
||||
const linkId = props.id ?? props.group?.id
|
||||
|
||||
if (link && linkId) {
|
||||
return (
|
||||
<Link
|
||||
to="/groups/$groupId"
|
||||
params={{ groupId: linkId }}
|
||||
className={CARD_CLASS_NAME}
|
||||
>
|
||||
<GroupCardContent {...props} />
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={CARD_CLASS_NAME}>
|
||||
<GroupCardContent {...props} />
|
||||
</div>
|
||||
)
|
||||
type GroupCardProps = {
|
||||
group: GroupListItem
|
||||
/** ACTIVE members with their alerts; `undefined` while they load, `null`
|
||||
* if they could not be loaded (the card keeps the occupancy). */
|
||||
members: AttentionMember[] | undefined | null
|
||||
}
|
||||
|
||||
export function GroupCardContent(props: GroupCardProps) {
|
||||
const name = props.name ?? props.group?.name ?? ''
|
||||
const members =
|
||||
props.members ??
|
||||
(props.group ? membersFromGroupAndRisk(props.group, props.risk) : [])
|
||||
const capacity =
|
||||
props.capacity ??
|
||||
props.group?.capacity ??
|
||||
props.group?.attendeesCount ??
|
||||
members.length
|
||||
|
||||
const counts = capacityCountsFromMembers(members, capacity)
|
||||
const alertText = alertTextFromMembers(members)
|
||||
const segmented = capacity <= SEGMENTED_CAPACITY_MAX
|
||||
export function GroupCard({ group, members }: GroupCardProps) {
|
||||
const status = members ? groupStatus(members, group.capacity, group.attendeesCount) : null
|
||||
const occupancy =
|
||||
group.capacity === null
|
||||
? `${group.attendeesCount} ${group.attendeesCount === 1 ? 'alumno' : 'alumnos'}`
|
||||
: `${group.attendeesCount} de ${group.capacity} lugares ocupados`
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3 className="min-w-0 text-xl leading-tight font-semibold tracking-tight text-primary sm:text-2xl">
|
||||
{name}
|
||||
</h3>
|
||||
|
||||
<div className="mt-5 flex min-w-0 items-center gap-3">
|
||||
<AttendanceCapacityIndicator
|
||||
counts={counts}
|
||||
capacity={capacity}
|
||||
segmented={segmented}
|
||||
places={true}
|
||||
/>
|
||||
|
||||
{/* The word "miembros" takes ~60px that the bar needs on a phone. On
|
||||
mobile only the "4/5" goes, which already reads on a capacity card
|
||||
and loses nothing: the indicator's `aria-label` still counts
|
||||
everything ("4 de 5 lugares ocupados: 2 en riesgo alto..."). */}
|
||||
<span className="shrink-0 whitespace-nowrap text-base tabular-nums text-secondary">
|
||||
{members.length}/{capacity}
|
||||
<span className="hidden sm:inline">
|
||||
{' '}
|
||||
{capacity === 1 ? 'miembro' : 'miembros'}
|
||||
</span>
|
||||
<Link
|
||||
to="/groups/$groupId"
|
||||
params={{ groupId: group.id }}
|
||||
aria-label={[group.name, occupancy, status?.text].filter(Boolean).join(', ')}
|
||||
className={CARD_CLASS_NAME}
|
||||
>
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<h3 className="min-w-0 truncate text-lg leading-tight font-semibold tracking-tight text-primary">
|
||||
{group.name}
|
||||
</h3>
|
||||
<span className="shrink-0 text-sm tabular-nums text-secondary">
|
||||
<span className="font-bold text-primary">{group.attendeesCount}</span>
|
||||
{group.capacity !== null ? ` / ${group.capacity}` : null}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{alertText ? (
|
||||
<p className="mt-3 flex min-w-0 items-center gap-2.5 text-sm leading-6 font-medium text-[#8B1A1A] dark:text-[#f87171]">
|
||||
<TriangleAlert
|
||||
className="size-4 shrink-0 text-[#8B1A1A] dark:text-[#f87171]"
|
||||
strokeWidth={2}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="min-w-0">{alertText}</span>
|
||||
</p>
|
||||
{members !== null ? (
|
||||
<div className="mt-3 flex min-h-8 items-center justify-between gap-3">
|
||||
{members ? (
|
||||
<AvatarRow members={members} capacity={group.capacity} occupied={group.attendeesCount} />
|
||||
) : (
|
||||
<span className="h-8 w-32 animate-pulse rounded-full bg-primary-soft motion-reduce:animate-none" />
|
||||
)}
|
||||
{status ? (
|
||||
<span className={cn('shrink-0 text-sm font-semibold whitespace-nowrap', STATUS_TONES[status.tone])}>
|
||||
{status.text}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user