From 0a4a7829b095a4a863d823969d475347f1bc3415 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 18 Nov 2026 11:55:00 +0300 Subject: [PATCH] Updated layout UI --- package-lock.json | 148 +++++++------- package.json | 13 +- src/components/Layout/Header.tsx | 126 +++++++----- src/components/Layout/MainLayout.tsx | 39 +++- src/components/Layout/Sidebar.module.css | 16 ++ src/components/Layout/Sidebar.tsx | 236 ++++------------------- src/components/Layout/navigation.ts | 118 ++++++++++++ src/components/ui/EmptyState.tsx | 25 +++ src/components/ui/PageHeader.tsx | 20 ++ src/main.tsx | 4 +- src/pages/users/UsersPage.tsx | 4 +- src/theme/global.css | 20 ++ src/theme/theme.ts | 41 ++++ 13 files changed, 487 insertions(+), 323 deletions(-) create mode 100644 src/components/Layout/Sidebar.module.css create mode 100644 src/components/Layout/navigation.ts create mode 100644 src/components/ui/EmptyState.tsx create mode 100644 src/components/ui/PageHeader.tsx create mode 100644 src/theme/global.css create mode 100644 src/theme/theme.ts diff --git a/package-lock.json b/package-lock.json index 0402a23..94ca433 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" diff --git a/package.json b/package.json index 9a1d8e4..2805e9a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/Layout/Header.tsx b/src/components/Layout/Header.tsx index d53691f..4d0aedd 100644 --- a/src/components/Layout/Header.tsx +++ b/src/components/Layout/Header.tsx @@ -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 ( + setColorScheme(computed === 'light' ? 'dark' : 'light')} + > + {computed === 'dark' ? : } + + ) +} + +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 ( - - - - - - Портал сотрудника РусПЭТ - + + + + + + + + Р + + Портал РусПЭТ + + + {trail.length > 0 && ( + + {trail.map((t, i) => ( + + {t} + + ))} + + )} - - + + + + + + + + + - - + + {user?.login?.charAt(0).toUpperCase() || 'A'} - + - - }> - {user?.login || 'Admin'} - + + {user?.login || 'Admin'} + {role} + - } - onClick={logout} - color="red" - > + } color="red" onClick={logout}> Выйти diff --git a/src/components/Layout/MainLayout.tsx b/src/components/Layout/MainLayout.tsx index cf5c1aa..2b158a6 100644 --- a/src/components/Layout/MainLayout.tsx +++ b/src/components/Layout/MainLayout.tsx @@ -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 ? : undefined, + onClick: () => { navigate(i.path); closeMobile() }, + })), + [user?.is_observer, navigate, closeMobile], + ) return (
- + - + + + ) } \ No newline at end of file diff --git a/src/components/Layout/Sidebar.module.css b/src/components/Layout/Sidebar.module.css new file mode 100644 index 0000000..5f5760d --- /dev/null +++ b/src/components/Layout/Sidebar.module.css @@ -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); +} \ No newline at end of file diff --git a/src/components/Layout/Sidebar.tsx b/src/components/Layout/Sidebar.tsx index 222e3f6..2ba8a25 100644 --- a/src/components/Layout/Sidebar.tsx +++ b/src/components/Layout/Sidebar.tsx @@ -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 ? : 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 ( - - : undefined} - rightSection={ - - } - active={hasActiveChild} - onClick={() => setOpened(!opened)} - styles={{ - root: { - paddingLeft, - paddingRight: 12, - borderRadius: '8px', - marginBottom: 2, - '&:hover': { - backgroundColor: 'var(--mantine-color-gray-0)', - }, - }, - }} - /> - {opened && ( - - {item.children!.map((child) => ( - - ))} - - )} - + + + {item.children.map((c) => )} + + ) } return ( : 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 ( - - - Главное меню - - - {/* 🆕 Индикатор режима наблюдателя */} + {isObserver && ( - - - Режим наблюдателя - - + Режим наблюдателя )} - - - {filteredMenuItems.map((item) => ( - + + {sections.map((section, i) => ( + + {section.title && {section.title}} + + {section.items.map((item) => )} + + ))} - + ) } \ No newline at end of file diff --git a/src/components/Layout/navigation.ts b/src/components/Layout/navigation.ts new file mode 100644 index 0000000..5b2d902 --- /dev/null +++ b/src/components/Layout/navigation.ts @@ -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 ?? [] +} \ No newline at end of file diff --git a/src/components/ui/EmptyState.tsx b/src/components/ui/EmptyState.tsx new file mode 100644 index 0000000..c07c645 --- /dev/null +++ b/src/components/ui/EmptyState.tsx @@ -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 ( +
+ + + + + {title} + {description && {description}} + {action} + +
+ ) +} \ No newline at end of file diff --git a/src/components/ui/PageHeader.tsx b/src/components/ui/PageHeader.tsx new file mode 100644 index 0000000..725e4d8 --- /dev/null +++ b/src/components/ui/PageHeader.tsx @@ -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 ( + + + {title} + {description && {description}} + + {actions && {actions}} + + ) +} \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index 670b2f6..60b14e7 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -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( - + diff --git a/src/pages/users/UsersPage.tsx b/src/pages/users/UsersPage.tsx index 510dc76..d49fa76 100644 --- a/src/pages/users/UsersPage.tsx +++ b/src/pages/users/UsersPage.tsx @@ -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' diff --git a/src/theme/global.css b/src/theme/global.css new file mode 100644 index 0000000..147913d --- /dev/null +++ b/src/theme/global.css @@ -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; +} \ No newline at end of file diff --git a/src/theme/theme.ts b/src/theme/theme.ts new file mode 100644 index 0000000..869c61d --- /dev/null +++ b/src/theme/theme.ts @@ -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 } }, + }, +}) \ No newline at end of file