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:
47
apps/web/src/features/student-app/FeeCard.tsx
Normal file
47
apps/web/src/features/student-app/FeeCard.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import type { StudentFee } from '@gruperly/shared'
|
||||
import { Receipt } from 'lucide-react'
|
||||
import { Badge } from '../../components/ui'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
import { feeLabel } from './format'
|
||||
import { FeeStatusBadge } from './FeeStatusBadge'
|
||||
|
||||
/* "Tu cuota": only while there is something unpaid. */
|
||||
export function FeeCard({ fees }: { fees: StudentFee[] }) {
|
||||
if (fees.length === 0) return null
|
||||
const first = fees[0] as StudentFee
|
||||
const toReport = fees.filter((fee) => fee.status !== 'reported')
|
||||
const total = toReport.reduce((sum, fee) => sum + fee.amount, 0)
|
||||
|
||||
return (
|
||||
<article className="rounded-2xl border border-border bg-surface p-5">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-secondary">Tu cuota</p>
|
||||
<h2 className="mt-1 truncate text-lg font-bold text-primary">
|
||||
{fees.length === 1 ? feeLabel(first) : `${fees.length} cuotas sin pagar`}
|
||||
</h2>
|
||||
<p className="mt-1 text-2xl font-bold text-primary">
|
||||
{formatPrice(toReport.length > 0 ? total : first.amount, first.currency)}
|
||||
</p>
|
||||
</div>
|
||||
{fees.length === 1 ? (
|
||||
<FeeStatusBadge status={first.status} />
|
||||
) : toReport.some((fee) => fee.status === 'overdue') ? (
|
||||
<Badge variant="warning">Hay vencidas</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
{toReport.length > 0 ? (
|
||||
<Link
|
||||
to="/alumno/informar-pago"
|
||||
className="mt-4 flex min-h-12 items-center justify-center gap-2 rounded-xl bg-accent font-semibold text-on-accent hover:bg-accent-strong"
|
||||
>
|
||||
<Receipt className="size-5" aria-hidden="true" />
|
||||
Informar pago
|
||||
</Link>
|
||||
) : (
|
||||
<p className="mt-3 text-sm text-secondary">Tu profe tiene que confirmar el pago que informaste.</p>
|
||||
)}
|
||||
</article>
|
||||
)
|
||||
}
|
||||
14
apps/web/src/features/student-app/FeeStatusBadge.tsx
Normal file
14
apps/web/src/features/student-app/FeeStatusBadge.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { StudentFeeStatus } from '@gruperly/shared'
|
||||
import { Badge } from '../../components/ui'
|
||||
|
||||
const LABELS: Record<StudentFeeStatus, string> = {
|
||||
pending: 'Pendiente',
|
||||
overdue: 'Vencida',
|
||||
reported: 'Informada',
|
||||
}
|
||||
|
||||
// Color always goes with the word: amber overdue, blue reported.
|
||||
export function FeeStatusBadge({ status }: { status: StudentFeeStatus }) {
|
||||
const variant = status === 'overdue' ? 'warning' : status === 'reported' ? 'info' : 'neutral'
|
||||
return <Badge variant={variant}>{LABELS[status]}</Badge>
|
||||
}
|
||||
14
apps/web/src/features/student-app/FlowDone.tsx
Normal file
14
apps/web/src/features/student-app/FlowDone.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { CheckCircle2 } from 'lucide-react'
|
||||
|
||||
export function FlowDone({ title, children }: { title: string; children?: ReactNode }) {
|
||||
return (
|
||||
<div role="status" className="space-y-4 py-10 text-center">
|
||||
<div className="mx-auto flex size-16 items-center justify-center rounded-full bg-success-soft text-success">
|
||||
<CheckCircle2 className="size-8" aria-hidden="true" />
|
||||
</div>
|
||||
<h1 className="text-2xl font-bold text-primary">{title}</h1>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
10
apps/web/src/features/student-app/FlowFooter.tsx
Normal file
10
apps/web/src/features/student-app/FlowFooter.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
/* Fixed action at the bottom of a flow screen, above the home indicator. */
|
||||
export function FlowFooter({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<div className="fixed inset-x-0 bottom-0 z-40 border-t border-border bg-surface/95 px-4 pt-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] backdrop-blur">
|
||||
<div className="mx-auto max-w-md">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
47
apps/web/src/features/student-app/NextClassCard.tsx
Normal file
47
apps/web/src/features/student-app/NextClassCard.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import type { StudentClass } from '@gruperly/shared'
|
||||
import { CalendarX2, Check } from 'lucide-react'
|
||||
import { dateParts, formatLongDate, formatRelativeDay, formatTime } from './format'
|
||||
|
||||
type NextClassCardProps = { item: StudentClass; timeZone: string }
|
||||
|
||||
/* "Próxima clase": the dark brand card is the one strong surface of the home.
|
||||
White on brand-night scores 15:1 in both themes. */
|
||||
export function NextClassCard({ item, timeZone }: NextClassCardProps) {
|
||||
const { day, month } = dateParts(item.startsAt, timeZone)
|
||||
|
||||
return (
|
||||
<article className="rounded-2xl bg-brand-night p-5 text-white shadow-sm">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-brand-celeste">
|
||||
Próxima clase · {formatRelativeDay(item.startsAt, timeZone)}
|
||||
</p>
|
||||
<div className="mt-3 flex items-center gap-4">
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="truncate text-xl font-bold">{item.groupName}</h2>
|
||||
<p className="mt-1 text-sm text-white/85">
|
||||
{formatLongDate(item.startsAt, timeZone)} · {formatTime(item.startsAt, timeZone)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex size-16 shrink-0 flex-col items-center justify-center rounded-xl bg-white/10" aria-hidden="true">
|
||||
<span className="text-2xl font-bold leading-none">{day}</span>
|
||||
<span className="mt-1 text-xs uppercase text-white/85">{month}</span>
|
||||
</div>
|
||||
</div>
|
||||
{item.notice ? (
|
||||
<p className="mt-4 flex min-h-11 items-center gap-2 rounded-xl bg-white/10 px-4 text-sm font-medium">
|
||||
<Check className="size-4" aria-hidden="true" />
|
||||
Avisaste que no vas
|
||||
</p>
|
||||
) : (
|
||||
<Link
|
||||
to="/alumno/avisar"
|
||||
search={{ clase: item.startsAt }}
|
||||
className="mt-4 flex min-h-12 items-center justify-center gap-2 rounded-xl bg-white font-semibold text-brand-night hover:bg-brand-cloud"
|
||||
>
|
||||
<CalendarX2 className="size-5" aria-hidden="true" />
|
||||
No voy a ir
|
||||
</Link>
|
||||
)}
|
||||
</article>
|
||||
)
|
||||
}
|
||||
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>
|
||||
)
|
||||
}
|
||||
65
apps/web/src/features/student-app/PasskeyCard.tsx
Normal file
65
apps/web/src/features/student-app/PasskeyCard.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useState } from 'react'
|
||||
import { CheckCircle2, Fingerprint, Loader2 } from 'lucide-react'
|
||||
import { Button } from '../../components/ui'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { isPasskeyCancel, supportsPasskeys } from '../student-access/passkeys'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* "Entrar con Face ID o huella". Not shown when the browser has no WebAuthn,
|
||||
unless there's already a passkey to remove. */
|
||||
export function PasskeyCard({ highlighted = false }: { highlighted?: boolean }) {
|
||||
const { me, activatePasskey, removePasskeys } = useStudentApp()
|
||||
const [failed, setFailed] = useState(false)
|
||||
const hasPasskey = me?.account.hasPasskey ?? false
|
||||
if (!supportsPasskeys() && !hasPasskey) return null
|
||||
|
||||
const activate = () => {
|
||||
setFailed(false)
|
||||
activatePasskey.mutate(undefined, {
|
||||
onError: (error) => {
|
||||
if (!isPasskeyCancel(error)) setFailed(true)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<section
|
||||
aria-labelledby="passkey-title"
|
||||
className={cn('rounded-2xl border p-5', highlighted ? 'border-accent bg-accent-soft' : 'border-border bg-surface')}
|
||||
>
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-surface text-accent-fg" aria-hidden="true">
|
||||
{hasPasskey ? <CheckCircle2 className="size-6 text-success" /> : <Fingerprint className="size-6" />}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 id="passkey-title" className="text-base font-bold text-primary">
|
||||
{hasPasskey ? 'Face ID activado' : 'Entrar con Face ID o huella'}
|
||||
</h2>
|
||||
<p className="mt-1 text-sm text-secondary">
|
||||
{hasPasskey
|
||||
? 'Si se cierra tu sesión, entrás con tu cara o tu huella, sin pedirle un link a tu profe.'
|
||||
: 'Si se cierra tu sesión o cambiás de navegador, vas a poder volver a entrar sin pedirle un link a tu profe.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{failed ? (
|
||||
<p role="alert" className="mt-3 text-sm text-danger-fg">
|
||||
No pudimos activarlo en este teléfono.
|
||||
</p>
|
||||
) : null}
|
||||
<div className="mt-4">
|
||||
{hasPasskey ? (
|
||||
<Button variant="outline" className="h-11 w-full" onClick={() => removePasskeys.mutate()} disabled={removePasskeys.isPending}>
|
||||
{removePasskeys.isPending ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : null}
|
||||
Quitar Face ID o huella
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="primary" className="h-11 w-full" onClick={activate} disabled={activatePasskey.isPending}>
|
||||
{activatePasskey.isPending ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : null}
|
||||
Activar
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
33
apps/web/src/features/student-app/PaymentReviewBanner.tsx
Normal file
33
apps/web/src/features/student-app/PaymentReviewBanner.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { StudentPaymentReport } from '@gruperly/shared'
|
||||
import { CheckCircle2, XCircle } from 'lucide-react'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
|
||||
const RECENT_MS = 7 * 24 * 60 * 60 * 1000
|
||||
|
||||
/* In-app notice of the teacher's review: the latest report reviewed in the
|
||||
last week (the student is also emailed if they confirmed a recovery email). */
|
||||
export function PaymentReviewBanner({ reports }: { reports: StudentPaymentReport[] }) {
|
||||
const latest = reports.find(
|
||||
(report) => report.status !== 'reported' && report.reviewedAt && Date.now() - Date.parse(report.reviewedAt) < RECENT_MS,
|
||||
)
|
||||
if (!latest) return null
|
||||
const amount = formatPrice(latest.totalAmount, latest.currency)
|
||||
|
||||
if (latest.status === 'confirmed') {
|
||||
return (
|
||||
<p role="status" className="flex gap-3 rounded-2xl bg-success-soft px-4 py-3 text-sm text-primary">
|
||||
<CheckCircle2 className="size-5 shrink-0 text-success" aria-hidden="true" />
|
||||
<span>Tu profe confirmó tu pago de {amount}.</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<p role="status" className="flex gap-3 rounded-2xl bg-danger-soft px-4 py-3 text-sm text-primary">
|
||||
<XCircle className="size-5 shrink-0 text-danger-fg" aria-hidden="true" />
|
||||
<span>
|
||||
Tu profe no pudo confirmar tu pago de {amount}.
|
||||
{latest.rejectionReason ? ` Motivo: ${latest.rejectionReason}.` : ''} Podés volver a informarlo.
|
||||
</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
93
apps/web/src/features/student-app/ReceiptDropzone.tsx
Normal file
93
apps/web/src/features/student-app/ReceiptDropzone.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import { useEffect, useId, useMemo, useState } from 'react'
|
||||
import { FileText, Paperclip, X } from 'lucide-react'
|
||||
import { RECEIPT_ACCEPT, RECEIPT_MAX_MB } from '@gruperly/shared'
|
||||
import { formatFileSize } from './format'
|
||||
|
||||
const ACCEPTED = new Set(RECEIPT_ACCEPT.split(','))
|
||||
// Safari's HEIC can't be previewed by other browsers: those show the file icon.
|
||||
const PREVIEWABLE = new Set(['image/jpeg', 'image/png', 'image/webp'])
|
||||
|
||||
type ReceiptDropzoneProps = {
|
||||
file: File | null
|
||||
onChange: (file: File | null) => void
|
||||
}
|
||||
|
||||
/* Attachment zone. The browser checks are only for a quick message: the API
|
||||
validates the real type (magic bytes) and size again. */
|
||||
export function ReceiptDropzone({ file, onChange }: ReceiptDropzoneProps) {
|
||||
const inputId = useId()
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const preview = useMemo(() => (file && PREVIEWABLE.has(file.type) ? URL.createObjectURL(file) : null), [file])
|
||||
|
||||
useEffect(() => () => {
|
||||
if (preview) URL.revokeObjectURL(preview)
|
||||
}, [preview])
|
||||
|
||||
const handleFile = (next: File | undefined) => {
|
||||
if (!next) return
|
||||
if (next.size > RECEIPT_MAX_MB * 1024 * 1024) {
|
||||
setError(`El archivo pesa más de ${RECEIPT_MAX_MB} MB.`)
|
||||
return
|
||||
}
|
||||
if (next.type && !ACCEPTED.has(next.type)) {
|
||||
setError('Tiene que ser una captura (JPG, PNG, WEBP, HEIC) o un PDF.')
|
||||
return
|
||||
}
|
||||
setError(null)
|
||||
onChange(next)
|
||||
}
|
||||
|
||||
if (file) {
|
||||
return (
|
||||
<div className="flex items-center gap-3 rounded-2xl border border-border bg-surface p-3">
|
||||
<div className="flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-primary-soft">
|
||||
{preview ? (
|
||||
<img src={preview} alt="" className="size-full object-cover" />
|
||||
) : (
|
||||
<FileText className="size-6 text-foreground" aria-hidden="true" />
|
||||
)}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium text-primary">{file.name}</p>
|
||||
<p className="text-xs text-secondary">{formatFileSize(file.size)}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(null)}
|
||||
aria-label="Quitar comprobante"
|
||||
className="flex size-11 shrink-0 items-center justify-center rounded-xl text-foreground hover:bg-primary-soft hover:text-primary"
|
||||
>
|
||||
<X className="size-5" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label
|
||||
htmlFor={inputId}
|
||||
className="flex min-h-28 cursor-pointer flex-col items-center justify-center gap-2 rounded-2xl border-2 border-dashed border-border bg-surface px-4 py-6 text-center hover:border-accent focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/30"
|
||||
>
|
||||
<Paperclip className="size-6 text-accent-fg" aria-hidden="true" />
|
||||
<span className="text-sm font-semibold text-primary">Adjuntar captura o PDF</span>
|
||||
<span className="text-xs text-secondary">Hasta {RECEIPT_MAX_MB} MB</span>
|
||||
<input
|
||||
id={inputId}
|
||||
type="file"
|
||||
accept={RECEIPT_ACCEPT}
|
||||
className="sr-only"
|
||||
onChange={(event) => {
|
||||
handleFile(event.target.files?.[0])
|
||||
event.target.value = ''
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
{error ? (
|
||||
<p role="alert" className="text-sm text-danger-fg">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
98
apps/web/src/features/student-app/RecoveryEmailCard.tsx
Normal file
98
apps/web/src/features/student-app/RecoveryEmailCard.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import { useState, type FormEvent } from 'react'
|
||||
import { Loader2, Mail } from 'lucide-react'
|
||||
import { Button, Input, Label } from '../../components/ui'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* Optional recovery email (Perfil). Saving it sends a confirmation link: until
|
||||
it's confirmed it doesn't recover anything. */
|
||||
export function RecoveryEmailCard() {
|
||||
const { me, saveRecoveryEmail, removeRecoveryEmail } = useStudentApp()
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [email, setEmail] = useState('')
|
||||
const current = me?.account.recoveryEmail ?? null
|
||||
const pending = me?.account.pendingRecoveryEmail ?? null
|
||||
const showForm = editing || (!current && !pending)
|
||||
|
||||
const submit = (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
if (!email.trim()) return
|
||||
saveRecoveryEmail.mutate(email.trim(), {
|
||||
onSuccess: () => {
|
||||
setEditing(false)
|
||||
setEmail('')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<section aria-labelledby="recovery-title" className="rounded-2xl border border-border bg-surface p-5">
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary-soft text-primary" aria-hidden="true">
|
||||
<Mail className="size-5" />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 id="recovery-title" className="text-base font-bold text-primary">
|
||||
Mail de recuperación <span className="font-normal text-secondary">(opcional)</span>
|
||||
</h2>
|
||||
{current ? (
|
||||
<p className="mt-1 truncate text-sm text-secondary">
|
||||
Confirmado: <span className="font-medium text-primary">{current}</span>
|
||||
</p>
|
||||
) : null}
|
||||
{pending ? (
|
||||
<p className="mt-1 text-sm text-secondary">
|
||||
Te mandamos un link a <span className="font-medium text-primary">{pending}</span> para confirmarlo.
|
||||
</p>
|
||||
) : null}
|
||||
{!current && !pending ? (
|
||||
<p className="mt-1 text-sm text-secondary">Para pedir un link de ingreso si perdés el acceso.</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showForm ? (
|
||||
<form onSubmit={submit} className="mt-4 space-y-3">
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="profile-recovery-email">Tu mail</Label>
|
||||
<Input
|
||||
id="profile-recovery-email"
|
||||
type="email"
|
||||
inputMode="email"
|
||||
autoComplete="email"
|
||||
autoFocus={editing}
|
||||
required
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
className="h-11"
|
||||
/>
|
||||
</div>
|
||||
{saveRecoveryEmail.isError ? (
|
||||
<p role="alert" className="text-sm text-danger-fg">
|
||||
No pudimos guardar el mail. Probá de nuevo en un rato.
|
||||
</p>
|
||||
) : null}
|
||||
<div className="flex gap-2">
|
||||
{editing ? (
|
||||
<Button variant="outline" className="h-11 flex-1" onClick={() => setEditing(false)}>
|
||||
Cancelar
|
||||
</Button>
|
||||
) : null}
|
||||
<Button type="submit" variant="primary" className="h-11 flex-1" disabled={saveRecoveryEmail.isPending}>
|
||||
{saveRecoveryEmail.isPending ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : null}
|
||||
Guardar
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<div className="mt-4 flex gap-2">
|
||||
<Button variant="outline" className="h-11 flex-1" onClick={() => setEditing(true)}>
|
||||
Cambiar
|
||||
</Button>
|
||||
<Button variant="ghost" className="h-11 flex-1" onClick={() => removeRecoveryEmail.mutate()} disabled={removeRecoveryEmail.isPending}>
|
||||
Quitar
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
133
apps/web/src/features/student-app/ReportPaymentView.tsx
Normal file
133
apps/web/src/features/student-app/ReportPaymentView.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
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>
|
||||
)
|
||||
}
|
||||
38
apps/web/src/features/student-app/SelectableRow.tsx
Normal file
38
apps/web/src/features/student-app/SelectableRow.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { Check } from 'lucide-react'
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
type SelectableRowProps = {
|
||||
pressed: boolean
|
||||
onToggle: () => void
|
||||
children: ReactNode
|
||||
trailing?: ReactNode
|
||||
}
|
||||
|
||||
/* Multiple choice as real toggle buttons (`aria-pressed`) with a visual
|
||||
checkbox: used for classes and fees. */
|
||||
export function SelectableRow({ pressed, onToggle, children, trailing }: SelectableRowProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={pressed}
|
||||
onClick={onToggle}
|
||||
className={cn(
|
||||
'flex min-h-16 w-full items-center gap-3 rounded-xl border px-4 py-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent',
|
||||
pressed ? 'border-accent bg-accent-soft' : 'border-border bg-surface hover:bg-primary-soft',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'flex size-6 shrink-0 items-center justify-center rounded-md border-2',
|
||||
pressed ? 'border-accent bg-accent text-on-accent' : 'border-foreground/50',
|
||||
)}
|
||||
>
|
||||
{pressed ? <Check className="size-4" strokeWidth={3} /> : null}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">{children}</span>
|
||||
{trailing}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
201
apps/web/src/features/student-app/StudentAppProvider.tsx
Normal file
201
apps/web/src/features/student-app/StudentAppProvider.tsx
Normal file
@@ -0,0 +1,201 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import type {
|
||||
CreateAbsenceNotices,
|
||||
StudentClassesDto,
|
||||
StudentFeesDto,
|
||||
StudentMe,
|
||||
StudentProfile,
|
||||
} from '@gruperly/shared'
|
||||
import {
|
||||
ApiError,
|
||||
cancelStudentAbsence,
|
||||
getStudentClasses,
|
||||
getStudentFees,
|
||||
getStudentMe,
|
||||
logoutStudent,
|
||||
markStudentWelcomed,
|
||||
notifyStudentAbsences,
|
||||
removeStudentPasskeys,
|
||||
removeStudentRecoveryEmail,
|
||||
reportStudentPayment,
|
||||
setStudentRecoveryEmail,
|
||||
} from '../../lib/api'
|
||||
import { registerPasskey } from '../student-access/passkeys'
|
||||
|
||||
const SELECTED_KEY = 'student-selected-attendee'
|
||||
const ME_KEY = ['student', 'me'] as const
|
||||
|
||||
function readSelected(): string | null {
|
||||
try {
|
||||
return localStorage.getItem(SELECTED_KEY)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
type StudentAppContextValue = {
|
||||
me: StudentMe | undefined
|
||||
mePending: boolean
|
||||
/** The selected attendee (a guardian may have several). */
|
||||
student: StudentProfile | null
|
||||
selectStudent: (attendeeId: string) => void
|
||||
classes: StudentClassesDto | undefined
|
||||
classesPending: boolean
|
||||
fees: StudentFeesDto | undefined
|
||||
feesPending: boolean
|
||||
notifyAbsences: ReturnType<typeof useNotifyAbsences>
|
||||
cancelAbsence: ReturnType<typeof useCancelAbsence>
|
||||
reportPayment: ReturnType<typeof useReportPayment>
|
||||
activatePasskey: ReturnType<typeof useMeMutation<void>>
|
||||
removePasskeys: ReturnType<typeof useMeMutation<void>>
|
||||
saveRecoveryEmail: ReturnType<typeof useMeMutation<string>>
|
||||
removeRecoveryEmail: ReturnType<typeof useMeMutation<void>>
|
||||
finishWelcome: ReturnType<typeof useMeMutation<void>>
|
||||
logout: () => void
|
||||
loggingOut: boolean
|
||||
}
|
||||
|
||||
const StudentAppContext = createContext<StudentAppContextValue | null>(null)
|
||||
|
||||
function useMeMutation<TInput>(fn: (input: TInput) => Promise<StudentMe>) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: fn,
|
||||
onSuccess: (me) => queryClient.setQueryData(ME_KEY, me),
|
||||
})
|
||||
}
|
||||
|
||||
function useNotifyAbsences(attendeeId: string | null) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (input: Omit<CreateAbsenceNotices, 'attendeeId'>) =>
|
||||
notifyStudentAbsences({ ...input, attendeeId: attendeeId ?? '' }),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['student', 'classes', attendeeId] }),
|
||||
})
|
||||
}
|
||||
|
||||
function useCancelAbsence(attendeeId: string | null) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: cancelStudentAbsence,
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['student', 'classes', attendeeId] }),
|
||||
})
|
||||
}
|
||||
|
||||
function useReportPayment(attendeeId: string | null) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (input: { paymentIds: string[]; file: File }) =>
|
||||
reportStudentPayment({ ...input, attendeeId: attendeeId ?? '' }),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['student', 'fees', attendeeId] }),
|
||||
})
|
||||
}
|
||||
|
||||
/* State of the student app: the session ("me"), the selected attendee and its
|
||||
classes and fees. Without a session (401) it sends the student to /acceso. */
|
||||
export function StudentAppProvider({ children }: { children: ReactNode }) {
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
const [selectedId, setSelectedId] = useState<string | null>(readSelected)
|
||||
|
||||
const meQuery = useQuery({ queryKey: ME_KEY, queryFn: getStudentMe, retry: false, staleTime: 60_000 })
|
||||
|
||||
useEffect(() => {
|
||||
if (meQuery.error instanceof ApiError && meQuery.error.status === 401) {
|
||||
void navigate({ to: '/acceso', replace: true })
|
||||
}
|
||||
}, [meQuery.error, navigate])
|
||||
|
||||
const students = meQuery.data?.students ?? []
|
||||
const student = students.find((item) => item.attendeeId === selectedId) ?? students[0] ?? null
|
||||
const attendeeId = student?.attendeeId ?? null
|
||||
|
||||
const selectStudent = useCallback((id: string) => {
|
||||
setSelectedId(id)
|
||||
try {
|
||||
localStorage.setItem(SELECTED_KEY, id)
|
||||
} catch {
|
||||
// Private mode: the choice just isn't remembered.
|
||||
}
|
||||
}, [])
|
||||
|
||||
const classesQuery = useQuery({
|
||||
queryKey: ['student', 'classes', attendeeId],
|
||||
queryFn: () => getStudentClasses(attendeeId as string),
|
||||
enabled: attendeeId !== null,
|
||||
})
|
||||
const feesQuery = useQuery({
|
||||
queryKey: ['student', 'fees', attendeeId],
|
||||
queryFn: () => getStudentFees(attendeeId as string),
|
||||
enabled: attendeeId !== null,
|
||||
})
|
||||
|
||||
const notifyAbsences = useNotifyAbsences(attendeeId)
|
||||
const cancelAbsence = useCancelAbsence(attendeeId)
|
||||
const reportPayment = useReportPayment(attendeeId)
|
||||
const activatePasskey = useMeMutation<void>(() => registerPasskey())
|
||||
const removePasskeys = useMeMutation<void>(() => removeStudentPasskeys())
|
||||
const saveRecoveryEmail = useMeMutation<string>((email) => setStudentRecoveryEmail(email))
|
||||
const removeRecoveryEmail = useMeMutation<void>(() => removeStudentRecoveryEmail())
|
||||
const finishWelcome = useMeMutation<void>(() => markStudentWelcomed())
|
||||
|
||||
const logoutMutation = useMutation({
|
||||
mutationFn: logoutStudent,
|
||||
onSettled: async () => {
|
||||
queryClient.removeQueries({ queryKey: ['student'] })
|
||||
await navigate({ to: '/acceso', replace: true })
|
||||
},
|
||||
})
|
||||
|
||||
const value = useMemo<StudentAppContextValue>(
|
||||
() => ({
|
||||
me: meQuery.data,
|
||||
mePending: meQuery.isPending,
|
||||
student,
|
||||
selectStudent,
|
||||
classes: classesQuery.data,
|
||||
classesPending: classesQuery.isPending,
|
||||
fees: feesQuery.data,
|
||||
feesPending: feesQuery.isPending,
|
||||
notifyAbsences,
|
||||
cancelAbsence,
|
||||
reportPayment,
|
||||
activatePasskey,
|
||||
removePasskeys,
|
||||
saveRecoveryEmail,
|
||||
removeRecoveryEmail,
|
||||
finishWelcome,
|
||||
logout: () => logoutMutation.mutate(),
|
||||
loggingOut: logoutMutation.isPending,
|
||||
}),
|
||||
[
|
||||
meQuery.data,
|
||||
meQuery.isPending,
|
||||
student,
|
||||
selectStudent,
|
||||
classesQuery.data,
|
||||
classesQuery.isPending,
|
||||
feesQuery.data,
|
||||
feesQuery.isPending,
|
||||
notifyAbsences,
|
||||
cancelAbsence,
|
||||
reportPayment,
|
||||
activatePasskey,
|
||||
removePasskeys,
|
||||
saveRecoveryEmail,
|
||||
removeRecoveryEmail,
|
||||
finishWelcome,
|
||||
logoutMutation,
|
||||
],
|
||||
)
|
||||
|
||||
return <StudentAppContext.Provider value={value}>{children}</StudentAppContext.Provider>
|
||||
}
|
||||
|
||||
export function useStudentApp() {
|
||||
const context = useContext(StudentAppContext)
|
||||
if (!context) throw new Error('useStudentApp must be used within StudentAppProvider')
|
||||
return context
|
||||
}
|
||||
41
apps/web/src/features/student-app/StudentBottomNav.tsx
Normal file
41
apps/web/src/features/student-app/StudentBottomNav.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Link, useLocation } from '@tanstack/react-router'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { isStudentNavItemActive, STUDENT_NAV_ITEMS } from './student-nav-items'
|
||||
|
||||
export function StudentBottomNav() {
|
||||
const location = useLocation()
|
||||
|
||||
return (
|
||||
<nav
|
||||
aria-label="Secciones"
|
||||
className="fixed inset-x-0 bottom-0 z-40 border-t border-border bg-surface/95 pb-[env(safe-area-inset-bottom)] backdrop-blur"
|
||||
>
|
||||
<div className="mx-auto grid max-w-md grid-cols-4">
|
||||
{STUDENT_NAV_ITEMS.map(({ label, to, icon: Icon }) => {
|
||||
const isActive = isStudentNavItemActive(location.pathname, to)
|
||||
return (
|
||||
<Link
|
||||
key={to}
|
||||
to={to}
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
className={cn(
|
||||
'flex min-h-14 flex-col items-center justify-center gap-1 py-2 text-[11px] font-medium transition-colors',
|
||||
isActive ? 'text-accent-fg' : 'text-foreground/80 hover:text-primary',
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
'flex size-8 items-center justify-center rounded-lg transition-colors duration-150',
|
||||
isActive && 'bg-accent-soft',
|
||||
)}
|
||||
>
|
||||
<Icon className="size-5" strokeWidth={isActive ? 2.25 : 2} aria-hidden="true" />
|
||||
</span>
|
||||
<span className="leading-none">{label}</span>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
76
apps/web/src/features/student-app/StudentClassesView.tsx
Normal file
76
apps/web/src/features/student-app/StudentClassesView.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { CalendarX2, Loader2, Undo2 } from 'lucide-react'
|
||||
import { Badge, Button, useToast } from '../../components/ui'
|
||||
import { ABSENCE_REASON_LABELS, formatShortDate, formatTime } from './format'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* Upcoming classes. A notified class can be undone while it hasn't started. */
|
||||
export function StudentClassesView() {
|
||||
const { classes, classesPending, cancelAbsence } = useStudentApp()
|
||||
const toast = useToast()
|
||||
const upcoming = (classes?.classes ?? []).filter((item) => !item.started)
|
||||
|
||||
const undo = (noticeId: string) => {
|
||||
cancelAbsence.mutate(noticeId, {
|
||||
onSuccess: () => toast.success('Listo, quedaste anotado/a otra vez.'),
|
||||
onError: () => toast.error('No pudimos deshacer el aviso. Si la clase ya empezó, ya no se puede.'),
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<h1 className="text-2xl font-bold text-primary">Clases</h1>
|
||||
</div>
|
||||
|
||||
<Link
|
||||
to="/alumno/avisar"
|
||||
className="flex min-h-12 items-center justify-center gap-2 rounded-xl bg-accent font-semibold text-on-accent hover:bg-accent-strong"
|
||||
>
|
||||
<CalendarX2 className="size-5" aria-hidden="true" />
|
||||
Avisar que no voy
|
||||
</Link>
|
||||
|
||||
{classesPending || !classes ? (
|
||||
<div className="flex justify-center py-8" role="status" aria-label="Cargando clases">
|
||||
<Loader2 className="size-6 animate-spin text-accent" aria-hidden="true" />
|
||||
</div>
|
||||
) : upcoming.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-border px-4 py-6 text-center text-sm text-secondary">
|
||||
No hay clases programadas en las próximas semanas.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-border rounded-2xl border border-border bg-surface">
|
||||
{upcoming.map((item) => (
|
||||
<li key={item.startsAt} className="flex min-h-16 items-center justify-between gap-3 px-4 py-3">
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm font-medium capitalize text-primary">
|
||||
{formatShortDate(item.startsAt, classes.timeZone)} · {formatTime(item.startsAt, classes.timeZone)}
|
||||
</p>
|
||||
<p className="truncate text-xs text-secondary">
|
||||
{item.groupName}
|
||||
{item.notice?.reason ? ` · ${ABSENCE_REASON_LABELS[item.notice.reason]}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
{item.notice ? (
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<Badge variant="neutral">Avisaste</Badge>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-11"
|
||||
onClick={() => undo(item.notice?.id as string)}
|
||||
disabled={cancelAbsence.isPending}
|
||||
aria-label={`Deshacer el aviso del ${formatShortDate(item.startsAt, classes.timeZone)}`}
|
||||
>
|
||||
<Undo2 className="size-4" aria-hidden="true" />
|
||||
Deshacer
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
apps/web/src/features/student-app/StudentHomeView.tsx
Normal file
40
apps/web/src/features/student-app/StudentHomeView.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { FeeCard } from './FeeCard'
|
||||
import { firstName } from './format'
|
||||
import { NextClassCard } from './NextClassCard'
|
||||
import { PaymentReviewBanner } from './PaymentReviewBanner'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
import { TeacherNoticeCard } from './TeacherNoticeCard'
|
||||
import { WeekClassesList } from './WeekClassesList'
|
||||
|
||||
export function StudentHomeView() {
|
||||
const { student, classes, classesPending, fees } = useStudentApp()
|
||||
if (!student) return null
|
||||
|
||||
const allClasses = classes?.classes ?? []
|
||||
const nextClass = allClasses.find((item) => !item.started) ?? null
|
||||
const weekEnd = classes ? Date.parse(classes.weekEndsAt) : 0
|
||||
const thisWeek = allClasses.filter((item) => Date.parse(item.startsAt) < weekEnd)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold text-primary">Hola, {firstName(student.fullName)}</h1>
|
||||
|
||||
{fees ? <PaymentReviewBanner reports={fees.reports} /> : null}
|
||||
|
||||
{classesPending ? (
|
||||
<div className="flex justify-center py-8" role="status" aria-label="Cargando clases">
|
||||
<Loader2 className="size-6 animate-spin text-accent" aria-hidden="true" />
|
||||
</div>
|
||||
) : nextClass && classes ? (
|
||||
<NextClassCard item={nextClass} timeZone={classes.timeZone} />
|
||||
) : null}
|
||||
|
||||
{fees ? <FeeCard fees={fees.fees} /> : null}
|
||||
|
||||
{classes ? <WeekClassesList classes={thisWeek} timeZone={classes.timeZone} /> : null}
|
||||
|
||||
<TeacherNoticeCard teacherName={student.teacherName} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
51
apps/web/src/features/student-app/StudentLayout.tsx
Normal file
51
apps/web/src/features/student-app/StudentLayout.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Outlet, useLocation } from '@tanstack/react-router'
|
||||
import { Loader2, UserX } from 'lucide-react'
|
||||
import { Logo } from '../../components/brand'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { StudentBottomNav } from './StudentBottomNav'
|
||||
import { StudentPicker } from './StudentPicker'
|
||||
import { STUDENT_FLOW_PATHS } from './student-nav-items'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* Shell of the student app: same mobile-first column (`max-w-md`) as the
|
||||
teacher's, with its own nav. It never mounts the teacher's header, sidebar or
|
||||
guards. */
|
||||
export function StudentLayout() {
|
||||
const { me, mePending, student } = useStudentApp()
|
||||
const location = useLocation()
|
||||
const isFlow = STUDENT_FLOW_PATHS.some((path) => location.pathname.startsWith(path))
|
||||
|
||||
return (
|
||||
<div className="min-h-dvh bg-background text-primary">
|
||||
<header className="sticky top-0 z-40 border-b border-border bg-background/90 backdrop-blur">
|
||||
<div className="mx-auto flex h-16 max-w-md items-center justify-between px-4">
|
||||
<Logo className="h-7 w-auto" />
|
||||
<StudentPicker />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main
|
||||
className={cn(
|
||||
'mx-auto w-full max-w-md px-4 pt-5',
|
||||
isFlow ? 'pb-[calc(7rem+env(safe-area-inset-bottom))]' : 'pb-[calc(6rem+env(safe-area-inset-bottom))]',
|
||||
)}
|
||||
>
|
||||
{mePending || !me ? (
|
||||
<div className="flex justify-center py-20" role="status" aria-label="Cargando">
|
||||
<Loader2 className="size-8 animate-spin text-accent" aria-hidden="true" />
|
||||
</div>
|
||||
) : !student && !location.pathname.startsWith('/alumno/perfil') ? (
|
||||
<div className="mt-10 space-y-3 rounded-2xl border border-border bg-surface p-6 text-center">
|
||||
<UserX className="mx-auto size-8 text-foreground" aria-hidden="true" />
|
||||
<h1 className="text-lg font-bold text-primary">No tenés grupos activos</h1>
|
||||
<p className="text-sm text-secondary">Si creés que es un error, hablá con tu profe.</p>
|
||||
</div>
|
||||
) : (
|
||||
<Outlet />
|
||||
)}
|
||||
</main>
|
||||
|
||||
{isFlow ? null : <StudentBottomNav />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
113
apps/web/src/features/student-app/StudentPaymentsView.tsx
Normal file
113
apps/web/src/features/student-app/StudentPaymentsView.tsx
Normal file
@@ -0,0 +1,113 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import type { StudentPaymentReport } from '@gruperly/shared'
|
||||
import { ExternalLink, Loader2, Receipt } from 'lucide-react'
|
||||
import { Badge } from '../../components/ui'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
import { FeeStatusBadge } from './FeeStatusBadge'
|
||||
import { feeLabel, formatDueDate } from './format'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
const REPORT_BADGE: Record<StudentPaymentReport['status'], { label: string; variant: 'info' | 'success' | 'danger' }> = {
|
||||
reported: { label: 'Informado', variant: 'info' },
|
||||
confirmed: { label: 'Confirmado', variant: 'success' },
|
||||
rejected: { label: 'Rechazado', variant: 'danger' },
|
||||
}
|
||||
|
||||
export function StudentPaymentsView() {
|
||||
const { fees, feesPending } = useStudentApp()
|
||||
|
||||
if (feesPending || !fees) {
|
||||
return (
|
||||
<div className="flex justify-center py-20" role="status" aria-label="Cargando pagos">
|
||||
<Loader2 className="size-8 animate-spin text-accent" aria-hidden="true" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const canReport = fees.fees.some((fee) => fee.status !== 'reported')
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold text-primary">Pagos</h1>
|
||||
|
||||
<section aria-labelledby="unpaid-title" className="space-y-3">
|
||||
<h2 id="unpaid-title" className="text-base font-bold text-primary">
|
||||
Cuotas sin pagar
|
||||
</h2>
|
||||
{fees.fees.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-border px-4 py-6 text-center text-sm text-secondary">
|
||||
Estás al día. 🎉
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-border rounded-2xl border border-border bg-surface">
|
||||
{fees.fees.map((fee) => (
|
||||
<li key={fee.id} className="space-y-2 px-4 py-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium text-primary">{feeLabel(fee)}</p>
|
||||
<p className="text-xs text-secondary">Vence {formatDueDate(fee.dueDate)}</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-col items-end gap-1">
|
||||
<span className="text-sm font-semibold text-primary">{formatPrice(fee.amount, fee.currency)}</span>
|
||||
<FeeStatusBadge status={fee.status} />
|
||||
</div>
|
||||
</div>
|
||||
{fee.checkoutUrl && fee.status !== 'reported' ? (
|
||||
<a
|
||||
href={fee.checkoutUrl}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex min-h-11 items-center gap-1 text-sm font-medium text-accent-fg hover:underline"
|
||||
>
|
||||
Pagar con Mercado Pago
|
||||
<ExternalLink className="size-4" aria-hidden="true" />
|
||||
</a>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{canReport ? (
|
||||
<Link
|
||||
to="/alumno/informar-pago"
|
||||
className="flex min-h-12 items-center justify-center gap-2 rounded-xl bg-accent font-semibold text-on-accent hover:bg-accent-strong"
|
||||
>
|
||||
<Receipt className="size-5" aria-hidden="true" />
|
||||
Informar pago
|
||||
</Link>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
{fees.reports.length > 0 ? (
|
||||
<section aria-labelledby="reports-title" className="space-y-3">
|
||||
<h2 id="reports-title" className="text-base font-bold text-primary">
|
||||
Pagos informados
|
||||
</h2>
|
||||
<ul className="divide-y divide-border rounded-2xl border border-border bg-surface">
|
||||
{fees.reports.map((report) => (
|
||||
<li key={report.id} className="px-4 py-3">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium text-primary">
|
||||
{report.fees.map((fee) => feeLabel(fee)).join(', ')}
|
||||
</p>
|
||||
<p className="text-xs text-secondary">
|
||||
Informado el {new Date(report.createdAt).toLocaleDateString('es-AR', { day: 'numeric', month: 'short' })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-col items-end gap-1">
|
||||
<span className="text-sm font-semibold text-primary">{formatPrice(report.totalAmount, report.currency)}</span>
|
||||
<Badge variant={REPORT_BADGE[report.status].variant}>{REPORT_BADGE[report.status].label}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
{report.status === 'rejected' && report.rejectionReason ? (
|
||||
<p className="mt-2 rounded-lg bg-danger-soft px-3 py-2 text-xs text-primary">Motivo: {report.rejectionReason}</p>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
82
apps/web/src/features/student-app/StudentPicker.tsx
Normal file
82
apps/web/src/features/student-app/StudentPicker.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Check, ChevronDown } from 'lucide-react'
|
||||
import { Avatar } from '../../components/ui'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { firstName } from './format'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* Selector of the attendee the screens show, only when the account has more
|
||||
than one (a guardian with several children). */
|
||||
export function StudentPicker() {
|
||||
const { me, student, selectStudent } = useStudentApp()
|
||||
const [open, setOpen] = useState(false)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
const close = (event: MouseEvent | KeyboardEvent) => {
|
||||
if (event instanceof KeyboardEvent ? event.key === 'Escape' : !containerRef.current?.contains(event.target as Node)) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', close)
|
||||
document.addEventListener('keydown', close)
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', close)
|
||||
document.removeEventListener('keydown', close)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
const students = me?.students ?? []
|
||||
if (!student || students.length < 2) return null
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded={open}
|
||||
aria-label={`Alumno: ${student.fullName}. Cambiar`}
|
||||
className="flex min-h-11 items-center gap-2 rounded-xl px-2 hover:bg-primary-soft"
|
||||
>
|
||||
<Avatar name={student.fullName} className="size-8 rounded-full text-xs" />
|
||||
<span className="max-w-[8rem] truncate text-sm font-medium text-primary">{firstName(student.fullName)}</span>
|
||||
<ChevronDown className="size-4 text-foreground" aria-hidden="true" />
|
||||
</button>
|
||||
{open ? (
|
||||
<ul
|
||||
role="listbox"
|
||||
aria-label="Elegí el alumno"
|
||||
className="absolute right-0 top-full z-50 mt-2 w-64 rounded-xl border border-border bg-surface p-1 shadow-xl"
|
||||
>
|
||||
{students.map((item) => {
|
||||
const selected = item.attendeeId === student.attendeeId
|
||||
return (
|
||||
<li key={item.attendeeId} role="option" aria-selected={selected}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
selectStudent(item.attendeeId)
|
||||
setOpen(false)
|
||||
}}
|
||||
className={cn(
|
||||
'flex min-h-11 w-full items-center gap-3 rounded-lg px-3 py-2 text-left hover:bg-primary-soft',
|
||||
selected && 'bg-accent-soft',
|
||||
)}
|
||||
>
|
||||
<Avatar name={item.fullName} className="size-8 rounded-full text-xs" />
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-primary">{item.fullName}</span>
|
||||
<span className="block truncate text-xs text-secondary">{item.groupName}</span>
|
||||
</span>
|
||||
{selected ? <Check className="size-4 text-accent-fg" aria-hidden="true" /> : null}
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
34
apps/web/src/features/student-app/StudentProfileView.tsx
Normal file
34
apps/web/src/features/student-app/StudentProfileView.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { LogOut } from 'lucide-react'
|
||||
import { Avatar, Button } from '../../components/ui'
|
||||
import { PasskeyCard } from './PasskeyCard'
|
||||
import { RecoveryEmailCard } from './RecoveryEmailCard'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
export function StudentProfileView() {
|
||||
const { me, logout, loggingOut } = useStudentApp()
|
||||
if (!me) return null
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold text-primary">Perfil</h1>
|
||||
|
||||
<section className="flex items-center gap-3 rounded-2xl border border-border bg-surface p-4">
|
||||
<Avatar name={me.account.name} className="size-12 rounded-full text-base" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate font-semibold text-primary">{me.account.name}</p>
|
||||
<p className="truncate text-sm text-secondary">
|
||||
{me.students.map((student) => `${student.groupName} · ${student.teacherName}`).join(' / ')}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<PasskeyCard />
|
||||
<RecoveryEmailCard />
|
||||
|
||||
<Button variant="outline" className="h-12 w-full" onClick={logout} disabled={loggingOut}>
|
||||
<LogOut className="size-5" aria-hidden="true" />
|
||||
Cerrar sesión en este teléfono
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
17
apps/web/src/features/student-app/TeacherNoticeCard.tsx
Normal file
17
apps/web/src/features/student-app/TeacherNoticeCard.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Megaphone } from 'lucide-react'
|
||||
|
||||
/* "Avisos del profe": gruperly doesn't publish announcements yet, so this is
|
||||
the empty state the feature will fill. */
|
||||
export function TeacherNoticeCard({ teacherName }: { teacherName: string }) {
|
||||
return (
|
||||
<section aria-labelledby="notices-title" className="space-y-3">
|
||||
<h2 id="notices-title" className="text-base font-bold text-primary">
|
||||
Avisos del profe
|
||||
</h2>
|
||||
<div className="flex gap-3 rounded-2xl border border-dashed border-border px-4 py-5 text-sm text-secondary">
|
||||
<Megaphone className="size-5 shrink-0" aria-hidden="true" />
|
||||
<p>Cuando {teacherName} publique un aviso, lo vas a ver acá.</p>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
34
apps/web/src/features/student-app/TransferDetailsCard.tsx
Normal file
34
apps/web/src/features/student-app/TransferDetailsCard.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { TransferDetails } from '@gruperly/shared'
|
||||
import { Check, Copy } from 'lucide-react'
|
||||
import { useCopyToClipboard } from '../attendee-detail/useCopyToClipboard'
|
||||
|
||||
export function TransferDetailsCard({ transfer }: { transfer: TransferDetails }) {
|
||||
const { copied, copy } = useCopyToClipboard()
|
||||
|
||||
return (
|
||||
<section aria-labelledby="transfer-title" className="rounded-2xl border border-border bg-primary-soft p-4">
|
||||
<h2 id="transfer-title" className="text-sm font-semibold text-primary">
|
||||
Datos para transferir
|
||||
</h2>
|
||||
<div className="mt-3 flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs text-secondary">Alias</p>
|
||||
<p className="truncate font-mono text-base font-semibold text-primary">{transfer.alias}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => copy(transfer.alias)}
|
||||
className="flex min-h-11 shrink-0 items-center gap-2 rounded-xl border border-border bg-surface px-3 text-sm font-medium text-primary hover:bg-primary-soft"
|
||||
>
|
||||
{copied ? <Check className="size-4 text-success" aria-hidden="true" /> : <Copy className="size-4" aria-hidden="true" />}
|
||||
<span aria-live="polite">{copied ? 'Copiado' : 'Copiar'}</span>
|
||||
</button>
|
||||
</div>
|
||||
{transfer.holder ? (
|
||||
<p className="mt-2 text-sm text-secondary">
|
||||
Titular: <span className="font-medium text-primary">{transfer.holder}</span>
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
40
apps/web/src/features/student-app/WeekClassesList.tsx
Normal file
40
apps/web/src/features/student-app/WeekClassesList.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { StudentClass } from '@gruperly/shared'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { formatShortDate, formatTime } from './format'
|
||||
|
||||
type WeekClassesListProps = { classes: StudentClass[]; timeZone: string }
|
||||
|
||||
/* "Esta semana": past classes dimmed, notified ones struck through with
|
||||
"Avisaste" next to them (the word, not only the strike, carries it). */
|
||||
export function WeekClassesList({ classes, timeZone }: WeekClassesListProps) {
|
||||
return (
|
||||
<section aria-labelledby="week-title" className="space-y-3">
|
||||
<h2 id="week-title" className="text-base font-bold text-primary">
|
||||
Esta semana
|
||||
</h2>
|
||||
{classes.length === 0 ? (
|
||||
<p className="rounded-xl border border-dashed border-border px-4 py-6 text-center text-sm text-secondary">
|
||||
No tenés clases esta semana.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-border rounded-2xl border border-border bg-surface">
|
||||
{classes.map((item) => (
|
||||
<li key={item.startsAt} className={cn('flex min-h-14 items-center justify-between gap-3 px-4 py-3', item.started && !item.notice && 'opacity-70')}>
|
||||
<div className={cn('min-w-0', item.notice && 'line-through decoration-foreground/60')}>
|
||||
<p className="text-sm font-medium capitalize text-primary">{formatShortDate(item.startsAt, timeZone)}</p>
|
||||
<p className="text-xs text-secondary">
|
||||
{formatTime(item.startsAt, timeZone)} · {item.groupName}
|
||||
</p>
|
||||
</div>
|
||||
{item.notice ? (
|
||||
<span className="shrink-0 rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-primary">Avisaste</span>
|
||||
) : item.started ? (
|
||||
<span className="shrink-0 text-xs text-secondary">Pasó</span>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
80
apps/web/src/features/student-app/WelcomeView.tsx
Normal file
80
apps/web/src/features/student-app/WelcomeView.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { CheckCircle2, Loader2 } from 'lucide-react'
|
||||
import { Button, Input, Label } from '../../components/ui'
|
||||
import { FlowFooter } from './FlowFooter'
|
||||
import { PasskeyCard } from './PasskeyCard'
|
||||
import { useStudentApp } from './StudentAppProvider'
|
||||
|
||||
/* First sign-in only. Both options are skippable: "Ahora no" goes straight in. */
|
||||
export function WelcomeView() {
|
||||
const navigate = useNavigate()
|
||||
const { finishWelcome, saveRecoveryEmail } = useStudentApp()
|
||||
const [email, setEmail] = useState('')
|
||||
|
||||
const goHome = () =>
|
||||
finishWelcome.mutate(undefined, { onSettled: () => void navigate({ to: '/alumno', replace: true }) })
|
||||
|
||||
const handleContinue = () => {
|
||||
const value = email.trim()
|
||||
if (!value) {
|
||||
goHome()
|
||||
return
|
||||
}
|
||||
saveRecoveryEmail.mutate(value, { onSuccess: goHome })
|
||||
}
|
||||
|
||||
const busy = finishWelcome.isPending || saveRecoveryEmail.isPending
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="pt-2 text-center">
|
||||
<div className="mx-auto flex size-16 items-center justify-center rounded-full bg-success-soft text-success">
|
||||
<CheckCircle2 className="size-8" aria-hidden="true" />
|
||||
</div>
|
||||
<h1 className="mt-4 text-2xl font-bold text-primary">¡Listo, ya estás adentro!</h1>
|
||||
<p className="mt-2 text-sm leading-relaxed text-secondary">
|
||||
Vas a quedar conectado/a en este teléfono. Si querés, sumá una de estas opciones para no perder el acceso.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<PasskeyCard highlighted />
|
||||
|
||||
<section aria-labelledby="welcome-email-title" className="rounded-2xl border border-border bg-surface p-5">
|
||||
<h2 id="welcome-email-title" className="text-base font-bold text-primary">
|
||||
Mail de recuperación <span className="font-normal text-secondary">(opcional)</span>
|
||||
</h2>
|
||||
<p className="mt-1 text-sm text-secondary">Te mandamos un link para confirmarlo.</p>
|
||||
<div className="mt-3 space-y-1.5">
|
||||
<Label htmlFor="welcome-email">Tu mail</Label>
|
||||
<Input
|
||||
id="welcome-email"
|
||||
type="email"
|
||||
inputMode="email"
|
||||
autoComplete="email"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
className="h-11"
|
||||
/>
|
||||
</div>
|
||||
{saveRecoveryEmail.isError ? (
|
||||
<p role="alert" className="mt-2 text-sm text-danger-fg">
|
||||
Revisá el mail o seguí sin cargarlo.
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
<FlowFooter>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" className="h-12 flex-1" onClick={goHome} disabled={busy}>
|
||||
Ahora no
|
||||
</Button>
|
||||
<Button variant="primary" className="h-12 flex-1" onClick={handleContinue} disabled={busy}>
|
||||
{busy ? <Loader2 className="size-5 animate-spin" aria-hidden="true" /> : null}
|
||||
Continuar
|
||||
</Button>
|
||||
</div>
|
||||
</FlowFooter>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
78
apps/web/src/features/student-app/format.ts
Normal file
78
apps/web/src/features/student-app/format.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import type { AbsenceReasonValue, StudentFee } from '@gruperly/shared'
|
||||
|
||||
/* Dates of the student app are shown on the teacher's clock (the class time
|
||||
zone the API returns), not the phone's: "18:00" is when the class starts. */
|
||||
|
||||
const DAY_MS = 86_400_000
|
||||
|
||||
function wallDate(date: Date, timeZone: string): string {
|
||||
return new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(date)
|
||||
}
|
||||
|
||||
/** Whole days between `now` and `iso` in `timeZone` (0 = today). */
|
||||
export function daysFromToday(iso: string, timeZone: string, now: Date = new Date()): number {
|
||||
const target = Date.parse(wallDate(new Date(iso), timeZone))
|
||||
const today = Date.parse(wallDate(now, timeZone))
|
||||
return Math.round((target - today) / DAY_MS)
|
||||
}
|
||||
|
||||
export function formatRelativeDay(iso: string, timeZone: string, now: Date = new Date()): string {
|
||||
const days = daysFromToday(iso, timeZone, now)
|
||||
if (days === 0) return 'hoy'
|
||||
if (days === 1) return 'mañana'
|
||||
if (days === -1) return 'ayer'
|
||||
return new Intl.DateTimeFormat('es-AR', { timeZone, weekday: 'long' }).format(new Date(iso))
|
||||
}
|
||||
|
||||
/** "Miércoles 28 de octubre" */
|
||||
export function formatLongDate(iso: string, timeZone: string): string {
|
||||
const text = new Intl.DateTimeFormat('es-AR', { timeZone, weekday: 'long', day: 'numeric', month: 'long' }).format(new Date(iso))
|
||||
return text.charAt(0).toUpperCase() + text.slice(1)
|
||||
}
|
||||
|
||||
/** "mié 28 oct" */
|
||||
export function formatShortDate(iso: string, timeZone: string): string {
|
||||
return new Intl.DateTimeFormat('es-AR', { timeZone, weekday: 'short', day: 'numeric', month: 'short' })
|
||||
.format(new Date(iso))
|
||||
.replace(/\./g, '')
|
||||
}
|
||||
|
||||
export function formatTime(iso: string, timeZone: string): string {
|
||||
return new Intl.DateTimeFormat('es-AR', { timeZone, hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(new Date(iso))
|
||||
}
|
||||
|
||||
/** Day of month and short month, for the mini date card: { day: '28', month: 'oct' }. */
|
||||
export function dateParts(iso: string, timeZone: string): { day: string; month: string } {
|
||||
const date = new Date(iso)
|
||||
return {
|
||||
day: new Intl.DateTimeFormat('es-AR', { timeZone, day: 'numeric' }).format(date),
|
||||
month: new Intl.DateTimeFormat('es-AR', { timeZone, month: 'short' }).format(date).replace('.', ''),
|
||||
}
|
||||
}
|
||||
|
||||
/** Fee title: its description, or the month it is due ("Noviembre"). */
|
||||
export function feeLabel(fee: Pick<StudentFee, 'description' | 'dueDate'>): string {
|
||||
if (fee.description) return fee.description
|
||||
const month = new Intl.DateTimeFormat('es-AR', { month: 'long', timeZone: 'UTC' }).format(new Date(fee.dueDate))
|
||||
return month.charAt(0).toUpperCase() + month.slice(1)
|
||||
}
|
||||
|
||||
export function formatDueDate(iso: string): string {
|
||||
return new Intl.DateTimeFormat('es-AR', { day: 'numeric', month: 'short', timeZone: 'UTC' }).format(new Date(iso)).replace('.', '')
|
||||
}
|
||||
|
||||
export function formatFileSize(bytes: number): string {
|
||||
if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1).replace('.', ',')} MB`
|
||||
}
|
||||
|
||||
export const ABSENCE_REASON_LABELS: Record<AbsenceReasonValue, string> = {
|
||||
health: 'Salud',
|
||||
travel: 'Viaje',
|
||||
work_study: 'Trabajo o estudio',
|
||||
other: 'Otro',
|
||||
}
|
||||
|
||||
export function firstName(fullName: string): string {
|
||||
return fullName.trim().split(/\s+/)[0] ?? fullName
|
||||
}
|
||||
19
apps/web/src/features/student-app/student-nav-items.ts
Normal file
19
apps/web/src/features/student-app/student-nav-items.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { CalendarDays, Home, User, Wallet } from 'lucide-react'
|
||||
import type { NavItem } from '../../components/layout/nav-items'
|
||||
|
||||
// Bottom nav of the student app: the single source for StudentBottomNav.
|
||||
export const STUDENT_NAV_ITEMS: NavItem[] = [
|
||||
{ label: 'Inicio', to: '/alumno', icon: Home },
|
||||
{ label: 'Clases', to: '/alumno/clases', icon: CalendarDays },
|
||||
{ label: 'Pagos', to: '/alumno/pagos', icon: Wallet },
|
||||
{ label: 'Perfil', to: '/alumno/perfil', icon: User },
|
||||
]
|
||||
|
||||
/* Flow screens with their own fixed bottom button: no nav there. */
|
||||
export const STUDENT_FLOW_PATHS = ['/alumno/bienvenida', '/alumno/avisar', '/alumno/informar-pago']
|
||||
|
||||
export function isStudentNavItemActive(pathname: string, to: string): boolean {
|
||||
const path = pathname.replace(/\/$/, '') || '/'
|
||||
if (to === '/alumno') return path === '/alumno'
|
||||
return path === to || path.startsWith(`${to}/`)
|
||||
}
|
||||
Reference in New Issue
Block a user