Updated layout UI
Deploy Frontend / build-and-deploy (push) Successful in 33s Details

This commit is contained in:
romanskijdev 2026-11-18 11:55:00 +03:00
parent 43fe957812
commit 0a4a7829b0
13 changed files with 487 additions and 323 deletions

148
package-lock.json generated
View File

@ -11,13 +11,14 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@mantine/core": "^9.4.1",
"@mantine/dates": "^9.4.1",
"@mantine/core": "^9.8.1",
"@mantine/dates": "^9.8.1",
"@mantine/form": "^9.3.1",
"@mantine/hooks": "^9.4.1",
"@mantine/modals": "^9.4.1",
"@mantine/notifications": "^9.4.1",
"@mantine/tiptap": "^9.4.1",
"@mantine/hooks": "^9.8.1",
"@mantine/modals": "^9.8.1",
"@mantine/notifications": "^9.8.1",
"@mantine/spotlight": "^9.8.1",
"@mantine/tiptap": "^9.8.1",
"@tabler/icons-react": "^3.44.0",
"@tanstack/react-query": "^5.101.0",
"@tiptap/extension-link": "^3.27.3",
@ -517,32 +518,32 @@
}
},
"node_modules/@floating-ui/core": {
"version": "1.7.5",
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.5.tgz",
"integrity": "sha512-1Ih4WTWyw0+lKyFMcBHGbb5U5FtuHJuujoyyr5zTaWS5EYMeT6Jb2AuDeftsCsEuchO+mM2ij5+q9crhydzLhQ==",
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.8.0.tgz",
"integrity": "sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==",
"license": "MIT",
"dependencies": {
"@floating-ui/utils": "^0.2.11"
"@floating-ui/utils": "^0.2.12"
}
},
"node_modules/@floating-ui/dom": {
"version": "1.7.6",
"resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.6.tgz",
"integrity": "sha512-9gZSAI5XM36880PPMm//9dfiEngYoC6Am2izES1FF406YFsjvyBMmeJ2g4SAju3xWwtuynNRFL2s9hgxpLI5SQ==",
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.8.0.tgz",
"integrity": "sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==",
"license": "MIT",
"dependencies": {
"@floating-ui/core": "^1.7.5",
"@floating-ui/utils": "^0.2.11"
"@floating-ui/core": "^1.8.0",
"@floating-ui/utils": "^0.2.12"
}
},
"node_modules/@floating-ui/react": {
"version": "0.27.19",
"resolved": "https://registry.npmjs.org/@floating-ui/react/-/react-0.27.19.tgz",
"integrity": "sha512-31B8h5mm8YxotlE7/AU/PhNAl8eWxAmjL/v2QOxroDNkTFLk3Uu82u63N3b6TXa4EGJeeZLVcd/9AlNlVqzeog==",
"version": "0.27.20",
"resolved": "https://registry.npmjs.org/@floating-ui/react/-/react-0.27.20.tgz",
"integrity": "sha512-CMqMy7OaXl9W0eq1Uy7L7i2Y/anPvHmFmESd2CEw0t5YvZhcVCeo4MBevAmswRllX7Y2dEidA4ozGPunLSTQpw==",
"license": "MIT",
"dependencies": {
"@floating-ui/react-dom": "^2.1.8",
"@floating-ui/utils": "^0.2.11",
"@floating-ui/react-dom": "^2.1.9",
"@floating-ui/utils": "^0.2.12",
"tabbable": "^6.0.0"
},
"peerDependencies": {
@ -551,12 +552,12 @@
}
},
"node_modules/@floating-ui/react-dom": {
"version": "2.1.8",
"resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.8.tgz",
"integrity": "sha512-cC52bHwM/n/CxS87FH0yWdngEZrjdtLW/qVruo68qg+prK7ZQ4YGdut2GyDVpoGeAYe/h899rVeOVm6Oi40k2A==",
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.9.tgz",
"integrity": "sha512-JDjEFGCpImxDCA7JJKviA0M9+RtmJdj0m/NVU5IMgBK+AmZouAQQ7/+2GLH0GXXY0YMw9oXPB8hKdbPYg5QLYg==",
"license": "MIT",
"dependencies": {
"@floating-ui/dom": "^1.7.6"
"@floating-ui/dom": "^1.8.0"
},
"peerDependencies": {
"react": ">=16.8.0",
@ -564,9 +565,9 @@
}
},
"node_modules/@floating-ui/utils": {
"version": "0.2.11",
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.11.tgz",
"integrity": "sha512-RiB/yIh78pcIxl6lLMG0CgBXAZ2Y0eVHqMPYugu+9U0AeT6YBeiJpf7lbdJNIugFP5SIjwNRgo4DhR1Qxi26Gg==",
"version": "0.2.12",
"resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.12.tgz",
"integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==",
"license": "MIT"
},
"node_modules/@humanfs/core": {
@ -686,34 +687,34 @@
}
},
"node_modules/@mantine/core": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/core/-/core-9.4.1.tgz",
"integrity": "sha512-lZWEICrum4+vwKxzh/mk4RB1N6BqZ0Cshdl6lhm7OYLiQzmOaxKtOgyaWz+vr65G8mqTXjalZalB+wmMVBYK2Q==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/core/-/core-9.8.1.tgz",
"integrity": "sha512-+ayBTxun7MslJL6x4qaylVy6TyHu3o68+PH22gt70eJSHgy0CHYR/c2q+BYxS8WvORuc4f5mr0xFbi0vzlgHug==",
"license": "MIT",
"dependencies": {
"@floating-ui/react": "^0.27.19",
"@floating-ui/react": "^0.27.20",
"clsx": "^2.1.1",
"react-number-format": "^5.4.5",
"react-remove-scroll": "^2.7.2",
"type-fest": "^5.7.0"
"type-fest": "^5.10.0"
},
"peerDependencies": {
"@mantine/hooks": "9.4.1",
"@mantine/hooks": "9.8.1",
"react": "^19.2.0",
"react-dom": "^19.2.0"
}
},
"node_modules/@mantine/dates": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/dates/-/dates-9.4.1.tgz",
"integrity": "sha512-DoQDvQMAlIw6ohwhUwYuTYQevG9y5AQmYWkhOHUuavABFEZmtBglkwziBoATvxT09I/6I56UMPhproXcS6XUfg==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/dates/-/dates-9.8.1.tgz",
"integrity": "sha512-BDYvM3hSvTkFNAqnRmL/nhf8NnoqwXOUe+jxq7xZZ1ME9NaVT5u3QuLY2zEilqF3Wm0iUtf3LP6deL9c4gunSQ==",
"license": "MIT",
"dependencies": {
"clsx": "^2.1.1"
},
"peerDependencies": {
"@mantine/core": "9.4.1",
"@mantine/hooks": "9.4.1",
"@mantine/core": "9.8.1",
"@mantine/hooks": "9.8.1",
"dayjs": ">=1.0.0",
"react": "^19.2.0",
"react-dom": "^19.2.0"
@ -734,59 +735,74 @@
}
},
"node_modules/@mantine/hooks": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-9.4.1.tgz",
"integrity": "sha512-eTI8wmzPx3r98zgKIEuvukmoGTHBhmtI6+9E6o2DbTmEU2eM1bCdjE2vFdf0op2AlRO0KEYEcZhNQi4T/SJk0A==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-9.8.1.tgz",
"integrity": "sha512-aAbY3zcqrS/n+wbMnKBXMiF5TJ7HZ06sH455Cf4ZkWRXko9Td2FYSe9aONCzXFaW62XqaWHBICyeIsAmUds3uA==",
"license": "MIT",
"peerDependencies": {
"react": "^19.2.0"
}
},
"node_modules/@mantine/modals": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-9.4.1.tgz",
"integrity": "sha512-z5G3Biz7/5Ybz5Z8u5Xyvo9UBmFhAX/YXMf6U96ejvtAB11xVnCo8m37R5DJyzeFEqB4D1tvUgWiVVPBb+yadw==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-9.8.1.tgz",
"integrity": "sha512-QwlPGmwyWXIq5YM3xzbeVQ6dJXTm98YBcrI7YQ6lraHxEXHZAr6M2HDIF4Pqd158mP/Oc+HL+UPd0cvSeZfHLQ==",
"license": "MIT",
"peerDependencies": {
"@mantine/core": "9.4.1",
"@mantine/hooks": "9.4.1",
"@mantine/core": "9.8.1",
"@mantine/hooks": "9.8.1",
"react": "^19.2.0",
"react-dom": "^19.2.0"
}
},
"node_modules/@mantine/notifications": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/notifications/-/notifications-9.4.1.tgz",
"integrity": "sha512-Sm1g8E8RkFmesxpNz9zFvOjkTVxOa7dJJjMGoHNIXH+9/wO0s9kInny4mVnxTbLJJsD6nTqIQlk1v8tq2C4Ftw==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/notifications/-/notifications-9.8.1.tgz",
"integrity": "sha512-lqi9+HfXMbMKzEsAIUkWRFw2rURzgVMv8//oCyq0rhy27X6NjSMMlzvwsjbSazT/+WugDIYLJ8khZ+JMW1gkMQ==",
"license": "MIT",
"dependencies": {
"@mantine/store": "9.4.1",
"@mantine/store": "9.8.1",
"react-transition-group": "4.4.5"
},
"peerDependencies": {
"@mantine/core": "9.4.1",
"@mantine/hooks": "9.4.1",
"@mantine/core": "9.8.1",
"@mantine/hooks": "9.8.1",
"react": "^19.2.0",
"react-dom": "^19.2.0"
}
},
"node_modules/@mantine/spotlight": {
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/spotlight/-/spotlight-9.8.1.tgz",
"integrity": "sha512-x5BL6D1Khp6GxhWWxhPgtoyPb40zFgwKx8XfjyoDMRANGhQ+vijyjyDHol7nYQq8DMiM2G4Hnue2vMyTDEkS1g==",
"license": "MIT",
"dependencies": {
"@mantine/store": "9.8.1"
},
"peerDependencies": {
"@mantine/core": "9.8.1",
"@mantine/hooks": "9.8.1",
"react": "^19.2.0",
"react-dom": "^19.2.0"
}
},
"node_modules/@mantine/store": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/store/-/store-9.4.1.tgz",
"integrity": "sha512-/DCZq0aqqIdm03J0RJ7pbzoau2cwY8ndSOjskHOKHhTeWMnOBdCKXA3oMO5aIDldDqJ9T7Io4Boh4Pt461zNQw==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/store/-/store-9.8.1.tgz",
"integrity": "sha512-Wb5+6i6m3GdNgOjX1IbDPYrP76v9y4zThRoKDWH9Es+qY2c6gT2NpH7n10/zYgNPL8ipB6H6gGUPhLurs1o4kg==",
"license": "MIT",
"peerDependencies": {
"react": "^19.2.0"
}
},
"node_modules/@mantine/tiptap": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/@mantine/tiptap/-/tiptap-9.4.1.tgz",
"integrity": "sha512-0qN6SFh9BuwXNOHUf4ygx8LPvWcgU1zUULY7IJ9zKiVHfa1K6b0BRa8LpLVKtVv7K5NLyj2uHJwv+mXB+ypOJw==",
"version": "9.8.1",
"resolved": "https://registry.npmjs.org/@mantine/tiptap/-/tiptap-9.8.1.tgz",
"integrity": "sha512-jpeLjEL0z6QUoTMuZnwfTem3ITuNd1zKjHqElptEuhFCUWKtV4sIobiRk6bOkPcANeAXCzy4P3Xquxlnq/+erg==",
"license": "MIT",
"peerDependencies": {
"@mantine/core": "9.4.1",
"@mantine/hooks": "9.4.1",
"@mantine/core": "9.8.1",
"@mantine/hooks": "9.8.1",
"@tiptap/extension-link": ">=3.3.0",
"@tiptap/react": ">=3.3.0",
"react": "^19.2.0",
@ -4356,9 +4372,9 @@
}
},
"node_modules/tabbable": {
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.4.0.tgz",
"integrity": "sha512-05PUHKSNE8ou2dwIxTngl4EzcnsCDZGJ/iCLtDflR/SHB/ny14rXc+qU5P4mG9JkusiV7EivzY9Mhm55AzAvCg==",
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.5.2.tgz",
"integrity": "sha512-XgdnB1nGU6KU4VgMnZPaZCx7M1hBrLyEiZYau2G2gq9UT0d7d4FUBlNX7vvPlm/B1vk1PjrzJBx9Lbv4fsqS9g==",
"license": "MIT"
},
"node_modules/tagged-tag": {
@ -4429,9 +4445,9 @@
}
},
"node_modules/type-fest": {
"version": "5.7.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-5.7.0.tgz",
"integrity": "sha512-1URUxUqfHFM1c+zfSPsa3gnkO7Aq21qyH75SIduNYz4SzY964rn1X2vCMQaHSHhktiw+0kPa2iyb6PUpXqB6Vg==",
"version": "5.10.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-5.10.0.tgz",
"integrity": "sha512-NoSdpq/WEiAg5sjmBkmV/hfxv6HJH4NqPNrqjtSO5CwRmpsDfaf4begxW34KdJykH/l1yHtwBWQkCRdoXO8mPA==",
"license": "(MIT OR CC0-1.0)",
"dependencies": {
"tagged-tag": "^1.0.0"

View File

@ -13,13 +13,14 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@mantine/core": "^9.4.1",
"@mantine/dates": "^9.4.1",
"@mantine/core": "^9.8.1",
"@mantine/dates": "^9.8.1",
"@mantine/form": "^9.3.1",
"@mantine/hooks": "^9.4.1",
"@mantine/modals": "^9.4.1",
"@mantine/notifications": "^9.4.1",
"@mantine/tiptap": "^9.4.1",
"@mantine/hooks": "^9.8.1",
"@mantine/modals": "^9.8.1",
"@mantine/notifications": "^9.8.1",
"@mantine/spotlight": "^9.8.1",
"@mantine/tiptap": "^9.8.1",
"@tabler/icons-react": "^3.44.0",
"@tanstack/react-query": "^5.101.0",
"@tiptap/extension-link": "^3.27.3",

View File

@ -1,13 +1,12 @@
import {
Group,
Burger,
Text,
Avatar,
Menu,
ActionIcon,
Group, Burger, Text, Avatar, Menu, ActionIcon, Button, Kbd, Breadcrumbs, Box, UnstyledButton,
useMantineColorScheme, useComputedColorScheme,
} from '@mantine/core'
import { IconLogout, IconUser } from '@tabler/icons-react'
import { spotlight } from '@mantine/spotlight'
import { IconLogout, IconSearch, IconSun, IconMoon, IconUser } from '@tabler/icons-react'
import { useLocation } from 'react-router-dom'
import { useAuth } from '@/hooks/useAuth'
import { findTrail } from './navigation'
interface HeaderProps {
toggleMobile: () => void
@ -16,54 +15,93 @@ interface HeaderProps {
desktopOpened: boolean
}
export default function Header({
toggleMobile,
toggleDesktop,
mobileOpened,
desktopOpened
}: HeaderProps) {
function ColorSchemeToggle() {
const { setColorScheme } = useMantineColorScheme()
const computed = useComputedColorScheme('light', { getInitialValueInEffect: true })
return (
<ActionIcon
size="lg"
aria-label="Переключить тему"
onClick={() => setColorScheme(computed === 'light' ? 'dark' : 'light')}
>
{computed === 'dark' ? <IconSun size={18} stroke={1.6} /> : <IconMoon size={18} stroke={1.6} />}
</ActionIcon>
)
}
export default function Header({ toggleMobile, toggleDesktop, mobileOpened, desktopOpened }: HeaderProps) {
const { user, logout } = useAuth()
const { pathname } = useLocation()
const trail = findTrail(pathname)
const role = user?.is_root ? 'Суперадмин' : user?.is_observer ? 'Наблюдатель' : 'Администратор'
return (
<Group h="100%" px="md" justify="space-between">
<Group h="100%" gap={0}>
<Burger
opened={mobileOpened}
onClick={toggleMobile}
hiddenFrom="sm"
size="sm"
/>
<Burger
opened={desktopOpened}
onClick={toggleDesktop}
visibleFrom="sm"
size="sm"
/>
<Text ml="md" fw={700}>
Портал сотрудника РусПЭТ
</Text>
<Group h="100%" px="md" justify="space-between" wrap="nowrap">
<Group gap="sm" wrap="nowrap">
<Burger opened={mobileOpened} onClick={toggleMobile} hiddenFrom="sm" size="sm" />
<Burger opened={desktopOpened} onClick={toggleDesktop} visibleFrom="sm" size="sm" />
<Group gap={8} wrap="nowrap">
<Box
w={28} h={28}
style={{
borderRadius: 8, display: 'grid', placeItems: 'center',
background: 'var(--mantine-primary-color-filled)', color: '#fff',
fontWeight: 700, fontSize: 14,
}}
>
Р
</Box>
<Text fw={600} size="sm" visibleFrom="xs">Портал РусПЭТ</Text>
</Group>
{trail.length > 0 && (
<Breadcrumbs separator="/" visibleFrom="md" ml="md">
{trail.map((t, i) => (
<Text key={i} size="sm" c={i === trail.length - 1 ? undefined : 'dimmed'} fw={i === trail.length - 1 ? 500 : 400}>
{t}
</Text>
))}
</Breadcrumbs>
)}
</Group>
<Group>
<Menu shadow="md" width={200}>
<Group gap="xs" wrap="nowrap">
<Button
variant="default"
size="xs"
visibleFrom="sm"
leftSection={<IconSearch size={14} />}
rightSection={<Kbd size="xs">Ctrl K</Kbd>}
onClick={spotlight.open}
c="dimmed"
fw={400}
w={220}
justify="space-between"
>
Поиск
</Button>
<ActionIcon size="lg" hiddenFrom="sm" onClick={spotlight.open} aria-label="Поиск">
<IconSearch size={18} stroke={1.6} />
</ActionIcon>
<ColorSchemeToggle />
<Menu width={220} position="bottom-end">
<Menu.Target>
<ActionIcon variant="subtle" size="lg">
<Avatar size="sm" radius="xl">
<UnstyledButton aria-label="Профиль">
<Avatar size="sm" radius="xl" color="brand">
{user?.login?.charAt(0).toUpperCase() || 'A'}
</Avatar>
</ActionIcon>
</UnstyledButton>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item leftSection={<IconUser size={14} />}>
{user?.login || 'Admin'}
</Menu.Item>
<Box px="sm" py={6}>
<Text size="sm" fw={600}>{user?.login || 'Admin'}</Text>
<Text size="xs" c="dimmed">{role}</Text>
</Box>
<Menu.Divider />
<Menu.Item
leftSection={<IconLogout size={14} />}
onClick={logout}
color="red"
>
<Menu.Item leftSection={<IconLogout size={14} />} color="red" onClick={logout}>
Выйти
</Menu.Item>
</Menu.Dropdown>

View File

@ -1,24 +1,42 @@
import { AppShell } from '@mantine/core'
import { useDisclosure } from '@mantine/hooks'
import { Outlet, useLocation } from 'react-router-dom'
import { Spotlight } from '@mantine/spotlight'
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
import { useMemo } from 'react'
import Sidebar from './Sidebar'
import Header from './Header'
import ErrorBoundary from '../DiagnosticErrorBoundary'
import { useAuth } from '@/hooks/useAuth'
import { navigation, flattenNav } from './navigation'
export default function MainLayout() {
const [mobileOpened, { toggle: toggleMobile }] = useDisclosure()
const [mobileOpened, { toggle: toggleMobile, close: closeMobile }] = useDisclosure()
const [desktopOpened, { toggle: toggleDesktop }] = useDisclosure(true)
const location = useLocation()
const navigate = useNavigate()
const { user } = useAuth()
const actions = useMemo(
() =>
flattenNav(navigation, user?.is_observer === true).map((i) => ({
id: i.path,
label: i.label,
description: i.trail.slice(0, -1).join(' / '),
leftSection: i.icon ? <i.icon size={20} stroke={1.5} /> : undefined,
onClick: () => { navigate(i.path); closeMobile() },
})),
[user?.is_observer, navigate, closeMobile],
)
return (
<AppShell
header={{ height: 60 }}
header={{ height: 56 }}
navbar={{
width: 280,
width: 264,
breakpoint: 'sm',
collapsed: { mobile: !mobileOpened, desktop: !desktopOpened },
}}
padding="md"
padding="lg"
>
<AppShell.Header>
<Header
@ -29,15 +47,22 @@ export default function MainLayout() {
/>
</AppShell.Header>
<AppShell.Navbar p={0}>
<AppShell.Navbar>
<Sidebar />
</AppShell.Navbar>
<AppShell.Main bg="gray.0" miw={0}>
<AppShell.Main miw={0} style={{ background: 'var(--app-bg)' }}>
<ErrorBoundary key={location.pathname}>
<Outlet />
</ErrorBoundary>
</AppShell.Main>
<Spotlight
actions={actions}
shortcut={['mod + K', '/']}
nothingFound="Ничего не найдено"
searchProps={{ placeholder: 'Перейти к разделу…' }}
/>
</AppShell>
)
}

View File

@ -0,0 +1,16 @@
.link {
border-radius: var(--mantine-radius-md);
padding: 8px 10px;
font-size: var(--mantine-font-size-sm);
font-weight: 500;
}
.sectionTitle {
padding: 0 10px;
margin-bottom: 6px;
font-size: 11px;
font-weight: 600;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--mantine-color-dimmed);
}

View File

@ -1,170 +1,41 @@
import { useState, useMemo } from 'react'
import { NavLink, Box, Text, Stack, Badge } from '@mantine/core'
import {
IconDashboard,
IconFileCheck,
IconSettings,
IconChevronRight,
IconList,
IconUsers,
IconBuilding,
IconShield,
IconKey,
IconCategory,
IconBriefcase,
IconUserCheck,
IconGitBranch,
IconUserCog,
IconCheck,
IconBellRinging,
IconBlocks,
IconHistory, IconChartBar, IconBrandTelegram,
} from '@tabler/icons-react'
import { useLocation, useNavigate } from 'react-router-dom'
import { Badge, Box, NavLink, ScrollArea, Stack, Text } from '@mantine/core'
import { Link, useLocation } from 'react-router-dom'
import { useMemo } from 'react'
import { useAuth } from '@/hooks/useAuth'
import {
navigation, filterNavigation, isPathActive, hasActiveDescendant, type NavItem,
} from './navigation'
import classes from './Sidebar.module.css'
interface MenuItem {
label: string
icon?: any
path?: string
children?: MenuItem[]
adminOnly?: boolean // скрывать от наблюдателей
}
function NavNode({ item }: { item: NavItem }) {
const { pathname } = useLocation()
const Icon = item.icon
const icon = Icon ? <Icon size={18} stroke={1.6} /> : undefined
const menuItems: MenuItem[] = [
{ label: 'Обзор', icon: IconDashboard, path: '/' },
{ label: 'Администраторы', icon: IconUserCog, path: '/admins', adminOnly: true },
{ label: 'Уведомления', icon: IconBellRinging, path: '/notifications', adminOnly: true },
{ label: 'Журнал действий', icon: IconHistory, path: '/logs', adminOnly: true },
{
label: 'Заказы на месяц',
icon: IconChartBar,
path: '/monthly-orders-settings',
adminOnly: true, // Скрываем от наблюдателей
// Если нужно скрыть от менеджеров, можно добавить флаг analystOnly: true и фильтровать
},
{ label: 'Телефония', icon: IconBrandTelegram, path: '/telegram-managers', adminOnly: true },
{
label: 'Система согласований',
icon: IconFileCheck,
children: [
{ label: 'Панель управления', icon: IconDashboard, path: '/approval-dash', adminOnly: true },
{ label: 'Заявки', icon: IconList, path: '/approvals' },
{ label: 'Задачи', icon: IconCheck, path: '/approval-tasks' },
{ label: 'Пользователи', icon: IconUsers, path: '/users', adminOnly: true },
{ label: 'Отделы', icon: IconBuilding, path: '/departments', adminOnly: true },
{ label: 'Роли', icon: IconShield, path: '/roles', adminOnly: true },
{ label: 'Права', icon: IconKey, path: '/permissions', adminOnly: true },
{
label: 'Темы согласований',
icon: IconBriefcase,
adminOnly: true,
children: [
{ label: 'Настройки категорий', icon: IconCategory, path: '/categories' },
{ label: 'Настройки тем', icon: IconBriefcase, path: '/topics', adminOnly: true },
{ label: 'Исполнители', icon: IconUserCheck, path: '/executors', adminOnly: true },
]
},
{ label: 'Конструктор тем', icon: IconBlocks, path: '/nodes', adminOnly: true },
{ label: 'Иерархия', icon: IconGitBranch, path: '/hierarchies', adminOnly: true },
]
},
{ label: 'Настройки', icon: IconSettings, path: '/settings'},
]
function filterMenuByRole(items: MenuItem[], isObserver: boolean): MenuItem[] {
return items
.filter((item) => {
if (isObserver && item.adminOnly) return false
return true
})
.map((item) => {
if (item.children) {
const filteredChildren = filterMenuByRole(item.children, isObserver)
// Если после фильтрации детей не осталось — скрываем родителя
if (filteredChildren.length === 0) return null
return { ...item, children: filteredChildren }
}
return item
})
.filter((item): item is MenuItem => item !== null)
}
function MenuItemLink({ item, level }: { item: MenuItem; level: number }) {
const location = useLocation()
const navigate = useNavigate()
const [opened, setOpened] = useState(false)
const hasChildren = item.children && item.children.length > 0
const isActive = item.path ? location.pathname === item.path : false
const hasActiveChild = item.children?.some(child =>
child.path ? location.pathname === child.path : false
) || false
const paddingLeft = 16 + level * 20
if (hasChildren) {
if (item.children?.length) {
return (
<Box>
<NavLink
label={item.label}
leftSection={item.icon ? <item.icon size={18} /> : undefined}
rightSection={
<IconChevronRight
size={16}
style={{
transform: opened ? 'rotate(90deg)' : 'none',
transition: 'transform 0.2s ease',
}}
/>
}
active={hasActiveChild}
onClick={() => setOpened(!opened)}
styles={{
root: {
paddingLeft,
paddingRight: 12,
borderRadius: '8px',
marginBottom: 2,
'&:hover': {
backgroundColor: 'var(--mantine-color-gray-0)',
},
},
}}
/>
{opened && (
<Stack gap={2} mt={2}>
{item.children!.map((child) => (
<MenuItemLink key={child.label} item={child} level={level + 1} />
))}
</Stack>
)}
</Box>
<NavLink
label={item.label}
leftSection={icon}
defaultOpened={hasActiveDescendant(item, pathname)}
childrenOffset={16}
classNames={{ root: classes.link }}
>
<Stack gap={2} mt={2}>
{item.children.map((c) => <NavNode key={c.label} item={c} />)}
</Stack>
</NavLink>
)
}
return (
<NavLink
component={Link}
to={item.path!}
label={item.label}
leftSection={item.icon ? <item.icon size={18} /> : undefined}
active={isActive}
onClick={() => {
if (item.path) navigate(item.path)
}}
styles={{
root: {
paddingLeft,
paddingRight: 12,
borderRadius: '8px',
marginBottom: 2,
'&:hover': {
backgroundColor: 'var(--mantine-color-gray-0)',
},
},
label: {
fontWeight: isActive ? 600 : 400,
},
}}
leftSection={icon}
active={isPathActive(item.path!, pathname)}
classNames={{ root: classes.link }}
/>
)
}
@ -172,50 +43,23 @@ function MenuItemLink({ item, level }: { item: MenuItem; level: number }) {
export default function Sidebar() {
const { user } = useAuth()
const isObserver = user?.is_observer === true
const isAnalyst = user?.is_analyst === true || user?.is_root === true
// 🆕 Фильтруем меню в зависимости от роли
const filteredMenuItems = useMemo(
() => filterMenuByRole(menuItems, isObserver),
[isObserver]
)
const sections = useMemo(() => filterNavigation(navigation, isObserver), [isObserver])
return (
<Box
style={{
padding: '12px 8px',
height: '100%',
overflowY: 'auto',
}}
>
<Text
size="xs"
c="dimmed"
fw={700}
mb="md"
px="sm"
style={{
textTransform: 'uppercase',
letterSpacing: '0.5px',
}}
>
Главное меню
</Text>
{/* 🆕 Индикатор режима наблюдателя */}
<ScrollArea h="100%" px="sm" py="md">
{isObserver && (
<Box px="sm" mb="md">
<Badge color="blue" variant="light" size="sm" fullWidth>
Режим наблюдателя
</Badge>
</Box>
<Badge color="blue" fullWidth mb="md">Режим наблюдателя</Badge>
)}
<Stack gap={4}>
{filteredMenuItems.map((item) => (
<MenuItemLink key={item.label} item={item} level={0} />
<Stack gap="lg">
{sections.map((section, i) => (
<Box key={section.title ?? `section-${i}`}>
{section.title && <Text className={classes.sectionTitle}>{section.title}</Text>}
<Stack gap={2}>
{section.items.map((item) => <NavNode key={item.label} item={item} />)}
</Stack>
</Box>
))}
</Stack>
</Box>
</ScrollArea>
)
}

View File

@ -0,0 +1,118 @@
import {
IconDashboard, IconFileCheck, IconSettings, IconList, IconUsers, IconBuilding,
IconShield, IconKey, IconCategory, IconBriefcase, IconUserCheck, IconGitBranch,
IconUserCog, IconCheck, IconBellRinging, IconBlocks, IconHistory, IconChartBar,
IconPhone, IconAdjustments, type Icon,
} from '@tabler/icons-react'
export interface NavItem {
label: string
icon?: Icon
path?: string
children?: NavItem[]
adminOnly?: boolean // скрывать от наблюдателей
}
export interface NavSection {
title?: string
items: NavItem[]
}
export const navigation: NavSection[] = [
{
items: [
{ label: 'Обзор', icon: IconDashboard, path: '/' },
{ label: 'Заявки', icon: IconList, path: '/approvals' },
{ label: 'Задачи', icon: IconCheck, path: '/approval-tasks' },
{ label: 'Заказы на месяц', icon: IconChartBar, path: '/monthly-orders-settings', adminOnly: true },
{ label: 'Телефония', icon: IconPhone, path: '/telegram-managers', adminOnly: true },
],
},
{
title: 'Согласования',
items: [
{ label: 'Панель управления', icon: IconFileCheck, path: '/approval-dash', adminOnly: true },
{
label: 'Темы согласований',
icon: IconBriefcase,
adminOnly: true,
children: [
{ label: 'Категории', icon: IconCategory, path: '/categories' },
{ label: 'Темы', icon: IconBriefcase, path: '/topics' },
{ label: 'Исполнители', icon: IconUserCheck, path: '/executors' },
],
},
{ label: 'Конструктор тем', icon: IconBlocks, path: '/nodes', adminOnly: true },
{ label: 'Иерархия', icon: IconGitBranch, path: '/hierarchies', adminOnly: true },
],
},
{
title: 'Организация',
items: [
{ label: 'Пользователи', icon: IconUsers, path: '/users', adminOnly: true },
{ label: 'Отделы', icon: IconBuilding, path: '/departments', adminOnly: true },
{ label: 'Роли', icon: IconShield, path: '/roles', adminOnly: true },
{ label: 'Права', icon: IconKey, path: '/permissions', adminOnly: true },
],
},
{
title: 'Система',
items: [
{ label: 'Администраторы', icon: IconUserCog, path: '/admins', adminOnly: true },
{ label: 'Уведомления', icon: IconBellRinging, path: '/notifications', adminOnly: true },
{ label: 'Журнал действий', icon: IconHistory, path: '/logs', adminOnly: true },
{ label: 'Настройки', icon: IconSettings, path: '/settings' },
],
},
]
export function isPathActive(path: string, pathname: string) {
return path === '/' ? pathname === '/' : pathname === path || pathname.startsWith(path + '/')
}
export function hasActiveDescendant(item: NavItem, pathname: string): boolean {
if (item.path && isPathActive(item.path, pathname)) return true
return item.children?.some((c) => hasActiveDescendant(c, pathname)) ?? false
}
function filterItems(items: NavItem[], isObserver: boolean): NavItem[] {
return items
.filter((i) => !(isObserver && i.adminOnly))
.map((i) => (i.children ? { ...i, children: filterItems(i.children, isObserver) } : i))
.filter((i) => !i.children || i.children.length > 0)
}
export function filterNavigation(sections: NavSection[], isObserver: boolean): NavSection[] {
return sections
.map((s) => ({ ...s, items: filterItems(s.items, isObserver) }))
.filter((s) => s.items.length > 0)
}
export interface FlatNavItem {
label: string
path: string
icon?: Icon
trail: string[]
}
export function flattenNav(sections: NavSection[], isObserver = false): FlatNavItem[] {
const out: FlatNavItem[] = []
const walk = (items: NavItem[], trail: string[]) => {
for (const i of items) {
const t = [...trail, i.label]
if (i.path) out.push({ label: i.label, path: i.path, icon: i.icon, trail: t })
if (i.children) walk(i.children, t)
}
}
filterNavigation(sections, isObserver).forEach((s) =>
walk(s.items, s.title ? [s.title] : []),
)
return out
}
export function findTrail(pathname: string): string[] {
const match = flattenNav(navigation)
.filter((i) => isPathActive(i.path, pathname))
.sort((a, b) => b.path.length - a.path.length)[0]
return match?.trail ?? []
}

View File

@ -0,0 +1,25 @@
import { Center, Stack, Text, ThemeIcon } from '@mantine/core'
import { IconInbox, type Icon } from '@tabler/icons-react'
import type { ReactNode } from 'react'
interface Props {
title: string
description?: string
icon?: Icon
action?: ReactNode
}
export function EmptyState({ title, description, icon: Icon = IconInbox, action }: Props) {
return (
<Center py={56}>
<Stack align="center" gap="xs" maw={320} ta="center">
<ThemeIcon variant="light" color="gray" size={44} radius="xl">
<Icon size={22} stroke={1.5} />
</ThemeIcon>
<Text fw={600}>{title}</Text>
{description && <Text size="sm" c="dimmed">{description}</Text>}
{action}
</Stack>
</Center>
)
}

View File

@ -0,0 +1,20 @@
import { Group, Stack, Text, Title } from '@mantine/core'
import type { ReactNode } from 'react'
interface Props {
title: string
description?: string
actions?: ReactNode
}
export function PageHeader({ title, description, actions }: Props) {
return (
<Group justify="space-between" align="flex-start" wrap="nowrap" mb="lg">
<Stack gap={2}>
<Title order={3}>{title}</Title>
{description && <Text size="sm" c="dimmed">{description}</Text>}
</Stack>
{actions && <Group gap="xs">{actions}</Group>}
</Group>
)
}

View File

@ -6,7 +6,7 @@ import { ModalsProvider } from '@mantine/modals'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { BrowserRouter } from 'react-router-dom'
import App from './App'
import { theme } from './theme'
import { theme } from './theme/theme'
import '@mantine/core/styles.css'
import '@mantine/notifications/styles.css'
import '@mantine/dates/styles.css'
@ -25,7 +25,7 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<MantineProvider theme={theme}>
<MantineProvider theme={theme} defaultColorScheme="auto">
<ModalsProvider>
<Notifications position="top-right" />
<ErrorBoundary fullPage>

View File

@ -8,7 +8,7 @@ import {
Text,
TextInput,
Select,
MultiSelect, // ✅ Добавлен
MultiSelect,
Pagination,
Loader,
Center,
@ -21,7 +21,7 @@ import {
import { IconPencil, IconSearch, IconTrash } from '@tabler/icons-react'
import { useUsers, useDeleteUser } from '@/features/users/hooks/useUsers'
import { useDepartments } from '@/features/users/hooks/useDepartments'
import { useRoles } from '@/features/users/hooks/useRoles' // ✅ Добавлен
import { useRoles } from '@/features/users/hooks/useRoles'
import UserEditModal from "@/components/UserEditModal.tsx"
import { useAuth } from '@/hooks/useAuth'

20
src/theme/global.css Normal file
View File

@ -0,0 +1,20 @@
:root {
--header-height: 56px;
}
[data-mantine-color-scheme='light'] {
--app-bg: var(--mantine-color-gray-0);
}
[data-mantine-color-scheme='dark'] {
--app-bg: var(--mantine-color-dark-8);
}
body {
-webkit-font-smoothing: antialiased;
}
/* Тонкий скроллбар */
* {
scrollbar-width: thin;
}

41
src/theme/theme.ts Normal file
View File

@ -0,0 +1,41 @@
import { createTheme, MantineColorsTuple } from '@mantine/core'
const brand: MantineColorsTuple = [
'#eef2ff', '#dfe5fb', '#bcc8f3', '#97a9ec', '#788fe6',
'#6580e3', '#5a78e2', '#4966c9', '#3f5bb4', '#324fa0',
]
// Холодная тёмная палитра: dark[8] — фон страницы, dark[7] — шапка/сайдбар, dark[6] — карточки
const dark: MantineColorsTuple = [
'#C9CCD1', '#A6AAB2', '#7D828C', '#5B606B', '#3A3E48',
'#2A2D35', '#1F2128', '#181A20', '#121418', '#0D0F12',
]
export const theme = createTheme({
primaryColor: 'brand',
colors: { brand, dark },
primaryShade: { light: 6, dark: 5 },
defaultRadius: 'md',
fontFamily: 'Inter Variable, Inter, -apple-system, Segoe UI, sans-serif',
fontFamilyMonospace: 'JetBrains Mono, ui-monospace, monospace',
headings: { fontFamily: 'Inter Variable, Inter, sans-serif', fontWeight: '600' },
cursorType: 'pointer',
components: {
Paper: { defaultProps: { withBorder: true, radius: 'md' } },
Button: { defaultProps: { fw: 500 } },
ActionIcon: { defaultProps: { variant: 'subtle', color: 'gray' } },
Badge: { defaultProps: { variant: 'light', radius: 'sm', fw: 600 } },
TextInput: { defaultProps: { size: 'sm' } },
Select: { defaultProps: { size: 'sm' } },
MultiSelect: { defaultProps: { size: 'sm' } },
Table: {
defaultProps: { verticalSpacing: 'sm', horizontalSpacing: 'md', highlightOnHover: true },
},
Modal: {
defaultProps: { centered: true, radius: 'md', overlayProps: { backgroundOpacity: 0.4, blur: 3 } },
},
Menu: { defaultProps: { shadow: 'md', radius: 'md' } },
Tooltip: { defaultProps: { withArrow: true, openDelay: 300 } },
},
})