- 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>
134 lines
5.3 KiB
TypeScript
134 lines
5.3 KiB
TypeScript
import { useState } from 'react'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { ArrowLeft, Info, Loader2 } from 'lucide-react'
|
|
import { Button } from '../../components/ui'
|
|
import { ApiError } from '../../lib/api'
|
|
import { formatPrice } from '../../lib/format'
|
|
import { FeeStatusBadge } from './FeeStatusBadge'
|
|
import { FlowDone } from './FlowDone'
|
|
import { FlowFooter } from './FlowFooter'
|
|
import { feeLabel, firstName, formatDueDate } from './format'
|
|
import { ReceiptDropzone } from './ReceiptDropzone'
|
|
import { SelectableRow } from './SelectableRow'
|
|
import { useStudentApp } from './StudentAppProvider'
|
|
import { TransferDetailsCard } from './TransferDetailsCard'
|
|
|
|
export function ReportPaymentView() {
|
|
const { student, fees, reportPayment } = useStudentApp()
|
|
const [selected, setSelected] = useState<string[] | null>(null)
|
|
const [file, setFile] = useState<File | null>(null)
|
|
|
|
if (!student || !fees) {
|
|
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 (reportPayment.isSuccess) {
|
|
return (
|
|
<FlowDone title="Pago informado">
|
|
<p className="text-sm text-secondary">
|
|
{teacher} va a revisar el comprobante. Te avisamos acá cuando lo confirme.
|
|
</p>
|
|
<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>
|
|
</FlowDone>
|
|
)
|
|
}
|
|
|
|
const reportable = fees.fees.filter((fee) => fee.status !== 'reported')
|
|
// Default: every fee pending or overdue, the common case of "pay what I owe".
|
|
const chosen = selected ?? reportable.map((fee) => fee.id)
|
|
const total = reportable.filter((fee) => chosen.includes(fee.id)).reduce((sum, fee) => sum + fee.amount, 0)
|
|
const currency = reportable[0]?.currency
|
|
const toggle = (id: string) =>
|
|
setSelected(chosen.includes(id) ? chosen.filter((value) => value !== id) : [...chosen, id])
|
|
|
|
const submit = () => {
|
|
if (chosen.length === 0 || !file) return
|
|
reportPayment.mutate({ paymentIds: chosen, file })
|
|
}
|
|
|
|
const errorText =
|
|
reportPayment.error instanceof ApiError && reportPayment.error.status === 409
|
|
? 'Ya informaste alguna de estas cuotas.'
|
|
: reportPayment.error instanceof ApiError && reportPayment.error.status === 400
|
|
? reportPayment.error.problem?.detail ?? 'Revisá el comprobante.'
|
|
: 'No pudimos enviar el pago. Probá de nuevo.'
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<Link to="/alumno/pagos" 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">Informar pago</h1>
|
|
|
|
<section aria-labelledby="fees-label" className="space-y-2">
|
|
<h2 id="fees-label" className="text-sm font-semibold text-primary">
|
|
¿Qué cuotas pagaste?
|
|
</h2>
|
|
{reportable.length === 0 ? (
|
|
<p className="rounded-xl border border-dashed border-border px-4 py-6 text-center text-sm text-secondary">
|
|
No tenés cuotas para informar.
|
|
</p>
|
|
) : (
|
|
<div className="space-y-2">
|
|
{reportable.map((fee) => (
|
|
<SelectableRow
|
|
key={fee.id}
|
|
pressed={chosen.includes(fee.id)}
|
|
onToggle={() => toggle(fee.id)}
|
|
trailing={<span className="shrink-0 text-sm font-semibold text-primary">{formatPrice(fee.amount, fee.currency)}</span>}
|
|
>
|
|
<span className="block text-sm font-medium text-primary">{feeLabel(fee)}</span>
|
|
<span className="mt-1 flex items-center gap-2 text-xs text-secondary">
|
|
<FeeStatusBadge status={fee.status} />
|
|
Vence {formatDueDate(fee.dueDate)}
|
|
</span>
|
|
</SelectableRow>
|
|
))}
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
{fees.transfer ? <TransferDetailsCard transfer={fees.transfer} /> : null}
|
|
|
|
<section aria-labelledby="receipt-label" className="space-y-2">
|
|
<h2 id="receipt-label" className="text-sm font-semibold text-primary">
|
|
Comprobante
|
|
</h2>
|
|
<ReceiptDropzone file={file} onChange={setFile} />
|
|
</section>
|
|
|
|
<p className="flex gap-2 text-xs text-secondary">
|
|
<Info className="mt-0.5 size-4 shrink-0" aria-hidden="true" />
|
|
{teacher} va a confirmar el pago. Mientras tanto figura como Informado.
|
|
</p>
|
|
|
|
{reportPayment.isError ? (
|
|
<p role="alert" className="text-sm text-danger-fg">
|
|
{errorText}
|
|
</p>
|
|
) : null}
|
|
|
|
<FlowFooter>
|
|
<Button
|
|
variant="primary"
|
|
className="h-12 w-full text-base"
|
|
disabled={chosen.length === 0 || !file || reportPayment.isPending}
|
|
onClick={submit}
|
|
>
|
|
{reportPayment.isPending ? <Loader2 className="size-5 animate-spin" aria-hidden="true" /> : null}
|
|
{chosen.length === 0 ? 'Elegí al menos una cuota' : !file ? 'Adjuntá el comprobante' : `Enviar · ${formatPrice(total, currency)}`}
|
|
</Button>
|
|
</FlowFooter>
|
|
</div>
|
|
)
|
|
}
|