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:
@@ -1,5 +1,6 @@
|
||||
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 { SeverityAvatar } from '../attention/SeverityAvatar'
|
||||
@@ -8,6 +9,7 @@ const PREVIEW_LIMIT = 4
|
||||
|
||||
/** "Requiere atención" on Grupos: the most urgent students, one row each. */
|
||||
export function AttentionPreview({ students }: { students: FlaggedStudent[] }) {
|
||||
const { t } = useTranslation('groups')
|
||||
if (students.length === 0) return null
|
||||
|
||||
return (
|
||||
@@ -17,18 +19,18 @@ export function AttentionPreview({ students }: { students: FlaggedStudent[] }) {
|
||||
id="attention-preview-title"
|
||||
className="flex items-center gap-2 text-xs font-semibold tracking-wider text-alert-urgent-fg uppercase"
|
||||
>
|
||||
Requiere atención
|
||||
{t('attentionPreview.title')}
|
||||
<span className="inline-flex min-w-5 items-center justify-center rounded-full bg-alert-urgent-soft px-1.5 py-0.5 text-[11px] leading-none tabular-nums">
|
||||
<span className="sr-only">: </span>
|
||||
{students.length}
|
||||
<span className="sr-only"> {students.length === 1 ? 'alumno' : 'alumnos'}</span>
|
||||
<span aria-hidden="true">{students.length}</span>
|
||||
<span className="sr-only">{t('attentionPreview.students', { count: students.length })}</span>
|
||||
</span>
|
||||
</h2>
|
||||
<Link
|
||||
to="/groups/attention"
|
||||
className="-mr-2 inline-flex min-h-11 items-center gap-0.5 rounded-xl px-2 text-sm font-medium text-accent-fg hover:underline focus-visible:ring-2 focus-visible:ring-accent focus-visible:outline-none"
|
||||
>
|
||||
Ver todos
|
||||
{t('attentionPreview.seeAll')}
|
||||
<ChevronRight className="size-4" aria-hidden="true" />
|
||||
</Link>
|
||||
</div>
|
||||
@@ -51,7 +53,7 @@ export function AttentionPreview({ students }: { students: FlaggedStudent[] }) {
|
||||
<span className="block truncate font-semibold text-primary">{student.fullName}</span>
|
||||
<span className="block truncate text-sm text-secondary">{student.groupName}</span>
|
||||
</span>
|
||||
<span className="sr-only">{student.worst.gravedad === 'urgente' ? 'Urgente:' : 'A vigilar:'}</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>
|
||||
</Link>
|
||||
</li>
|
||||
|
||||
@@ -2,11 +2,14 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import type { CreateFirstGroup } from '@gruperly/shared'
|
||||
import { ChevronLeft } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { errorMessage } from '../../i18n'
|
||||
import { createGroup } from '../../lib/api'
|
||||
import { GroupForm } from './GroupForm'
|
||||
|
||||
export function CreateGroupView() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation('groups')
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const create = useMutation({
|
||||
@@ -24,16 +27,16 @@ export function CreateGroupView() {
|
||||
className="mb-6 hidden items-center gap-1 text-sm font-medium text-foreground/70 transition-colors hover:text-primary lg:inline-flex"
|
||||
>
|
||||
<ChevronLeft className="size-4" />
|
||||
Grupos
|
||||
{t('title')}
|
||||
</Link>
|
||||
|
||||
<GroupForm
|
||||
heading="Nuevo grupo"
|
||||
description="Definí los datos de la clase que vas a cobrar. Después siempre podés editarlos."
|
||||
submitLabel="Crear grupo"
|
||||
heading={t('create.heading')}
|
||||
description={t('create.description')}
|
||||
submitLabel={t('create.submit')}
|
||||
isSubmitting={create.isPending}
|
||||
errorMessage={
|
||||
create.isError ? 'No pudimos crear el grupo. Revisá los datos e intentá de nuevo.' : null
|
||||
create.isError ? errorMessage(create.error, t('create.error')) : null
|
||||
}
|
||||
onSubmit={(values) => create.mutate(values)}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AttentionMember, GroupListItem } from '@gruperly/shared'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { AvatarRow } from './AvatarRow'
|
||||
import { groupStatus, type GroupStatus } from './card'
|
||||
@@ -22,11 +23,12 @@ type GroupCardProps = {
|
||||
}
|
||||
|
||||
export function GroupCard({ group, members }: GroupCardProps) {
|
||||
const { t } = useTranslation('groups')
|
||||
const status = members ? groupStatus(members, group.capacity, group.attendeesCount) : null
|
||||
const occupancy =
|
||||
group.capacity === null
|
||||
? `${group.attendeesCount} ${group.attendeesCount === 1 ? 'alumno' : 'alumnos'}`
|
||||
: `${group.attendeesCount} de ${group.capacity} lugares ocupados`
|
||||
? t('card.students', { count: group.attendeesCount })
|
||||
: t('card.occupancy', { count: group.attendeesCount, capacity: group.capacity })
|
||||
|
||||
return (
|
||||
<Link
|
||||
|
||||
@@ -3,10 +3,11 @@ import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import type { BillingType, CountryCode, CreateFirstGroup, WeekDay } from '@gruperly/shared'
|
||||
import { CreateFirstGroupSchema, DEFAULT_COUNTRY } from '@gruperly/shared'
|
||||
import { ArrowLeft, Check, Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { sortWeekDays } from '../../lib/format'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { Button, FieldError, Input, Label } from '../../components/ui'
|
||||
import { BILLING_TYPES, WEEK_DAY_CHIPS } from '../onboarding/constants'
|
||||
import { BILLING_TYPES, WEEK_DAYS } from '../onboarding/constants'
|
||||
|
||||
type GroupFormProps = {
|
||||
heading: string
|
||||
@@ -30,6 +31,7 @@ export function GroupForm({
|
||||
onSubmit,
|
||||
onBack,
|
||||
}: GroupFormProps) {
|
||||
const { t } = useTranslation(['groups', 'common'])
|
||||
// The price starts empty on purpose: a pre-filled $0 got submitted as is and
|
||||
// the group ended up unable to charge. The capacity starts at a typical
|
||||
// class size instead of 1, which had to be overwritten every time.
|
||||
@@ -76,11 +78,11 @@ export function GroupForm({
|
||||
</header>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="name">Nombre del grupo</Label>
|
||||
<Label htmlFor="name">{t('form.name')}</Label>
|
||||
<Input
|
||||
id="name"
|
||||
autoFocus
|
||||
placeholder="Ej: Yoga Vinyasa · Nivel 1"
|
||||
placeholder={t('form.namePlaceholder')}
|
||||
invalid={!!errors.name}
|
||||
{...register('name')}
|
||||
/>
|
||||
@@ -88,9 +90,9 @@ export function GroupForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Días de clase</Label>
|
||||
<Label>{t('form.days')}</Label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{WEEK_DAY_CHIPS.map(({ value, label }) => {
|
||||
{WEEK_DAYS.map((value) => {
|
||||
const isActive = days.includes(value)
|
||||
return (
|
||||
<button
|
||||
@@ -105,7 +107,7 @@ export function GroupForm({
|
||||
: 'border-border bg-surface text-primary hover:bg-primary-soft',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{t(`common:weekDayShort.${value}`)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
@@ -114,7 +116,7 @@ export function GroupForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="time">Horario</Label>
|
||||
<Label htmlFor="time">{t('form.time')}</Label>
|
||||
<Input
|
||||
id="time"
|
||||
type="time"
|
||||
@@ -126,7 +128,7 @@ export function GroupForm({
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<Label htmlFor="capacity">Cupo máximo</Label>
|
||||
<Label htmlFor="capacity">{t('form.capacity')}</Label>
|
||||
<Input
|
||||
id="capacity"
|
||||
type="number"
|
||||
@@ -140,7 +142,7 @@ export function GroupForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="price">Precio</Label>
|
||||
<Label htmlFor="price">{t('form.price')}</Label>
|
||||
<div className="relative">
|
||||
<span className="pointer-events-none absolute inset-y-0 left-3 flex items-center text-base text-foreground/50 sm:text-sm">
|
||||
$
|
||||
@@ -151,7 +153,7 @@ export function GroupForm({
|
||||
inputMode="decimal"
|
||||
min={0}
|
||||
step="0.01"
|
||||
placeholder="Por alumno"
|
||||
placeholder={t('form.pricePlaceholder')}
|
||||
className="pl-7"
|
||||
invalid={!!errors.price}
|
||||
{...register('price', { valueAsNumber: true })}
|
||||
@@ -162,9 +164,9 @@ export function GroupForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Tipo de cobro</Label>
|
||||
<Label>{t('form.billingType')}</Label>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{BILLING_TYPES.map(({ value, label, hint }) => {
|
||||
{BILLING_TYPES.map((value) => {
|
||||
const isActive = billingType === value
|
||||
return (
|
||||
<button
|
||||
@@ -185,9 +187,9 @@ export function GroupForm({
|
||||
isActive ? 'text-accent' : 'text-primary',
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{t(`common:billingType.${value}`)}
|
||||
</span>
|
||||
<span className="block text-xs text-foreground/50">{hint}</span>
|
||||
<span className="block text-xs text-foreground/50">{t(`common:billingTypeHint.${value}`)}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
@@ -195,7 +197,7 @@ export function GroupForm({
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="dueDay">Día de vencimiento</Label>
|
||||
<Label htmlFor="dueDay">{t('form.dueDay')}</Label>
|
||||
<Input
|
||||
id="dueDay"
|
||||
type="number"
|
||||
@@ -207,7 +209,7 @@ export function GroupForm({
|
||||
{...register('dueDay', { valueAsNumber: true })}
|
||||
/>
|
||||
<p className="mt-1 text-xs text-foreground/50">
|
||||
Los cobros vencerán el día {isFinite(dueDay) && dueDay ? dueDay : '1'} de cada mes.
|
||||
{t('form.dueDayHint', { day: isFinite(dueDay) && dueDay ? dueDay : 1 })}
|
||||
</p>
|
||||
<FieldError message={errors.dueDay?.message} />
|
||||
</div>
|
||||
@@ -220,12 +222,12 @@ export function GroupForm({
|
||||
{onBack ? (
|
||||
<Button variant="outline" onClick={onBack} disabled={isSubmitting}>
|
||||
<ArrowLeft className="size-4" />
|
||||
Volver
|
||||
{t('common:actions.back')}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button type="submit" variant="primary" className="flex-1" disabled={isSubmitting}>
|
||||
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : <Check className="size-4" />}
|
||||
{isSubmitting ? 'Creando…' : submitLabel}
|
||||
{isSubmitting ? t('form.submitting') : submitLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { CalendarPlus, Loader2, Plus } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '../../components/ui'
|
||||
import { getGroups } from '../../lib/api'
|
||||
import { flaggedStudents } from '../attention/attention'
|
||||
@@ -12,6 +13,7 @@ import { NewGroupFab } from './NewGroupFab'
|
||||
|
||||
export function GroupsView() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation(['groups', 'common'])
|
||||
const groupsQuery = useQuery({
|
||||
queryKey: ['groups'],
|
||||
queryFn: getGroups,
|
||||
@@ -24,21 +26,21 @@ export function GroupsView() {
|
||||
return (
|
||||
// The FAB floats over the last card: 88px of room so it can be read.
|
||||
<section className="pb-[88px]">
|
||||
<h1 className="text-2xl font-bold text-primary">Grupos</h1>
|
||||
<h1 className="text-2xl font-bold text-primary">{t('title')}</h1>
|
||||
{hasGroups ? <p className="mt-1 text-sm text-secondary">{groupsSummary(groups)}</p> : null}
|
||||
|
||||
{groupsQuery.isPending ? (
|
||||
<div className="mt-8 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 grupos</span>
|
||||
<span className="sr-only">{t('loading')}</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{groupsQuery.isError ? (
|
||||
<div className="mt-8 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
||||
<p>No pudimos cargar tus grupos.</p>
|
||||
<p>{t('loadError')}</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void groupsQuery.refetch()}>
|
||||
Reintentar
|
||||
{t('common:actions.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -50,9 +52,9 @@ export function GroupsView() {
|
||||
<span className="mx-auto flex size-14 items-center justify-center rounded-2xl bg-accent-soft text-accent-fg">
|
||||
<CalendarPlus className="size-7" aria-hidden="true" />
|
||||
</span>
|
||||
<p className="mt-4 text-base font-semibold text-primary">Todavía no tenés grupos</p>
|
||||
<p className="mt-4 text-base font-semibold text-primary">{t('empty.title')}</p>
|
||||
<p className="mx-auto mt-1.5 max-w-[30ch] text-sm leading-relaxed text-secondary">
|
||||
Creá tu primer grupo y empezá a cobrar las cuotas de tus alumnos.
|
||||
{t('empty.description')}
|
||||
</p>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -60,7 +62,7 @@ export function GroupsView() {
|
||||
onClick={() => void navigate({ to: '/groups/new' })}
|
||||
>
|
||||
<Plus className="size-4" />
|
||||
Crear primer grupo
|
||||
{t('empty.cta')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -74,7 +76,7 @@ export function GroupsView() {
|
||||
id="my-groups-title"
|
||||
className="text-xs font-semibold tracking-wider text-secondary uppercase"
|
||||
>
|
||||
Mis grupos
|
||||
{t('myGroups')}
|
||||
</h2>
|
||||
<div className="mt-2 grid gap-3 lg:grid-cols-2">
|
||||
{groups.map((group) => (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useCollapseOnScroll } from '../../hooks/useCollapseOnScroll'
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
@@ -9,11 +10,12 @@ import { cn } from '../../lib/utils'
|
||||
accessible name never changes. `motion-reduce` swaps without animating. */
|
||||
export function NewGroupFab() {
|
||||
const collapsed = useCollapseOnScroll()
|
||||
const { t } = useTranslation('groups')
|
||||
|
||||
return (
|
||||
<Link
|
||||
to="/groups/new"
|
||||
aria-label="Nuevo grupo"
|
||||
aria-label={t('newGroup')}
|
||||
className="fixed right-4 bottom-[calc(3.5rem+env(safe-area-inset-bottom)+1rem)] z-40 inline-flex h-14 items-center rounded-[18px] bg-accent px-4 font-semibold text-on-accent shadow-[0_10px_28px_-8px_rgb(37_68_234/0.65)] transition-colors hover:bg-accent-strong focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none lg:right-8 lg:bottom-8"
|
||||
>
|
||||
<Plus className="size-6 shrink-0" strokeWidth={2.25} aria-hidden="true" />
|
||||
@@ -24,7 +26,7 @@ export function NewGroupFab() {
|
||||
collapsed ? 'ml-0 max-w-0 opacity-0' : 'ml-2 max-w-40 opacity-100',
|
||||
)}
|
||||
>
|
||||
Nuevo grupo
|
||||
{t('newGroup')}
|
||||
</span>
|
||||
</Link>
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { ArrowLeft, Loader2 } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { useAddAttendee } from './AddAttendeeProvider'
|
||||
import { BulkCapacityModal } from './BulkCapacityModal'
|
||||
@@ -8,13 +9,14 @@ import { CapacityModal } from './CapacityModal'
|
||||
import { QuickAddForm } from './QuickAddForm'
|
||||
|
||||
const TABS = [
|
||||
{ value: 'quick' as const, label: 'Carga Rápida (Individual)' },
|
||||
{ value: 'bulk' as const, label: 'Carga Masiva (CSV / Excel)' },
|
||||
{ value: 'quick' as const, label: 'tabs.quick' as const },
|
||||
{ value: 'bulk' as const, label: 'tabs.bulk' as const },
|
||||
]
|
||||
|
||||
export function AddAttendeePage() {
|
||||
const { groupId, groupName, attendeesTotal, capacity, groupPending, activeTab, setActiveTab } =
|
||||
useAddAttendee()
|
||||
const { t } = useTranslation('groupAdd')
|
||||
|
||||
if (groupPending) {
|
||||
return (
|
||||
@@ -32,24 +34,26 @@ export function AddAttendeePage() {
|
||||
className="hidden items-center gap-1 text-sm text-foreground/60 transition-colors hover:text-primary lg:inline-flex"
|
||||
>
|
||||
<ArrowLeft className="size-4" />
|
||||
<span>Volver al grupo</span>
|
||||
<span>{t('back')}</span>
|
||||
</Link>
|
||||
|
||||
<header className="space-y-1">
|
||||
<h1 className="text-2xl font-bold text-primary">Agregar miembros</h1>
|
||||
<h1 className="text-2xl font-bold text-primary">{t('title')}</h1>
|
||||
<p className="text-sm text-foreground/60">
|
||||
{groupName ? (
|
||||
<>
|
||||
Sumá miembros a <span className="font-medium text-primary">{groupName}</span> de forma
|
||||
individual o masiva desde una lista.
|
||||
</>
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="subtitleGroup"
|
||||
values={{ group: groupName }}
|
||||
components={{ strong: <span className="font-medium text-primary" /> }}
|
||||
/>
|
||||
) : (
|
||||
'Sumá miembros de forma individual o masiva desde una lista.'
|
||||
t('subtitle')
|
||||
)}
|
||||
</p>
|
||||
{capacity != null ? (
|
||||
<p className="text-xs text-foreground/50">
|
||||
{attendeesTotal} de {capacity} lugares ocupados.
|
||||
{t('occupancy', { count: attendeesTotal, capacity })}
|
||||
</p>
|
||||
) : null}
|
||||
</header>
|
||||
@@ -68,7 +72,7 @@ export function AddAttendeePage() {
|
||||
: 'text-foreground/60 hover:text-primary',
|
||||
)}
|
||||
>
|
||||
{tab.label}
|
||||
{t(tab.label)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -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(' ')
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Check } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { useAddAttendee } from './AddAttendeeProvider'
|
||||
|
||||
@@ -12,24 +13,28 @@ export function BulkCapacityModal() {
|
||||
groupName,
|
||||
capacity,
|
||||
} = useAddAttendee()
|
||||
const { t } = useTranslation(['groupAdd', 'common'])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isBulkCapacityModalOpen}
|
||||
onClose={closeBulkCapacityModal}
|
||||
title="Aviso de cupo"
|
||||
description="La carga supera el cupo del grupo."
|
||||
title={t('bulkCapacity.title')}
|
||||
description={t('bulkCapacity.description')}
|
||||
maxWidth="md"
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-foreground/70">
|
||||
Estás por importar <strong className="text-primary">{validRowsCount}</strong> miembro(s), pero el
|
||||
grupo ya tiene <strong className="text-primary">{attendeesTotal}</strong> inscrito(s) y su cupo es
|
||||
de <strong className="text-primary">{capacity}</strong>. ¿Deseas importarlos de todos modos?
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="bulkCapacity.body"
|
||||
values={{ rows: validRowsCount, current: attendeesTotal, capacity }}
|
||||
components={{ strong: <strong className="text-primary" /> }}
|
||||
/>
|
||||
</p>
|
||||
<div className="flex flex-col-reverse gap-2.5 pt-2 sm:flex-row sm:items-center sm:justify-end">
|
||||
<Button variant="ghost" onClick={closeBulkCapacityModal} className="w-full sm:w-auto">
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -37,7 +42,7 @@ export function BulkCapacityModal() {
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
<Check className="size-4" />
|
||||
Importar de todos modos
|
||||
{t('bulkCapacity.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useRef } from 'react'
|
||||
import { Check, Download, FileSpreadsheet, Loader2, Trash2, UploadCloud } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Badge, Button, useToast } from '../../../components/ui'
|
||||
import {
|
||||
downloadAttendeeTemplateCsv,
|
||||
@@ -28,12 +29,13 @@ export function BulkImportPanel() {
|
||||
requestBulkImport,
|
||||
} = useAddAttendee()
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation(['groupAdd', 'common'])
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const processFile = async (file: File) => {
|
||||
const fileExtension = file.name.split('.').pop()?.toLowerCase()
|
||||
if (!['csv', 'xlsx', 'xls', 'txt'].includes(fileExtension ?? '')) {
|
||||
toast.error('Formato no compatible. Sube un archivo .csv o .xlsx')
|
||||
toast.error(t('bulk.unsupported'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,14 +49,14 @@ export function BulkImportPanel() {
|
||||
|
||||
const contacts = normalizeRowsToContacts(rawRows)
|
||||
if (contacts.length === 0) {
|
||||
toast.error('No se detectaron contactos en el archivo.')
|
||||
toast.error(t('bulk.noContacts'))
|
||||
} else {
|
||||
setParsedContacts(contacts)
|
||||
const validCount = contacts.filter((c) => c.isValid).length
|
||||
toast.info(`Se detectaron ${contacts.length} filas (${validCount} válidas).`)
|
||||
toast.info(t('bulk.detected', { count: contacts.length, valid: validCount }))
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Error al procesar el archivo.'
|
||||
const message = err instanceof Error ? err.message : t('bulk.processError')
|
||||
toast.error(message)
|
||||
} finally {
|
||||
setIsParsingFile(false)
|
||||
@@ -103,9 +105,9 @@ export function BulkImportPanel() {
|
||||
/>
|
||||
<UploadCloud className="mb-2 size-10 text-accent" />
|
||||
<p className="text-sm font-semibold text-primary">
|
||||
Arrastra tu archivo aquí o haz clic para seleccionarlo
|
||||
{t('bulk.dropzone')}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-foreground/60">Formatos soportados: CSV (.csv) o Excel (.xlsx)</p>
|
||||
<p className="mt-1 text-xs text-foreground/60">{t('bulk.formats')}</p>
|
||||
|
||||
{fileName ? (
|
||||
<div className="mt-3 flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-1.5 text-xs font-medium text-primary">
|
||||
@@ -116,21 +118,21 @@ export function BulkImportPanel() {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-start gap-1 px-1 text-xs sm:flex-row sm:items-center sm:justify-between">
|
||||
<span className="text-foreground/60">¿No tienes el archivo listo? Usa nuestra plantilla.</span>
|
||||
<span className="text-foreground/60">{t('bulk.templateHint')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={downloadAttendeeTemplateCsv}
|
||||
className="inline-flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-accent transition-colors hover:text-accent-strong"
|
||||
>
|
||||
<Download className="size-3.5" />
|
||||
<span>Descargar plantilla CSV</span>
|
||||
<span>{t('bulk.downloadTemplate')}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isParsingFile ? (
|
||||
<div className="flex items-center justify-center gap-2 py-6 text-sm text-foreground/60">
|
||||
<Loader2 className="size-4 animate-spin text-accent" />
|
||||
<span>Leyendo y analizando archivo...</span>
|
||||
<span>{t('bulk.parsing')}</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -138,9 +140,9 @@ export function BulkImportPanel() {
|
||||
<div className="space-y-3 pt-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 text-xs">
|
||||
<span className="font-semibold text-primary">Vista Previa:</span>
|
||||
<Badge variant="success">{validRowsCount} listos para importar</Badge>
|
||||
{invalidRowsCount > 0 ? <Badge variant="danger">{invalidRowsCount} con errores</Badge> : null}
|
||||
<span className="font-semibold text-primary">{t('bulk.preview')}</span>
|
||||
<Badge variant="success">{t('bulk.ready', { count: validRowsCount })}</Badge>
|
||||
{invalidRowsCount > 0 ? <Badge variant="danger">{t('bulk.withErrors', { count: invalidRowsCount })}</Badge> : null}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
@@ -152,7 +154,7 @@ export function BulkImportPanel() {
|
||||
}}
|
||||
className="h-7 px-2 text-xs text-foreground/50 hover:text-danger"
|
||||
>
|
||||
Limpiar lista
|
||||
{t('bulk.clear')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -160,10 +162,10 @@ export function BulkImportPanel() {
|
||||
<table className="w-full text-left text-xs">
|
||||
<thead className="sticky top-0 border-b border-border bg-surface font-semibold text-foreground/70">
|
||||
<tr>
|
||||
<th className="px-3 py-2">Nombre</th>
|
||||
<th className="px-3 py-2">Teléfono</th>
|
||||
<th className="px-3 py-2">Email</th>
|
||||
<th className="px-3 py-2">Estado</th>
|
||||
<th className="px-3 py-2">{t('bulk.name')}</th>
|
||||
<th className="px-3 py-2">{t('bulk.phone')}</th>
|
||||
<th className="px-3 py-2">{t('bulk.email')}</th>
|
||||
<th className="px-3 py-2">{t('bulk.status')}</th>
|
||||
<th className="px-2 py-2 text-right" />
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -174,16 +176,16 @@ export function BulkImportPanel() {
|
||||
className={!contact.isValid ? 'bg-danger-soft/30' : 'hover:bg-primary-soft/30'}
|
||||
>
|
||||
<td className="px-3 py-2 font-medium text-primary">
|
||||
{contact.fullName || <span className="italic text-danger">Sin nombre</span>}
|
||||
{contact.fullName || <span className="italic text-danger">{t('bulk.noName')}</span>}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-foreground/80">
|
||||
{contact.phone || <span className="italic text-danger">Sin teléfono</span>}
|
||||
{contact.phone || <span className="italic text-danger">{t('bulk.noPhone')}</span>}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-foreground/60">{contact.email || '—'}</td>
|
||||
<td className="px-3 py-2">
|
||||
{contact.isValid ? (
|
||||
<Badge variant="success" className="py-0 text-[10px]">
|
||||
Válido
|
||||
{t('bulk.valid')}
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="danger" className="py-0 text-[10px]" title={contact.error}>
|
||||
@@ -196,7 +198,7 @@ export function BulkImportPanel() {
|
||||
type="button"
|
||||
onClick={() => removeParsedContact(contact.id)}
|
||||
className="rounded p-1 text-foreground/40 transition-colors hover:text-danger"
|
||||
title="Eliminar fila"
|
||||
title={t('bulk.removeRow')}
|
||||
>
|
||||
<Trash2 className="size-3.5" />
|
||||
</button>
|
||||
@@ -209,7 +211,7 @@ export function BulkImportPanel() {
|
||||
|
||||
<div className="flex flex-col-reverse gap-2.5 border-t border-border pt-3 sm:flex-row sm:items-center sm:justify-end">
|
||||
<Button variant="ghost" onClick={cancelAddAttendee} className="w-full sm:w-auto">
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -218,7 +220,7 @@ export function BulkImportPanel() {
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
{isSubmittingBulkImport ? <Loader2 className="size-4 animate-spin" /> : <Check className="size-4" />}
|
||||
<span>Confirmar e Importar ({validRowsCount})</span>
|
||||
<span>{t('bulk.confirm', { count: validRowsCount })}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Clock, Loader2, UserPlus } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { useAddAttendee } from './AddAttendeeProvider'
|
||||
|
||||
@@ -14,25 +15,30 @@ export function CapacityModal() {
|
||||
isSubmittingForcedAttendee,
|
||||
isSubmittingWaitlistEntry,
|
||||
} = useAddAttendee()
|
||||
const { t } = useTranslation('groupAdd')
|
||||
const isBusy = isSubmittingForcedAttendee || isSubmittingWaitlistEntry
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isCapacityModalOpen}
|
||||
onClose={closeCapacityModal}
|
||||
title="Cupo alcanzado"
|
||||
description="El grupo llegó a su cupo máximo de miembros."
|
||||
title={t('capacity.title')}
|
||||
description={t('capacity.description')}
|
||||
maxWidth="md"
|
||||
>
|
||||
{capacityPayload ? (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-foreground/70">
|
||||
El grupo <strong className="text-primary">{groupName}</strong> ya alcanzó su cupo de{' '}
|
||||
<strong className="text-primary">{capacity}</strong> miembros. ¿Qué deseas hacer con{' '}
|
||||
<strong className="text-primary">
|
||||
{`${capacityPayload.firstName.trim()} ${(capacityPayload.lastName ?? '').trim()}`.trim()}
|
||||
</strong>
|
||||
?
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="capacity.body"
|
||||
values={{
|
||||
group: groupName ?? '',
|
||||
capacity,
|
||||
name: `${capacityPayload.firstName.trim()} ${(capacityPayload.lastName ?? '').trim()}`.trim(),
|
||||
}}
|
||||
components={{ strong: <strong className="text-primary" /> }}
|
||||
/>
|
||||
</p>
|
||||
<div className="flex flex-col gap-2.5">
|
||||
<Button
|
||||
@@ -46,7 +52,7 @@ export function CapacityModal() {
|
||||
) : (
|
||||
<UserPlus className="size-4" />
|
||||
)}
|
||||
<span>Agregar de todos modos</span>
|
||||
<span>{t('capacity.force')}</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -59,11 +65,11 @@ export function CapacityModal() {
|
||||
) : (
|
||||
<Clock className="size-4" />
|
||||
)}
|
||||
<span>Sumar a la lista de espera</span>
|
||||
<span>{t('capacity.waitlist')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-center text-[11px] text-foreground/50">
|
||||
Si eliges agregarlo de todos modos, el grupo quedará por encima de su cupo.
|
||||
{t('capacity.forceHint')}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { UserCheck } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import type { PersonSummary } from '@gruperly/shared'
|
||||
import { Button } from '../../../components/ui'
|
||||
|
||||
@@ -22,12 +23,13 @@ export function ExistingPersonNotice({
|
||||
onUnlink,
|
||||
onChangePhone,
|
||||
}: ExistingPersonNoticeProps) {
|
||||
const { t } = useTranslation('groupAdd')
|
||||
const groupNames = person.groups.map((group) => group.groupName).join(', ')
|
||||
|
||||
if (alreadyInGroup) {
|
||||
return (
|
||||
<div role="alert" className="mt-2 rounded-xl bg-danger-soft px-3 py-2.5 text-sm text-danger-fg">
|
||||
{person.fullName} ya es miembro de este grupo.
|
||||
{t('existing.alreadyInGroup', { name: person.fullName })}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -38,30 +40,29 @@ export function ExistingPersonNotice({
|
||||
<UserCheck className="mt-0.5 size-4 shrink-0 text-accent-fg" aria-hidden="true" />
|
||||
<p className="min-w-0">
|
||||
{isLinked ? (
|
||||
<>
|
||||
Vas a agregar a <strong>{person.fullName}</strong> a este grupo. Sus datos de contacto
|
||||
y notas son los mismos que en sus otros grupos.
|
||||
</>
|
||||
<Trans t={t} i18nKey="existing.linked" values={{ name: person.fullName }} components={{ strong: <strong /> }} />
|
||||
) : (
|
||||
<>
|
||||
Ya tenés a <strong>{person.fullName}</strong> con este teléfono
|
||||
{groupNames ? ` (en ${groupNames})` : ''}. ¿Es la misma persona?
|
||||
</>
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={groupNames ? 'existing.foundInGroups' : 'existing.found'}
|
||||
values={{ name: person.fullName, groups: groupNames }}
|
||||
components={{ strong: <strong /> }}
|
||||
/>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-2.5 flex flex-wrap justify-end gap-2">
|
||||
{isLinked ? (
|
||||
<Button variant="ghost" onClick={onUnlink} size="sm">
|
||||
No es esta persona
|
||||
{t('existing.notThisPerson')}
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="ghost" onClick={onChangePhone} size="sm">
|
||||
Usar otro teléfono
|
||||
{t('existing.otherPhone')}
|
||||
</Button>
|
||||
<Button variant="primary" onClick={onLink} size="sm">
|
||||
Sí, agregarla
|
||||
{t('existing.confirm')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import { Check, Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button, Input, Label, useToast } from '../../../components/ui'
|
||||
import { useAddAttendee } from './AddAttendeeProvider'
|
||||
import { ExistingPersonNotice } from './ExistingPersonNotice'
|
||||
@@ -8,6 +9,7 @@ import { usePersonLookup } from './usePersonLookup'
|
||||
export function QuickAddForm() {
|
||||
const { groupId, submitQuickAttendee, isSubmittingAttendee, cancelAddAttendee } = useAddAttendee()
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation(['groupAdd', 'common'])
|
||||
const [firstName, setFirstName] = useState('')
|
||||
const [lastName, setLastName] = useState('')
|
||||
const [phone, setPhone] = useState('')
|
||||
@@ -39,11 +41,11 @@ export function QuickAddForm() {
|
||||
return
|
||||
}
|
||||
if (mustLink) {
|
||||
toast.info('Ese teléfono ya es de una persona registrada: agregala o usá otro teléfono.')
|
||||
toast.info(t('quick.mustLink'))
|
||||
return
|
||||
}
|
||||
if (!firstName.trim() || !phone.trim()) {
|
||||
toast.error('Nombre y teléfono son obligatorios.')
|
||||
toast.error(t('quick.required'))
|
||||
return
|
||||
}
|
||||
submitQuickAttendee({
|
||||
@@ -69,11 +71,11 @@ export function QuickAddForm() {
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<Label htmlFor="quick-first-name" className="mb-1 block text-xs">
|
||||
Nombre <span className="text-danger">*</span>
|
||||
{t('quick.firstName')} <span className="text-danger">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="quick-first-name"
|
||||
placeholder="Ej. Lucas"
|
||||
placeholder={t('quick.firstNamePlaceholder')}
|
||||
value={linkedPerson ? linkedPerson.fullName : firstName}
|
||||
onChange={(e) => setFirstName(e.target.value)}
|
||||
disabled={isLinked}
|
||||
@@ -82,11 +84,11 @@ export function QuickAddForm() {
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="quick-last-name" className="mb-1 block text-xs">
|
||||
Apellido
|
||||
{t('quick.lastName')}
|
||||
</Label>
|
||||
<Input
|
||||
id="quick-last-name"
|
||||
placeholder="Ej. González"
|
||||
placeholder={t('quick.lastNamePlaceholder')}
|
||||
value={isLinked ? '' : lastName}
|
||||
onChange={(e) => setLastName(e.target.value)}
|
||||
disabled={isLinked}
|
||||
@@ -96,11 +98,11 @@ export function QuickAddForm() {
|
||||
|
||||
<div>
|
||||
<Label htmlFor="quick-phone" className="mb-1 block text-xs">
|
||||
Teléfono / WhatsApp <span className="text-danger">*</span>
|
||||
{t('quick.phone')} <span className="text-danger">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="quick-phone"
|
||||
placeholder="Ej. +54 9 11 2345-6789"
|
||||
placeholder={t('quick.phonePlaceholder')}
|
||||
ref={phoneRef}
|
||||
value={phone}
|
||||
onChange={(e) => {
|
||||
@@ -123,19 +125,19 @@ export function QuickAddForm() {
|
||||
/>
|
||||
) : (
|
||||
<p className="mt-1 text-[11px] text-foreground/50">
|
||||
Usado para contacto y validación de duplicados.
|
||||
{t('quick.phoneHint')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label htmlFor="quick-email" className="mb-1 block text-xs">
|
||||
Email (opcional)
|
||||
{t('quick.email')}
|
||||
</Label>
|
||||
<Input
|
||||
id="quick-email"
|
||||
type="email"
|
||||
placeholder="alumno@ejemplo.com"
|
||||
placeholder={t('quick.emailPlaceholder')}
|
||||
value={linkedPerson ? (linkedPerson.email ?? '') : email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
disabled={isLinked}
|
||||
@@ -144,11 +146,11 @@ export function QuickAddForm() {
|
||||
|
||||
<div>
|
||||
<Label htmlFor="quick-notes" className="mb-1 block text-xs">
|
||||
Notas u Observaciones (opcional)
|
||||
{t('quick.notes')}
|
||||
</Label>
|
||||
<Input
|
||||
id="quick-notes"
|
||||
placeholder="Ej. Nivel intermedio, trae materiales propios"
|
||||
placeholder={t('quick.notesPlaceholder')}
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
disabled={isLinked}
|
||||
@@ -164,7 +166,7 @@ export function QuickAddForm() {
|
||||
}}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -173,7 +175,7 @@ export function QuickAddForm() {
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
{isSubmittingAttendee ? <Loader2 className="size-4 animate-spin" /> : <Check className="size-4" />}
|
||||
<span>Guardar Miembro</span>
|
||||
<span>{t('quick.submit')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -3,8 +3,10 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { Link, useParams } from '@tanstack/react-router'
|
||||
import type { GroupDto, StudentAtRiskDto } from '@gruperly/shared'
|
||||
import { ArrowLeft, CalendarCheck, DoorOpen, Loader2, Percent, Users } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { LargeTitle } from '../../../components/layout/LargeTitle'
|
||||
import { Badge, Button, useToast } from '../../../components/ui'
|
||||
import { errorMessage, useIntlLocale } from '../../../i18n'
|
||||
import { getAttendeeHistory, getGroupAnalytics, getStudentsAtRisk, updateAttendeeStatus } from '../../../lib/api'
|
||||
import { KpiCard } from './KpiCard'
|
||||
import { AtRiskStudentCard, type StatusAction } from './AtRiskStudentCard'
|
||||
@@ -15,6 +17,8 @@ export function AnalyticsView() {
|
||||
const { groupId } = useParams({ strict: false }) as { groupId: string }
|
||||
const queryClient = useQueryClient()
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation(['analytics', 'common', 'groupDetail'])
|
||||
const locale = useIntlLocale()
|
||||
|
||||
const [historyStudent, setHistoryStudent] = useState<StudentAtRiskDto | null>(null)
|
||||
const [statusAction, setStatusAction] = useState<StatusAction>(null)
|
||||
@@ -45,8 +49,8 @@ export function AnalyticsView() {
|
||||
const name = action.student.fullName.split(' ')[0]
|
||||
toast.success(
|
||||
action.status === 'DROPPED'
|
||||
? `${name} fue dado de baja del grupo. Su vacante quedó disponible.`
|
||||
: `La vacante de ${name} quedó pausada.`,
|
||||
? t('status.dropped', { name })
|
||||
: t('status.paused', { name }),
|
||||
)
|
||||
setStatusAction(null)
|
||||
void queryClient.invalidateQueries({ queryKey: ['students-at-risk', groupId] })
|
||||
@@ -57,21 +61,18 @@ export function AnalyticsView() {
|
||||
void queryClient.invalidateQueries({ queryKey: ['groups-risk-overview'] })
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
toast.error(err.message || 'No pudimos actualizar el estado del alumno.')
|
||||
toast.error(errorMessage(err, t('status.error')))
|
||||
},
|
||||
})
|
||||
|
||||
const handleReengage = async (student: StudentAtRiskDto, groupName: string) => {
|
||||
if (!student.phone) return
|
||||
const firstName = student.fullName.split(' ')[0] ?? student.fullName
|
||||
const message =
|
||||
`¡Hola ${firstName}! 👋 Te extrañamos en ${groupName}. ` +
|
||||
'Notamos que no asististe a las últimas clases y queremos que vuelvas. ' +
|
||||
'Si tenés algún problema con tus horarios o tu membresía, escribinos y lo resolvemos juntos.'
|
||||
const message = t('atRisk.reengageMessage', { name: firstName, group: groupName })
|
||||
const waUrl = `https://wa.me/${student.phone.replace(/\D/g, '')}?text=${encodeURIComponent(message)}`
|
||||
try {
|
||||
await navigator.clipboard.writeText(message)
|
||||
toast.success('¡Abriendo WhatsApp! Mensaje copiado al portapapeles.')
|
||||
toast.success(t('atRisk.openingWhatsapp'))
|
||||
} catch {
|
||||
// If clipboard fails, we still open WhatsApp with the message.
|
||||
}
|
||||
@@ -98,7 +99,7 @@ export function AnalyticsView() {
|
||||
the bar its height and stops the layout from jumping when the data
|
||||
arrives. */}
|
||||
<LargeTitle
|
||||
title={groupName ?? 'Grupo'}
|
||||
title={groupName ?? t('groupDetail:fallbackTitle')}
|
||||
leading={
|
||||
<Link
|
||||
to="/groups/$groupId"
|
||||
@@ -106,7 +107,7 @@ export function AnalyticsView() {
|
||||
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" />
|
||||
Volver al grupo
|
||||
{t('back')}
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
@@ -116,14 +117,14 @@ export function AnalyticsView() {
|
||||
<div className="mt-2 flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<p className="text-[14px] font-semibold uppercase tracking-wide text-foreground/70">
|
||||
Estadísticas
|
||||
{t('subtitle')}
|
||||
</p>
|
||||
<p className="mt-0.5 text-pretty text-sm text-foreground/80">
|
||||
Asistencia y gestión de riesgo
|
||||
{t('description')}
|
||||
</p>
|
||||
</div>
|
||||
<span className="shrink-0 rounded-xl bg-primary-soft px-3 py-1.5 text-xs font-semibold text-foreground/70">
|
||||
Últimos 30 días
|
||||
{t('period')}
|
||||
</span>
|
||||
</div>
|
||||
</LargeTitle>
|
||||
@@ -136,8 +137,8 @@ export function AnalyticsView() {
|
||||
|
||||
{hasFailed ? (
|
||||
<div className="mt-6 rounded-xl border border-danger/20 bg-danger-soft p-6 text-danger">
|
||||
<h2 className="text-lg font-semibold">No pudimos cargar las estadísticas</h2>
|
||||
<p className="mt-2 text-sm">Verificá tu conexión e intentá de nuevo.</p>
|
||||
<h2 className="text-lg font-semibold">{t('loadError.title')}</h2>
|
||||
<p className="mt-2 text-sm">{t('loadError.description')}</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-4"
|
||||
@@ -146,7 +147,7 @@ export function AnalyticsView() {
|
||||
void riskQuery.refetch()
|
||||
}}
|
||||
>
|
||||
Reintentar
|
||||
{t('common:actions.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -156,43 +157,43 @@ export function AnalyticsView() {
|
||||
<div className="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-3">
|
||||
<KpiCard
|
||||
icon={<Percent className="size-5" />}
|
||||
label="Asistencia promedio"
|
||||
label={t('kpi.attendanceRate')}
|
||||
value={`${analytics.attendanceRate}%`}
|
||||
hint="últimos 30 días"
|
||||
hint={t('kpi.attendanceRateHint')}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={<CalendarCheck className="size-5" />}
|
||||
label="Asistencias del mes"
|
||||
value={analytics.totalPresent.toLocaleString('es-MX')}
|
||||
hint={`${analytics.totalClasses} clases dictadas`}
|
||||
label={t('kpi.present')}
|
||||
value={analytics.totalPresent.toLocaleString(locale)}
|
||||
hint={t('kpi.presentHint', { count: analytics.totalClasses })}
|
||||
/>
|
||||
<KpiCard
|
||||
icon={<DoorOpen className="size-5" />}
|
||||
label="Cupos recuperados"
|
||||
value={analytics.recoveredSlots.toLocaleString('es-MX')}
|
||||
hint="por ausencias avisadas"
|
||||
label={t('kpi.recovered')}
|
||||
value={analytics.recoveredSlots.toLocaleString(locale)}
|
||||
hint={t('kpi.recoveredHint')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<div className="flex items-center gap-2">
|
||||
<Users className="size-5 text-accent" />
|
||||
<h2 className="text-lg font-semibold text-primary">Alumnos en riesgo</h2>
|
||||
<h2 className="text-lg font-semibold text-primary">{t('atRisk.title')}</h2>
|
||||
{atRisk.length > 0 ? (
|
||||
<Badge variant={atRisk.some((s) => s.riskLevel === 'HIGH') ? 'danger' : 'warning'}>
|
||||
{atRisk.length} {atRisk.length === 1 ? 'alumno' : 'alumnos'}
|
||||
{t('atRisk.count', { count: atRisk.length })}
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-foreground/60">
|
||||
Alumnos con faltas seguidas, que dejaron de venir o cuya asistencia viene en baja.
|
||||
{t('atRisk.description')}
|
||||
</p>
|
||||
|
||||
{atRisk.length === 0 ? (
|
||||
<div className="mt-4 rounded-xl border border-dashed border-border bg-surface px-4 py-10 text-center">
|
||||
<p className="font-medium text-primary">¡Sin alumnos en riesgo!</p>
|
||||
<p className="font-medium text-primary">{t('atRisk.emptyTitle')}</p>
|
||||
<p className="mt-1 text-sm text-foreground/60">
|
||||
No hay ausencias consecutivas ni asistencia por debajo del 50%.
|
||||
{t('atRisk.emptyDescription')}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
@@ -206,7 +207,7 @@ export function AnalyticsView() {
|
||||
setMenuOpenFor(menuOpenFor === student.attendeeId ? null : student.attendeeId)
|
||||
}
|
||||
onViewHistory={() => setHistoryStudent(student)}
|
||||
onReengage={() => void handleReengage(student, groupName ?? 'tu clase')}
|
||||
onReengage={() => void handleReengage(student, groupName ?? t('atRisk.yourClass'))}
|
||||
onRequestStatusAction={(action) => {
|
||||
setStatusAction(action)
|
||||
setMenuOpenFor(null)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { StudentAtRiskDto } from '@gruperly/shared'
|
||||
import { MessageCircle, MoreVertical, Pause, UserMinus } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Avatar, Badge, Button } from '../../../components/ui'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
|
||||
export type StatusAction = { student: StudentAtRiskDto; status: 'PAUSED' | 'DROPPED' } | null
|
||||
@@ -20,6 +22,7 @@ export function AtRiskStudentCard({
|
||||
onReengage: () => void
|
||||
onRequestStatusAction: (action: Exclude<StatusAction, null>) => void
|
||||
}) {
|
||||
const { t } = useTranslation('analytics')
|
||||
return (
|
||||
<li className="rounded-xl border border-border bg-surface p-4 transition-colors hover:border-accent/40">
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -32,10 +35,9 @@ export function AtRiskStudentCard({
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-semibold text-primary">{student.fullName}</p>
|
||||
<p className="mt-0.5 text-xs text-foreground/50">
|
||||
{student.phone
|
||||
? `${formatPhoneDisplay(student.phone)} · `
|
||||
: 'Sin teléfono · '}
|
||||
{student.monthlyAttendanceRate}% de asistencia mensual
|
||||
{student.phone ? formatPhoneDisplay(student.phone) : t('atRisk.noPhone')}
|
||||
{' · '}
|
||||
{t('atRisk.monthlyRate', { rate: student.monthlyAttendanceRate })}
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
@@ -53,14 +55,14 @@ export function AtRiskStudentCard({
|
||||
className="flex-1 gap-2 border-0 bg-[#25D366] text-white hover:bg-[#1EBE5D] disabled:bg-foreground/10 disabled:text-foreground/40"
|
||||
>
|
||||
<MessageCircle className="size-4" />
|
||||
Reenganchar por WhatsApp
|
||||
{t('atRisk.reengage')}
|
||||
</Button>
|
||||
|
||||
<div className="relative">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Gestión de la vacante"
|
||||
aria-label={t('atRisk.manage')}
|
||||
onClick={onToggleMenu}
|
||||
>
|
||||
<MoreVertical className="size-4" />
|
||||
@@ -80,7 +82,7 @@ export function AtRiskStudentCard({
|
||||
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-primary transition-colors hover:bg-primary-soft"
|
||||
>
|
||||
<Pause className="size-4" />
|
||||
Pausar vacante
|
||||
{t('atRisk.pause')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@@ -88,7 +90,7 @@ export function AtRiskStudentCard({
|
||||
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-danger transition-colors hover:bg-danger-soft"
|
||||
>
|
||||
<UserMinus className="size-4" />
|
||||
Dar de baja
|
||||
{t('atRisk.drop')}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
@@ -105,10 +107,10 @@ const DAY_MS = 86_400_000
|
||||
then the time without coming, and last the declining trend (the only thing
|
||||
left that can flag someone with neither). */
|
||||
function riskReason(student: StudentAtRiskDto): string {
|
||||
if (student.consecutiveAbsences >= 2) return `${student.consecutiveAbsences} faltas seguidas`
|
||||
if (student.consecutiveAbsences >= 2) return i18n.t('analytics:atRisk.reasonStreak', { count: student.consecutiveAbsences })
|
||||
if (student.riskLevel === 'HIGH' && student.lastAttendedAt) {
|
||||
const days = Math.floor((Date.now() - new Date(student.lastAttendedAt).getTime()) / DAY_MS)
|
||||
return `${days} días sin venir`
|
||||
return i18n.t('analytics:atRisk.reasonDays', { count: days })
|
||||
}
|
||||
return 'Asistencia en baja'
|
||||
return i18n.t('analytics:atRisk.reasonTrend')
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { StudentAtRiskDto } from '@gruperly/shared'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Modal } from '../../../components/ui'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { dotClass, formatSessionDate, sessionStatusTextClass, statusLabel } from './format'
|
||||
@@ -25,12 +26,13 @@ export function AttendeeHistoryModal({
|
||||
isError: boolean
|
||||
onClose: () => void
|
||||
}) {
|
||||
const { t } = useTranslation('analytics')
|
||||
return (
|
||||
<Modal
|
||||
isOpen={student !== null}
|
||||
onClose={onClose}
|
||||
title={student?.fullName ?? 'Historial'}
|
||||
description={student ? 'Historial de presentismo de las últimas clases.' : undefined}
|
||||
title={student?.fullName ?? t('history.title')}
|
||||
description={student ? t('history.description') : undefined}
|
||||
maxWidth="md"
|
||||
>
|
||||
{student ? (
|
||||
@@ -41,14 +43,14 @@ export function AttendeeHistoryModal({
|
||||
</div>
|
||||
) : isError || !sessions ? (
|
||||
<div className="rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
|
||||
No pudimos cargar el historial de este alumno.
|
||||
{t('history.error')}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex items-center gap-3 rounded-xl border border-border bg-primary-soft/50 p-3">
|
||||
<span className="text-2xl font-bold text-primary">{attendanceRate}%</span>
|
||||
<span className="text-xs font-medium uppercase text-foreground/60">
|
||||
Presentismo general ({sessions.length} clases)
|
||||
{t('history.overall', { count: sessions.length })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Loader2, Pause, UserMinus } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import type { StatusAction } from './AtRiskStudentCard'
|
||||
@@ -16,35 +17,28 @@ export function StatusActionModal({
|
||||
onCancel: () => void
|
||||
onConfirm: () => void
|
||||
}) {
|
||||
const { t } = useTranslation(['analytics', 'common'])
|
||||
const title = action?.status === 'DROPPED' ? t('status.dropTitle') : t('status.pauseTitle')
|
||||
return (
|
||||
<Modal
|
||||
isOpen={action !== null}
|
||||
onClose={onCancel}
|
||||
title={action?.status === 'DROPPED' ? 'Dar de baja' : 'Pausar vacante'}
|
||||
title={title}
|
||||
maxWidth="md"
|
||||
>
|
||||
{action ? (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-foreground/70">
|
||||
{action.student.fullName}{' '}
|
||||
{action.status === 'DROPPED' ? (
|
||||
<>
|
||||
dejará de asistir al grupo y <strong className="text-primary">{groupName}</strong>. Su
|
||||
vacante quedará <strong className="text-primary">disponible</strong> para otro alumno, y
|
||||
su historial de asistencia se conservará.
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
será <strong className="text-primary">pausado</strong> en{' '}
|
||||
<strong className="text-primary">{groupName}</strong>. Su vacante quedará{' '}
|
||||
<strong className="text-primary">libre</strong> y podés reactivarla en cualquier
|
||||
momento.
|
||||
</>
|
||||
)}
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={action.status === 'DROPPED' ? 'status.dropBody' : 'status.pauseBody'}
|
||||
values={{ name: action.student.fullName, group: groupName ?? '' }}
|
||||
components={{ strong: <strong className="text-primary" /> }}
|
||||
/>
|
||||
</p>
|
||||
<div className="flex flex-col gap-2.5 sm:flex-row sm:justify-end">
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -62,7 +56,7 @@ export function StatusActionModal({
|
||||
) : (
|
||||
<Pause className="size-4" />
|
||||
)}
|
||||
<span>{action.status === 'DROPPED' ? 'Dar de baja' : 'Pausar vacante'}</span>
|
||||
<span>{title}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
|
||||
export function statusLabel(status: string | null): string {
|
||||
switch (status) {
|
||||
case 'PRESENT':
|
||||
return 'Presente'
|
||||
case 'ABSENT':
|
||||
return 'Ausente'
|
||||
case 'EXCUSED':
|
||||
return 'Avisó ausencia'
|
||||
return i18n.t(`common:attendanceStatus.${status}`)
|
||||
default:
|
||||
return 'Sin registrar'
|
||||
return i18n.t('common:attendanceStatus.NONE')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export function sessionStatusTextClass(status: string | null): string {
|
||||
}
|
||||
|
||||
export function formatSessionDate(iso: string): string {
|
||||
return new Date(iso).toLocaleDateString('es-MX', {
|
||||
return new Date(iso).toLocaleDateString(i18n.language, {
|
||||
weekday: 'short',
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AttentionGroup, AttentionMember, GroupListItem, StudentAlertSeverity, UrgentMemberSummary } from '@gruperly/shared'
|
||||
import { compareByWorstAlert, worstAlert } from '@gruperly/shared'
|
||||
import { i18n } from '../../i18n/instance'
|
||||
|
||||
/* Derivations for the group listing card. The card queries nothing: it decides
|
||||
here what is shown and in what order, so the JSX only builds the layout and
|
||||
@@ -74,12 +75,12 @@ export function groupStatus(
|
||||
const flagged = members.filter((member) => member.alerts.length > 0)
|
||||
if (flagged.length > 0) {
|
||||
const urgent = flagged.some((member) => member.alerts.some((alert) => alert.gravedad === 'urgente'))
|
||||
return { tone: urgent ? 'urgente' : 'vigilar', text: `${flagged.length} en riesgo` }
|
||||
return { tone: urgent ? 'urgente' : 'vigilar', text: i18n.t('groups:card.atRisk', { count: flagged.length }) }
|
||||
}
|
||||
if (capacity === null) return null
|
||||
const free = freeSpots(capacity, occupied)
|
||||
if (free > 0) return { tone: 'free', text: `${free} ${free === 1 ? 'libre' : 'libres'}` }
|
||||
return { tone: 'full', text: 'Completo' }
|
||||
if (free > 0) return { tone: 'free', text: i18n.t('groups:card.free', { count: free }) }
|
||||
return { tone: 'full', text: i18n.t('groups:card.full') }
|
||||
}
|
||||
|
||||
/** "4 grupos · 37 alumnos · 7 lugares libres" under the page title. */
|
||||
@@ -87,9 +88,9 @@ export function groupsSummary(groups: Pick<GroupListItem, 'attendeesCount' | 'ca
|
||||
const students = groups.reduce((total, group) => total + group.attendeesCount, 0)
|
||||
const free = groups.reduce((total, group) => total + freeSpots(group.capacity, group.attendeesCount), 0)
|
||||
return [
|
||||
plural(groups.length, 'grupo', 'grupos'),
|
||||
plural(students, 'alumno', 'alumnos'),
|
||||
plural(free, 'lugar libre', 'lugares libres'),
|
||||
i18n.t('groups:summary.groups', { count: groups.length }),
|
||||
i18n.t('groups:summary.students', { count: students }),
|
||||
i18n.t('groups:summary.freeSpots', { count: free }),
|
||||
].join(' · ')
|
||||
}
|
||||
|
||||
@@ -102,10 +103,6 @@ function freeSpots(capacity: number | null, occupied: number): number {
|
||||
return capacity === null ? 0 : Math.max(capacity - occupied, 0)
|
||||
}
|
||||
|
||||
function plural(count: number, one: string, many: string): string {
|
||||
return `${count} ${count === 1 ? one : many}`
|
||||
}
|
||||
|
||||
/* The reason Home shows next to an at-risk student: first a streak of absences
|
||||
(something that is going away), then the time since last showing up, and
|
||||
last the attendance rate. A single absence only names them when nothing else
|
||||
@@ -113,9 +110,9 @@ function plural(count: number, one: string, many: string): string {
|
||||
export function absenceReason(miembro: UrgentMemberSummary): string | null {
|
||||
const { consecutiveAbsences: faltas, daysSinceLastAttendance: dias, attendanceRate: asistencia } = miembro
|
||||
|
||||
if (faltas >= 2) return `${faltas} faltas`
|
||||
if (dias != null && dias > 0) return `${dias} ${dias === 1 ? 'día' : 'días'} sin venir`
|
||||
if (faltas === 1) return '1 falta'
|
||||
if (asistencia != null && asistencia < 100) return `asistencia ${asistencia}%`
|
||||
if (faltas >= 2) return i18n.t('groups:absence.streak', { count: faltas })
|
||||
if (dias != null && dias > 0) return i18n.t('groups:absence.daysAway', { count: dias })
|
||||
if (faltas === 1) return i18n.t('groups:absence.single')
|
||||
if (asistencia != null && asistencia < 100) return i18n.t('groups:absence.rate', { rate: asistencia })
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import type { GroupRiskLevel } from '@gruperly/shared'
|
||||
|
||||
export const RISK_LABELS: Record<Exclude<GroupRiskLevel, 'NONE'>, string> = {
|
||||
HIGH: 'Riesgo alto',
|
||||
MEDIUM: 'Riesgo moderado',
|
||||
}
|
||||
|
||||
/* The badge only says "Riesgo moderado"; this sentence explains what it is about
|
||||
(an attendee dropping out, not fraud or collections) and lives in the tooltip. */
|
||||
export const RISK_HINT =
|
||||
'Riesgo de abandono: probabilidad estimada de que algún miembro abandone el grupo.'
|
||||
/* Copy: `groups:risk.HIGH` / `groups:risk.MEDIUM`. The badge only says "Riesgo
|
||||
moderado"; `groups:risk.hint` explains what it is about (an attendee dropping
|
||||
out, not fraud or collections) and lives in the tooltip. */
|
||||
export type VisibleRiskLevel = Exclude<GroupRiskLevel, 'NONE'>
|
||||
|
||||
/* The concrete reason ("4 members with consecutive absences") is not computed
|
||||
here anymore: it lives in `card.ts`, which also decides the badge's visual
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import type { AbsenceReasonValue } from '@gruperly/shared'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Avatar, Badge } from '../../../components/ui'
|
||||
import { useIntlLocale } from '../../../i18n'
|
||||
import { getGroupAbsenceNotices } from '../../../lib/api'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
const REASON_LABELS: Record<AbsenceReasonValue, string> = {
|
||||
health: 'Salud',
|
||||
travel: 'Viaje',
|
||||
work_study: 'Trabajo o estudio',
|
||||
other: 'Otro',
|
||||
}
|
||||
|
||||
function classLabel(iso: string): string {
|
||||
function classLabel(iso: string, locale: string): string {
|
||||
return new Date(iso)
|
||||
.toLocaleString('es-AR', { weekday: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })
|
||||
.toLocaleString(locale, { weekday: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })
|
||||
.replace(/\./g, '')
|
||||
}
|
||||
|
||||
@@ -21,6 +15,8 @@ function classLabel(iso: string): string {
|
||||
when there is something to show, so it doesn't push the members list down. */
|
||||
export function AbsenceNoticesCard() {
|
||||
const { groupId } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const locale = useIntlLocale()
|
||||
const query = useQuery({
|
||||
queryKey: ['absence-notices', groupId],
|
||||
queryFn: () => getGroupAbsenceNotices(groupId),
|
||||
@@ -31,7 +27,7 @@ export function AbsenceNoticesCard() {
|
||||
return (
|
||||
<section aria-labelledby="absence-notices-title" className="rounded-xl border border-border bg-surface">
|
||||
<h2 id="absence-notices-title" className="px-4 pt-4 text-sm font-semibold text-primary">
|
||||
Faltas avisadas · esta semana
|
||||
{t('absenceNotices.title')}
|
||||
</h2>
|
||||
<ul className="divide-y divide-border">
|
||||
{notices.map((notice) => (
|
||||
@@ -40,11 +36,11 @@ export function AbsenceNoticesCard() {
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="truncate text-sm font-medium text-primary">{notice.attendee.fullName}</p>
|
||||
<Badge variant="success">Justificada</Badge>
|
||||
<Badge variant="success">{t('absenceNotices.excused')}</Badge>
|
||||
</div>
|
||||
<p className="text-xs capitalize text-secondary">
|
||||
{classLabel(notice.startsAt)}
|
||||
{notice.reason ? ` · ${REASON_LABELS[notice.reason]}` : ''}
|
||||
{classLabel(notice.startsAt, locale)}
|
||||
{notice.reason ? ` · ${t(`absenceNotices.reason.${notice.reason}`)}` : ''}
|
||||
</p>
|
||||
{notice.message ? <p className="mt-1 text-sm text-primary">“{notice.message}”</p> : null}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,10 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { Check, Copy, Loader2, TriangleAlert, Wallet } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Badge, Button, Input, Label, Modal } from '../../../components/ui'
|
||||
import { errorMessage } from '../../../i18n'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import { ApiError, createPaymentsBatch } from '../../../lib/api'
|
||||
import { formatPrice } from '../../../lib/format'
|
||||
import { mpStatusBadgeVariant, mpStatusLabel, useMpStatus } from '../../mp'
|
||||
@@ -23,7 +26,7 @@ function localDateValue(date: Date): string {
|
||||
}
|
||||
|
||||
function monthLabel(date: Date): string {
|
||||
return date.toLocaleDateString('es-MX', { month: 'long', year: 'numeric' })
|
||||
return date.toLocaleDateString(i18n.language, { month: 'long', year: 'numeric' })
|
||||
}
|
||||
|
||||
function defaultDueDate(): Date {
|
||||
@@ -38,11 +41,12 @@ type LinkRowProps = {
|
||||
}
|
||||
|
||||
function LinkRow({ item, copiedId, onCopy }: LinkRowProps) {
|
||||
const { t } = useTranslation('groupDetail')
|
||||
if (item.outcome !== 'LINKED' || !item.checkoutUrl) {
|
||||
return (
|
||||
<li className="flex items-center justify-between gap-3 rounded-lg bg-primary-soft px-3 py-2.5">
|
||||
<span className="min-w-0 truncate text-sm text-primary">{item.attendeeName}</span>
|
||||
<Badge variant="danger">No se generó</Badge>
|
||||
<Badge variant="danger">{t('charge.notGenerated')}</Badge>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
@@ -63,7 +67,7 @@ function LinkRow({ item, copiedId, onCopy }: LinkRowProps) {
|
||||
) : (
|
||||
<Copy className="size-3.5 text-accent" />
|
||||
)}
|
||||
{copied ? 'Copiado' : 'Copiar link'}
|
||||
{copied ? t('charge.copied') : t('charge.copyLink')}
|
||||
</Button>
|
||||
</li>
|
||||
)
|
||||
@@ -76,6 +80,7 @@ function LinkRow({ item, copiedId, onCopy }: LinkRowProps) {
|
||||
*/
|
||||
export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps) {
|
||||
const { group } = useGroupDetail()
|
||||
const { t } = useTranslation(['groupDetail', 'common'])
|
||||
const navigate = useNavigate()
|
||||
const queryClient = useQueryClient()
|
||||
const statusQuery = useMpStatus()
|
||||
@@ -107,19 +112,16 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
void queryClient.invalidateQueries({ queryKey: ['payments'] })
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
if (error instanceof ApiError) {
|
||||
setSubmissionError(
|
||||
error.problem?.code === 'mp_not_connected'
|
||||
? 'Tu cuenta de Mercado Pago no está vinculada.'
|
||||
: error.problem?.code === 'group_without_price'
|
||||
? 'Este grupo todavía no tiene precio.'
|
||||
: error.problem?.code === 'no_attendees_to_bill'
|
||||
? 'No hay miembros activos para cobrar.'
|
||||
: (error.problem?.detail ?? error.problem?.title ?? 'No pudimos crear los cobros.'),
|
||||
)
|
||||
} else {
|
||||
setSubmissionError('No pudimos crear los cobros.')
|
||||
}
|
||||
const code = error instanceof ApiError ? error.problem?.code : undefined
|
||||
setSubmissionError(
|
||||
code === 'mp_not_connected'
|
||||
? t('charge.mpNotConnected')
|
||||
: code === 'group_without_price'
|
||||
? t('charge.noPrice')
|
||||
: code === 'no_attendees_to_bill'
|
||||
? t('charge.noAttendees')
|
||||
: errorMessage(error, t('charge.error')),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -142,8 +144,8 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
title="Cobrar período"
|
||||
description={group?.name ? `Links de pago para ${group.name}` : undefined}
|
||||
title={t('charge.title')}
|
||||
description={group?.name ? t('charge.description', { group: group.name }) : undefined}
|
||||
maxWidth="md"
|
||||
>
|
||||
{!isConnected ? (
|
||||
@@ -151,21 +153,21 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
<Badge variant={mpStatusBadgeVariant(status)}>{mpStatusLabel(status)}</Badge>
|
||||
<p className="flex items-start gap-2 rounded-xl bg-warning-soft px-4 py-3 text-sm text-warning">
|
||||
<TriangleAlert className="mt-0.5 size-4 shrink-0" />
|
||||
Para crear links de pago primero vinculá tu cuenta de Mercado Pago.
|
||||
{t('charge.notConnected')}
|
||||
</p>
|
||||
<Button
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
onClick={() => void navigate({ to: '/settings' })}
|
||||
>
|
||||
Conectar Mercado Pago
|
||||
{t('charge.connect')}
|
||||
</Button>
|
||||
</div>
|
||||
) : result ? (
|
||||
<div className="space-y-5">
|
||||
<p className="flex items-center gap-2 text-sm text-primary">
|
||||
<Wallet className="size-4 text-accent" />
|
||||
{result.linked} de {result.total} links creados
|
||||
{t('charge.created', { linked: result.linked, total: result.total })}
|
||||
</p>
|
||||
|
||||
<ul className="space-y-2">
|
||||
@@ -176,14 +178,13 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
|
||||
{result.failed > 0 ? (
|
||||
<p className="rounded-xl bg-primary-soft px-4 py-3 text-xs leading-relaxed text-foreground/70">
|
||||
Los que no se generaron quedaron guardados: vas a poder crearles el link desde
|
||||
Cobros sin cargarle nada al alumno.
|
||||
{t('charge.failedNote')}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="primary" onClick={onClose}>
|
||||
Listo
|
||||
{t('charge.done')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -197,14 +198,14 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
}}
|
||||
>
|
||||
<div className="flex items-center justify-between rounded-xl bg-primary-soft px-4 py-3">
|
||||
<span className="text-sm text-foreground/70">Cuota del grupo</span>
|
||||
<span className="text-sm text-foreground/70">{t('charge.fee')}</span>
|
||||
<span className="text-sm font-semibold text-primary">{formatPrice(price)}</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label htmlFor="charge-due-date" className="mb-1.5 block">
|
||||
Vencimiento
|
||||
{t('charge.dueDate')}
|
||||
</Label>
|
||||
<Input
|
||||
id="charge-due-date"
|
||||
@@ -225,7 +226,7 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
|
||||
<div>
|
||||
<Label htmlFor="charge-description" className="mb-1.5 block">
|
||||
Período o concepto
|
||||
{t('charge.period')}
|
||||
</Label>
|
||||
<Input
|
||||
id="charge-description"
|
||||
@@ -233,7 +234,7 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
maxLength={120}
|
||||
value={description}
|
||||
onChange={(event) => setDescription(event.target.value)}
|
||||
placeholder="Ej.: Octubre 2026"
|
||||
placeholder={t('charge.periodPlaceholder')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -246,7 +247,7 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
|
||||
<div className="flex items-center justify-end gap-3">
|
||||
<Button type="button" variant="ghost" onClick={onClose}>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button type="submit" variant="primary" disabled={create.isPending}>
|
||||
{create.isPending ? (
|
||||
@@ -254,7 +255,7 @@ export function ChargeMembersModal({ isOpen, onClose }: ChargeMembersModalProps)
|
||||
) : (
|
||||
<Wallet className="size-4" />
|
||||
)}
|
||||
Crear links de pago
|
||||
{t('charge.submit')}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { GroupAutomationsDto } from '@gruperly/shared'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { ChevronDown, MessageCircle } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Badge, Switch } from '../../../components/ui'
|
||||
import { hasPlanFeature, useBillingStatus } from '../../billing'
|
||||
import { cn } from '../../../lib/utils'
|
||||
@@ -11,22 +12,23 @@ import { useGroupDetail } from './GroupDetailProvider'
|
||||
type Automation = {
|
||||
key: keyof GroupAutomationsDto
|
||||
kind: 'PAYMENT_REMINDER' | 'REENGAGEMENT'
|
||||
title: string
|
||||
description: string
|
||||
/** Keys in `groupDetail:automations`. */
|
||||
title: 'automations.paymentReminderTitle' | 'automations.reengagementTitle'
|
||||
description: 'automations.paymentReminderDescription' | 'automations.reengagementDescription'
|
||||
}
|
||||
|
||||
const AUTOMATIONS: readonly Automation[] = [
|
||||
{
|
||||
key: 'autoPaymentReminders',
|
||||
kind: 'PAYMENT_REMINDER',
|
||||
title: 'Recordatorio semanal de pago',
|
||||
description: 'A quien tenga un cobro pendiente o vencido, con su link de pago.',
|
||||
title: 'automations.paymentReminderTitle',
|
||||
description: 'automations.paymentReminderDescription',
|
||||
},
|
||||
{
|
||||
key: 'autoReengagement',
|
||||
kind: 'REENGAGEMENT',
|
||||
title: 'Mensaje de reenganche semanal',
|
||||
description: 'A los miembros en riesgo por faltas. Como mucho uno cada 2 semanas.',
|
||||
title: 'automations.reengagementTitle',
|
||||
description: 'automations.reengagementDescription',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -41,6 +43,7 @@ const AUTOMATIONS: readonly Automation[] = [
|
||||
*/
|
||||
export function GroupAutomationsCard() {
|
||||
const { group, updateAutomations, isUpdatingAutomations, isGroupOwner } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const whatsappQuery = useWhatsappStatus({ enabled: isGroupOwner })
|
||||
const billingQuery = useBillingStatus({ enabled: isGroupOwner })
|
||||
// `null` until the owner touches it: the default follows the data, which may
|
||||
@@ -51,7 +54,7 @@ export function GroupAutomationsCard() {
|
||||
const activeCount = AUTOMATIONS.filter((automation) => group[automation.key]).length
|
||||
const expanded = expandedByUser ?? activeCount > 0
|
||||
const summary =
|
||||
activeCount === 0 ? 'Apagados' : activeCount === 1 ? '1 activo' : `${activeCount} activos`
|
||||
activeCount === 0 ? t('automations.summaryOff') : t('automations.summary', { count: activeCount })
|
||||
|
||||
return (
|
||||
<section className="rounded-xl border border-border bg-surface">
|
||||
@@ -67,10 +70,10 @@ export function GroupAutomationsCard() {
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="text-sm font-semibold text-primary">Mensajes automáticos</span>
|
||||
<span className="text-sm font-semibold text-primary">{t('automations.title')}</span>
|
||||
{includedInPlan ? null : <Badge variant="info">Pro</Badge>}
|
||||
</span>
|
||||
<span className="block text-xs text-foreground/50">WhatsApp · {summary}</span>
|
||||
<span className="block text-xs text-foreground/50">{t('automations.channel', { summary })}</span>
|
||||
</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
@@ -88,9 +91,9 @@ export function GroupAutomationsCard() {
|
||||
{includedInPlan ? null : (
|
||||
<>
|
||||
{' '}
|
||||
Disponible en el plan Pro.{' '}
|
||||
{t('automations.proOnly')}{' '}
|
||||
<Link to="/billing" className="font-medium text-accent-fg underline">
|
||||
Ver planes
|
||||
{t('automations.seePlans')}
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
@@ -104,16 +107,16 @@ export function GroupAutomationsCard() {
|
||||
return (
|
||||
<li key={automation.key} className="flex items-start gap-3 px-4 py-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm text-primary">{automation.title}</p>
|
||||
<p className="text-sm text-primary">{t(automation.title)}</p>
|
||||
<p id={hintId} className="text-xs text-foreground/50">
|
||||
{automation.description}
|
||||
{t(automation.description)}
|
||||
{blocked && !checked ? (
|
||||
<>
|
||||
{' '}
|
||||
<span className="text-warning">{blocked}</span>{' '}
|
||||
{whatsappQuery.data?.status !== 'active' ? (
|
||||
<Link to="/settings" className="font-medium text-accent-fg underline">
|
||||
Ir a Ajustes
|
||||
{t('automations.goToSettings')}
|
||||
</Link>
|
||||
) : null}
|
||||
</>
|
||||
@@ -125,7 +128,7 @@ export function GroupAutomationsCard() {
|
||||
disabled={
|
||||
isUpdatingAutomations || (!checked && (blocked !== null || !includedInPlan))
|
||||
}
|
||||
aria-label={automation.title}
|
||||
aria-label={t(automation.title)}
|
||||
aria-describedby={hintId}
|
||||
onCheckedChange={(next) => updateAutomations({ [automation.key]: next })}
|
||||
/>
|
||||
|
||||
@@ -11,7 +11,10 @@ import type {
|
||||
GroupWaitlistEntryDto,
|
||||
GroupRiskLevel,
|
||||
} from '@gruperly/shared'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useToast } from '../../../components/ui'
|
||||
import { errorMessage } from '../../../i18n'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import { useAuth } from '../../../context/AuthProvider'
|
||||
import {
|
||||
ApiError,
|
||||
@@ -108,6 +111,8 @@ export function GroupDetailProvider({
|
||||
}) {
|
||||
const queryClient = useQueryClient()
|
||||
const toast = useToast()
|
||||
// Subscribes the provider to the language: it builds copy (title, invite message).
|
||||
useTranslation()
|
||||
const { user } = useAuth()
|
||||
|
||||
const [isInviteModalOpen, setIsInviteModalOpen] = useState(false)
|
||||
@@ -189,10 +194,10 @@ export function GroupDetailProvider({
|
||||
mutationFn: () => getInviteToken(groupId, true),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(['invite-token', groupId], data)
|
||||
toast.success('Se generó un nuevo enlace de invitación.')
|
||||
toast.success(i18n.t('groupDetail:invite.regenerated'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error('No se pudo regenerar el enlace de invitación.')
|
||||
toast.error(i18n.t('groupDetail:invite.regenerateError'))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -202,10 +207,10 @@ export function GroupDetailProvider({
|
||||
queryClient.setQueryData<GroupDto>(['group', groupId], (current) =>
|
||||
current ? { ...current, ...automations } : current,
|
||||
)
|
||||
toast.success('Guardamos los mensajes automáticos del grupo.')
|
||||
toast.success(i18n.t('groupDetail:automations.saved'))
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
toast.error(err.message || 'No se pudieron guardar los mensajes automáticos.')
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:automations.saveError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -219,10 +224,10 @@ export function GroupDetailProvider({
|
||||
promoteGroupWaitlistEntry(groupId, entryId, targetGroupId),
|
||||
onSuccess: (result, { targetGroupId }) => {
|
||||
if (targetGroupId === groupId) {
|
||||
toast.success(`${result.attendee.fullName} pasó de la lista de espera al grupo.`)
|
||||
toast.success(i18n.t('groupDetail:waitlistEntry.promoted', { name: result.attendee.fullName }))
|
||||
} else {
|
||||
const targetName = groupsQuery.data?.data.find((g) => g.id === targetGroupId)?.name ?? 'otro grupo'
|
||||
toast.success(`${result.attendee.fullName} pasó a ${targetName}.`)
|
||||
const targetName = groupsQuery.data?.data.find((g) => g.id === targetGroupId)?.name ?? i18n.t('groupDetail:waitlistEntry.otherGroup')
|
||||
toast.success(i18n.t('groupDetail:waitlistEntry.promotedTo', { name: result.attendee.fullName, group: targetName }))
|
||||
void queryClient.invalidateQueries({ queryKey: ['group-attendees', targetGroupId] })
|
||||
void queryClient.invalidateQueries({ queryKey: ['group', targetGroupId] })
|
||||
}
|
||||
@@ -231,9 +236,9 @@ export function GroupDetailProvider({
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
if (err instanceof ApiError && err.problem?.code === 'group_capacity_reached') {
|
||||
toast.error('El grupo alcanzó su cupo. Quita un miembro o aumenta el cupo primero.')
|
||||
toast.error(i18n.t('groupDetail:waitlistEntry.capacityReached'))
|
||||
} else {
|
||||
toast.error(err.message || 'No se pudo pasar al miembro al grupo.')
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:waitlistEntry.promoteError')))
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -241,11 +246,11 @@ export function GroupDetailProvider({
|
||||
const removeWaitlistEntryMutation = useMutation({
|
||||
mutationFn: (entry: GroupWaitlistEntryDto) => removeGroupWaitlistEntry(groupId, entry.id),
|
||||
onSuccess: (_result, entry) => {
|
||||
toast.success(`${entry.fullName} fue quitado de la lista de espera.`)
|
||||
toast.success(i18n.t('groupDetail:waitlistEntry.removed', { name: entry.fullName }))
|
||||
invalidateGroupQueries()
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
toast.error(err.message || 'No se pudo quitar de la lista de espera.')
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:waitlistEntry.removeError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -256,24 +261,24 @@ export function GroupDetailProvider({
|
||||
setSelectedPreRegistration(null)
|
||||
toast.success(
|
||||
result.outcome === 'added'
|
||||
? `${entry.fullName} ahora es miembro del grupo.`
|
||||
: `${entry.fullName} fue agregado a la lista de espera: el grupo está completo.`,
|
||||
? i18n.t('groupDetail:preRegistration.added', { name: entry.fullName })
|
||||
: i18n.t('groupDetail:preRegistration.waitlisted', { name: entry.fullName }),
|
||||
)
|
||||
invalidateGroupQueries()
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
if (err instanceof ApiError) {
|
||||
if (err.problem?.code === 'attendee_already_registered') {
|
||||
toast.error('Ya hay un miembro con ese teléfono en el grupo. Puedes rechazar la pre-inscripción.')
|
||||
toast.error(i18n.t('groupDetail:preRegistration.alreadyRegistered'))
|
||||
return
|
||||
}
|
||||
if (err.problem?.code === 'pre_registration_already_reviewed') {
|
||||
toast.error('Esta pre-inscripción ya fue revisada.')
|
||||
toast.error(i18n.t('groupDetail:preRegistration.alreadyReviewed'))
|
||||
invalidateGroupQueries()
|
||||
return
|
||||
}
|
||||
}
|
||||
toast.error(err.message || 'No se pudo aprobar la pre-inscripción.')
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:preRegistration.approveError')))
|
||||
},
|
||||
})
|
||||
|
||||
@@ -282,23 +287,23 @@ export function GroupDetailProvider({
|
||||
rejectGroupPreRegistration(groupId, entry.id),
|
||||
onSuccess: (_result, entry) => {
|
||||
setSelectedPreRegistration(null)
|
||||
toast.success(`La pre-inscripción de ${entry.fullName} fue rechazada.`)
|
||||
toast.success(i18n.t('groupDetail:preRegistration.rejected', { name: entry.fullName }))
|
||||
invalidateGroupQueries()
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
if (err instanceof ApiError && err.problem?.code === 'pre_registration_already_reviewed') {
|
||||
toast.error('Esta pre-inscripción ya fue revisada.')
|
||||
toast.error(i18n.t('groupDetail:preRegistration.alreadyReviewed'))
|
||||
invalidateGroupQueries()
|
||||
return
|
||||
}
|
||||
toast.error(err.message || 'No se pudo rechazar la pre-inscripción.')
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:preRegistration.rejectError')))
|
||||
},
|
||||
})
|
||||
|
||||
const inviteUrl = inviteTokenQuery.data?.inviteUrl
|
||||
const whatsappMessage =
|
||||
group && inviteUrl
|
||||
? `¡Hola! 👋 Te invito a unirte al grupo *${group.name}*.\n\nCompleta tu pre-inscripción en el siguiente enlace. El profesor revisará tu solicitud:\n${inviteUrl}`
|
||||
? i18n.t('groupDetail:invite.message', { group: group.name, url: inviteUrl })
|
||||
: ''
|
||||
const whatsappShareUrl = whatsappMessage
|
||||
? `https://wa.me/?text=${encodeURIComponent(whatsappMessage)}`
|
||||
@@ -308,9 +313,9 @@ export function GroupDetailProvider({
|
||||
if (!inviteUrl) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(inviteUrl)
|
||||
toast.success('¡Enlace de invitación copiado al portapapeles!')
|
||||
toast.success(i18n.t('groupDetail:invite.linkCopied'))
|
||||
} catch {
|
||||
toast.error('No se pudo copiar automáticamente. Copia el texto manualmente.')
|
||||
toast.error(i18n.t('groupDetail:invite.copyError'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,9 +323,9 @@ export function GroupDetailProvider({
|
||||
if (!whatsappMessage) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(whatsappMessage)
|
||||
toast.success('¡Mensaje copiado al portapapeles!')
|
||||
toast.success(i18n.t('groupDetail:invite.messageCopied'))
|
||||
} catch {
|
||||
toast.error('No se pudo copiar automáticamente. Copia el texto manualmente.')
|
||||
toast.error(i18n.t('groupDetail:invite.copyError'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +334,7 @@ export function GroupDetailProvider({
|
||||
try {
|
||||
if (whatsappMessage) {
|
||||
await navigator.clipboard.writeText(whatsappMessage)
|
||||
toast.success('¡Abriendo WhatsApp! Mensaje copiado al portapapeles.')
|
||||
toast.success(i18n.t('groupDetail:invite.openingWhatsapp'))
|
||||
}
|
||||
} catch {
|
||||
// If the clipboard fails, we still open WhatsApp with the message.
|
||||
@@ -342,7 +347,7 @@ export function GroupDetailProvider({
|
||||
// the group detail page the name is already cached; on the first load it falls
|
||||
// back to "Grupo".
|
||||
const cachedGroupName = queryClient.getQueryData<GroupDto>(['group', groupId])?.name
|
||||
const groupTitle = group?.name ?? cachedGroupName ?? 'Grupo'
|
||||
const groupTitle = group?.name ?? cachedGroupName ?? i18n.t('groupDetail:fallbackTitle')
|
||||
|
||||
const value: GroupDetailContextValue = {
|
||||
groupId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '../../../components/ui'
|
||||
import {
|
||||
@@ -33,6 +34,7 @@ export function GroupDetailView() {
|
||||
isGroupOwner,
|
||||
} = useGroupDetail()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const [isChargeModalOpen, setIsChargeModalOpen] = useState(false)
|
||||
// El plan que cuenta es el del dueño: para un ADMIN no sabemos el suyo y
|
||||
// decide el backend (un 402 abre el mismo aviso).
|
||||
@@ -58,14 +60,14 @@ export function GroupDetailView() {
|
||||
</div>
|
||||
) : !group ? (
|
||||
<div className="rounded-xl border border-danger/20 bg-danger-soft p-6 text-danger">
|
||||
<h2 className="text-lg font-semibold">Grupo no encontrado</h2>
|
||||
<p className="mt-2 text-sm">No se pudo cargar la información de este grupo.</p>
|
||||
<h2 className="text-lg font-semibold">{t('notFound.title')}</h2>
|
||||
<p className="mt-2 text-sm">{t('notFound.description')}</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-4"
|
||||
onClick={() => void navigate({ to: '/groups' })}
|
||||
>
|
||||
Volver a Grupos
|
||||
{t('notFound.back')}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import { ArrowLeft, BarChart3, Share2, UserPlus, Wallet } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Badge, Button, Tooltip } from '../../../components/ui'
|
||||
import { LargeTitle } from '../../../components/layout/LargeTitle'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { RISK_HINT, RISK_LABELS } from '../constants'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
@@ -21,6 +21,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
waitlistPending,
|
||||
} = useGroupDetail()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation(['groupDetail', 'groups'])
|
||||
const hasRisk = riskLevel === 'HIGH' || riskLevel === 'MEDIUM'
|
||||
|
||||
// Brand new group (no members, nothing pending): each tab's empty state
|
||||
@@ -45,7 +46,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
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" />
|
||||
<span>Volver a grupos</span>
|
||||
<span>{t('header.backToGroups')}</span>
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
@@ -55,13 +56,13 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<Badge variant="success" className="gap-1.5 text-[11px]">
|
||||
<span className="size-1.5 rounded-full bg-success" aria-hidden="true" />
|
||||
Activo
|
||||
{t('header.active')}
|
||||
</Badge>
|
||||
{hasRisk ? (
|
||||
// The badge cannot carry long text without cluttering the header:
|
||||
// the explanation (dropout risk, not collections risk) lives in the
|
||||
// tooltip.
|
||||
<Tooltip content={RISK_HINT}>
|
||||
<Tooltip content={t('groups:risk.hint')}>
|
||||
<Badge
|
||||
variant={riskLevel === 'HIGH' ? 'danger' : 'warning'}
|
||||
className="gap-1.5 text-[11px]"
|
||||
@@ -73,7 +74,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{RISK_LABELS[riskLevel]}
|
||||
{t(`groups:risk.${riskLevel}`)}
|
||||
</Badge>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
@@ -109,7 +110,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
className="col-span-3 h-11 justify-center sm:w-auto"
|
||||
>
|
||||
<UserPlus className="size-4" />
|
||||
<span>Agregar miembro</span>
|
||||
<span>{t('header.addMember')}</span>
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
@@ -118,17 +119,17 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
className={SECONDARY_ACTION_CLASS_NAME}
|
||||
>
|
||||
<BarChart3 className="size-4 shrink-0 text-accent" />
|
||||
<span className="truncate">Estadísticas</span>
|
||||
<span className="truncate">{t('header.stats')}</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onCharge}
|
||||
disabled={group?.price == null}
|
||||
title={group?.price == null ? 'Definí el precio del grupo para poder cobrar' : undefined}
|
||||
title={group?.price == null ? t('header.chargeNoPrice') : undefined}
|
||||
className={SECONDARY_ACTION_CLASS_NAME}
|
||||
>
|
||||
<Wallet className="size-4 shrink-0 text-accent" />
|
||||
<span className="truncate">Cobrar</span>
|
||||
<span className="truncate">{t('header.charge')}</span>
|
||||
</Button>
|
||||
{!isEmptyGroup ? (
|
||||
<Button
|
||||
@@ -137,7 +138,7 @@ export function GroupHeader({ onCharge }: { onCharge?: () => void }) {
|
||||
className={SECONDARY_ACTION_CLASS_NAME}
|
||||
>
|
||||
<Share2 className="size-4 shrink-0 text-accent" />
|
||||
<span className="truncate">Compartir</span>
|
||||
<span className="truncate">{t('header.share')}</span>
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { CalendarClock, CircleDollarSign, Users } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
formatBillingMeta,
|
||||
formatPrice,
|
||||
@@ -17,6 +18,7 @@ const CELL_CLASS = 'flex items-start gap-3 py-2.5 first:pt-0 last:pb-0 md:py-0'
|
||||
|
||||
export function GroupInfoCard() {
|
||||
const { group, attendeesTotal, attendeesPending, waitlistTotal } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
if (!group) return null
|
||||
|
||||
const daysLabel = sortWeekDays(group.days ?? []).map(weekDayLabel).join(', ')
|
||||
@@ -27,20 +29,20 @@ export function GroupInfoCard() {
|
||||
const billingMeta = formatBillingMeta(group.billingType, group.dueDay)
|
||||
|
||||
const capacityMeta = !capacity
|
||||
? 'Sin cupo definido'
|
||||
? t('info.noCapacity')
|
||||
: isFull
|
||||
? 'Cupo completo'
|
||||
: `${freeSpots} ${freeSpots === 1 ? 'lugar libre' : 'lugares libres'}`
|
||||
const waitlistMeta = waitlistTotal > 0 ? ` · ${waitlistTotal} en espera` : ''
|
||||
? t('info.full')
|
||||
: t('info.freeSpots', { count: freeSpots ?? 0 })
|
||||
const waitlistMeta = waitlistTotal > 0 ? t('info.waiting', { count: waitlistTotal }) : ''
|
||||
|
||||
return (
|
||||
<div className="divide-y divide-border/70 rounded-2xl bg-primary-soft p-3.5 sm:p-4 md:grid md:grid-cols-3 md:divide-x md:divide-y-0">
|
||||
<div className={cn(CELL_CLASS, 'md:pr-6')}>
|
||||
<CalendarClock className="mt-0.5 size-5 shrink-0 text-accent" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className={LABEL_CLASS}>Horario</p>
|
||||
<p className={LABEL_CLASS}>{t('info.schedule')}</p>
|
||||
<p className="mt-0.5 text-base font-semibold leading-snug text-primary">
|
||||
{daysLabel || 'Sin horario definido'}
|
||||
{daysLabel || t('info.noSchedule')}
|
||||
</p>
|
||||
{daysLabel && group.time ? (
|
||||
<p className="mt-0.5 text-sm tabular-nums text-foreground">{group.time}</p>
|
||||
@@ -51,7 +53,7 @@ export function GroupInfoCard() {
|
||||
<div className={cn(CELL_CLASS, 'md:px-6')}>
|
||||
<Users className="mt-0.5 size-5 shrink-0 text-accent" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className={LABEL_CLASS}>Miembros & Cupo</p>
|
||||
<p className={LABEL_CLASS}>{t('info.membersCapacity')}</p>
|
||||
<p className="mt-0.5 flex items-baseline text-2xl font-semibold leading-none tracking-tight tabular-nums text-primary">
|
||||
<span>{attendeesPending ? '—' : attendeesTotal}</span>
|
||||
{capacity ? (
|
||||
@@ -62,11 +64,11 @@ export function GroupInfoCard() {
|
||||
{capacity ? (
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label="Ocupación del cupo"
|
||||
aria-label={t('info.occupancy')}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={capacity}
|
||||
aria-valuenow={attendeesPending ? 0 : attendeesTotal}
|
||||
aria-valuetext={`${attendeesTotal} de ${capacity}`}
|
||||
aria-valuetext={t('info.occupancyValue', { count: attendeesTotal, capacity })}
|
||||
className="mt-1.5 h-1.5 w-full max-w-[9rem] overflow-hidden rounded-full bg-accent/15"
|
||||
>
|
||||
<div
|
||||
@@ -91,9 +93,9 @@ export function GroupInfoCard() {
|
||||
<div className={cn(CELL_CLASS, 'md:pl-6')}>
|
||||
<CircleDollarSign className="mt-0.5 size-5 shrink-0 text-accent" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className={LABEL_CLASS}>Cobro</p>
|
||||
<p className={LABEL_CLASS}>{t('info.billing')}</p>
|
||||
<p className="mt-0.5 text-base font-semibold tabular-nums text-primary">
|
||||
{group.price != null ? formatPrice(group.price) : 'Sin precio'}
|
||||
{group.price != null ? formatPrice(group.price) : t('info.noPrice')}
|
||||
</p>
|
||||
{billingMeta && group.price != null ? (
|
||||
<p className="mt-0.5 text-sm text-foreground">{billingMeta}</p>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Copy, Loader2, MessageCircle, RefreshCw } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { Button, Input, Label, Modal } from '../../../components/ui'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -16,13 +17,14 @@ export function InviteLinkModal() {
|
||||
copyWhatsappMessage,
|
||||
openWhatsapp,
|
||||
} = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isInviteModalOpen}
|
||||
onClose={closeInviteModal}
|
||||
title="Compartir Link de Invitación"
|
||||
description="Envía este enlace a tus miembros para que completen sus datos e ingresen directamente al grupo."
|
||||
title={t('invite.title')}
|
||||
description={t('invite.description')}
|
||||
maxWidth="md"
|
||||
>
|
||||
<div className="space-y-5">
|
||||
@@ -34,7 +36,7 @@ export function InviteLinkModal() {
|
||||
<>
|
||||
<div>
|
||||
<Label htmlFor="invite-link-input" className="mb-1.5 block">
|
||||
Enlace único del grupo
|
||||
{t('invite.linkLabel')}
|
||||
</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
@@ -47,35 +49,36 @@ export function InviteLinkModal() {
|
||||
variant="outline"
|
||||
onClick={() => void copyInviteLink()}
|
||||
className="shrink-0 gap-1.5 px-3"
|
||||
title="Copiar al portapapeles"
|
||||
title={t('invite.copyTitle')}
|
||||
>
|
||||
<Copy className="size-4" />
|
||||
<span>Copiar</span>
|
||||
<span>{t('invite.copy')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2.5 rounded-xl border border-accent/20 bg-accent-soft p-4 text-xs text-foreground/80">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<p className="font-semibold text-primary">Vista previa del mensaje para WhatsApp:</p>
|
||||
<p className="font-semibold text-primary">{t('invite.previewTitle')}</p>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => void copyWhatsappMessage()}
|
||||
className="h-7 shrink-0 gap-1.5 px-2 text-xs text-primary hover:text-primary/80"
|
||||
title="Copiar mensaje completo al portapapeles"
|
||||
title={t('invite.copyMessageTitle')}
|
||||
>
|
||||
<Copy className="size-3.5" />
|
||||
<span>Copiar mensaje</span>
|
||||
<span>{t('invite.copyMessage')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="whitespace-pre-line rounded-lg border border-accent/10 bg-surface/70 p-3 font-sans text-xs leading-relaxed text-foreground">
|
||||
{`¡Hola! 👋 Te invito a unirte al grupo `}
|
||||
<strong>{group?.name}</strong>.
|
||||
{'\n\n'}
|
||||
Completa tu pre-inscripción en el siguiente enlace. El profesor revisará tu solicitud:
|
||||
{'\n'}
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="invite.messagePreview"
|
||||
values={{ group: group?.name ?? '' }}
|
||||
components={{ strong: <strong /> }}
|
||||
/>
|
||||
<span className="break-all text-accent underline">{inviteUrl}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -87,7 +90,7 @@ export function InviteLinkModal() {
|
||||
className="w-full gap-2 border-0 bg-[#25D366] text-white hover:bg-[#1EBE5D] sm:flex-1"
|
||||
>
|
||||
<MessageCircle className="size-4" />
|
||||
<span>Abrir en WhatsApp</span>
|
||||
<span>{t('invite.openWhatsapp')}</span>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
@@ -96,18 +99,22 @@ export function InviteLinkModal() {
|
||||
onClick={regenerateInvite}
|
||||
disabled={isRegeneratingInvite}
|
||||
className="w-full gap-1.5 text-xs text-foreground/60 hover:text-danger sm:w-auto"
|
||||
title="Invalida el enlace anterior y genera uno nuevo"
|
||||
title={t('invite.regenerateTitle')}
|
||||
>
|
||||
<RefreshCw className={cn('size-3.5', isRegeneratingInvite && 'animate-spin')} />
|
||||
<span>Regenerar enlace</span>
|
||||
<span>{t('invite.regenerate')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p className="text-center text-[11px] font-normal leading-normal text-foreground/50 sm:text-left">
|
||||
Al hacer clic en <strong>Abrir en WhatsApp</strong>, el mensaje completo se copia
|
||||
automáticamente al portapapeles. Si WhatsApp Web solo carga el enlace, podés pegarlo
|
||||
directamente con <kbd className="rounded bg-primary-soft px-1 py-0.5 font-mono text-[10px] text-primary">Ctrl+V</kbd>{' '}
|
||||
o <kbd className="rounded bg-primary-soft px-1 py-0.5 font-mono text-[10px] text-primary">Cmd+V</kbd>.
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="invite.footnote"
|
||||
components={{
|
||||
strong: <strong />,
|
||||
kbd: <kbd className="rounded bg-primary-soft px-1 py-0.5 font-mono text-[10px] text-primary" />,
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { AttendeeListItem, AttendanceStatus } from '@gruperly/shared'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { Check } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { dotClass, statusLabel } from '../analytics/format'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -32,6 +33,7 @@ function PaymentLabel({ state }: { state: PaymentState }) {
|
||||
}
|
||||
|
||||
function AttendanceStrip({ recent }: { recent: AttendanceStatus[] }) {
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const summary = summarizeAttendance(recent)
|
||||
|
||||
if (summary.recorded === 0) {
|
||||
@@ -47,7 +49,7 @@ function AttendanceStrip({ recent }: { recent: AttendanceStatus[] }) {
|
||||
<span
|
||||
key={index}
|
||||
role="img"
|
||||
aria-label={`Clase ${index + 1} de ${summary.recorded}: ${statusLabel(status).toLowerCase()}`}
|
||||
aria-label={t('members.classDot', { index: index + 1, total: summary.recorded, status: statusLabel(status).toLowerCase() })}
|
||||
className={cn('size-2 rounded-full', dotClass(status))}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { Loader2, Plus, Share2, Users, X } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '../../../components/ui'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -8,6 +9,7 @@ import { byFullName, isOverdue, resolvePaymentState } from './member-row'
|
||||
|
||||
function OverdueFilter({ count }: { count: number }) {
|
||||
const { overdueOnly, setOverdueOnly } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
return (
|
||||
<div className="px-3 pb-1.5">
|
||||
@@ -28,7 +30,7 @@ function OverdueFilter({ count }: { count: number }) {
|
||||
{/* The ✕ only shows with the filter on: it is the signal that tapping it
|
||||
takes the filter off, without having to say so. */}
|
||||
{overdueOnly ? <X className="size-3.5 shrink-0" aria-hidden="true" /> : null}
|
||||
<span className="whitespace-nowrap">{count} con pago vencido</span>
|
||||
<span className="whitespace-nowrap">{t('members.overdueFilter', { count })}</span>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
@@ -44,6 +46,7 @@ export function MembersView() {
|
||||
openInviteModal,
|
||||
} = useGroupDetail()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
const query = searchFilter.trim().toLowerCase()
|
||||
// The phone is not shown on the row but is still a search path: it is how most
|
||||
@@ -79,16 +82,15 @@ export function MembersView() {
|
||||
<div className="bg-surface px-4 py-10 text-center">
|
||||
<Users className="mx-auto mb-2 size-10 text-foreground/40" />
|
||||
<p className="text-sm font-semibold text-primary">
|
||||
Todavía no hay miembros en este grupo
|
||||
{t('members.emptyTitle')}
|
||||
</p>
|
||||
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
|
||||
Puedes compartir el enlace de invitación único o agregar miembros de forma manual o
|
||||
masiva.
|
||||
{t('members.emptyDescription')}
|
||||
</p>
|
||||
<div className="mt-4 flex flex-col gap-2.5 sm:flex-row sm:items-center sm:justify-center sm:gap-3">
|
||||
<Button variant="outline" onClick={openInviteModal} className="h-11 w-full sm:w-auto">
|
||||
<Share2 className="size-4" />
|
||||
Compartir enlace
|
||||
{t('members.shareLink')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -98,7 +100,7 @@ export function MembersView() {
|
||||
className="h-11 w-full sm:w-auto"
|
||||
>
|
||||
<Plus className="size-4" />
|
||||
Agregar miembros
|
||||
{t('members.addMembers')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -115,8 +117,8 @@ export function MembersView() {
|
||||
{filterBar}
|
||||
<div className="px-4 py-8 text-center text-sm text-foreground">
|
||||
{overdueOnly
|
||||
? 'Ningún miembro con pago vencido coincide con la búsqueda.'
|
||||
: 'No se encontraron miembros que coincidan con la búsqueda.'}
|
||||
? t('members.noOverdueMatch')
|
||||
: t('members.noMatch')}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Search } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Input } from '../../../components/ui'
|
||||
import { MEMBER_SEARCH_MIN } from './constants'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -8,6 +9,7 @@ import { SectionChips } from './SectionChips'
|
||||
|
||||
export function MembersWaitlistSection() {
|
||||
const { listSection, searchFilter, setSearchFilter, attendeesTotal } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
// With few attendees the search is noise: scrolling the list is enough. It is
|
||||
// removed from the tree instead of hidden, so as not to leave a gap in the
|
||||
@@ -39,10 +41,10 @@ export function MembersWaitlistSection() {
|
||||
<div className="relative w-full sm:w-72 lg:shrink-0">
|
||||
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-foreground/70" />
|
||||
<Input
|
||||
placeholder="Buscar por nombre o teléfono..."
|
||||
placeholder={t('sections.searchPlaceholder')}
|
||||
value={searchFilter}
|
||||
onChange={(e) => setSearchFilter(e.target.value)}
|
||||
aria-label="Buscar en el listado"
|
||||
aria-label={t('sections.searchLabel')}
|
||||
className="h-11 rounded-lg border-transparent pl-9 shadow-xs"
|
||||
/>
|
||||
</div>
|
||||
@@ -57,8 +59,7 @@ export function MembersWaitlistSection() {
|
||||
there; `pt-2` is the gap the row's `p-3` used to leave. */}
|
||||
{listSection === 'pending' ? (
|
||||
<p className="max-w-2xl px-3 pb-3 pt-2 text-xs leading-snug text-foreground/80">
|
||||
Pre-inscripciones que esperan tu aprobación y personas en lista de espera por un cupo
|
||||
libre.
|
||||
{t('sections.pendingHint')}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Clock, Inbox, Loader2, Share2, UserCheck } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button } from '../../../components/ui'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -14,6 +15,7 @@ export function PendingView() {
|
||||
searchFilter,
|
||||
openInviteModal,
|
||||
} = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
const query = searchFilter.trim().toLowerCase()
|
||||
const matches = (fullName: string, phone: string | null | undefined, email?: string | null) =>
|
||||
@@ -42,15 +44,14 @@ export function PendingView() {
|
||||
// `primary-soft` sinks the block; with the previous wash it camouflaged.
|
||||
<div className="bg-surface px-4 py-10 text-center">
|
||||
<Inbox className="mx-auto mb-2 size-10 text-foreground/40" />
|
||||
<p className="text-sm font-semibold text-primary">No hay pendientes</p>
|
||||
<p className="text-sm font-semibold text-primary">{t('pending.emptyTitle')}</p>
|
||||
<p className="mx-auto mt-1 max-w-sm text-sm text-foreground/80">
|
||||
Las pre-inscripciones que lleguen por el enlace compartido y las personas en lista de
|
||||
espera aparecerán aquí para que las revises.
|
||||
{t('pending.emptyDescription')}
|
||||
</p>
|
||||
<div className="mt-4 flex justify-center">
|
||||
<Button variant="primary" onClick={openInviteModal} className="h-11 w-full sm:w-auto">
|
||||
<Share2 className="size-4" />
|
||||
Compartir enlace
|
||||
{t('members.shareLink')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,7 +61,7 @@ export function PendingView() {
|
||||
if (filteredPrereg.length === 0 && filteredWaitlist.length === 0) {
|
||||
return (
|
||||
<div className="py-8 text-center text-sm text-foreground/80">
|
||||
No se encontraron pendientes que coincidan con la búsqueda.
|
||||
{t('pending.noMatch')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -68,20 +69,20 @@ export function PendingView() {
|
||||
const sections = [
|
||||
{
|
||||
key: 'preregistrations',
|
||||
title: 'Pre-inscripciones',
|
||||
title: t('pending.preRegistrations'),
|
||||
icon: UserCheck,
|
||||
attention: true,
|
||||
count: filteredPrereg.length,
|
||||
emptyNote: 'Sin pre-inscripciones pendientes.',
|
||||
emptyNote: t('pending.preRegistrationsEmpty'),
|
||||
table: <PreRegistrationsTable entries={filteredPrereg} />,
|
||||
},
|
||||
{
|
||||
key: 'waitlist',
|
||||
title: 'Lista de espera',
|
||||
title: t('pending.waitlist'),
|
||||
icon: Clock,
|
||||
attention: false,
|
||||
count: filteredWaitlist.length,
|
||||
emptyNote: 'Sin nadie en la lista de espera.',
|
||||
emptyNote: t('pending.waitlistEmpty'),
|
||||
table: <WaitlistTable entries={filteredWaitlist} />,
|
||||
},
|
||||
]
|
||||
@@ -91,7 +92,7 @@ export function PendingView() {
|
||||
{sections.map((section) => {
|
||||
const Icon = section.icon
|
||||
const hasRows = section.count > 0
|
||||
const titleId = `pending-${section.title.replace(/\s+/g, '-').toLowerCase()}`
|
||||
const titleId = `pending-${section.key}`
|
||||
// With the search on, sections with no matches are hidden.
|
||||
if (!hasRows && query) return null
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Ban, Loader2, Mail, MessageCircle, Phone, UserCheck } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { useIntlLocale } from '../../../i18n'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
import { DetailRow } from './DetailRow'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -14,12 +16,14 @@ export function PreRegistrationDetailModal() {
|
||||
isSubmittingApproval,
|
||||
isSubmittingRejection,
|
||||
} = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const locale = useIntlLocale()
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={selectedPreRegistration !== null}
|
||||
onClose={() => setSelectedPreRegistration(null)}
|
||||
title="Detalle de la pre-inscripción"
|
||||
title={t('preRegistration.title')}
|
||||
maxWidth="sm"
|
||||
>
|
||||
{selectedPreRegistration ? (
|
||||
@@ -33,18 +37,19 @@ export function PreRegistrationDetailModal() {
|
||||
{selectedPreRegistration.fullName}
|
||||
</p>
|
||||
<p className="text-xs text-foreground/50">
|
||||
Solicitado el{' '}
|
||||
{new Date(selectedPreRegistration.createdAt).toLocaleDateString('es-ES', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
{t('preRegistration.requestedOn', {
|
||||
date: new Date(selectedPreRegistration.createdAt).toLocaleDateString(locale, {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
}),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1 divide-y divide-border rounded-xl border border-border bg-primary-soft/30">
|
||||
<DetailRow icon={<Phone className="size-4 text-accent" />} label="Teléfono">
|
||||
<DetailRow icon={<Phone className="size-4 text-accent" />} label={t('preRegistration.phone')}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-primary">{formatPhoneDisplay(selectedPreRegistration.phone)}</span>
|
||||
<a
|
||||
@@ -60,7 +65,7 @@ export function PreRegistrationDetailModal() {
|
||||
</DetailRow>
|
||||
|
||||
{selectedPreRegistration.email ? (
|
||||
<DetailRow icon={<Mail className="size-4 text-accent" />} label="Email">
|
||||
<DetailRow icon={<Mail className="size-4 text-accent" />} label={t('preRegistration.email')}>
|
||||
<a
|
||||
href={`mailto:${selectedPreRegistration.email}`}
|
||||
className="text-primary transition-colors hover:text-accent"
|
||||
@@ -73,8 +78,7 @@ export function PreRegistrationDetailModal() {
|
||||
|
||||
{!hasFreeCapacity ? (
|
||||
<p className="rounded-xl border border-border bg-primary-soft/30 px-4 py-3 text-xs text-foreground/70">
|
||||
El grupo alcanzó su cupo de miembros. Si aprobás, esta persona quedará en la lista de
|
||||
espera hasta que se libere un lugar.
|
||||
{t('preRegistration.fullWarning')}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
@@ -90,7 +94,7 @@ export function PreRegistrationDetailModal() {
|
||||
) : (
|
||||
<UserCheck className="size-4" />
|
||||
)}
|
||||
<span>Aprobar</span>
|
||||
<span>{t('preRegistration.approve')}</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -103,7 +107,7 @@ export function PreRegistrationDetailModal() {
|
||||
) : (
|
||||
<Ban className="size-4" />
|
||||
)}
|
||||
Rechazar
|
||||
{t('preRegistration.reject')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import type { GroupPreRegistrationDto } from '@gruperly/shared'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useIntlLocale } from '../../../i18n'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
export function PreRegistrationsTable({ entries }: { entries: GroupPreRegistrationDto[] }) {
|
||||
const { setSelectedPreRegistration } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const locale = useIntlLocale()
|
||||
|
||||
return (
|
||||
<table className="w-full table-fixed text-left text-sm">
|
||||
@@ -13,12 +17,12 @@ export function PreRegistrationsTable({ entries }: { entries: GroupPreRegistrati
|
||||
as `primary-soft`, the row's background, and the separator would
|
||||
disappear. */}
|
||||
<tr className="border-b border-foreground/10 text-xs font-semibold text-foreground/80">
|
||||
<th scope="col" className="w-[47%] px-3 pb-1.5">Nombre</th>
|
||||
<th scope="col" className="px-3 pb-1.5">Teléfono</th>
|
||||
<th scope="col" className="w-[47%] px-3 pb-1.5">{t('table.name')}</th>
|
||||
<th scope="col" className="px-3 pb-1.5">{t('table.phone')}</th>
|
||||
{/* On mobile the phone leads: the date lives in the detail. */}
|
||||
<th scope="col" className="hidden px-3 pb-1.5 sm:table-cell">Solicitado</th>
|
||||
<th scope="col" className="hidden px-3 pb-1.5 sm:table-cell">{t('table.requested')}</th>
|
||||
<th scope="col" className="w-8 px-1 pb-1.5">
|
||||
<span className="sr-only">Detalle</span>
|
||||
<span className="sr-only">{t('table.detail')}</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -63,7 +67,7 @@ export function PreRegistrationsTable({ entries }: { entries: GroupPreRegistrati
|
||||
</span>
|
||||
</td>
|
||||
<td className="hidden min-w-0 px-3 py-2 text-xs text-foreground/70 sm:table-cell">
|
||||
{new Date(entry.createdAt).toLocaleDateString('es-ES', {
|
||||
{new Date(entry.createdAt).toLocaleDateString(locale, {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
})}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AttendeeDto, GroupWaitlistEntryDto } from '@gruperly/shared'
|
||||
import { Clock, Loader2, Trash2, UserCheck, UserMinus } from 'lucide-react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
|
||||
@@ -24,22 +25,26 @@ export function RemoveAttendeeModal({
|
||||
onCancel,
|
||||
onConfirm,
|
||||
}: RemoveAttendeeModalProps) {
|
||||
const { t } = useTranslation(['groupDetail', 'common'])
|
||||
return (
|
||||
<Modal
|
||||
isOpen={attendee !== null}
|
||||
onClose={onCancel}
|
||||
title="Quitar del grupo"
|
||||
title={t('remove.title')}
|
||||
maxWidth="md"
|
||||
>
|
||||
{attendee ? (
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-foreground/70">
|
||||
{attendee.fullName} dejará de ser miembro del grupo{' '}
|
||||
<strong className="text-primary">{groupName}</strong>
|
||||
{firstWaitlistEntry ? ' y el cupo quedará libre.' : '.'}
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={firstWaitlistEntry ? 'remove.bodyFreeSpot' : 'remove.body'}
|
||||
values={{ name: attendee.fullName, group: groupName ?? '' }}
|
||||
components={{ strong: <strong className="text-primary" /> }}
|
||||
/>
|
||||
{attendee.phone ? (
|
||||
<span className="mt-1 block text-xs text-foreground/50">
|
||||
Teléfono: {formatPhoneDisplay(attendee.phone)}
|
||||
{t('remove.phone', { phone: formatPhoneDisplay(attendee.phone) })}
|
||||
</span>
|
||||
) : null}
|
||||
</p>
|
||||
@@ -52,13 +57,15 @@ export function RemoveAttendeeModal({
|
||||
<div className="space-y-3 rounded-xl border border-accent/20 bg-accent-soft p-4">
|
||||
<div className="flex items-center gap-2 text-xs font-semibold text-primary">
|
||||
<Clock className="size-4 text-accent" />
|
||||
<span>
|
||||
Hay {waitlistTotal} persona{waitlistTotal === 1 ? '' : 's'} esperando un cupo
|
||||
</span>
|
||||
<span>{t('remove.waiting', { count: waitlistTotal })}</span>
|
||||
</div>
|
||||
<p className="text-sm text-foreground/80">
|
||||
¿Quieres pasar a <strong className="text-primary">{firstWaitlistEntry.fullName}</strong>, el
|
||||
primero de la lista de espera, al grupo?
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="remove.promoteQuestion"
|
||||
values={{ name: firstWaitlistEntry.fullName }}
|
||||
components={{ strong: <strong className="text-primary" /> }}
|
||||
/>
|
||||
</p>
|
||||
<div className="flex flex-col gap-2.5 pt-1">
|
||||
<Button
|
||||
@@ -72,7 +79,7 @@ export function RemoveAttendeeModal({
|
||||
) : (
|
||||
<UserCheck className="size-4" />
|
||||
)}
|
||||
<span>Quitar y pasar a {firstWaitlistEntry.fullName} al grupo</span>
|
||||
<span>{t('remove.removeAndPromote', { name: firstWaitlistEntry.fullName })}</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -85,14 +92,14 @@ export function RemoveAttendeeModal({
|
||||
) : (
|
||||
<UserMinus className="size-4" />
|
||||
)}
|
||||
<span>Solo quitar del grupo</span>
|
||||
<span>{t('remove.removeOnly')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center justify-end gap-2.5 border-t border-border pt-2">
|
||||
<Button variant="ghost" onClick={onCancel}>
|
||||
Cancelar
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
@@ -105,7 +112,7 @@ export function RemoveAttendeeModal({
|
||||
) : (
|
||||
<Trash2 className="size-4" />
|
||||
)}
|
||||
<span>Quitar del grupo</span>
|
||||
<span>{t('remove.confirm')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Inbox, Users } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { cn } from '../../../lib/utils'
|
||||
import { type ListSection, useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
const SECTIONS = [
|
||||
{ id: 'members', label: 'Miembros', icon: Users },
|
||||
{ id: 'pending', label: 'Pendientes', icon: Inbox },
|
||||
{ id: 'members', label: 'sections.members', icon: Users },
|
||||
{ id: 'pending', label: 'sections.pending', icon: Inbox },
|
||||
] as const satisfies ReadonlyArray<{
|
||||
id: ListSection
|
||||
label: string
|
||||
@@ -19,6 +20,7 @@ export function SectionChips() {
|
||||
preRegistrationsTotal,
|
||||
waitlistTotal,
|
||||
} = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
const counts: Record<ListSection, number> = {
|
||||
members: attendeesTotal,
|
||||
@@ -28,7 +30,7 @@ export function SectionChips() {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
aria-label="Listado del grupo"
|
||||
aria-label={t('sections.label')}
|
||||
className="flex w-full flex-wrap items-center gap-2"
|
||||
>
|
||||
{SECTIONS.map((section) => {
|
||||
@@ -56,7 +58,7 @@ export function SectionChips() {
|
||||
)}
|
||||
>
|
||||
<Icon className="size-3.5 shrink-0" />
|
||||
<span className="whitespace-nowrap">{section.label}</span>
|
||||
<span className="whitespace-nowrap">{t(section.label)}</span>
|
||||
{count > 0 ? (
|
||||
<span
|
||||
className={cn(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { GroupListItem } from '@gruperly/shared'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Loader2, Mail, MessageCircle, Phone, StickyNote, Trash2, UserCheck } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Button, Modal } from '../../../components/ui'
|
||||
import { useIntlLocale } from '../../../i18n'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
import { DetailRow } from './DetailRow'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
@@ -22,6 +24,8 @@ export function WaitlistEntryDetailModal() {
|
||||
isSubmittingPromotion,
|
||||
isSubmittingWaitlistRemoval,
|
||||
} = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
const locale = useIntlLocale()
|
||||
|
||||
// Por defecto pasa al grupo en el que se anotó; el profe puede elegir otro.
|
||||
const [targetGroupId, setTargetGroupId] = useState(groupId)
|
||||
@@ -37,7 +41,7 @@ export function WaitlistEntryDetailModal() {
|
||||
<Modal
|
||||
isOpen={selectedWaitlistEntry !== null}
|
||||
onClose={() => setSelectedWaitlistEntry(null)}
|
||||
title="Detalle de la lista de espera"
|
||||
title={t('waitlistEntry.title')}
|
||||
maxWidth="sm"
|
||||
>
|
||||
{selectedWaitlistEntry ? (
|
||||
@@ -49,18 +53,19 @@ export function WaitlistEntryDetailModal() {
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-lg font-semibold text-primary">{selectedWaitlistEntry.fullName}</p>
|
||||
<p className="text-xs text-foreground/50">
|
||||
En espera desde el{' '}
|
||||
{new Date(selectedWaitlistEntry.createdAt).toLocaleDateString('es-ES', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
{t('waitlistEntry.since', {
|
||||
date: new Date(selectedWaitlistEntry.createdAt).toLocaleDateString(locale, {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
}),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1 divide-y divide-border rounded-xl border border-border bg-primary-soft/30">
|
||||
<DetailRow icon={<Phone className="size-4 text-accent" />} label="Teléfono">
|
||||
<DetailRow icon={<Phone className="size-4 text-accent" />} label={t('waitlistEntry.phone')}>
|
||||
{selectedWaitlistEntry.phone ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-primary">{formatPhoneDisplay(selectedWaitlistEntry.phone)}</span>
|
||||
@@ -75,12 +80,12 @@ export function WaitlistEntryDetailModal() {
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-foreground/40">Sin teléfono</span>
|
||||
<span className="text-foreground/40">{t('waitlistEntry.noPhone')}</span>
|
||||
)}
|
||||
</DetailRow>
|
||||
|
||||
{selectedWaitlistEntry.email ? (
|
||||
<DetailRow icon={<Mail className="size-4 text-accent" />} label="Email">
|
||||
<DetailRow icon={<Mail className="size-4 text-accent" />} label={t('waitlistEntry.email')}>
|
||||
<a
|
||||
href={`mailto:${selectedWaitlistEntry.email}`}
|
||||
className="text-primary transition-colors hover:text-accent"
|
||||
@@ -90,18 +95,18 @@ export function WaitlistEntryDetailModal() {
|
||||
</DetailRow>
|
||||
) : null}
|
||||
|
||||
<DetailRow icon={<StickyNote className="size-4 text-accent" />} label="Notas">
|
||||
<DetailRow icon={<StickyNote className="size-4 text-accent" />} label={t('waitlistEntry.notes')}>
|
||||
{selectedWaitlistEntry.notes ? (
|
||||
<span className="text-xs leading-relaxed text-primary">{selectedWaitlistEntry.notes}</span>
|
||||
) : (
|
||||
<span className="text-foreground/40">Sin notas</span>
|
||||
<span className="text-foreground/40">{t('waitlistEntry.noNotes')}</span>
|
||||
)}
|
||||
</DetailRow>
|
||||
</div>
|
||||
|
||||
{groups.length > 1 ? (
|
||||
<label className="block">
|
||||
<span className="mb-1.5 block text-sm font-medium text-primary">Asignar a</span>
|
||||
<span className="mb-1.5 block text-sm font-medium text-primary">{t('waitlistEntry.assignTo')}</span>
|
||||
<select
|
||||
value={targetGroupId}
|
||||
onChange={(event) => setTargetGroupId(event.target.value)}
|
||||
@@ -113,8 +118,11 @@ export function WaitlistEntryDetailModal() {
|
||||
const full = !isOwnGroup && isFull(group)
|
||||
return (
|
||||
<option key={group.id} value={group.id} disabled={full}>
|
||||
{group.name}
|
||||
{isOwnGroup ? ' (en el que se anotó)' : full ? ' (sin cupo)' : ''}
|
||||
{isOwnGroup
|
||||
? t('waitlistEntry.ownGroup', { name: group.name })
|
||||
: full
|
||||
? t('waitlistEntry.fullGroup', { name: group.name })
|
||||
: group.name}
|
||||
</option>
|
||||
)
|
||||
})}
|
||||
@@ -125,8 +133,8 @@ export function WaitlistEntryDetailModal() {
|
||||
{!targetHasFreeCapacity ? (
|
||||
<p className="rounded-xl border border-border bg-primary-soft/30 px-4 py-3 text-xs text-foreground/70">
|
||||
{isCurrentGroup
|
||||
? 'El grupo alcanzó su cupo de miembros. Quita un miembro o aumenta el cupo para poder pasar a esta persona al grupo.'
|
||||
: 'Ese grupo alcanzó su cupo de miembros. Elige otro grupo o libera un lugar primero.'}
|
||||
? t('waitlistEntry.currentFull')
|
||||
: t('waitlistEntry.targetFull')}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
@@ -143,7 +151,7 @@ export function WaitlistEntryDetailModal() {
|
||||
<UserCheck className="size-4" />
|
||||
)}
|
||||
<span className="truncate">
|
||||
{isCurrentGroup || !targetGroup ? 'Pasar al grupo' : `Pasar a ${targetGroup.name}`}
|
||||
{isCurrentGroup || !targetGroup ? t('waitlistEntry.promote') : t('waitlistEntry.promoteTo', { group: targetGroup.name })}
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
@@ -153,7 +161,7 @@ export function WaitlistEntryDetailModal() {
|
||||
className="gap-2 border border-danger/20 text-danger hover:bg-danger/10 hover:text-danger"
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
Quitar de la lista de espera
|
||||
{t('waitlistEntry.remove')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import type { GroupWaitlistEntryDto } from '@gruperly/shared'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { formatPhoneDisplay } from '../../../lib/format'
|
||||
import { useGroupDetail } from './GroupDetailProvider'
|
||||
|
||||
export function WaitlistTable({ entries }: { entries: GroupWaitlistEntryDto[] }) {
|
||||
const { setSelectedWaitlistEntry } = useGroupDetail()
|
||||
const { t } = useTranslation('groupDetail')
|
||||
|
||||
return (
|
||||
<table className="w-full table-fixed text-left text-sm">
|
||||
@@ -13,10 +15,10 @@ export function WaitlistTable({ entries }: { entries: GroupWaitlistEntryDto[] })
|
||||
as `primary-soft`, the row's background, and the separator would
|
||||
disappear. */}
|
||||
<tr className="border-b border-foreground/10 text-xs font-semibold text-foreground/80">
|
||||
<th scope="col" className="w-[47%] px-3 pb-1.5">Nombre</th>
|
||||
<th scope="col" className="px-3 pb-1.5">Teléfono</th>
|
||||
<th scope="col" className="w-[47%] px-3 pb-1.5">{t('table.name')}</th>
|
||||
<th scope="col" className="px-3 pb-1.5">{t('table.phone')}</th>
|
||||
<th scope="col" className="w-8 px-1 pb-1.5">
|
||||
<span className="sr-only">Detalle</span>
|
||||
<span className="sr-only">{t('table.detail')}</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AttendeeListItem, AttendanceStatus } from '@gruperly/shared'
|
||||
import { RECENT_ATTENDANCE_LIMIT } from '@gruperly/shared'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import { PAYMENT_DUE_SOON_DAYS } from './constants'
|
||||
|
||||
/* The listing's row does not ask the backend for presentation verdicts: it asks
|
||||
@@ -56,14 +57,14 @@ export function isOverdue(state: PaymentState | null): boolean {
|
||||
export function paymentStateLabel(state: PaymentState): string {
|
||||
switch (state.kind) {
|
||||
case 'settled':
|
||||
return 'Al día'
|
||||
return i18n.t('groupDetail:row.settled')
|
||||
case 'dueSoon':
|
||||
// "Vence en 0 d" is not natural Spanish: today and tomorrow have words.
|
||||
if (state.days === 0) return 'Vence hoy'
|
||||
if (state.days === 1) return 'Vence mañana'
|
||||
return `Vence en ${state.days} d`
|
||||
// "Vence en 0 d" is not natural: today and tomorrow have words.
|
||||
if (state.days === 0) return i18n.t('groupDetail:row.dueToday')
|
||||
if (state.days === 1) return i18n.t('groupDetail:row.dueTomorrow')
|
||||
return i18n.t('groupDetail:row.dueIn', { days: state.days })
|
||||
case 'overdue':
|
||||
return `Vencido · ${state.days} d`
|
||||
return i18n.t('groupDetail:row.overdue', { days: state.days })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ export function summarizeAttendance(
|
||||
const recorded = dots.length
|
||||
|
||||
if (recorded === 0) {
|
||||
return { dots, attended: 0, recorded: 0, label: 'Sin clases aún' }
|
||||
return { dots, attended: 0, recorded: 0, label: i18n.t('groupDetail:row.noClasses') }
|
||||
}
|
||||
|
||||
const attended = dots.filter((status) => status === 'PRESENT').length
|
||||
@@ -94,7 +95,7 @@ export function summarizeAttendance(
|
||||
dots,
|
||||
attended,
|
||||
recorded,
|
||||
label: `${attended} de ${recorded} ${recorded === 1 ? 'clase' : 'clases'}`,
|
||||
label: i18n.t('groupDetail:row.attended', { attended, count: recorded }),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import type { AttendeeDto, RemoveAttendeeResult } from '@gruperly/shared'
|
||||
import { useToast } from '../../../components/ui'
|
||||
import { ApiError, removeGroupAttendee } from '../../../lib/api'
|
||||
import { errorMessage } from '../../../i18n'
|
||||
import { i18n } from '../../../i18n/instance'
|
||||
import { removeGroupAttendee } from '../../../lib/api'
|
||||
|
||||
type RemoveAttendeePayload = {
|
||||
attendee: AttendeeDto
|
||||
@@ -23,10 +25,13 @@ export function useRemoveAttendee({ groupId, onRemoved }: UseRemoveAttendeeOptio
|
||||
onSuccess: (result, { attendee }) => {
|
||||
if (result.promoted) {
|
||||
toast.success(
|
||||
`${attendee.fullName} fue quitado del grupo y ${result.promoted.fullName} pasó de la lista de espera al grupo.`,
|
||||
i18n.t('groupDetail:remove.removedPromoted', {
|
||||
name: attendee.fullName,
|
||||
promoted: result.promoted.fullName,
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
toast.success(`${attendee.fullName} fue quitado del grupo.`)
|
||||
toast.success(i18n.t('groupDetail:remove.removed', { name: attendee.fullName }))
|
||||
}
|
||||
void queryClient.invalidateQueries({ queryKey: ['group-attendees', groupId] })
|
||||
void queryClient.invalidateQueries({ queryKey: ['group-waitlist', groupId] })
|
||||
@@ -34,11 +39,8 @@ export function useRemoveAttendee({ groupId, onRemoved }: UseRemoveAttendeeOptio
|
||||
onRemoved?.(result)
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
if (err instanceof ApiError && err.problem?.code === 'attendee_has_payments') {
|
||||
toast.error(err.problem.detail ?? 'Este miembro tiene cobros asociados.')
|
||||
} else {
|
||||
toast.error(err.message || 'Error al quitar al miembro del grupo.')
|
||||
}
|
||||
// `attendee_has_payments` comes translated by its code.
|
||||
toast.error(errorMessage(err, i18n.t('groupDetail:remove.error')))
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -12,17 +12,5 @@ export const WEEK_DAYS: readonly WeekDay[] = [
|
||||
'SUNDAY',
|
||||
]
|
||||
|
||||
export const WEEK_DAY_CHIPS: readonly { value: WeekDay; label: string }[] = [
|
||||
{ value: 'MONDAY', label: 'Lun' },
|
||||
{ value: 'TUESDAY', label: 'Mar' },
|
||||
{ value: 'WEDNESDAY', label: 'Mié' },
|
||||
{ value: 'THURSDAY', label: 'Jue' },
|
||||
{ value: 'FRIDAY', label: 'Vie' },
|
||||
{ value: 'SATURDAY', label: 'Sáb' },
|
||||
{ value: 'SUNDAY', label: 'Dom' },
|
||||
]
|
||||
|
||||
export const BILLING_TYPES: readonly { value: BillingType; label: string; hint: string }[] = [
|
||||
{ value: 'MONTHLY', label: 'Mensual', hint: 'Un cobro por mes' },
|
||||
{ value: 'PER_CLASS', label: 'Por clase', hint: 'Cada clase que asista' },
|
||||
]
|
||||
// Labels: `common:weekDayShort.*`, `common:billingType.*` and `common:billingTypeHint.*`.
|
||||
export const BILLING_TYPES: readonly BillingType[] = ['MONTHLY', 'PER_CLASS']
|
||||
Reference in New Issue
Block a user