feat: app de alumnos sin contraseña (invitación de un solo uso, avisos de falta y pagos informados)
- Acceso del alumno o tutor con link de un solo uso (hash SHA-256, consumo atómico, el GET no consume), sesión propia de 90 días deslizante, passkeys opcionales (SimpleWebAuthn) y mail de recuperación con rate limit. - Lado alumno (/i/:token, /acceso, /alumno/*): inicio, clases, avisar falta, pagos, informar pago con comprobante (S3 privado, magic bytes) y perfil. - Lado profe: acceso a la app en la ficha del alumno (invitar/reinvitar), "Pagos para verificar" en Cobros con badge, faltas avisadas en la ficha de grupo y datos para transferir en Ajustes. - "Requiere atención" y el recordatorio de WhatsApp excluyen cuotas informadas. - Zona horaria por defecto: Buenos Aires. - Migración add_student_access, tests contra Postgres real (test:db) y docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
142
apps/web/src/features/student-app/NotifyAbsenceView.tsx
Normal file
142
apps/web/src/features/student-app/NotifyAbsenceView.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import { useState } from 'react'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import type { AbsenceReasonValue } from '@gruperly/shared'
|
||||
import { ArrowLeft, Loader2 } from 'lucide-react'
|
||||
import { Button, Label } from '../../components/ui'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { FlowDone } from './FlowDone'
|
||||
import { FlowFooter } from './FlowFooter'
|
||||
import { ABSENCE_REASON_LABELS, firstName, formatShortDate, formatTime } from './format'
|
||||
import { SelectableRow } from './SelectableRow'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
const REASONS = Object.keys(ABSENCE_REASON_LABELS) as AbsenceReasonValue[]
|
||||
|
||||
export function NotifyAbsenceView({ preselected }: { preselected?: string }) {
|
||||
const { student, classes, notifyAbsences } = useStudentApp()
|
||||
const [selected, setSelected] = useState<string[]>(preselected ? [preselected] : [])
|
||||
const [reason, setReason] = useState<AbsenceReasonValue | null>(null)
|
||||
const [message, setMessage] = useState('')
|
||||
|
||||
if (!student || !classes) {
|
||||
return (
|
||||
<div className="flex justify-center py-20" role="status" aria-label="Cargando">
|
||||
<Loader2 className="size-8 animate-spin text-accent" aria-hidden="true" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const teacher = firstName(student.teacherName)
|
||||
|
||||
if (notifyAbsences.isSuccess) {
|
||||
return (
|
||||
<FlowDone title={`Listo, le avisamos a ${teacher}`}>
|
||||
<p className="text-sm text-secondary">Si cambiás de idea, podés deshacerlo desde Clases mientras la clase no haya empezado.</p>
|
||||
<div className="space-y-2 pt-2">
|
||||
<Link to="/alumno" className="flex min-h-12 items-center justify-center rounded-xl bg-accent font-semibold text-on-accent hover:bg-accent-strong">
|
||||
Volver al inicio
|
||||
</Link>
|
||||
<Link to="/alumno/clases" className="flex min-h-12 items-center justify-center rounded-xl border border-border font-medium text-primary hover:bg-primary-soft">
|
||||
Ver mis clases
|
||||
</Link>
|
||||
</div>
|
||||
</FlowDone>
|
||||
)
|
||||
}
|
||||
|
||||
// Classes not started and not notified yet.
|
||||
const available = classes.classes.filter((item) => !item.started && !item.notice)
|
||||
const toggle = (startsAt: string) =>
|
||||
setSelected((current) => (current.includes(startsAt) ? current.filter((value) => value !== startsAt) : [...current, startsAt]))
|
||||
const count = selected.filter((value) => available.some((item) => item.startsAt === value)).length
|
||||
|
||||
const submit = () => {
|
||||
if (count === 0) return
|
||||
notifyAbsences.mutate({
|
||||
startsAt: selected.filter((value) => available.some((item) => item.startsAt === value)),
|
||||
reason,
|
||||
message: message.trim() || null,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Link to="/alumno" className="hidden items-center gap-1 text-sm text-secondary hover:text-primary lg:inline-flex">
|
||||
<ArrowLeft className="size-4" aria-hidden="true" />
|
||||
Volver
|
||||
</Link>
|
||||
<h1 className="text-2xl font-bold text-primary">Avisar que no voy</h1>
|
||||
|
||||
<section aria-labelledby="classes-label" className="space-y-2">
|
||||
<h2 id="classes-label" className="text-sm font-semibold text-primary">
|
||||
¿A qué clases no vas?
|
||||
</h2>
|
||||
{available.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-border px-4 py-6 text-center text-sm text-secondary">
|
||||
No hay clases para avisar.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{available.map((item) => (
|
||||
<SelectableRow key={item.startsAt} pressed={selected.includes(item.startsAt)} onToggle={() => toggle(item.startsAt)}>
|
||||
<span className="block text-sm font-medium capitalize text-primary">
|
||||
{formatShortDate(item.startsAt, classes.timeZone)} · {formatTime(item.startsAt, classes.timeZone)}
|
||||
</span>
|
||||
<span className="block truncate text-xs text-secondary">{item.groupName}</span>
|
||||
</SelectableRow>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="reason-label" className="space-y-2">
|
||||
<h2 id="reason-label" className="text-sm font-semibold text-primary">
|
||||
Motivo <span className="font-normal text-secondary">(opcional)</span>
|
||||
</h2>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{REASONS.map((value) => (
|
||||
<button
|
||||
key={value}
|
||||
type="button"
|
||||
aria-pressed={reason === value}
|
||||
onClick={() => setReason((current) => (current === value ? null : value))}
|
||||
className={cn(
|
||||
'min-h-11 rounded-full border px-4 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent',
|
||||
reason === value ? 'border-accent bg-accent-soft text-accent-fg' : 'border-border bg-surface text-primary hover:bg-primary-soft',
|
||||
)}
|
||||
>
|
||||
{ABSENCE_REASON_LABELS[value]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="absence-message">Mensaje para {teacher} (opcional)</Label>
|
||||
<textarea
|
||||
id="absence-message"
|
||||
value={message}
|
||||
onChange={(event) => setMessage(event.target.value)}
|
||||
maxLength={500}
|
||||
rows={3}
|
||||
className="w-full rounded-xl border border-border bg-surface px-3 py-2 text-base text-primary placeholder:text-foreground/50 focus:border-accent focus:outline-none focus:ring-2 focus:ring-accent/30 sm:text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-secondary">Si avisás antes de la clase, la falta queda como justificada.</p>
|
||||
|
||||
{notifyAbsences.isError ? (
|
||||
<p role="alert" className="text-sm text-danger-fg">
|
||||
No pudimos mandar el aviso. Si alguna clase ya empezó, sacala y probá de nuevo.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<FlowFooter>
|
||||
<Button variant="primary" className="h-12 w-full text-base" disabled={count === 0 || notifyAbsences.isPending} onClick={submit}>
|
||||
{notifyAbsences.isPending ? <Loader2 className="size-5 animate-spin" aria-hidden="true" /> : null}
|
||||
{count === 0 ? 'Elegí al menos una clase' : count === 1 ? 'Avisar 1 clase' : `Avisar ${count} clases`}
|
||||
</Button>
|
||||
</FlowFooter>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user