Files
gruperly/apps/web/src/components/layout/Sidebar.tsx
Jose Selesan cb872eb8bc feat: soporte multi idioma en la web (infraestructura)
i18next + react-i18next con es-AR (fuente), es-419, pt-BR y en; el idioma
sale del dispositivo (fallback a inglés) y se puede cambiar en Ajustes.
La elección se guarda en localStorage y, para el profe, en users.locale.
Las validaciones de shared pasan a claves y los errores de la API se
traducen por code (con params para límites de plan y cupo).
Migrados: layout, Ajustes, auth, PWA y lib/format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 12:14:59 -03:00

53 lines
2.0 KiB
TypeScript

import { Link, useLocation } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
import { cn } from '../../lib/utils'
import { Logo } from '../brand'
import { NavBadge } from './NavBadge'
import { isNavItemActive, NAV_ITEMS } from './nav-items'
export function Sidebar({ immersive = false }: { immersive?: boolean }) {
const location = useLocation()
const { t } = useTranslation('layout')
return (
// Without the global header there's nothing to clear above: the sidebar
// column takes over the whole window and lines up with the height of the
// LargeTitle bar.
<aside
className={cn(
'sticky hidden w-64 shrink-0 flex-col border-r border-border bg-surface px-4 py-6 lg:flex',
immersive ? 'top-0 h-dvh' : 'top-16 h-[calc(100dvh-4rem)]',
)}
>
{/* `Link` and not `<a>`: an anchor would reload the document and lose the
in-memory state (React Query cache, install event). */}
<Link to="/" className="mb-8 flex items-center px-1" aria-label={t('homeLink')}>
<Logo className="h-10" />
</Link>
<nav className="flex flex-col gap-1">
{NAV_ITEMS.map(({ labelKey, to, icon: Icon, badge }) => {
const isActive = isNavItemActive(location.pathname, to)
return (
<Link
key={to}
to={to}
aria-current={isActive ? 'page' : undefined}
className={cn(
'flex items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium transition-colors',
isActive
? 'bg-accent-soft text-accent-fg'
: 'text-foreground/80 hover:bg-primary-soft hover:text-primary',
)}
>
<Icon className="size-5" strokeWidth={isActive ? 2.2 : 2} />
{t(labelKey)}
{badge ? <NavBadge kind={badge} className="ml-auto" /> : null}
</Link>
)
})}
</nav>
</aside>
)
}