feat(i18n): traducir el acceso de alumnos (links, passkey, recuperación)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-03 14:02:56 -03:00
parent b615c17a16
commit 486fbaf2ca
10 changed files with 230 additions and 34 deletions

View File

@@ -4,11 +4,13 @@ import { CheckCircle2, Loader2, MailWarning, Mail } from 'lucide-react'
import { Button } from '../../components/ui'
import { confirmStudentRecoveryEmail } from '../../lib/api'
import { StudentAuthShell } from './StudentAuthShell'
import { Trans, useTranslation } from 'react-i18next'
/* Confirming takes a tap (POST), like entering with a link: a mail scanner that
opens the URL doesn't confirm anything by itself. */
export function ConfirmRecoveryEmailView({ token }: { token: string }) {
const mutation = useMutation({ mutationFn: () => confirmStudentRecoveryEmail(token) })
const { t } = useTranslation('studentAccess')
return (
<StudentAuthShell>
@@ -19,13 +21,18 @@ export function ConfirmRecoveryEmailView({ token }: { token: string }) {
<CheckCircle2 className="size-7" aria-hidden="true" />
</div>
<div role="status">
<h1 className="text-2xl font-bold text-primary">Mail confirmado</h1>
<h1 className="text-2xl font-bold text-primary">{t('confirmEmail.doneTitle')}</h1>
<p className="mt-2 text-sm text-secondary">
Si algún día perdés el acceso, pedí un link a <strong className="text-primary">{mutation.data.email}</strong>.
<Trans
t={t}
i18nKey="confirmEmail.done"
values={{ email: mutation.data.email }}
components={{ strong: <strong className="text-primary" /> }}
/>
</p>
</div>
<Link to="/student" className="inline-flex h-12 w-full items-center justify-center rounded-xl bg-accent font-medium text-on-accent hover:bg-accent-strong">
Ir a gruperly
{t('confirmEmail.goToApp')}
</Link>
</>
) : mutation.isError ? (
@@ -34,9 +41,9 @@ export function ConfirmRecoveryEmailView({ token }: { token: string }) {
<MailWarning className="size-7" aria-hidden="true" />
</div>
<div role="alert">
<h1 className="text-2xl font-bold text-primary">Este link ya no sirve</h1>
<h1 className="text-2xl font-bold text-primary">{t('confirmEmail.expiredTitle')}</h1>
<p className="mt-2 text-sm text-secondary">
Ya fue usado o venció. Podés volver a cargar tu mail desde Perfil en la app.
{t('confirmEmail.expired')}
</p>
</div>
</>
@@ -46,12 +53,12 @@ export function ConfirmRecoveryEmailView({ token }: { token: string }) {
<Mail className="size-7" aria-hidden="true" />
</div>
<div>
<h1 className="text-2xl font-bold text-primary">Confirmá tu mail</h1>
<p className="mt-2 text-sm text-secondary">Lo vas a poder usar para pedir un link si perdés el acceso.</p>
<h1 className="text-2xl font-bold text-primary">{t('confirmEmail.title')}</h1>
<p className="mt-2 text-sm text-secondary">{t('confirmEmail.description')}</p>
</div>
<Button variant="primary" className="h-12 w-full text-base" onClick={() => mutation.mutate()} disabled={mutation.isPending}>
{mutation.isPending ? <Loader2 className="size-5 animate-spin" aria-hidden="true" /> : null}
Confirmar mail
{t('confirmEmail.confirm')}
</Button>
</>
)}

View File

@@ -4,6 +4,7 @@ import { Button } from '../../components/ui'
import { PasskeyLoginButton } from './PasskeyLoginButton'
import { RecoveryLinkForm } from './RecoveryLinkForm'
import { StudentAuthShell } from './StudentAuthShell'
import { useTranslation } from 'react-i18next'
type LinkUsedViewProps = {
/** `used`: a dead link (used, expired or never valid). `signed-out`: the
@@ -13,6 +14,7 @@ type LinkUsedViewProps = {
export function LinkUsedView({ variant }: LinkUsedViewProps) {
const [showEmail, setShowEmail] = useState(false)
const { t } = useTranslation('studentAccess')
const Icon = variant === 'used' ? Link2Off : LogIn
return (
@@ -23,12 +25,12 @@ export function LinkUsedView({ variant }: LinkUsedViewProps) {
<Icon className="size-7" aria-hidden="true" />
</div>
<h1 className="text-2xl font-bold text-primary">
{variant === 'used' ? 'Este link ya fue usado' : 'Volvé a entrar'}
{variant === 'used' ? t('linkUsed.usedTitle') : t('linkUsed.signedOutTitle')}
</h1>
<p className="mt-3 text-sm leading-relaxed text-secondary">
{variant === 'used'
? 'Los links de gruperly sirven una sola vez. Si ya entraste desde otro teléfono, seguí desde ahí. Si no fuiste vos, avisale a tu profe para que te mande uno nuevo: el anterior deja de funcionar.'
: 'No encontramos tu sesión en este teléfono. Pedile a tu profe un link nuevo o usá una de estas opciones.'}
? t('linkUsed.used')
: t('linkUsed.signedOut')}
</p>
</div>
@@ -39,10 +41,10 @@ export function LinkUsedView({ variant }: LinkUsedViewProps) {
) : (
<Button variant="outline" className="h-12 w-full text-base" onClick={() => setShowEmail(true)}>
<Mail className="size-5" aria-hidden="true" />
Pedir un link a mi mail
{t('linkUsed.askEmail')}
</Button>
)}
<p className="text-center text-xs text-secondary">Estas opciones funcionan solo si las activaste antes.</p>
<p className="text-center text-xs text-secondary">{t('linkUsed.note')}</p>
</div>
</section>
</StudentAuthShell>

View File

@@ -4,11 +4,13 @@ import { useQueryClient } from '@tanstack/react-query'
import { Fingerprint, Loader2 } from 'lucide-react'
import { Button } from '../../components/ui'
import { isPasskeyCancel, loginWithPasskey, supportsPasskeys } from './passkeys'
import { useTranslation } from 'react-i18next'
export function PasskeyLoginButton() {
const navigate = useNavigate()
const queryClient = useQueryClient()
const [pending, setPending] = useState(false)
const { t } = useTranslation('studentAccess')
const [failed, setFailed] = useState(false)
if (!supportsPasskeys()) return null
@@ -31,11 +33,11 @@ export function PasskeyLoginButton() {
<div className="space-y-2">
<Button variant="primary" className="h-12 w-full text-base" onClick={() => void handleClick()} disabled={pending}>
{pending ? <Loader2 className="size-5 animate-spin" /> : <Fingerprint className="size-5" />}
Entrar con Face ID o huella
{t('passkey.login')}
</Button>
{failed ? (
<p role="alert" className="text-center text-sm text-danger-fg">
No pudimos verificar tu Face ID o huella en este teléfono.
{t('passkey.error')}
</p>
) : null}
</div>

View File

@@ -3,11 +3,13 @@ import { useMutation } from '@tanstack/react-query'
import { Loader2, MailCheck } from 'lucide-react'
import { Button, Input, Label } from '../../components/ui'
import { ApiError, requestStudentRecoveryLink } from '../../lib/api'
import { Trans, useTranslation } from 'react-i18next'
/* "Pedir un link a mi mail". The answer is the same whether the email exists
or not, so the screen says it conditionally. */
export function RecoveryLinkForm() {
const [email, setEmail] = useState('')
const { t } = useTranslation('studentAccess')
const mutation = useMutation({ mutationFn: requestStudentRecoveryLink })
const handleSubmit = (event: FormEvent) => {
@@ -20,8 +22,12 @@ export function RecoveryLinkForm() {
<div role="status" className="flex gap-3 rounded-xl border border-border bg-primary-soft p-4 text-sm text-secondary">
<MailCheck className="size-5 shrink-0 text-accent-fg" aria-hidden="true" />
<p>
Si <strong className="text-primary">{email.trim()}</strong> es tu mail de recuperación, te mandamos un link
para entrar. Vence en 15 minutos.
<Trans
t={t}
i18nKey="recovery.sent"
values={{ email: email.trim() }}
components={{ strong: <strong className="text-primary" /> }}
/>
</p>
</div>
)
@@ -32,7 +38,7 @@ export function RecoveryLinkForm() {
return (
<form onSubmit={handleSubmit} className="space-y-3">
<div className="space-y-1.5">
<Label htmlFor="recovery-email">Tu mail de recuperación</Label>
<Label htmlFor="recovery-email">{t('recovery.label')}</Label>
<Input
id="recovery-email"
type="email"
@@ -47,12 +53,12 @@ export function RecoveryLinkForm() {
</div>
{mutation.isError ? (
<p role="alert" className="text-sm text-danger-fg">
{tooMany ? 'Pediste varios links seguidos. Probá de nuevo en 15 minutos.' : 'No pudimos enviar el pedido. Probá de nuevo.'}
{tooMany ? t('recovery.tooMany') : t('recovery.error')}
</p>
) : null}
<Button type="submit" variant="outline" className="h-12 w-full" disabled={mutation.isPending}>
{mutation.isPending ? <Loader2 className="size-5 animate-spin" /> : null}
Mandarme el link
{t('recovery.submit')}
</Button>
</form>
)

View File

@@ -3,22 +3,24 @@ import { Avatar, Button } from '../../components/ui'
import { LinkUsedView } from './LinkUsedView'
import { StudentAuthShell } from './StudentAuthShell'
import { useStudentLink } from './StudentLinkProvider'
import { useTranslation } from 'react-i18next'
const CAPABILITIES = [
{ icon: CalendarX2, text: 'Avisar si no vas a una clase' },
{ icon: Receipt, text: 'Informar pagos con el comprobante' },
{ icon: CalendarDays, text: 'Ver tus próximas clases' },
]
{ icon: CalendarX2, text: 'link.capNotify' },
{ icon: Receipt, text: 'link.capReport' },
{ icon: CalendarDays, text: 'link.capClasses' },
] as const
export function StudentLinkView() {
const { info, infoPending, infoFailed, enter, entering, consumedElsewhere, enterFailed } = useStudentLink()
const { t } = useTranslation('studentAccess')
if (infoPending) {
return (
<StudentAuthShell>
<div className="flex flex-col items-center gap-3 py-20" role="status">
<Loader2 className="size-8 animate-spin text-accent" aria-hidden="true" />
<p className="text-sm text-secondary">Cargando…</p>
<p className="text-sm text-secondary">{t('loading')}</p>
</div>
</StudentAuthShell>
)
@@ -44,13 +46,13 @@ export function StudentLinkView() {
className={`size-14 rounded-full text-lg ring-4 ring-surface ${info.teacherName ? '-ml-3' : ''}`}
/>
</div>
<h1 className="text-2xl font-bold text-primary">Hola, {firstName}</h1>
<h1 className="text-2xl font-bold text-primary">{t('link.greeting', { name: firstName })}</h1>
<p className="mt-2 text-sm leading-relaxed text-secondary">
{isRecovery
? 'Este es tu link para volver a entrar a gruperly.'
? t('link.recovery')
: info.teacherName && info.groupName
? `${info.teacherName} te invitó a ${info.groupName} en gruperly.`
: 'Te invitaron a gruperly.'}
? t('link.invitedBy', { teacher: info.teacherName, group: info.groupName })
: t('link.invited')}
</p>
</div>
@@ -59,7 +61,7 @@ export function StudentLinkView() {
{CAPABILITIES.map(({ icon: Icon, text }) => (
<li key={text} className="flex items-center gap-3 rounded-xl bg-primary-soft px-4 py-3 text-sm text-primary">
<Icon className="size-5 shrink-0 text-accent-fg" aria-hidden="true" />
{text}
{t(text)}
</li>
))}
</ul>
@@ -68,18 +70,17 @@ export function StudentLinkView() {
<div className="space-y-3">
<Button variant="primary" className="h-12 w-full text-base" onClick={enter} disabled={entering}>
{entering ? <Loader2 className="size-5 animate-spin" aria-hidden="true" /> : null}
Ingresar
{t('link.enter')}
</Button>
{enterFailed ? (
<p role="alert" className="text-center text-sm text-danger-fg">
No pudimos conectarte. Revisá tu conexión y probá de nuevo.
{t('link.error')}
</p>
) : null}
<p className="flex gap-2 text-xs leading-relaxed text-secondary">
<Lock className="mt-0.5 size-4 shrink-0" aria-hidden="true" />
<span>
Sin contraseñas: vas a quedar conectado/a en este teléfono. Este link es personal y sirve una sola vez.
Si no sos {firstName}, no continúes.
{t('link.security', { name: firstName })}
</span>
</p>
</div>