feat(i18n): traducir Grupos (lista, ficha, alta de miembros y estadísticas)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,13 +3,17 @@ import type { ReactNode } from 'react'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import type {
|
||||
BulkCreateAttendeesResult,
|
||||
CreateAttendee,
|
||||
CreateAttendeeResult,
|
||||
CreateGroupWaitlistEntry,
|
||||
GroupWaitlistEntryDto,
|
||||
GroupWaitlistList,
|
||||
} from '@gruperly/shared'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useToast } from '../../../components/ui'
|
||||
import { errorMessage } from '../../../i18n'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import {
|
||||
addToGroupWaitlist,
|
||||
ApiError,
|
||||
@@ -72,6 +76,7 @@ const AddAttendeeContext = createContext<AddAttendeeContextValue | null>(null)
|
||||
export function AddAttendeeProvider({ groupId, children }: { groupId: string; children: ReactNode }) {
|
||||
const queryClient = useQueryClient()
|
||||
const toast = useToast()
|
||||
useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [activeTab, setActiveTab] = useState<AddAttendeeTab>('quick')
|
||||
@@ -116,11 +121,12 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
void queryClient.invalidateQueries({ queryKey: ['group', groupId] })
|
||||
}
|
||||
|
||||
const handleCreateSuccess = (result: CreateAttendeeResult) => {
|
||||
const handleCreateSuccess = (result: CreateAttendeeResult, payload: CreateAttendee) => {
|
||||
if (result.outcome === 'created') {
|
||||
toast.success(`Miembro ${result.attendee.fullName} agregado con éxito.`)
|
||||
toast.success(i18n.t('groupAdd:toast.created', { name: result.attendee.fullName }))
|
||||
} else {
|
||||
toast.info(result.message)
|
||||
const name = `${payload.firstName} ${payload.lastName ?? ''}`.trim()
|
||||
toast.info(i18n.t('groupAdd:toast.waitlisted', { name }))
|
||||
}
|
||||
void queryClient.invalidateQueries({ queryKey: ['group-attendees', groupId] })
|
||||
// Si era alguien de otro grupo, su ficha allá ahora lo muestra también acá.
|
||||
@@ -142,10 +148,10 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
// refresca la búsqueda para que aparezca la opción de agregar a esa persona.
|
||||
if (err instanceof ApiError && err.problem?.code === 'person_exists') {
|
||||
void queryClient.invalidateQueries({ queryKey: ['person-lookup', groupId] })
|
||||
toast.info('Ya tenés registrada a una persona con este teléfono. Podés agregarla a este grupo.')
|
||||
toast.info(i18n.t('groupAdd:toast.personExists'))
|
||||
return
|
||||
}
|
||||
toast.error(err.message || 'Error al agregar miembro.')
|
||||
toast.error(errorMessage(err, i18n.t('groupAdd:toast.addError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -153,7 +159,7 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
mutationFn: (payload: CreateAttendee) => createAttendee(groupId, payload, { allowOverflow: true }),
|
||||
onSuccess: handleCreateSuccess,
|
||||
onError: (err: Error) => {
|
||||
toast.error(err.message || 'Error al agregar miembro.')
|
||||
toast.error(errorMessage(err, i18n.t('groupAdd:toast.addError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -187,7 +193,7 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
return { previousWaitlist }
|
||||
},
|
||||
onSuccess: (entry) => {
|
||||
toast.info(`${entry.fullName} fue agregado a la lista de espera del grupo.`)
|
||||
toast.info(i18n.t('groupAdd:toast.waitlisted', { name: entry.fullName }))
|
||||
invalidateGroupQueries()
|
||||
goBackToGroup()
|
||||
},
|
||||
@@ -196,9 +202,9 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
queryClient.setQueryData<GroupWaitlistList>(['group-waitlist', groupId], context.previousWaitlist)
|
||||
}
|
||||
if (err instanceof ApiError && err.problem?.code === 'already_waitlisted') {
|
||||
toast.info('Este número ya está en la lista de espera del grupo.')
|
||||
toast.info(i18n.t('groupAdd:toast.alreadyWaitlisted'))
|
||||
} else {
|
||||
toast.error(err.message || 'Error al agregar a la lista de espera.')
|
||||
toast.error(errorMessage(err, i18n.t('groupAdd:toast.waitlistError')))
|
||||
}
|
||||
closeCapacityFlow()
|
||||
},
|
||||
@@ -207,14 +213,14 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
const bulkImportMutation = useMutation({
|
||||
mutationFn: (rows: BulkAttendeeRow[]) => bulkCreateAttendees(groupId, { attendees: rows }),
|
||||
onSuccess: (res) => {
|
||||
toast.success(res.message)
|
||||
toast.success(importSummary(res))
|
||||
setParsedContacts([])
|
||||
setFileName(null)
|
||||
void queryClient.invalidateQueries({ queryKey: ['group-attendees', groupId] })
|
||||
goBackToGroup()
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
toast.error(err.message || 'Error al importar miembros.')
|
||||
toast.error(errorMessage(err, i18n.t('groupAdd:toast.importError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -235,7 +241,7 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
|
||||
const runBulkImport = () => {
|
||||
if (validRows.length === 0) {
|
||||
toast.error('No hay miembros válidos para importar.')
|
||||
toast.error(i18n.t('groupAdd:bulk.noValidRows'))
|
||||
return
|
||||
}
|
||||
bulkImportMutation.mutate(validRows)
|
||||
@@ -243,7 +249,7 @@ export function AddAttendeeProvider({ groupId, children }: { groupId: string; ch
|
||||
|
||||
const requestBulkImport = () => {
|
||||
if (validRows.length === 0) {
|
||||
toast.error('No hay miembros válidos para importar.')
|
||||
toast.error(i18n.t('groupAdd:bulk.noValidRows'))
|
||||
return
|
||||
}
|
||||
if (capacity != null && attendeesTotal + validRows.length > capacity) {
|
||||
@@ -310,3 +316,16 @@ export function useAddAttendee() {
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
/** The bulk import summary, built from the counts (the API's `message` is Spanish only). */
|
||||
function importSummary(result: BulkCreateAttendeesResult): string {
|
||||
return [
|
||||
i18n.t('groupAdd:toast.imported', { count: result.createdCount }),
|
||||
result.linkedCount > 0 ? i18n.t('groupAdd:toast.importedLinked', { count: result.linkedCount }) : null,
|
||||
result.duplicatesCount > 0
|
||||
? i18n.t('groupAdd:toast.importedDuplicates', { count: result.duplicatesCount })
|
||||
: null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user