74 lines
3.5 KiB
TypeScript
74 lines
3.5 KiB
TypeScript
import type { AdminAccountListItem } from '@gruperly/shared'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { ChevronRight } from 'lucide-react'
|
|
import { Badge } from '../../components/ui'
|
|
import { formatPrice } from '../../lib/format'
|
|
import { formatBillingDate, subscriptionStatusLabel } from '../billing'
|
|
import { countryLabel, planLabel, planVariant, subscriptionVariant } from './copy'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
/** Columnas de la grilla en `lg+`; el encabezado de `AdminAccountsView` usa las mismas. */
|
|
export const ACCOUNT_GRID_COLUMNS =
|
|
'lg:grid-cols-[minmax(0,2.2fr)_minmax(0,1fr)_minmax(0,0.8fr)_minmax(0,1.6fr)_4.5rem_4.5rem_1rem]'
|
|
|
|
/* Una cuenta de la lista: tarjeta en móvil, fila de la grilla en escritorio. */
|
|
export function AdminAccountRow({ account }: { account: AdminAccountListItem }) {
|
|
const subscription = account.subscription
|
|
const { t } = useTranslation(['admin', 'common', 'billing'])
|
|
const status = subscription?.status ?? null
|
|
const paidThrough = formatBillingDate(subscription?.paidThrough ?? null)
|
|
const planBadge = <Badge variant={planVariant(account.plan)}>{planLabel(account.plan)}</Badge>
|
|
const statusBadge = <Badge variant={subscriptionVariant(status)}>{subscriptionStatusLabel(status)}</Badge>
|
|
|
|
return (
|
|
<li>
|
|
<Link
|
|
to="/admin/accounts/$accountId"
|
|
params={{ accountId: account.id }}
|
|
className="block rounded-xl border border-border bg-surface px-4 py-3 transition-colors hover:bg-primary-soft lg:rounded-none lg:border-0 lg:border-b lg:bg-transparent"
|
|
>
|
|
{/* Móvil */}
|
|
<div className="lg:hidden">
|
|
<div className="flex items-center gap-3">
|
|
<div className="min-w-0 flex-1">
|
|
<p className="truncate text-sm font-semibold text-primary">{account.name}</p>
|
|
<p className="truncate text-xs text-foreground/60">{account.email}</p>
|
|
</div>
|
|
<ChevronRight className="size-4 shrink-0 text-foreground/40" aria-hidden="true" />
|
|
</div>
|
|
<div className="mt-2 flex flex-wrap items-center gap-1.5">
|
|
{planBadge}
|
|
{statusBadge}
|
|
</div>
|
|
<p className="mt-2 text-xs text-foreground/60">
|
|
{countryLabel(account.country)} · {t('row.groups', { count: account.groupsCount })} ·{' '}
|
|
{t('row.students', { count: account.attendeesCount })}
|
|
</p>
|
|
</div>
|
|
|
|
{/* Escritorio */}
|
|
<div className={`hidden items-center gap-4 lg:grid ${ACCOUNT_GRID_COLUMNS}`}>
|
|
<div className="min-w-0">
|
|
<p className="truncate text-sm font-semibold text-primary">{account.name}</p>
|
|
<p className="truncate text-xs text-foreground/60">{account.email}</p>
|
|
</div>
|
|
<p className="truncate text-sm text-foreground/70">{countryLabel(account.country)}</p>
|
|
<div>{planBadge}</div>
|
|
<div className="min-w-0">
|
|
{statusBadge}
|
|
{subscription ? (
|
|
<p className="mt-1 truncate text-xs text-foreground/50">
|
|
{formatPrice(subscription.amount, subscription.currency)}
|
|
{paidThrough ? t('row.until', { date: paidThrough }) : ''}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
<p className="text-right text-sm tabular-nums text-foreground/70">{account.groupsCount}</p>
|
|
<p className="text-right text-sm tabular-nums text-foreground/70">{account.attendeesCount}</p>
|
|
<ChevronRight className="size-4 text-foreground/40" aria-hidden="true" />
|
|
</div>
|
|
</Link>
|
|
</li>
|
|
)
|
|
}
|