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:
@@ -0,0 +1,49 @@
|
||||
import type { Prisma } from '@generated/prisma/client';
|
||||
import type { ProblemDetails, ResolveAlert, Result } from '@gruperly/shared';
|
||||
import { err, ok } from '@gruperly/shared';
|
||||
import { notFoundResourceProblem } from '@/http/problem-builders';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { buildGroupWhereForUser } from '@/modules/groups/lib';
|
||||
import { ALERT_TYPE_TO_KIND } from '../../lib/alert-kind';
|
||||
|
||||
type ResolveAlertDeps = {
|
||||
db?: {
|
||||
attendee: Prisma.AttendeeDelegate;
|
||||
attendeeAlertResolution: Prisma.AttendeeAlertResolutionDelegate;
|
||||
};
|
||||
};
|
||||
|
||||
export type ResolveAlertResult = ResolveAlert & { attendeeId: string };
|
||||
|
||||
/* "Resuelto": stores the signature of the alert the professor saw. One row per
|
||||
attendee and type, overwritten on each resolve, so the table never grows past
|
||||
two rows per attendee. An attendee outside the user's groups is a 404, not a
|
||||
403: we don't confirm that the id exists. */
|
||||
export class ResolveStudentAlert {
|
||||
constructor(private readonly deps: ResolveAlertDeps = {}) {}
|
||||
|
||||
async execute(
|
||||
attendeeId: string,
|
||||
userId: string,
|
||||
payload: ResolveAlert,
|
||||
): Promise<Result<ResolveAlertResult, ProblemDetails>> {
|
||||
const db = this.deps.db ?? prisma;
|
||||
|
||||
const attendee = await db.attendee.findFirst({
|
||||
where: { id: attendeeId, group: buildGroupWhereForUser(userId) as Prisma.GroupWhereInput },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!attendee) {
|
||||
return err(notFoundResourceProblem('Attendee', attendeeId));
|
||||
}
|
||||
|
||||
const kind = ALERT_TYPE_TO_KIND[payload.tipo];
|
||||
await db.attendeeAlertResolution.upsert({
|
||||
where: { attendeeId_kind: { attendeeId, kind } },
|
||||
create: { attendeeId, kind, signature: payload.firma, resolvedById: userId },
|
||||
update: { signature: payload.firma, resolvedById: userId, resolvedAt: new Date() },
|
||||
});
|
||||
|
||||
return ok({ attendeeId, tipo: payload.tipo, firma: payload.firma });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user