CD / update-wiki (push) Successful in 6s
quality / commitlint (push) Skipped
quality / changes (push) Successful in 11s
quality / api (push) Skipped
quality / docker-check (push) Skipped
quality / web (push) Failing after 52s
CD / quality (push) Failing after 1m5s
CD / publish (push) Skipped
Подключить stats-12, card-12, settings-3 и empty-state-12 к оболочке, спискам, карточкам и настройкам, чтобы метрики и пустые состояния шли из одних блоков. Co-authored-by: Cursor <cursoragent@cursor.com>
321 lines
8.8 KiB
TypeScript
321 lines
8.8 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useEffect, useState } from 'react'
|
|
import { useTheme } from 'next-themes'
|
|
import {
|
|
ChevronsUpDownIcon,
|
|
LogOutIcon,
|
|
MonitorIcon,
|
|
MoonIcon,
|
|
PaletteIcon,
|
|
SettingsIcon,
|
|
SunIcon,
|
|
} from 'lucide-react'
|
|
|
|
import { cn } from '@cfdm/ui/lib/utils'
|
|
import {
|
|
Avatar,
|
|
AvatarFallback,
|
|
} from '@cfdm/ui/components/avatar'
|
|
import { Button } from '@cfdm/ui/components/button'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from '@cfdm/ui/components/dropdown-menu'
|
|
import {
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
useSidebar,
|
|
} from '@cfdm/ui/components/sidebar'
|
|
|
|
import {
|
|
can,
|
|
clearToken,
|
|
getClaims,
|
|
isAuthEnabled,
|
|
redirectToPortalLogout,
|
|
resetPortalHandoff,
|
|
} from '@/lib/auth'
|
|
import {
|
|
readContrast,
|
|
readDensity,
|
|
writeContrast,
|
|
writeDensity,
|
|
type ContrastMode,
|
|
type DensityMode,
|
|
} from '@/lib/appearance-mode'
|
|
|
|
/** Sidebar footer account menu — ReUI app-shell-1 NavUser. @see https://reui.io/preview/base/app-shell-1 */
|
|
|
|
const THEMES = [
|
|
{
|
|
value: 'light',
|
|
label: 'Светлая',
|
|
icon: <SunIcon className="size-3.5" aria-hidden />,
|
|
},
|
|
{
|
|
value: 'dark',
|
|
label: 'Тёмная',
|
|
icon: <MoonIcon className="size-3.5" aria-hidden />,
|
|
},
|
|
{
|
|
value: 'system',
|
|
label: 'Системная',
|
|
icon: <MonitorIcon className="size-3.5" aria-hidden />,
|
|
},
|
|
] as const
|
|
|
|
function ThemeSegmentedToggle() {
|
|
const { theme, setTheme } = useTheme()
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
useEffect(() => {
|
|
setMounted(true)
|
|
}, [])
|
|
|
|
const currentTheme = mounted ? (theme ?? 'system') : 'system'
|
|
|
|
return (
|
|
<div
|
|
role="radiogroup"
|
|
aria-label="Тема"
|
|
className="bg-muted/60 inline-flex items-center gap-0.5 rounded-full p-0.5"
|
|
onClick={(e) => e.stopPropagation()}
|
|
onPointerDown={(e) => e.stopPropagation()}
|
|
>
|
|
{THEMES.map(({ value, label, icon }) => {
|
|
const isActive = currentTheme === value
|
|
return (
|
|
<Button
|
|
key={value}
|
|
type="button"
|
|
role="radio"
|
|
aria-checked={isActive}
|
|
aria-label={label}
|
|
variant="ghost"
|
|
size="icon-xs"
|
|
onClick={() => setTheme(value)}
|
|
className={cn(
|
|
'rounded-full',
|
|
isActive
|
|
? 'bg-background text-foreground shadow-sm'
|
|
: 'text-muted-foreground hover:text-foreground',
|
|
)}
|
|
>
|
|
{icon}
|
|
</Button>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function SegmentedChoice<T extends string>({
|
|
label,
|
|
value,
|
|
options,
|
|
onChange,
|
|
}: {
|
|
label: string
|
|
value: T
|
|
options: readonly { value: T; label: string }[]
|
|
onChange: (value: T) => void
|
|
}) {
|
|
return (
|
|
<div
|
|
role="radiogroup"
|
|
aria-label={label}
|
|
className="bg-muted/60 inline-flex items-center gap-0.5 rounded-full p-0.5"
|
|
onClick={(event) => event.stopPropagation()}
|
|
onPointerDown={(event) => event.stopPropagation()}
|
|
>
|
|
{options.map((option) => {
|
|
const isActive = value === option.value
|
|
return (
|
|
<Button
|
|
key={option.value}
|
|
type="button"
|
|
role="radio"
|
|
aria-checked={isActive}
|
|
size="xs"
|
|
variant={isActive ? 'secondary' : 'ghost'}
|
|
onClick={() => onChange(option.value)}
|
|
>
|
|
{option.label}
|
|
</Button>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function AppearanceToggles() {
|
|
const [contrast, setContrast] = useState<ContrastMode>('standard')
|
|
const [density, setDensity] = useState<DensityMode>('normal')
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
useEffect(() => {
|
|
setContrast(readContrast())
|
|
setDensity(readDensity())
|
|
setMounted(true)
|
|
}, [])
|
|
|
|
if (!mounted) return null
|
|
|
|
return (
|
|
<>
|
|
<DropdownMenuItem className="cursor-default focus:bg-transparent">
|
|
<span className="text-sm">Контраст</span>
|
|
<div className="ml-auto">
|
|
<SegmentedChoice
|
|
label="Контраст"
|
|
value={contrast}
|
|
options={[
|
|
{ value: 'standard', label: 'Обычный' },
|
|
{ value: 'high', label: 'Высокий' },
|
|
]}
|
|
onChange={(next) => {
|
|
setContrast(next)
|
|
writeContrast(next)
|
|
}}
|
|
/>
|
|
</div>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="cursor-default focus:bg-transparent">
|
|
<span className="text-sm">Плотность</span>
|
|
<div className="ml-auto">
|
|
<SegmentedChoice
|
|
label="Плотность"
|
|
value={density}
|
|
options={[
|
|
{ value: 'normal', label: 'Обычная' },
|
|
{ value: 'compact', label: 'Компакт' },
|
|
]}
|
|
onChange={(next) => {
|
|
setDensity(next)
|
|
writeDensity(next)
|
|
}}
|
|
/>
|
|
</div>
|
|
</DropdownMenuItem>
|
|
</>
|
|
)
|
|
}
|
|
|
|
function initials(name: string, email: string): string {
|
|
const base = name.trim() || email.trim()
|
|
if (!base) return '?'
|
|
const parts = base.split(/\s+/).filter(Boolean)
|
|
if (parts.length >= 2) {
|
|
return `${parts[0]![0] ?? ''}${parts[1]![0] ?? ''}`.toUpperCase()
|
|
}
|
|
return base.slice(0, 2).toUpperCase()
|
|
}
|
|
|
|
export function NavUser() {
|
|
const { isMobile } = useSidebar()
|
|
const claims = getClaims()
|
|
const authOn = isAuthEnabled()
|
|
|
|
const name = claims?.name?.trim() || (authOn ? 'Пользователь' : 'Гость')
|
|
const email = claims?.email?.trim() || (authOn ? '' : 'auth выключен')
|
|
const fallback = initials(name, email)
|
|
|
|
function handleSignOut() {
|
|
clearToken()
|
|
resetPortalHandoff()
|
|
if (authOn) {
|
|
redirectToPortalLogout()
|
|
return
|
|
}
|
|
window.location.href = '/login'
|
|
}
|
|
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger
|
|
render={
|
|
<SidebarMenuButton
|
|
size="lg"
|
|
className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground"
|
|
/>
|
|
}
|
|
>
|
|
<Avatar className="size-8 rounded-lg">
|
|
<AvatarFallback className="rounded-lg text-xs">
|
|
{fallback}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-semibold">{name}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{email || '—'}
|
|
</span>
|
|
</div>
|
|
<ChevronsUpDownIcon className="ml-auto size-4" />
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent
|
|
className="w-(--anchor-width) min-w-56 rounded-lg"
|
|
side={isMobile ? 'bottom' : 'right'}
|
|
align="end"
|
|
sideOffset={4}
|
|
>
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel className="flex items-center gap-2 py-2 font-normal text-foreground">
|
|
<Avatar className="size-8 rounded-lg">
|
|
<AvatarFallback className="rounded-lg text-xs">
|
|
{fallback}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div className="grid min-w-0 flex-1 text-left text-sm leading-tight">
|
|
<span className="truncate font-semibold">{name}</span>
|
|
<span className="truncate text-xs text-muted-foreground">
|
|
{email || '—'}
|
|
</span>
|
|
</div>
|
|
</DropdownMenuLabel>
|
|
</DropdownMenuGroup>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuGroup>
|
|
{can('cfdm:settings:admin') ? (
|
|
<DropdownMenuItem
|
|
nativeButton={false}
|
|
render={<Link to="/settings/appearance" />}
|
|
>
|
|
<SettingsIcon aria-hidden />
|
|
Настройки
|
|
</DropdownMenuItem>
|
|
) : null}
|
|
<DropdownMenuItem className="cursor-default focus:bg-transparent">
|
|
<PaletteIcon aria-hidden />
|
|
Тема
|
|
<div className="ml-auto">
|
|
<ThemeSegmentedToggle />
|
|
</div>
|
|
</DropdownMenuItem>
|
|
<AppearanceToggles />
|
|
</DropdownMenuGroup>
|
|
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem onClick={handleSignOut}>
|
|
<LogOutIcon aria-hidden />
|
|
Выйти
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
)
|
|
}
|