feat(i18n): traducir inscripción por link y aviso de ausencia público

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-03 14:02:02 -03:00
parent 243530fab2
commit b615c17a16
14 changed files with 281 additions and 62 deletions

View File

@@ -4,6 +4,8 @@ import { useMutation, useQuery } from '@tanstack/react-query'
import type { AbsenceDetails } from '@gruperly/shared'
import { useToast } from '../../components/ui'
import { ApiError, getAbsenceDetails, publicNotifyAbsence } from '../../lib/api'
import { errorMessage } from '../../i18n'
import { i18n } from '../../i18n/instance'
type AbsenceNotifyContextValue = {
token: string
@@ -32,14 +34,14 @@ export function AbsenceNotifyProvider({ token, children }: { token: string; chil
mutationFn: (sessionId: string) => publicNotifyAbsence({ token, classSessionId: sessionId }),
onSuccess: (_data, sessionId) => {
setLocallyNotified((prev) => [...prev, sessionId])
toast.success('Tu profesor ya tiene registrado el aviso. Gracias por avisar.', 'Ausencia avisada')
toast.success(i18n.t('public:absence.done'), i18n.t('public:absence.doneTitle'))
},
onError: (error: unknown) => {
if (error instanceof ApiError && error.problem?.status === 404) {
toast.error('Este enlace ya no es válido. Consultá a tu profesor.')
toast.error(i18n.t('public:absence.invalidLink'))
return
}
toast.error(error instanceof Error ? error.message : 'No pudimos registrar el aviso.')
toast.error(errorMessage(error, i18n.t('public:absence.error')))
},
})

View File

@@ -3,9 +3,11 @@ import { PublicFooter, PublicHeader } from '../../components/layout'
import { Badge } from '../../components/ui'
import { AbsenceSessionRow } from './AbsenceSessionRow'
import { useAbsenceNotify } from './AbsenceNotifyProvider'
import { Trans, useTranslation } from 'react-i18next'
export function AbsenceNotifyView() {
const { details, detailsPending, detailsFailed } = useAbsenceNotify()
const { t } = useTranslation('public')
return (
<div className="flex min-h-screen flex-col justify-between bg-background text-primary selection:bg-accent selection:text-white">
@@ -16,15 +18,15 @@ export function AbsenceNotifyView() {
{detailsPending ? (
<div className="flex flex-col items-center justify-center gap-3 py-20">
<Loader2 className="size-8 animate-spin text-accent" />
<p className="text-sm text-foreground/60">Cargando tus clases...</p>
<p className="text-sm text-foreground/60">{t('absence.loading')}</p>
</div>
) : null}
{detailsFailed || (!details && !detailsPending) ? (
<div className="space-y-3 rounded-2xl border border-danger/20 bg-danger-soft p-6 text-center sm:p-8">
<h2 className="text-xl font-bold text-danger">Enlace no válido</h2>
<h2 className="text-xl font-bold text-danger">{t('absence.invalidTitle')}</h2>
<p className="mx-auto max-w-sm text-sm leading-relaxed text-foreground/70">
No pudimos identificarte con este enlace. Consultá con tu profesor para solicitar uno nuevo.
{t('absence.invalidDescription')}
</p>
</div>
) : null}
@@ -36,18 +38,22 @@ export function AbsenceNotifyView() {
<CalendarX2 className="size-7" />
</div>
<Badge variant="neutral" className="mb-2">
Aviso de ausencia
{t('absence.badge')}
</Badge>
<h1 className="text-2xl font-bold text-primary">Hola, {details.fullName}</h1>
<h1 className="text-2xl font-bold text-primary">{t('absence.greeting', { name: details.fullName })}</h1>
<p className="mt-1 text-sm font-medium text-foreground/80">
Grupo: <span className="text-primary">{details.groupName}</span>
<Trans
t={t}
i18nKey="absence.group"
values={{ group: details.groupName }}
components={{ strong: <span className="text-primary" /> }}
/>
</p>
</div>
{details.sessions.length === 0 ? (
<p className="rounded-xl border border-dashed border-border bg-primary-soft/40 px-4 py-8 text-center text-sm text-foreground/60">
No tenés clases programadas para hoy. Si necesitás avisar de todas formas, contactá a tu
profesor.
{t('absence.noClasses')}
</p>
) : (
<ul className="space-y-3">
@@ -58,7 +64,7 @@ export function AbsenceNotifyView() {
)}
<p className="text-center text-xs leading-relaxed text-foreground/50">
Si avisás con anticipación, tu cupo se libera para una clase de recuperación.
{t('absence.hint')}
</p>
</div>
) : null}

View File

@@ -1,6 +1,8 @@
import { CheckCircle2, Loader2 } from 'lucide-react'
import { Button } from '../../components/ui'
import { useAbsenceNotify } from './AbsenceNotifyProvider'
import { useTranslation } from 'react-i18next'
import { useIntlLocale } from '../../i18n'
type AbsenceSession = {
sessionId: string
@@ -11,22 +13,20 @@ type AbsenceSession = {
export function AbsenceSessionRow({ session }: { session: AbsenceSession }) {
const { isNotified, isNotifying, notify } = useAbsenceNotify()
const time = new Date(session.startsAt).toLocaleTimeString('es-MX', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
})
const { t } = useTranslation('public')
const locale = useIntlLocale()
const time = new Date(session.startsAt).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })
return (
<li className="flex items-center justify-between gap-3 rounded-xl border border-border bg-primary-soft/30 px-4 py-3">
<div className="min-w-0">
<p className="text-sm font-semibold text-primary">Hoy · {time} hs</p>
<p className="text-sm font-semibold text-primary">{t('absence.today', { time })}</p>
<p className="truncate text-xs text-foreground/60">{session.groupName}</p>
</div>
{isNotified(session) ? (
<span className="inline-flex shrink-0 items-center gap-1.5 rounded-full bg-success-soft px-2.5 py-1 text-xs font-medium text-success">
<CheckCircle2 className="size-3.5" />
Ya avisaste
{t('absence.notified')}
</span>
) : (
<Button
@@ -36,7 +36,7 @@ export function AbsenceSessionRow({ session }: { session: AbsenceSession }) {
onClick={() => notify(session.sessionId)}
>
{isNotifying(session.sessionId) ? <Loader2 className="size-4 animate-spin" /> : null}
Avisar ausencia
{t('absence.notify')}
</Button>
)}
</li>

View File

@@ -2,9 +2,11 @@ import { CalendarClock, GraduationCap, Users } from 'lucide-react'
import { Badge } from '../../components/ui'
import { billingTypeLabel, formatPrice, formatSchedule } from '../../lib/format'
import { useJoinGroup } from './JoinGroupProvider'
import { Trans, useTranslation } from 'react-i18next'
export function GroupInviteSummary() {
const { group } = useJoinGroup()
const { t } = useTranslation('public')
if (!group) return null
return (
@@ -12,12 +14,17 @@ export function GroupInviteSummary() {
<div className="mb-2 flex items-center gap-2">
<Badge variant="neutral" className="gap-1 text-[11px]">
<GraduationCap className="size-3.5 text-accent" />
<span>Invitación Oficial</span>
<span>{t('join.badge')}</span>
</Badge>
</div>
<h1 className="text-2xl font-bold text-primary">{group.name}</h1>
<p className="mt-1 text-sm font-medium text-foreground/80">
Profesor: <span className="font-semibold text-primary">{group.teacherName}</span>
<Trans
t={t}
i18nKey="join.teacher"
values={{ name: group.teacherName }}
components={{ strong: <span className="font-semibold text-primary" /> }}
/>
</p>
{group.description ? <p className="mt-2 text-sm text-foreground/60">{group.description}</p> : null}
@@ -39,14 +46,13 @@ export function GroupInviteSummary() {
{group.capacity ? (
<div className="inline-flex items-center gap-1.5 rounded-lg bg-primary-soft px-2.5 py-1 text-foreground/80">
<Users className="size-3.5 text-accent" />
<span>Cupo {group.capacity}</span>
<span>{t('join.capacity', { count: group.capacity })}</span>
</div>
) : null}
</div>
<p className="mt-3 text-xs leading-relaxed text-foreground/60">
Al completar el formulario envías una solicitud de pre-inscripción. El profesor revisará tus
datos y te confirmará el lugar.
{t('join.notice')}
</p>
</div>
)

View File

@@ -1,10 +1,12 @@
import { useTranslation } from 'react-i18next'
export function InvalidInviteCard() {
const { t } = useTranslation('public')
return (
<div className="space-y-3 rounded-2xl border border-danger/20 bg-danger-soft p-6 text-center sm:p-8">
<h2 className="text-xl font-bold text-danger">Enlace no válido o expirado</h2>
<h2 className="text-xl font-bold text-danger">{t('join.invalidTitle')}</h2>
<p className="mx-auto max-w-sm text-sm text-foreground/70">
No pudimos encontrar este grupo. Por favor consulta con tu profesor para solicitar un nuevo enlace de
invitación.
{t('join.invalidDescription')}
</p>
</div>
)

View File

@@ -1,6 +1,7 @@
import { Loader2 } from 'lucide-react'
import { Button, Input, Label } from '../../components/ui'
import { useJoinGroup } from './JoinGroupProvider'
import { useTranslation } from 'react-i18next'
export function JoinForm() {
const {
@@ -16,13 +17,14 @@ export function JoinForm() {
submit,
isSubmitting,
} = useJoinGroup()
const { t } = useTranslation('public')
return (
<div className="space-y-6">
<div>
<h2 className="text-lg font-bold text-primary">Completa tus datos</h2>
<h2 className="text-lg font-bold text-primary">{t('join.formTitle')}</h2>
<p className="mt-0.5 text-xs text-foreground/60">
Ingresa tus datos para registrarte en la lista de alumnos de este grupo.
{t('join.formDescription')}
</p>
</div>
@@ -42,11 +44,11 @@ export function JoinForm() {
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
<div>
<Label htmlFor="student-first-name" className="mb-1 block text-xs">
Nombre <span className="text-danger">*</span>
{t('join.firstName')} <span className="text-danger">*</span>
</Label>
<Input
id="student-first-name"
placeholder="Ej. Sofía"
placeholder={t('join.firstNamePlaceholder')}
value={firstName}
onChange={(e) => setFirstName(e.target.value)}
required
@@ -55,11 +57,11 @@ export function JoinForm() {
<div>
<Label htmlFor="student-last-name" className="mb-1 block text-xs">
Apellido <span className="text-danger">*</span>
{t('join.lastName')} <span className="text-danger">*</span>
</Label>
<Input
id="student-last-name"
placeholder="Ej. Fernández"
placeholder={t('join.lastNamePlaceholder')}
value={lastName}
onChange={(e) => setLastName(e.target.value)}
required
@@ -69,28 +71,28 @@ export function JoinForm() {
<div>
<Label htmlFor="student-phone" className="mb-1 block text-xs">
Teléfono / WhatsApp <span className="text-danger">*</span>
{t('join.phone')} <span className="text-danger">*</span>
</Label>
<Input
id="student-phone"
placeholder="Ej. +54 9 11 2345-6789"
placeholder={t('join.phonePlaceholder')}
value={phone}
onChange={(e) => setPhone(e.target.value)}
required
/>
<p className="mt-1 text-[11px] text-foreground/50">
El profesor se comunicará contigo por WhatsApp a este número.
{t('join.phoneHint')}
</p>
</div>
<div>
<Label htmlFor="student-email" className="mb-1 block text-xs">
Email (opcional)
{t('join.email')}
</Label>
<Input
id="student-email"
type="email"
placeholder="alumno@ejemplo.com"
placeholder={t('join.emailPlaceholder')}
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
@@ -104,7 +106,7 @@ export function JoinForm() {
className="w-full gap-2 py-2.5 text-sm font-semibold"
>
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
<span>Enviar Solicitud</span>
<span>{t('join.submit')}</span>
</Button>
</div>
</form>

View File

@@ -3,6 +3,9 @@ import type { ReactNode } from 'react'
import { useMutation, useQuery } from '@tanstack/react-query'
import type { GroupInviteInfoDto } from '@gruperly/shared'
import { ApiError, getInviteInfo, joinViaInvite } from '../../lib/api'
import { useTranslation } from 'react-i18next'
import { errorMessage as apiErrorMessage } from '../../i18n'
import { i18n } from '../../i18n/instance'
type JoinGroupContextValue = {
token: string
@@ -26,6 +29,7 @@ type JoinGroupContextValue = {
const JoinGroupContext = createContext<JoinGroupContextValue | null>(null)
export function JoinGroupProvider({ token, children }: { token: string; children: ReactNode }) {
useTranslation()
const [firstName, setFirstName] = useState('')
const [lastName, setLastName] = useState('')
const [phone, setPhone] = useState('')
@@ -50,41 +54,33 @@ export function JoinGroupProvider({ token, children }: { token: string; children
}),
onSuccess: (data) => {
setErrorMessage(null)
setPreRegistrationMessage(data.message)
// The API's `message` is Spanish only: the card words it in the UI language.
void data
setPreRegistrationMessage(i18n.t('public:join.sentMessage'))
},
onError: (error: unknown) => {
if (error instanceof ApiError) {
if (error.problem?.code === 'attendee_already_registered') {
setErrorMessage(
'Ya te encuentras registrado en este grupo con ese número de teléfono. El profesor ya tiene tus datos.',
)
setErrorMessage(i18n.t('public:join.alreadyRegistered'))
return
}
if (error.problem?.code === 'pre_registration_already_pending') {
setErrorMessage(
'Ya enviaste una solicitud de inscripción para este grupo y está pendiente de revisión. Pronto recibirás novedades.',
)
setErrorMessage(i18n.t('public:join.alreadyPending'))
return
}
if (error.problem?.code === 'pre_registration_already_approved') {
setErrorMessage('Tu inscripción para este grupo ya fue aprobada.')
setErrorMessage(i18n.t('public:join.alreadyApproved'))
return
}
setErrorMessage(error.message || 'Error al procesar la inscripción.')
return
}
if (error instanceof Error) {
setErrorMessage(error.message)
return
}
setErrorMessage('Ocurrió un error inesperado. Por favor, intenta de nuevo.')
setErrorMessage(apiErrorMessage(error, i18n.t('public:join.error')))
},
})
const submit = () => {
setErrorMessage(null)
if (!firstName.trim() || !lastName.trim() || !phone.trim()) {
setErrorMessage('Por favor completa los campos requeridos (Nombre, Apellido y Teléfono).')
setErrorMessage(i18n.t('public:join.required'))
return
}
joinMutation.mutate()

View File

@@ -5,9 +5,11 @@ import { InvalidInviteCard } from './InvalidInviteCard'
import { JoinForm } from './JoinForm'
import { useJoinGroup } from './JoinGroupProvider'
import { PreRegistrationNoticeCard } from './PreRegistrationNoticeCard'
import { useTranslation } from 'react-i18next'
export function JoinGroupView() {
const { group, invitePending, inviteFailed, preRegistrationMessage } = useJoinGroup()
const { t } = useTranslation('public')
return (
<div className="flex min-h-screen flex-col justify-between bg-background text-primary selection:bg-accent selection:text-white">
@@ -18,7 +20,7 @@ export function JoinGroupView() {
{invitePending ? (
<div className="flex flex-col items-center justify-center gap-3 py-20">
<Loader2 className="size-8 animate-spin text-accent" />
<p className="text-sm text-foreground/60">Cargando información del grupo...</p>
<p className="text-sm text-foreground/60">{t('join.loading')}</p>
</div>
) : null}

View File

@@ -1,9 +1,11 @@
import { Clock } from 'lucide-react'
import { Badge } from '../../components/ui'
import { useJoinGroup } from './JoinGroupProvider'
import { Trans, useTranslation } from 'react-i18next'
export function PreRegistrationNoticeCard() {
const { group, preRegistrationMessage } = useJoinGroup()
const { t } = useTranslation('public')
if (!group || !preRegistrationMessage) return null
return (
@@ -14,16 +16,19 @@ export function PreRegistrationNoticeCard() {
<div>
<Badge variant="neutral" className="mb-2">
Pre-inscripción
{t('join.sentBadge')}
</Badge>
<h1 className="text-2xl font-bold text-primary">Solicitud enviada</h1>
<h1 className="text-2xl font-bold text-primary">{t('join.sentTitle')}</h1>
<p className="mt-2 text-sm leading-relaxed text-foreground/70">{preRegistrationMessage}</p>
</div>
<p className="text-xs text-foreground/60">
El profesor revisará tu solicitud para el grupo{' '}
<strong className="font-semibold text-primary">{group.name}</strong> y se pondrá en contacto
contigo por WhatsApp para confirmarte el lugar.
<Trans
t={t}
i18nKey="join.sentFooter"
values={{ group: group.name }}
components={{ strong: <strong className="font-semibold text-primary" /> }}
/>
</p>
</div>
)