feat(i18n): traducir Requiere atención y redactar las alertas en cada idioma
Las alertas de shared suman razon + valores para que la web las redacte; etiqueta/detalle se mantienen en español para el backend. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { Check } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { AlertTag } from './AlertTag'
|
||||
import { reminderMessage, whatsappLink, type AttentionItem } from './attention'
|
||||
import { alertDetail, alertLabel, reminderMessage, whatsappLink, type AttentionItem } from './attention'
|
||||
import { SeverityAvatar } from './SeverityAvatar'
|
||||
|
||||
const ACTION_CLASS =
|
||||
@@ -15,10 +16,12 @@ type AttentionCardProps = {
|
||||
|
||||
export function AttentionCard({ item, onResolve }: AttentionCardProps) {
|
||||
const { student, alert } = item
|
||||
const { t } = useTranslation('attention')
|
||||
const label = alertLabel(alert)
|
||||
const urgent = alert.gravedad === 'urgente'
|
||||
const isPayment = alert.tipo === 'pago'
|
||||
|
||||
const actionLabel = isPayment ? 'Enviar recordatorio' : 'Contactar'
|
||||
const actionLabel = isPayment ? t('card.remind') : t('card.contact')
|
||||
const href = whatsappLink(student, isPayment ? reminderMessage(student) : undefined)
|
||||
// Urgent: light fill, the strongest action on screen. To watch: subtle gray.
|
||||
const primaryTone = urgent
|
||||
@@ -39,10 +42,10 @@ export function AttentionCard({ item, onResolve }: AttentionCardProps) {
|
||||
</Link>
|
||||
<p className="truncate text-sm text-secondary">{student.groupName}</p>
|
||||
</div>
|
||||
<AlertTag severity={alert.gravedad}>{alert.etiqueta}</AlertTag>
|
||||
<AlertTag severity={alert.gravedad}>{label}</AlertTag>
|
||||
</div>
|
||||
|
||||
<p className="mt-3 text-sm text-primary">{alert.detalle}</p>
|
||||
<p className="mt-3 text-sm text-primary">{alertDetail(alert)}</p>
|
||||
|
||||
<div className="mt-3 grid grid-cols-2 gap-2">
|
||||
{href ? (
|
||||
@@ -50,7 +53,7 @@ export function AttentionCard({ item, onResolve }: AttentionCardProps) {
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={`${actionLabel} a ${student.fullName} por WhatsApp`}
|
||||
aria-label={t('card.actionWhatsapp', { action: actionLabel, name: student.fullName })}
|
||||
className={cn(ACTION_CLASS, primaryTone)}
|
||||
>
|
||||
{actionLabel}
|
||||
@@ -59,7 +62,7 @@ export function AttentionCard({ item, onResolve }: AttentionCardProps) {
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
aria-label={`${actionLabel}: ${student.fullName} no tiene teléfono cargado`}
|
||||
aria-label={t('card.noPhone', { action: actionLabel, name: student.fullName })}
|
||||
className={cn(ACTION_CLASS, primaryTone, 'cursor-not-allowed opacity-45')}
|
||||
>
|
||||
{actionLabel}
|
||||
@@ -68,11 +71,11 @@ export function AttentionCard({ item, onResolve }: AttentionCardProps) {
|
||||
<button
|
||||
type="button"
|
||||
onClick={onResolve}
|
||||
aria-label={`Marcar como resuelto: ${student.fullName}, ${alert.etiqueta}`}
|
||||
aria-label={t('card.resolveLabel', { name: student.fullName, alert: label })}
|
||||
className={cn(ACTION_CLASS, 'border border-border text-primary hover:bg-primary-soft')}
|
||||
>
|
||||
<Check className="size-4" aria-hidden="true" />
|
||||
Resuelto
|
||||
{t('card.resolve')}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { ArrowLeft, ListFilter } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useImmersiveBarHost } from '../../context/ImmersiveBarProvider'
|
||||
|
||||
@@ -10,18 +11,19 @@ import { useImmersiveBarHost } from '../../context/ImmersiveBarProvider'
|
||||
sticky box, like `LargeTitle`. */
|
||||
export function AttentionHeader({ subtitle }: { subtitle: string }) {
|
||||
const host = useImmersiveBarHost()
|
||||
const { t } = useTranslation('attention')
|
||||
|
||||
const bar = (
|
||||
<div className="flex h-full items-center gap-1 border-b border-border bg-background/90 px-2 backdrop-blur-md lg:px-0">
|
||||
<Link
|
||||
to="/groups"
|
||||
aria-label="Volver"
|
||||
aria-label={t('back')}
|
||||
className="inline-flex size-11 shrink-0 items-center justify-center rounded-xl text-primary hover:bg-primary-soft focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none"
|
||||
>
|
||||
<ArrowLeft className="size-5" aria-hidden="true" />
|
||||
</Link>
|
||||
<div className="min-w-0 flex-1 px-1">
|
||||
<h1 className="truncate text-base leading-tight font-semibold text-primary">Requiere atención</h1>
|
||||
<h1 className="truncate text-base leading-tight font-semibold text-primary">{t('title')}</h1>
|
||||
<p className="truncate text-xs text-secondary" aria-live="polite">
|
||||
{subtitle}
|
||||
</p>
|
||||
@@ -29,7 +31,7 @@ export function AttentionHeader({ subtitle }: { subtitle: string }) {
|
||||
{/* TODO: ordenar/filtrar por grupo. Por ahora no hace nada. */}
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Ordenar y filtrar"
|
||||
aria-label={t('sortFilter')}
|
||||
className="inline-flex size-11 shrink-0 items-center justify-center rounded-xl text-secondary hover:bg-primary-soft focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none"
|
||||
>
|
||||
<ListFilter className="size-5" aria-hidden="true" />
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createContext, useContext, useMemo, useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type { AttentionOverview, StudentAlert } from '@gruperly/shared'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
import { useToast } from '../../components/ui'
|
||||
import { resolveAlert } from '../../lib/api'
|
||||
import {
|
||||
@@ -49,7 +50,7 @@ export function AttentionProvider({ children }: { children: ReactNode }) {
|
||||
},
|
||||
onError: (_error, _variables, context) => {
|
||||
if (context?.previous) queryClient.setQueryData(attentionQueryOptions.queryKey, context.previous)
|
||||
toast.error('No pudimos marcarlo como resuelto. Probá de nuevo.')
|
||||
toast.error(i18n.t('attention:card.resolveError'))
|
||||
},
|
||||
onSettled: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: attentionQueryOptions.queryKey })
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import type { StudentAlertSeverity } from '@gruperly/shared'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { AttentionCard } from './AttentionCard'
|
||||
import type { AttentionItem } from './attention'
|
||||
|
||||
const SECTIONS: Record<StudentAlertSeverity, { title: string; dot: string; text: string }> = {
|
||||
urgente: { title: 'Urgente', dot: 'bg-alert-urgent-ring', text: 'text-alert-urgent-fg' },
|
||||
vigilar: { title: 'A vigilar', dot: 'bg-alert-watch-ring', text: 'text-alert-watch-fg' },
|
||||
const SECTIONS: Record<StudentAlertSeverity, { dot: string; text: string }> = {
|
||||
urgente: { dot: 'bg-alert-urgent-ring', text: 'text-alert-urgent-fg' },
|
||||
vigilar: { dot: 'bg-alert-watch-ring', text: 'text-alert-watch-fg' },
|
||||
}
|
||||
|
||||
type AttentionSectionProps = {
|
||||
@@ -16,6 +17,7 @@ type AttentionSectionProps = {
|
||||
|
||||
/** One severity block. Not rendered when it is empty. */
|
||||
export function AttentionSection({ severity, items, onResolve }: AttentionSectionProps) {
|
||||
const { t } = useTranslation('attention')
|
||||
if (items.length === 0) return null
|
||||
const section = SECTIONS[severity]
|
||||
const headingId = `attention-${severity}`
|
||||
@@ -27,7 +29,7 @@ export function AttentionSection({ severity, items, onResolve }: AttentionSectio
|
||||
className={cn('flex items-center gap-2 text-xs font-semibold tracking-wider uppercase', section.text)}
|
||||
>
|
||||
<span className={cn('size-2 rounded-full', section.dot)} aria-hidden="true" />
|
||||
{section.title}
|
||||
{t(`sections.${severity}`)}
|
||||
<span aria-hidden="true">·</span>
|
||||
<span className="tabular-nums">{items.length}</span>
|
||||
</h2>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '../../components/ui'
|
||||
import { AttentionHeader } from './AttentionHeader'
|
||||
import { AttentionSection } from './AttentionSection'
|
||||
@@ -9,6 +10,7 @@ import { FilterChips } from './FilterChips'
|
||||
|
||||
export function AttentionView() {
|
||||
const { items, isPending, isError, retry, filter, setFilter, resolve } = useAttention()
|
||||
const { t } = useTranslation(['attention', 'common'])
|
||||
|
||||
const visible = filterItems(items, filter)
|
||||
const { urgente, vigilar } = itemsBySeverity(visible)
|
||||
@@ -16,7 +18,7 @@ export function AttentionView() {
|
||||
|
||||
return (
|
||||
<section className="pb-6">
|
||||
<AttentionHeader subtitle={isPending ? 'Cargando…' : attentionSubtitle(items)} />
|
||||
<AttentionHeader subtitle={isPending ? t('loading') : attentionSubtitle(items)} />
|
||||
|
||||
{/* The chips stay under the bar (56px) while the cards scroll. */}
|
||||
<div className="sticky top-14 z-30 -mx-4 bg-background px-4 lg:mx-0 lg:px-0">
|
||||
@@ -26,13 +28,13 @@ export function AttentionView() {
|
||||
{isPending ? (
|
||||
<div className="flex items-center justify-center py-16" role="status">
|
||||
<Loader2 className="size-6 animate-spin text-secondary/50" aria-hidden="true" />
|
||||
<span className="sr-only">Cargando alertas</span>
|
||||
<span className="sr-only">{t('loadingAlerts')}</span>
|
||||
</div>
|
||||
) : isError ? (
|
||||
<div className="mt-4 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
||||
<p>No pudimos cargar las alertas.</p>
|
||||
<p>{t('loadError')}</p>
|
||||
<Button variant="outline" size="sm" onClick={retry}>
|
||||
Reintentar
|
||||
{t('common:actions.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
) : visible.length === 0 ? (
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { Check } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export function EmptyAttention() {
|
||||
const { t } = useTranslation('attention')
|
||||
return (
|
||||
<div className="mt-10 flex flex-col items-center px-6 text-center" role="status">
|
||||
<span className="flex size-14 items-center justify-center rounded-full bg-success-soft text-success">
|
||||
<Check className="size-7" strokeWidth={2.5} aria-hidden="true" />
|
||||
</span>
|
||||
<p className="mt-4 text-base font-semibold text-primary">Todo en orden</p>
|
||||
<p className="mt-4 text-base font-semibold text-primary">{t('empty.title')}</p>
|
||||
<p className="mt-1 max-w-[32ch] text-sm text-secondary">
|
||||
No hay alumnos que requieran atención en este filtro.
|
||||
{t('empty.description')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { ATTENTION_FILTERS, type AttentionFilter } from './attention'
|
||||
|
||||
@@ -8,16 +9,17 @@ type FilterChipsProps = {
|
||||
}
|
||||
|
||||
export function FilterChips({ value, counts, onChange }: FilterChipsProps) {
|
||||
const { t } = useTranslation('attention')
|
||||
return (
|
||||
<div role="group" aria-label="Filtrar alertas" className="flex gap-2 overflow-x-auto py-3">
|
||||
<div role="group" aria-label={t('filters.label')} className="flex gap-2 overflow-x-auto py-3">
|
||||
{ATTENTION_FILTERS.map((filter) => {
|
||||
const active = filter.id === value
|
||||
const active = filter === value
|
||||
return (
|
||||
<button
|
||||
key={filter.id}
|
||||
key={filter}
|
||||
type="button"
|
||||
aria-pressed={active}
|
||||
onClick={() => onChange(filter.id)}
|
||||
onClick={() => onChange(filter)}
|
||||
className={cn(
|
||||
'inline-flex min-h-11 shrink-0 items-center gap-1.5 rounded-full border px-4 text-sm font-semibold transition-colors focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none motion-reduce:transition-none',
|
||||
active
|
||||
@@ -25,9 +27,9 @@ export function FilterChips({ value, counts, onChange }: FilterChipsProps) {
|
||||
: 'border-border bg-surface text-primary hover:bg-primary-soft',
|
||||
)}
|
||||
>
|
||||
{filter.label}
|
||||
{t(`filters.${filter}`)}
|
||||
<span className={cn('tabular-nums', active ? 'text-background/70' : 'text-secondary')}>
|
||||
{counts[filter.id]}
|
||||
{counts[filter]}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
StudentAlertType,
|
||||
} from '@gruperly/shared'
|
||||
import { compareAlerts, compareByWorstAlert, worstAlert } from '@gruperly/shared'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
|
||||
/* Derivations for "Requiere atención" (the Grupos preview and the "Ver todos"
|
||||
@@ -16,11 +17,8 @@ import { formatPrice } from '../../lib/format'
|
||||
|
||||
export type AttentionFilter = 'todos' | StudentAlertType
|
||||
|
||||
export const ATTENTION_FILTERS: { id: AttentionFilter; label: string }[] = [
|
||||
{ id: 'todos', label: 'Todos' },
|
||||
{ id: 'asistencia', label: 'Asistencia' },
|
||||
{ id: 'pago', label: 'Pagos' },
|
||||
]
|
||||
/** Labels: `attention:filters.<id>`. */
|
||||
export const ATTENTION_FILTERS: AttentionFilter[] = ['todos', 'asistencia', 'pago']
|
||||
|
||||
/** A student with at least one alert, with their group. */
|
||||
export type FlaggedStudent = AttentionMember & {
|
||||
@@ -77,12 +75,12 @@ export function itemsBySeverity(items: AttentionItem[]): Record<StudentAlertSeve
|
||||
/** "7 alumnos · 3 urgentes", or "Nada pendiente". Students, not cards. */
|
||||
export function attentionSubtitle(items: AttentionItem[]): string {
|
||||
const students = new Set(items.map((item) => item.student.attendeeId))
|
||||
if (students.size === 0) return 'Nada pendiente'
|
||||
if (students.size === 0) return i18n.t('attention:subtitle.none')
|
||||
const urgent = new Set(
|
||||
items.filter((item) => item.alert.gravedad === 'urgente').map((item) => item.student.attendeeId),
|
||||
)
|
||||
const parts = [`${students.size} ${students.size === 1 ? 'alumno' : 'alumnos'}`]
|
||||
if (urgent.size > 0) parts.push(`${urgent.size} ${urgent.size === 1 ? 'urgente' : 'urgentes'}`)
|
||||
const parts = [i18n.t('attention:subtitle.students', { count: students.size })]
|
||||
if (urgent.size > 0) parts.push(i18n.t('attention:subtitle.urgent', { count: urgent.size }))
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
@@ -119,17 +117,74 @@ export function reminderMessage(student: FlaggedStudent): string {
|
||||
const amount = formatPrice(total, payments[0]?.currency)
|
||||
const owed =
|
||||
payments.length === 1
|
||||
? `la cuota de ${student.groupName} (${amount}) que venció el ${shortDate(payments[0].dueDate)}`
|
||||
: `${payments.length} cuotas de ${student.groupName} (${amount} en total)`
|
||||
? i18n.t('attention:reminder.one', { group: student.groupName, amount, date: shortDate(payments[0].dueDate) })
|
||||
: i18n.t('attention:reminder.many', { count: payments.length, group: student.groupName, amount })
|
||||
const link = payments.find((payment) => payment.checkoutUrl)?.checkoutUrl
|
||||
return (
|
||||
`¡Hola ${firstName}! 👋 Te escribo para recordarte que quedó pendiente ${owed}.` +
|
||||
(link ? ` Podés pagar acá: ${link}` : '') +
|
||||
' Cualquier cosa, avisame.'
|
||||
i18n.t('attention:reminder.message', { name: firstName, owed }) +
|
||||
(link ? i18n.t('attention:reminder.pay', { link }) : '') +
|
||||
i18n.t('attention:reminder.closing')
|
||||
)
|
||||
}
|
||||
|
||||
/* Due dates are calendar days sent at 12:00 UTC: read in UTC so the day doesn't
|
||||
shift with the time zone. */
|
||||
function shortDate(iso: string): string {
|
||||
const date = new Date(iso)
|
||||
return `${date.getUTCDate()}/${date.getUTCMonth() + 1}`
|
||||
return new Intl.DateTimeFormat(i18n.language, { day: 'numeric', month: 'numeric', timeZone: 'UTC' }).format(
|
||||
new Date(iso),
|
||||
)
|
||||
}
|
||||
|
||||
function monthName(iso: string): string {
|
||||
return new Intl.DateTimeFormat(i18n.language, { month: 'long', timeZone: 'UTC' }).format(new Date(iso))
|
||||
}
|
||||
|
||||
/** The alert's short tag ("4 faltas") in the UI language. Alerts without
|
||||
* `razon` (older API) keep the Spanish `etiqueta`. */
|
||||
export function alertLabel(alert: StudentAlert): string {
|
||||
const values = alert.valores ?? {}
|
||||
switch (alert.razon) {
|
||||
case 'racha':
|
||||
return i18n.t('attention:alert.racha', { count: values.faltas })
|
||||
case 'ventana':
|
||||
case 'ultimas':
|
||||
return i18n.t('attention:alert.ventana', { count: values.faltas })
|
||||
case 'cuotas':
|
||||
return i18n.t('attention:alert.cuotas', { count: values.cuotas })
|
||||
case 'cuota':
|
||||
return i18n.t('attention:alert.cuota')
|
||||
default:
|
||||
return alert.etiqueta
|
||||
}
|
||||
}
|
||||
|
||||
/** The alert's sentence ("Faltó a 4 de las últimas 6 clases.") in the UI language. */
|
||||
export function alertDetail(alert: StudentAlert): string {
|
||||
const values = alert.valores ?? {}
|
||||
const dueDates = values.vencimientos ?? []
|
||||
switch (alert.razon) {
|
||||
case 'racha':
|
||||
return i18n.t('attention:alert.rachaDetail', { count: values.faltas })
|
||||
case 'ventana':
|
||||
return i18n.t('attention:alert.ventanaDetail', { count: values.faltas, classes: values.clases })
|
||||
case 'ultimas':
|
||||
return i18n.t('attention:alert.ultimasDetail', { count: values.faltas })
|
||||
case 'cuotas': {
|
||||
// Two fees in the same month (a re-created link) would read "las cuotas
|
||||
// de octubre": fall back to the count.
|
||||
const months = [...new Set(dueDates.map(monthName))]
|
||||
if (months.length === dueDates.length && months.length > 0) {
|
||||
const list = new Intl.ListFormat(i18n.language, { type: 'conjunction' }).format(months)
|
||||
return i18n.t('attention:alert.cuotasMonthsDetail', { months: list })
|
||||
}
|
||||
return i18n.t('attention:alert.cuotasDetail', { count: values.cuotas })
|
||||
}
|
||||
case 'cuota': {
|
||||
const [dueDate] = dueDates
|
||||
if (!dueDate) return alert.detalle
|
||||
return i18n.t('attention:alert.cuotaDetail', { month: monthName(dueDate), date: shortDate(dueDate) })
|
||||
}
|
||||
default:
|
||||
return alert.detalle
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Link } from '@tanstack/react-router'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { AlertTag } from '../attention/AlertTag'
|
||||
import type { FlaggedStudent } from '../attention/attention'
|
||||
import { alertLabel, type FlaggedStudent } from '../attention/attention'
|
||||
import { SeverityAvatar } from '../attention/SeverityAvatar'
|
||||
|
||||
const PREVIEW_LIMIT = 4
|
||||
@@ -54,7 +54,7 @@ export function AttentionPreview({ students }: { students: FlaggedStudent[] }) {
|
||||
<span className="block truncate text-sm text-secondary">{student.groupName}</span>
|
||||
</span>
|
||||
<span className="sr-only">{student.worst.gravedad === 'urgente' ? t('attentionPreview.urgent') : t('attentionPreview.watch')}</span>
|
||||
<AlertTag severity={student.worst.gravedad}>{student.worst.etiqueta}</AlertTag>
|
||||
<AlertTag severity={student.worst.gravedad}>{alertLabel(student.worst)}</AlertTag>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user