diff --git a/apps/web/src/features/home/AttentionList.tsx b/apps/web/src/features/home/AttentionList.tsx index f707c28..9dac80b 100644 --- a/apps/web/src/features/home/AttentionList.tsx +++ b/apps/web/src/features/home/AttentionList.tsx @@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query' import { Link } from '@tanstack/react-router' import type { PendingPreRegistrations } from '@gruperly/shared' import { CheckCircle2, ChevronRight, Inbox, Wallet } from 'lucide-react' +import { useTranslation } from 'react-i18next' import { Avatar } from '../../components/ui' import { getGroupsRiskOverview, getPayments } from '../../lib/api' import { absenceReason } from '../groups/card' @@ -19,6 +20,7 @@ export function AttentionList({ }: { pendingPreRegistrations: PendingPreRegistrations[] }) { + const { t } = useTranslation('home') const riskQuery = useQuery({ queryKey: ['groups-risk-overview'], queryFn: getGroupsRiskOverview, @@ -45,12 +47,12 @@ export function AttentionList({ return (
-

Para atender

+

{t('attention.title')}

{atRisk.length === 0 && overdue === 0 && pendingPreRegistrations.length === 0 ? (

) : ( diff --git a/apps/web/src/features/home/HomeView.tsx b/apps/web/src/features/home/HomeView.tsx index 7f16658..04a826c 100644 --- a/apps/web/src/features/home/HomeView.tsx +++ b/apps/web/src/features/home/HomeView.tsx @@ -1,8 +1,10 @@ import { useQuery } from '@tanstack/react-query' import { Link, useNavigate } from '@tanstack/react-router' import { Loader2, Plus } from 'lucide-react' +import { useTranslation } from 'react-i18next' import { Button } from '../../components/ui' import { useAuth } from '../../context/AuthProvider' +import { useIntlLocale } from '../../i18n' import { getClassesToday, getHomeSummary } from '../../lib/api' import { useMpStatus } from '../mp/useMpStatus' import { AttentionList } from './AttentionList' @@ -13,11 +15,13 @@ import { UpcomingPaymentRow } from './UpcomingPaymentRow' export function HomeView() { const navigate = useNavigate() + const { t } = useTranslation(['home', 'common']) + const locale = useIntlLocale() const { user } = useAuth() const mpStatusQuery = useMpStatus() const firstName = user?.name?.trim().split(/\s+/)[0] // "martes 27 de octubre": the date anchors "Clase de hoy" and the due dates below. - const today = new Date().toLocaleDateString('es-AR', { + const today = new Date().toLocaleDateString(locale, { weekday: 'long', day: 'numeric', month: 'long', @@ -38,7 +42,7 @@ export function HomeView() {

{today}

- {firstName ? `Hola, ${firstName}` : 'Hola'} + {firstName ? t('greetingName', { name: firstName }) : t('greeting')}

@@ -50,18 +54,18 @@ export function HomeView() { {summaryQuery.isError ? (
-

No pudimos cargar tu resumen.

+

{t('loadError')}

) : null} {summaryQuery.isSuccess && summaryQuery.data.stats.groups === 0 ? (
-

Todavía no tenés grupos

+

{t('empty.title')}

- Crea tu primer grupo para empezar a cobrar. + {t('empty.description')}

) : null} @@ -86,9 +90,9 @@ export function HomeView() { ) : (
-

Sin clases programadas

+

{t('noClasses.title')}

- Agregá días y horario a tus grupos para ver tu próxima clase acá. + {t('noClasses.description')}

)} @@ -99,9 +103,9 @@ export function HomeView() {
-

Próximos cobros

+

{t('upcoming.title')}

@@ -113,7 +117,7 @@ export function HomeView() { ) : (
-

Sin cobros pendientes por ahora.

+

{t('upcoming.empty')}

{/* The empty state says how to get out of it: without Mercado Pago there is no way to create payment links. */} {mpStatusQuery.data && mpStatusQuery.data.status !== 'active' ? ( @@ -121,10 +125,10 @@ export function HomeView() { to="/settings" className="mt-2 inline-block font-medium text-accent hover:underline" > - Vinculá Mercado Pago para cobrar + {t('upcoming.linkMp')} ) : ( -

Los creás desde la ficha de cada grupo.

+

{t('upcoming.hint')}

)}
)} diff --git a/apps/web/src/features/home/NextClassHero.tsx b/apps/web/src/features/home/NextClassHero.tsx index fab5834..e716e41 100644 --- a/apps/web/src/features/home/NextClassHero.tsx +++ b/apps/web/src/features/home/NextClassHero.tsx @@ -1,11 +1,13 @@ import { useNavigate } from '@tanstack/react-router' import type { NextClassDto } from '@gruperly/shared' import { CalendarClock } from 'lucide-react' +import { useTranslation } from 'react-i18next' import { Badge, Button } from '../../components/ui' import { formatRelativeDateTime, formatSchedule } from '../../lib/format' export function NextClassHero({ nextClass }: { nextClass: NextClassDto }) { const navigate = useNavigate() + const { t } = useTranslation('home') const hasSchedule = (nextClass.days?.length ?? 0) > 0 return ( @@ -13,7 +15,7 @@ export function NextClassHero({ nextClass }: { nextClass: NextClassDto }) {

- {nextClass.isNow ? 'Clase en curso' : 'Próxima clase'} + {nextClass.isNow ? t('nextClass.now') : t('nextClass.next')}

{nextClass.name}

{hasSchedule ? ( @@ -25,7 +27,7 @@ export function NextClassHero({ nextClass }: { nextClass: NextClassDto }) {
- {nextClass.isNow ? 'En curso ahora' : formatRelativeDateTime(nextClass.occurrenceAt)} + {nextClass.isNow ? t('nextClass.nowBadge') : formatRelativeDateTime(nextClass.occurrenceAt)}
@@ -35,7 +37,7 @@ export function NextClassHero({ nextClass }: { nextClass: NextClassDto }) { size="sm" onClick={() => void navigate({ to: `/groups/${nextClass.groupId}` })} > - Ver grupo + {t('nextClass.seeGroup')}
diff --git a/apps/web/src/features/home/SummaryStats.tsx b/apps/web/src/features/home/SummaryStats.tsx index 94e8bcb..6dd4a35 100644 --- a/apps/web/src/features/home/SummaryStats.tsx +++ b/apps/web/src/features/home/SummaryStats.tsx @@ -1,6 +1,7 @@ import { useNavigate } from '@tanstack/react-router' import type { HomeSummaryDto } from '@gruperly/shared' import { UserCheck, Users, Wallet, type LucideIcon } from 'lucide-react' +import { useTranslation } from 'react-i18next' import { cn } from '../../lib/utils' import { formatPrice } from '../../lib/format' @@ -12,6 +13,7 @@ type StatTarget = '/groups' | '/payments' the label for a sub-line and read "0 / 0 por cobrar". */ export function SummaryStats({ summary }: { summary: HomeSummaryDto }) { const navigate = useNavigate() + const { t } = useTranslation('home') const { pendingAmount, pendingPayments } = summary.stats const stats: { label: string @@ -20,19 +22,19 @@ export function SummaryStats({ summary }: { summary: HomeSummaryDto }) { to: StatTarget }[] = [ { - label: summary.stats.groups === 1 ? 'Grupo' : 'Grupos', + label: t('stats.groups', { count: summary.stats.groups }), value: String(summary.stats.groups), icon: Users, to: '/groups', }, { - label: pendingPayments > 0 ? `Por cobrar · ${pendingPayments}` : 'Por cobrar', + label: pendingPayments > 0 ? t('stats.toCollectCount', { count: pendingPayments }) : t('stats.toCollect'), value: formatPrice(pendingAmount), icon: Wallet, to: '/payments', }, { - label: summary.stats.attendees === 1 ? 'Alumno' : 'Alumnos', + label: t('stats.students', { count: summary.stats.attendees }), value: String(summary.stats.attendees), icon: UserCheck, to: '/groups', diff --git a/apps/web/src/features/home/TodayClassCard.tsx b/apps/web/src/features/home/TodayClassCard.tsx index d6664e0..cc25e80 100644 --- a/apps/web/src/features/home/TodayClassCard.tsx +++ b/apps/web/src/features/home/TodayClassCard.tsx @@ -1,25 +1,25 @@ import { Link, useNavigate } from '@tanstack/react-router' import type { ClassTodayDto } from '@gruperly/shared' import { CalendarClock, ChevronRight, ClipboardCheck } from 'lucide-react' +import { useTranslation } from 'react-i18next' import { Badge, Button } from '../../components/ui' +import { useIntlLocale } from '../../i18n' export function TodayClassCard({ item }: { item: ClassTodayDto }) { const navigate = useNavigate() - const time = new Date(item.startsAt).toLocaleTimeString('es-MX', { - hour: '2-digit', - minute: '2-digit', - hour12: false, - }) + const { t } = useTranslation('home') + const locale = useIntlLocale() + const time = new Date(item.startsAt).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' }) return (

- Clase de hoy + {t('today.label')}

{/* Only the done state earns a badge: "Por tomar" repeated what the button below already says. */} - {item.hasAttendance ? Asistencia tomada : null} + {item.hasAttendance ? {t('today.attendanceTaken')} : null}
- Hoy · {time} hs + {t('today.time', { time })}

- {item.enrolledCount} inscrito{item.enrolledCount === 1 ? '' : 's'} - {item.availableSlots != null - ? ` · ${item.availableSlots} cupo${item.availableSlots === 1 ? '' : 's'} disponible${item.availableSlots === 1 ? '' : 's'}` - : ''} + {t('today.enrolled', { count: item.enrolledCount })} + {item.availableSlots != null ? ` · ${t('today.slots', { count: item.availableSlots })}` : ''}

) diff --git a/apps/web/src/features/home/UpcomingPaymentRow.tsx b/apps/web/src/features/home/UpcomingPaymentRow.tsx index de49f13..8a1d36b 100644 --- a/apps/web/src/features/home/UpcomingPaymentRow.tsx +++ b/apps/web/src/features/home/UpcomingPaymentRow.tsx @@ -1,9 +1,12 @@ import type { UpcomingPaymentDto } from '@gruperly/shared' +import { useTranslation } from 'react-i18next' import { Badge } from '../../components/ui' import { formatPrice, formatRelativeDateTime, paymentStatusLabel } from '../../lib/format' import { PAYMENT_BADGE_VARIANT } from './constants' export function UpcomingPaymentRow({ payment }: { payment: UpcomingPaymentDto }) { + // Re-render on language change: the labels come from lib/format. + useTranslation() return (
  • diff --git a/apps/web/src/i18n/i18next.d.ts b/apps/web/src/i18n/i18next.d.ts index 7bd3341..109f7c0 100644 --- a/apps/web/src/i18n/i18next.d.ts +++ b/apps/web/src/i18n/i18next.d.ts @@ -5,6 +5,7 @@ import type errors from './locales/es-AR/errors.json' import type layout from './locales/es-AR/layout.json' import type pwa from './locales/es-AR/pwa.json' import type settings from './locales/es-AR/settings.json' +import type home from './locales/es-AR/home.json' import type validation from './locales/es-AR/validation.json' // es-AR es la fuente: una clave que no exista ahí rompe el typecheck. @@ -19,6 +20,7 @@ declare module 'i18next' { pwa: typeof pwa settings: typeof settings validation: typeof validation + 'home': typeof home } } } diff --git a/apps/web/src/i18n/instance.ts b/apps/web/src/i18n/instance.ts index 54dc2d9..7c17dda 100644 --- a/apps/web/src/i18n/instance.ts +++ b/apps/web/src/i18n/instance.ts @@ -12,6 +12,7 @@ export const NAMESPACES = [ 'pwa', 'errors', 'validation', + 'home', ] as const export type Namespace = (typeof NAMESPACES)[number] diff --git a/apps/web/src/i18n/locales/en/home.json b/apps/web/src/i18n/locales/en/home.json new file mode 100644 index 0000000..2d748c6 --- /dev/null +++ b/apps/web/src/i18n/locales/en/home.json @@ -0,0 +1,56 @@ +{ + "greeting": "Hi", + "greetingName": "Hi, {{name}}", + "loadError": "We couldn't load your summary.", + "empty": { + "title": "You don't have any groups yet", + "description": "Create your first group to start collecting payments.", + "cta": "Create your first group" + }, + "noClasses": { + "title": "No classes scheduled", + "description": "Add days and times to your groups to see your next class here." + }, + "upcoming": { + "title": "Upcoming payments", + "seeAll": "See all", + "empty": "No pending payments for now.", + "linkMp": "Link Mercado Pago to get paid", + "hint": "You create them from each group's page." + }, + "stats": { + "groups_one": "Group", + "groups_other": "Groups", + "toCollect": "To collect", + "toCollectCount": "To collect · {{count}}", + "students_one": "Student", + "students_other": "Students" + }, + "nextClass": { + "now": "Class in progress", + "next": "Next class", + "nowBadge": "Happening now", + "seeGroup": "View group" + }, + "today": { + "label": "Today's class", + "attendanceTaken": "Attendance taken", + "time": "Today · {{time}}", + "enrolled_one": "{{count}} enrolled", + "enrolled_other": "{{count}} enrolled", + "slots_one": "{{count}} spot left", + "slots_other": "{{count}} spots left", + "seeAttendance": "View attendance", + "takeAttendance": "Take attendance" + }, + "attention": { + "title": "Needs attention", + "allGood": "All good: no one at risk, no overdue payments or pre-registrations.", + "overdue_one": "{{count}} overdue payment", + "overdue_other": "{{count}} overdue payments", + "overdueHint": "Review them in Payments", + "preRegistrations_one": "{{count}} pre-registration to approve", + "preRegistrations_other": "{{count}} pre-registrations to approve", + "moreAtRisk": "And {{count}} more at risk. Check each group's stats." + } +} diff --git a/apps/web/src/i18n/locales/es-419/home.json b/apps/web/src/i18n/locales/es-419/home.json new file mode 100644 index 0000000..8a0fe2e --- /dev/null +++ b/apps/web/src/i18n/locales/es-419/home.json @@ -0,0 +1,56 @@ +{ + "greeting": "Hola", + "greetingName": "Hola, {{name}}", + "loadError": "No pudimos cargar tu resumen.", + "empty": { + "title": "Todavía no tienes grupos", + "description": "Crea tu primer grupo para empezar a cobrar.", + "cta": "Crear tu primer grupo" + }, + "noClasses": { + "title": "Sin clases programadas", + "description": "Agrega días y horario a tus grupos para ver aquí tu próxima clase." + }, + "upcoming": { + "title": "Próximos cobros", + "seeAll": "Ver todos", + "empty": "Sin cobros pendientes por ahora.", + "linkMp": "Vincula Mercado Pago para cobrar", + "hint": "Los creas desde la ficha de cada grupo." + }, + "stats": { + "groups_one": "Grupo", + "groups_other": "Grupos", + "toCollect": "Por cobrar", + "toCollectCount": "Por cobrar · {{count}}", + "students_one": "Alumno", + "students_other": "Alumnos" + }, + "nextClass": { + "now": "Clase en curso", + "next": "Próxima clase", + "nowBadge": "En curso ahora", + "seeGroup": "Ver grupo" + }, + "today": { + "label": "Clase de hoy", + "attendanceTaken": "Asistencia tomada", + "time": "Hoy · {{time}} h", + "enrolled_one": "{{count}} inscrito", + "enrolled_other": "{{count}} inscritos", + "slots_one": "{{count}} lugar disponible", + "slots_other": "{{count}} lugares disponibles", + "seeAttendance": "Ver asistencia", + "takeAttendance": "Tomar asistencia" + }, + "attention": { + "title": "Para atender", + "allGood": "Todo en orden: nadie en riesgo, sin cobros vencidos ni preinscripciones.", + "overdue_one": "{{count}} cobro vencido", + "overdue_other": "{{count}} cobros vencidos", + "overdueHint": "Revísalos en Cobros", + "preRegistrations_one": "{{count}} preinscripción por aprobar", + "preRegistrations_other": "{{count}} preinscripciones por aprobar", + "moreAtRisk": "Y {{count}} más en riesgo. Revisa las estadísticas de cada grupo." + } +} diff --git a/apps/web/src/i18n/locales/es-AR/home.json b/apps/web/src/i18n/locales/es-AR/home.json new file mode 100644 index 0000000..0b05580 --- /dev/null +++ b/apps/web/src/i18n/locales/es-AR/home.json @@ -0,0 +1,56 @@ +{ + "greeting": "Hola", + "greetingName": "Hola, {{name}}", + "loadError": "No pudimos cargar tu resumen.", + "empty": { + "title": "Todavía no tenés grupos", + "description": "Creá tu primer grupo para empezar a cobrar.", + "cta": "Crear tu primer grupo" + }, + "noClasses": { + "title": "Sin clases programadas", + "description": "Agregá días y horario a tus grupos para ver tu próxima clase acá." + }, + "upcoming": { + "title": "Próximos cobros", + "seeAll": "Ver todos", + "empty": "Sin cobros pendientes por ahora.", + "linkMp": "Vinculá Mercado Pago para cobrar", + "hint": "Los creás desde la ficha de cada grupo." + }, + "stats": { + "groups_one": "Grupo", + "groups_other": "Grupos", + "toCollect": "Por cobrar", + "toCollectCount": "Por cobrar · {{count}}", + "students_one": "Alumno", + "students_other": "Alumnos" + }, + "nextClass": { + "now": "Clase en curso", + "next": "Próxima clase", + "nowBadge": "En curso ahora", + "seeGroup": "Ver grupo" + }, + "today": { + "label": "Clase de hoy", + "attendanceTaken": "Asistencia tomada", + "time": "Hoy · {{time}} hs", + "enrolled_one": "{{count}} inscrito", + "enrolled_other": "{{count}} inscritos", + "slots_one": "{{count}} cupo disponible", + "slots_other": "{{count}} cupos disponibles", + "seeAttendance": "Ver asistencia", + "takeAttendance": "Tomar asistencia" + }, + "attention": { + "title": "Para atender", + "allGood": "Todo en orden: nadie en riesgo, sin cobros vencidos ni preinscripciones.", + "overdue_one": "{{count}} cobro vencido", + "overdue_other": "{{count}} cobros vencidos", + "overdueHint": "Revisalos en Cobros", + "preRegistrations_one": "{{count}} preinscripción por aprobar", + "preRegistrations_other": "{{count}} preinscripciones por aprobar", + "moreAtRisk": "Y {{count}} más en riesgo. Mirá las estadísticas de cada grupo." + } +} diff --git a/apps/web/src/i18n/locales/pt-BR/home.json b/apps/web/src/i18n/locales/pt-BR/home.json new file mode 100644 index 0000000..a5b6b49 --- /dev/null +++ b/apps/web/src/i18n/locales/pt-BR/home.json @@ -0,0 +1,56 @@ +{ + "greeting": "Olá", + "greetingName": "Olá, {{name}}", + "loadError": "Não conseguimos carregar seu resumo.", + "empty": { + "title": "Você ainda não tem grupos", + "description": "Crie seu primeiro grupo para começar a cobrar.", + "cta": "Criar seu primeiro grupo" + }, + "noClasses": { + "title": "Nenhuma aula agendada", + "description": "Adicione dias e horário aos seus grupos para ver sua próxima aula aqui." + }, + "upcoming": { + "title": "Próximas cobranças", + "seeAll": "Ver todas", + "empty": "Nenhuma cobrança pendente por enquanto.", + "linkMp": "Vincule o Mercado Pago para cobrar", + "hint": "Você cria as cobranças na página de cada grupo." + }, + "stats": { + "groups_one": "Grupo", + "groups_other": "Grupos", + "toCollect": "A receber", + "toCollectCount": "A receber · {{count}}", + "students_one": "Aluno", + "students_other": "Alunos" + }, + "nextClass": { + "now": "Aula em andamento", + "next": "Próxima aula", + "nowBadge": "Acontecendo agora", + "seeGroup": "Ver grupo" + }, + "today": { + "label": "Aula de hoje", + "attendanceTaken": "Presença registrada", + "time": "Hoje · {{time}}", + "enrolled_one": "{{count}} inscrito", + "enrolled_other": "{{count}} inscritos", + "slots_one": "{{count}} vaga disponível", + "slots_other": "{{count}} vagas disponíveis", + "seeAttendance": "Ver presença", + "takeAttendance": "Fazer chamada" + }, + "attention": { + "title": "Para resolver", + "allGood": "Tudo certo: ninguém em risco, sem cobranças vencidas nem pré-inscrições.", + "overdue_one": "{{count}} cobrança vencida", + "overdue_other": "{{count}} cobranças vencidas", + "overdueHint": "Confira em Cobranças", + "preRegistrations_one": "{{count}} pré-inscrição para aprovar", + "preRegistrations_other": "{{count}} pré-inscrições para aprovar", + "moreAtRisk": "E mais {{count}} em risco. Veja as estatísticas de cada grupo." + } +} diff --git a/apps/web/src/lib/format.ts b/apps/web/src/lib/format.ts index f365c9b..f74b09d 100644 --- a/apps/web/src/lib/format.ts +++ b/apps/web/src/lib/format.ts @@ -37,11 +37,8 @@ function startOfDay(date: Date): number { export function formatRelativeDateTime(iso: string, now: Date = new Date()): string { const locale = i18n.language const date = new Date(iso) - const time = date.toLocaleTimeString(locale, { - hour: '2-digit', - minute: '2-digit', - hour12: false, - }) + // No hour cycle is forced: each language uses its own (24 h in es/pt, 12 h in en). + const time = date.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' }) const diffDays = Math.round((startOfDay(date) - startOfDay(now)) / DAY_MS) if (diffDays === 0) return i18n.t('common:relativeDay.today', { time })