- 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>
102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { CalendarPlus, Loader2, Plus } from 'lucide-react'
|
|
import { Button } from '../../components/ui'
|
|
import { getGroups } from '../../lib/api'
|
|
import { flaggedStudents } from '../attention/attention'
|
|
import { attentionQueryOptions } from '../attention/queries'
|
|
import { AttentionPreview } from './AttentionPreview'
|
|
import { GroupCard } from './GroupCard'
|
|
import { groupsSummary, membersOf } from './card'
|
|
import { NewGroupFab } from './NewGroupFab'
|
|
|
|
export function GroupsView() {
|
|
const navigate = useNavigate()
|
|
const groupsQuery = useQuery({
|
|
queryKey: ['groups'],
|
|
queryFn: getGroups,
|
|
})
|
|
const attentionQuery = useQuery(attentionQueryOptions)
|
|
|
|
const groups = groupsQuery.data?.data ?? []
|
|
const hasGroups = groupsQuery.isSuccess && groups.length > 0
|
|
|
|
return (
|
|
// The FAB floats over the last card: 88px of room so it can be read.
|
|
<section className="pb-[88px]">
|
|
<h1 className="text-2xl font-bold text-primary">Grupos</h1>
|
|
{hasGroups ? <p className="mt-1 text-sm text-secondary">{groupsSummary(groups)}</p> : null}
|
|
|
|
{groupsQuery.isPending ? (
|
|
<div className="mt-8 flex items-center justify-center py-16" role="status">
|
|
<Loader2 className="size-6 animate-spin text-secondary/50" aria-hidden="true" />
|
|
<span className="sr-only">Cargando grupos</span>
|
|
</div>
|
|
) : null}
|
|
|
|
{groupsQuery.isError ? (
|
|
<div className="mt-8 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
|
<p>No pudimos cargar tus grupos.</p>
|
|
<Button variant="outline" size="sm" onClick={() => void groupsQuery.refetch()}>
|
|
Reintentar
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
|
|
{groupsQuery.isSuccess && groups.length === 0 ? (
|
|
/* A single icon, one focal point, and the text in secondary: the empty
|
|
state competes with the action and must not win. */
|
|
<div className="mt-8 rounded-xl bg-primary-soft px-5 py-12 text-center">
|
|
<span className="mx-auto flex size-14 items-center justify-center rounded-2xl bg-accent-soft text-accent-fg">
|
|
<CalendarPlus className="size-7" aria-hidden="true" />
|
|
</span>
|
|
<p className="mt-4 text-base font-semibold text-primary">Todavía no tenés grupos</p>
|
|
<p className="mx-auto mt-1.5 max-w-[30ch] text-sm leading-relaxed text-secondary">
|
|
Creá tu primer grupo y empezá a cobrar las cuotas de tus alumnos.
|
|
</p>
|
|
<Button
|
|
variant="primary"
|
|
className="mt-6 h-11"
|
|
onClick={() => void navigate({ to: '/groups/new' })}
|
|
>
|
|
<Plus className="size-4" />
|
|
Crear primer grupo
|
|
</Button>
|
|
</div>
|
|
) : null}
|
|
|
|
{hasGroups ? (
|
|
<>
|
|
<AttentionPreview students={flaggedStudents(attentionQuery.data)} />
|
|
|
|
<section aria-labelledby="my-groups-title" className="mt-6">
|
|
<h2
|
|
id="my-groups-title"
|
|
className="text-xs font-semibold tracking-wider text-secondary uppercase"
|
|
>
|
|
Mis grupos
|
|
</h2>
|
|
<div className="mt-2 grid gap-3 lg:grid-cols-2">
|
|
{groups.map((group) => (
|
|
<GroupCard
|
|
key={group.id}
|
|
group={group}
|
|
members={
|
|
attentionQuery.isSuccess
|
|
? (membersOf(attentionQuery.data.groups, group.id) ?? [])
|
|
: attentionQuery.isError
|
|
? null
|
|
: undefined
|
|
}
|
|
/>
|
|
))}
|
|
</div>
|
|
</section>
|
|
</>
|
|
) : null}
|
|
|
|
<NewGroupFab />
|
|
</section>
|
|
)
|
|
}
|