feat(i18n): traducir la toma de asistencia
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import { useToast } from '../../components/ui'
|
|||||||
import { getSessionStudents, markAttendance } from '../../lib/api'
|
import { getSessionStudents, markAttendance } from '../../lib/api'
|
||||||
import { isAttendanceLocked } from './utils'
|
import { isAttendanceLocked } from './utils'
|
||||||
import type { AttendanceChoice } from './utils'
|
import type { AttendanceChoice } from './utils'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { errorMessage, useIntlLocale } from '../../i18n'
|
||||||
|
|
||||||
type AttendanceContextValue = {
|
type AttendanceContextValue = {
|
||||||
sessionId: string
|
sessionId: string
|
||||||
@@ -27,6 +29,8 @@ const AttendanceContext = createContext<AttendanceContextValue | null>(null)
|
|||||||
export function AttendanceProvider({ sessionId, children }: { sessionId: string; children: ReactNode }) {
|
export function AttendanceProvider({ sessionId, children }: { sessionId: string; children: ReactNode }) {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
const { t } = useTranslation(['classAttendance', 'common'])
|
||||||
|
const locale = useIntlLocale()
|
||||||
|
|
||||||
const studentsQuery = useQuery({
|
const studentsQuery = useQuery({
|
||||||
queryKey: ['class-students', sessionId],
|
queryKey: ['class-students', sessionId],
|
||||||
@@ -73,22 +77,18 @@ export function AttendanceProvider({ sessionId, children }: { sessionId: string;
|
|||||||
return markAttendance(sessionId, { classSessionId: sessionId, records })
|
return markAttendance(sessionId, { classSessionId: sessionId, records })
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success('Asistencia guardada correctamente.', 'Listo')
|
toast.success(t('saved'), t('savedTitle'))
|
||||||
void queryClient.invalidateQueries({ queryKey: ['classes-today'] })
|
void queryClient.invalidateQueries({ queryKey: ['classes-today'] })
|
||||||
void queryClient.invalidateQueries({ queryKey: ['class-students', sessionId] })
|
void queryClient.invalidateQueries({ queryKey: ['class-students', sessionId] })
|
||||||
void queryClient.invalidateQueries({ queryKey: ['attendee-stats'] })
|
void queryClient.invalidateQueries({ queryKey: ['attendee-stats'] })
|
||||||
},
|
},
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
toast.error(error.message || 'No pudimos guardar la asistencia.')
|
toast.error(errorMessage(error, t('saveError')))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const startTime = sessionInfo
|
const startTime = sessionInfo
|
||||||
? new Date(sessionInfo.startsAt).toLocaleTimeString('es-MX', {
|
? new Date(sessionInfo.startsAt).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
})
|
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const value: AttendanceContextValue = {
|
const value: AttendanceContextValue = {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Check, X } from 'lucide-react'
|
import { Check, X } from 'lucide-react'
|
||||||
import { cn } from '../../lib/utils'
|
import { cn } from '../../lib/utils'
|
||||||
import type { AttendanceChoice } from './utils'
|
import type { AttendanceChoice } from './utils'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
export function AttendanceToggle({
|
export function AttendanceToggle({
|
||||||
choice,
|
choice,
|
||||||
@@ -14,13 +15,14 @@ export function AttendanceToggle({
|
|||||||
fullName: string
|
fullName: string
|
||||||
}) {
|
}) {
|
||||||
const isPresent = choice === 'PRESENT'
|
const isPresent = choice === 'PRESENT'
|
||||||
|
const { t } = useTranslation('classAttendance')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
role="switch"
|
role="switch"
|
||||||
aria-checked={isPresent}
|
aria-checked={isPresent}
|
||||||
aria-label={`${isPresent ? 'Presente' : 'Ausente'}: ${fullName}`}
|
aria-label={t(`toggle.${choice}`, { name: fullName })}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { LargeTitle } from '../../components/layout/LargeTitle'
|
|||||||
import { Badge, Button } from '../../components/ui'
|
import { Badge, Button } from '../../components/ui'
|
||||||
import { useAttendance } from './AttendanceProvider'
|
import { useAttendance } from './AttendanceProvider'
|
||||||
import { StudentRow } from './StudentRow'
|
import { StudentRow } from './StudentRow'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
export function ClassAttendanceView() {
|
export function ClassAttendanceView() {
|
||||||
const {
|
const {
|
||||||
@@ -16,6 +17,7 @@ export function ClassAttendanceView() {
|
|||||||
saveAttendance,
|
saveAttendance,
|
||||||
isSaving,
|
isSaving,
|
||||||
} = useAttendance()
|
} = useAttendance()
|
||||||
|
const { t } = useTranslation(['classAttendance', 'common'])
|
||||||
|
|
||||||
const total = sessionInfo?.students.length ?? 0
|
const total = sessionInfo?.students.length ?? 0
|
||||||
|
|
||||||
@@ -25,14 +27,14 @@ export function ClassAttendanceView() {
|
|||||||
orients and gives the bar its anchor height. The present counter, on the
|
orients and gives the bar its anchor height. The present counter, on the
|
||||||
other hand, only shows once there are students on screen. */}
|
other hand, only shows once there are students on screen. */}
|
||||||
<LargeTitle
|
<LargeTitle
|
||||||
title={sessionInfo?.groupName ?? 'Asistencia'}
|
title={sessionInfo?.groupName ?? t('fallbackTitle')}
|
||||||
leading={
|
leading={
|
||||||
<Link
|
<Link
|
||||||
to="/"
|
to="/"
|
||||||
className="hidden shrink-0 items-center gap-1 text-sm text-foreground/80 transition-colors hover:text-primary lg:inline-flex"
|
className="hidden shrink-0 items-center gap-1 text-sm text-foreground/80 transition-colors hover:text-primary lg:inline-flex"
|
||||||
>
|
>
|
||||||
<ArrowLeft className="size-4" />
|
<ArrowLeft className="size-4" />
|
||||||
<span>Volver al inicio</span>
|
<span>{t('backHome')}</span>
|
||||||
</Link>
|
</Link>
|
||||||
}
|
}
|
||||||
barTrailing={
|
barTrailing={
|
||||||
@@ -46,10 +48,10 @@ export function ClassAttendanceView() {
|
|||||||
{sessionInfo ? (
|
{sessionInfo ? (
|
||||||
<div className="mt-2 flex items-center justify-between gap-3">
|
<div className="mt-2 flex items-center justify-between gap-3">
|
||||||
<p className="text-sm text-foreground/60">
|
<p className="text-sm text-foreground/60">
|
||||||
{startTime ? `Hoy · ${startTime} hs` : 'Clase de hoy'}
|
{startTime ? t('today', { time: startTime }) : t('todayClass')}
|
||||||
</p>
|
</p>
|
||||||
<Badge variant="success" className="shrink-0 text-xs tabular-nums">
|
<Badge variant="success" className="shrink-0 text-xs tabular-nums">
|
||||||
{presentCount}/{total} presentes
|
{t('present', { present: presentCount, total })}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -63,9 +65,9 @@ export function ClassAttendanceView() {
|
|||||||
|
|
||||||
{studentsFailed ? (
|
{studentsFailed ? (
|
||||||
<div className="mt-4 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
<div className="mt-4 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
||||||
<p>No pudimos cargar la lista de alumnos.</p>
|
<p>{t('loadError')}</p>
|
||||||
<Button variant="outline" size="sm" onClick={retryStudents}>
|
<Button variant="outline" size="sm" onClick={retryStudents}>
|
||||||
Reintentar
|
{t('common:actions.retry')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -74,9 +76,9 @@ export function ClassAttendanceView() {
|
|||||||
<>
|
<>
|
||||||
{total === 0 ? (
|
{total === 0 ? (
|
||||||
<div className="mt-6 rounded-xl border border-dashed border-border bg-surface px-4 py-10 text-center">
|
<div className="mt-6 rounded-xl border border-dashed border-border bg-surface px-4 py-10 text-center">
|
||||||
<p className="text-sm font-medium text-primary">Este grupo no tiene alumnos</p>
|
<p className="text-sm font-medium text-primary">{t('emptyTitle')}</p>
|
||||||
<p className="mt-1 text-sm text-foreground/60">
|
<p className="mt-1 text-sm text-foreground/60">
|
||||||
Agregá miembros desde la ficha del grupo para tomar asistencia.
|
{t('emptyDescription')}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -96,7 +98,7 @@ export function ClassAttendanceView() {
|
|||||||
onClick={saveAttendance}
|
onClick={saveAttendance}
|
||||||
>
|
>
|
||||||
{isSaving ? <Loader2 className="size-4 animate-spin" /> : null}
|
{isSaving ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||||
Guardar Asistencia
|
{t('save')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -3,13 +3,20 @@ import { Avatar, Badge } from '../../components/ui'
|
|||||||
import { AttendanceToggle } from './AttendanceToggle'
|
import { AttendanceToggle } from './AttendanceToggle'
|
||||||
import { useAttendance } from './AttendanceProvider'
|
import { useAttendance } from './AttendanceProvider'
|
||||||
import { isAttendanceLocked } from './utils'
|
import { isAttendanceLocked } from './utils'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
function PaymentBadge({ status }: { status: SessionStudentDto['paymentStatus'] }) {
|
function PaymentBadge({ status }: { status: SessionStudentDto['paymentStatus'] }) {
|
||||||
return status === 'UP_TO_DATE' ? <Badge variant="success">Al día</Badge> : <Badge variant="danger">Pendiente</Badge>
|
const { t } = useTranslation('classAttendance')
|
||||||
|
return status === 'UP_TO_DATE' ? (
|
||||||
|
<Badge variant="success">{t('upToDate')}</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="danger">{t('pending')}</Badge>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StudentRow({ student }: { student: SessionStudentDto }) {
|
export function StudentRow({ student }: { student: SessionStudentDto }) {
|
||||||
const { choiceFor, toggleStudent } = useAttendance()
|
const { choiceFor, toggleStudent } = useAttendance()
|
||||||
|
const { t } = useTranslation('classAttendance')
|
||||||
const locked = isAttendanceLocked(student)
|
const locked = isAttendanceLocked(student)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -23,7 +30,7 @@ export function StudentRow({ student }: { student: SessionStudentDto }) {
|
|||||||
<p className="truncate text-sm font-semibold text-primary">{student.fullName}</p>
|
<p className="truncate text-sm font-semibold text-primary">{student.fullName}</p>
|
||||||
<div className="mt-1 flex flex-wrap items-center gap-1.5">
|
<div className="mt-1 flex flex-wrap items-center gap-1.5">
|
||||||
<PaymentBadge status={student.paymentStatus} />
|
<PaymentBadge status={student.paymentStatus} />
|
||||||
{locked ? <Badge variant="warning">Avisó ausencia</Badge> : null}
|
{locked ? <Badge variant="warning">{t('notified')}</Badge> : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<AttendanceToggle
|
<AttendanceToggle
|
||||||
|
|||||||
2
apps/web/src/i18n/i18next.d.ts
vendored
2
apps/web/src/i18n/i18next.d.ts
vendored
@@ -12,6 +12,7 @@ import type groupAdd from './locales/es-AR/groupAdd.json'
|
|||||||
import type analytics from './locales/es-AR/analytics.json'
|
import type analytics from './locales/es-AR/analytics.json'
|
||||||
import type attention from './locales/es-AR/attention.json'
|
import type attention from './locales/es-AR/attention.json'
|
||||||
import type attendeeDetail from './locales/es-AR/attendeeDetail.json'
|
import type attendeeDetail from './locales/es-AR/attendeeDetail.json'
|
||||||
|
import type classAttendance from './locales/es-AR/classAttendance.json'
|
||||||
import type validation from './locales/es-AR/validation.json'
|
import type validation from './locales/es-AR/validation.json'
|
||||||
|
|
||||||
// es-AR es la fuente: una clave que no exista ahí rompe el typecheck.
|
// es-AR es la fuente: una clave que no exista ahí rompe el typecheck.
|
||||||
@@ -26,6 +27,7 @@ declare module 'i18next' {
|
|||||||
pwa: typeof pwa
|
pwa: typeof pwa
|
||||||
settings: typeof settings
|
settings: typeof settings
|
||||||
validation: typeof validation
|
validation: typeof validation
|
||||||
|
'classAttendance': typeof classAttendance
|
||||||
'attendeeDetail': typeof attendeeDetail
|
'attendeeDetail': typeof attendeeDetail
|
||||||
'attention': typeof attention
|
'attention': typeof attention
|
||||||
'analytics': typeof analytics
|
'analytics': typeof analytics
|
||||||
|
|||||||
21
apps/web/src/i18n/locales/en/classAttendance.json
Normal file
21
apps/web/src/i18n/locales/en/classAttendance.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"fallbackTitle": "Attendance",
|
||||||
|
"backHome": "Back to home",
|
||||||
|
"today": "Today · {{time}}",
|
||||||
|
"todayClass": "Today's class",
|
||||||
|
"present": "{{present}}/{{total}} present",
|
||||||
|
"loadError": "We couldn't load the student list.",
|
||||||
|
"emptyTitle": "This group has no students",
|
||||||
|
"emptyDescription": "Add members from the group's page to take attendance.",
|
||||||
|
"save": "Save attendance",
|
||||||
|
"saved": "Attendance saved.",
|
||||||
|
"savedTitle": "Done",
|
||||||
|
"saveError": "We couldn't save the attendance.",
|
||||||
|
"upToDate": "Up to date",
|
||||||
|
"pending": "Pending",
|
||||||
|
"notified": "Gave notice",
|
||||||
|
"toggle": {
|
||||||
|
"PRESENT": "Present: {{name}}",
|
||||||
|
"ABSENT": "Absent: {{name}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
21
apps/web/src/i18n/locales/es-419/classAttendance.json
Normal file
21
apps/web/src/i18n/locales/es-419/classAttendance.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"fallbackTitle": "Asistencia",
|
||||||
|
"backHome": "Volver al inicio",
|
||||||
|
"today": "Hoy · {{time}} h",
|
||||||
|
"todayClass": "Clase de hoy",
|
||||||
|
"present": "{{present}}/{{total}} presentes",
|
||||||
|
"loadError": "No pudimos cargar la lista de alumnos.",
|
||||||
|
"emptyTitle": "Este grupo no tiene alumnos",
|
||||||
|
"emptyDescription": "Agrega miembros desde la ficha del grupo para tomar asistencia.",
|
||||||
|
"save": "Guardar asistencia",
|
||||||
|
"saved": "Asistencia guardada correctamente.",
|
||||||
|
"savedTitle": "Listo",
|
||||||
|
"saveError": "No pudimos guardar la asistencia.",
|
||||||
|
"upToDate": "Al día",
|
||||||
|
"pending": "Pendiente",
|
||||||
|
"notified": "Avisó ausencia",
|
||||||
|
"toggle": {
|
||||||
|
"PRESENT": "Presente: {{name}}",
|
||||||
|
"ABSENT": "Ausente: {{name}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
21
apps/web/src/i18n/locales/es-AR/classAttendance.json
Normal file
21
apps/web/src/i18n/locales/es-AR/classAttendance.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"fallbackTitle": "Asistencia",
|
||||||
|
"backHome": "Volver al inicio",
|
||||||
|
"today": "Hoy · {{time}} hs",
|
||||||
|
"todayClass": "Clase de hoy",
|
||||||
|
"present": "{{present}}/{{total}} presentes",
|
||||||
|
"loadError": "No pudimos cargar la lista de alumnos.",
|
||||||
|
"emptyTitle": "Este grupo no tiene alumnos",
|
||||||
|
"emptyDescription": "Agregá miembros desde la ficha del grupo para tomar asistencia.",
|
||||||
|
"save": "Guardar asistencia",
|
||||||
|
"saved": "Asistencia guardada correctamente.",
|
||||||
|
"savedTitle": "Listo",
|
||||||
|
"saveError": "No pudimos guardar la asistencia.",
|
||||||
|
"upToDate": "Al día",
|
||||||
|
"pending": "Pendiente",
|
||||||
|
"notified": "Avisó ausencia",
|
||||||
|
"toggle": {
|
||||||
|
"PRESENT": "Presente: {{name}}",
|
||||||
|
"ABSENT": "Ausente: {{name}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
21
apps/web/src/i18n/locales/pt-BR/classAttendance.json
Normal file
21
apps/web/src/i18n/locales/pt-BR/classAttendance.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"fallbackTitle": "Chamada",
|
||||||
|
"backHome": "Voltar ao início",
|
||||||
|
"today": "Hoje · {{time}}",
|
||||||
|
"todayClass": "Aula de hoje",
|
||||||
|
"present": "{{present}}/{{total}} presentes",
|
||||||
|
"loadError": "Não conseguimos carregar a lista de alunos.",
|
||||||
|
"emptyTitle": "Este grupo não tem alunos",
|
||||||
|
"emptyDescription": "Adicione membros na página do grupo para fazer a chamada.",
|
||||||
|
"save": "Salvar chamada",
|
||||||
|
"saved": "Chamada salva com sucesso.",
|
||||||
|
"savedTitle": "Pronto",
|
||||||
|
"saveError": "Não conseguimos salvar a chamada.",
|
||||||
|
"upToDate": "Em dia",
|
||||||
|
"pending": "Pendente",
|
||||||
|
"notified": "Avisou falta",
|
||||||
|
"toggle": {
|
||||||
|
"PRESENT": "Presente: {{name}}",
|
||||||
|
"ABSENT": "Ausente: {{name}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user