/acceso → /access, /alumno/* → /student/* (welcome, classes, payments, profile, notify-absence, report-payment). El link del mail de confirmación pasa a /access/email/:token. AGENTS.md documenta que los paths van en inglés. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
6.2 KiB
TypeScript
143 lines
6.2 KiB
TypeScript
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="/student" 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="/student/classes" 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="/student" 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>
|
|
)
|
|
}
|