diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 8927615..c8f52cb 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -1,54 +1,76 @@ -import { Menu } from 'antd' +import { ProfileOutlined } from '@ant-design/icons' +import { Layout, Menu, Spin } from 'antd' import { useEffect, useState } from 'react' -import { Navigate, Outlet, useNavigate } from 'react-router-dom' +import { Navigate, Outlet, useLocation } from 'react-router-dom' -import Header from '@components/Header' +import { localStorageKeys } from '@constants/localStorageKeys.ts' -import { useAppSelector } from '@hooks/redux.ts' -import { useRole } from '@hooks/useRole.tsx' +import { + MenuItemKeys, + MenuItemType, + menuKeys +} from '@components/Layout/layout.type.ts' +import UserMenu from '@components/UserMenu' +import { LocalStorage } from '@utils/localStorageUtils.ts' + +import { useAppDispatch, useAppSelector } from '@hooks/redux.ts' +import useRole from '@hooks/useRole.tsx' + +import { fetchProfile } from '@stores/redusers/ActionCreators.ts' import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts' import { routePaths } from '@routes/routePaths.ts' import { PermissionKeys } from '@type/roles.type.ts' -import { MenuItemKeys, menuKeys } from './layout.type.ts' - import './layout.scss' -const Layout = () => { - const { hasPermission } = useRole() - const navigate = useNavigate() - const { status } = useAppSelector((state) => state.profileReducer) +const { Header, Content, Sider } = Layout - const [openKeys, setOpenKeys] = useState([]) +const LayoutComponent = () => { + const [collapsed, setCollapsed] = useState(false) const [selectedMenuKeys, setSelectedMenuKeys] = useState([]) + const [openKeys, setOpenKeys] = useState([]) + const dispatch = useAppDispatch() + const { status } = useAppSelector((state) => state.profileReducer) + const location = useLocation() + const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN) + + const { hasPermission } = useRole() const hideItem = (permission: PermissionKeys | PermissionKeys[]) => { if (Array.isArray(permission)) { const result = permission.reduce((acc, currentValue) => { - const isHasPermission = hasPermission(currentValue) - return isHasPermission || acc + const hasPermissionFunc = hasPermission(currentValue) + return hasPermissionFunc || acc }, false) return result ? '' : 'hide-item' } return hasPermission(permission) ? '' : 'hide-item' } - - const menuItems = [ + const menuItems: MenuItemType[] = [ { - label: 'Profile', - key: 'users', - className: hideItem(PermissionKeys.user_view) - }, - { - label: 'Profile2', - key: 'roles', - className: hideItem(PermissionKeys.user_view) + label: 'Пользователи и роли', + key: 'sessionManagement', + className: hideItem([PermissionKeys.user_view]), + icon: , + children: [ + { + label: 'Пользователи', + key: 'users', + className: hideItem(PermissionKeys.user_view) + } + ] } ] + useEffect(() => { + if (userToken) { + dispatch(fetchProfile()) + } + }, []) + useEffect(() => { const menuKey = location.pathname.split('/')[1] as MenuItemKeys @@ -62,12 +84,6 @@ const Layout = () => { const handlerOnClickMenu = ({ key }: any): void => { switch (key) { - case MenuItemKeys.roles: - navigate(routePaths.error) - break - case MenuItemKeys.users: - navigate(routePaths.home) - break default: } } @@ -77,20 +93,41 @@ const Layout = () => { } return ( -
-
- setOpenKeys(keys)} - openKeys={openKeys} - selectedKeys={selectedMenuKeys} - onClick={handlerOnClickMenu} - theme="light" - mode="inline" - items={menuItems} - /> - -
+ + {status === StateProfileStatus.pending ? ( + + ) : ( + <> + setCollapsed(value)} + > + setOpenKeys(keys)} + openKeys={openKeys} + selectedKeys={selectedMenuKeys} + onClick={handlerOnClickMenu} + theme="light" + mode="inline" + items={menuItems} + /> + + +
+ +
+ + + +
+ + )} + ) } -export default Layout +export default LayoutComponent diff --git a/src/components/Layout/layout.scss b/src/components/Layout/layout.scss index cdfbc06..3f59ccb 100644 --- a/src/components/Layout/layout.scss +++ b/src/components/Layout/layout.scss @@ -1,4 +1,65 @@ + .layout { - min-height: calc(100vh - 96px); - width: 100%; + min-height: 100vh !important; + position: relative; + + .hide-item { + display: none !important; + } + + .ant-spin { + position: absolute; + top: 50%; + left: 50%; + } + .header { + display: flex; + align-items: center; + justify-content: flex-end; + line-height: 18px; + background: #fff; + padding: 0; + &__search { + max-width: 300px; + border: none; + margin-right: auto; + padding-right: 40px; + position: relative; + &:after { + content: ''; + background: url("/src/assets/icon/search-icon.svg"); + width: 13px; + height: 13px; + position: absolute; + right: 45px; + top: 50%; + transform: translateY(-50%); + } + .ant-input-search .ant-input:focus, .ant-input-search .ant-input:hover { + border-color: red !important; + } + & .ant-input { + border: none; + } + & button { + border: none; + display: none; + } + } + & .user { + padding-right: 34px; + } + } + .ant-menu { + border-inline-end: none !important; + } + .ant-layout-sider { + padding-top: 64px; + } + .ant-menu-title-content { + color: #1B1B1B; + padding-left: 15px; + + } + } diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index b588fc5..414fad7 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -1,8 +1,7 @@ import { MenuProps } from 'antd' export enum MenuItemKeys { - users = 'users', - roles = 'roles' + users = 'users' } type MenuItem = { @@ -13,10 +12,6 @@ export const menuKeys: Record = { [MenuItemKeys.users]: { key: MenuItemKeys.users, parent: ['sessionManagement'] - }, - [MenuItemKeys.roles]: { - key: MenuItemKeys.roles, - parent: ['sessionManagement'] } } diff --git a/src/type/roles.type.ts b/src/type/roles.type.ts index 12f924c..bf9e13e 100644 --- a/src/type/roles.type.ts +++ b/src/type/roles.type.ts @@ -5,7 +5,10 @@ export enum RoleKeys { export enum PermissionKeys { user_view = 'user_view', // Просмотр списка пользователей - admin_view = 'admin_view' // роль суперадмина, требуется для интерфейса + admin_view = 'admin_view', // роль суперадмина, требуется для интерфейса + session_view = 'session_view', // Просмотр списка пользовательских сессий + security_log_view = 'security_log_view', // Просмотр журналов ИБ + role_view = 'role_view', // Просмотр экрана ролей } export type ConfigRoles = {