Merge branch 'MSP-3155_user-menu' into 'main'
MSP-3155 "User menu" See merge request isp/isp-admin-ui!9
This commit is contained in:
commit
ea087dec13
9 files changed
+101
-107
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
## 0.2.5
|
||||||
|
- UserMenu изменен и перенесен из Header в Menu из Layout, удален Header
|
||||||
## 0.2.4
|
## 0.2.4
|
||||||
- Изменен Layout
|
- Изменен Layout
|
||||||
## 0.2.3
|
## 0.2.3
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "unsubscribe_landing",
|
"name": "unsubscribe_landing",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
.header {
|
|
||||||
width: 100%;
|
|
||||||
border: none;
|
|
||||||
display: flex;
|
|
||||||
justify-content: end;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { Segmented, theme } from 'antd'
|
|
||||||
import { useContext } from 'react'
|
|
||||||
|
|
||||||
import { darkTheme, lightTheme } from '@constants/theme.ts'
|
|
||||||
|
|
||||||
import { Context } from '@stores/index.tsx'
|
|
||||||
|
|
||||||
import './header.scss'
|
|
||||||
|
|
||||||
const options = [
|
|
||||||
{ label: 'Light', value: 'light' },
|
|
||||||
{ label: 'Dark', value: 'dark' }
|
|
||||||
]
|
|
||||||
|
|
||||||
const Header = () => {
|
|
||||||
const { setTheme } = useContext(Context)
|
|
||||||
const { useToken } = theme
|
|
||||||
const { token } = useToken()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<header className="header" style={{ backgroundColor: token.colorBgLayout }}>
|
|
||||||
<Segmented
|
|
||||||
onChange={(v) => setTheme(v === 'light' ? lightTheme : darkTheme)}
|
|
||||||
options={options}
|
|
||||||
/>
|
|
||||||
</header>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Header
|
|
||||||
@@ -26,7 +26,7 @@ import { PermissionKeys } from '@type/roles.type.ts'
|
|||||||
|
|
||||||
import './layout.scss'
|
import './layout.scss'
|
||||||
|
|
||||||
const { Header, Content, Sider } = Layout
|
const { Content, Sider } = Layout
|
||||||
|
|
||||||
const LayoutComponent = () => {
|
const LayoutComponent = () => {
|
||||||
const [collapsed, setCollapsed] = useState<boolean>(false)
|
const [collapsed, setCollapsed] = useState<boolean>(false)
|
||||||
@@ -106,6 +106,7 @@ const LayoutComponent = () => {
|
|||||||
collapsed={collapsed}
|
collapsed={collapsed}
|
||||||
onCollapse={(value) => setCollapsed(value)}
|
onCollapse={(value) => setCollapsed(value)}
|
||||||
>
|
>
|
||||||
|
<UserMenu />
|
||||||
<Menu
|
<Menu
|
||||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||||
openKeys={openKeys}
|
openKeys={openKeys}
|
||||||
@@ -117,9 +118,6 @@ const LayoutComponent = () => {
|
|||||||
/>
|
/>
|
||||||
</Sider>
|
</Sider>
|
||||||
<Layout className="site-layout">
|
<Layout className="site-layout">
|
||||||
<Header className="site-layout-background header" data-cy="header">
|
|
||||||
<UserMenu />
|
|
||||||
</Header>
|
|
||||||
<Content className="site-layout__content">
|
<Content className="site-layout__content">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
@@ -53,13 +53,18 @@
|
|||||||
.ant-menu {
|
.ant-menu {
|
||||||
border-inline-end: none !important;
|
border-inline-end: none !important;
|
||||||
}
|
}
|
||||||
.ant-layout-sider {
|
|
||||||
padding-top: 64px;
|
|
||||||
}
|
|
||||||
.ant-menu-title-content {
|
.ant-menu-title-content {
|
||||||
color: #1B1B1B;
|
color: #1B1B1B;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.user-menu {
|
||||||
|
padding-top: 20px;
|
||||||
|
padding-bottom: 100px;
|
||||||
|
& ul {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
& .ant-menu-submenu-arrow {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
import { LogoutOutlined, ProfileOutlined } from '@ant-design/icons'
|
import { LogoutOutlined, ProfileOutlined } from '@ant-design/icons'
|
||||||
import { Dropdown, MenuProps } from 'antd'
|
import { Menu, MenuProps } from 'antd'
|
||||||
import { useAuth } from 'isp-ui-kit'
|
import { useAuth } from 'isp-ui-kit'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
|
||||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||||
|
|
||||||
import { UserMenuKeys } from '@components/UserMenu/user-menu.type.ts'
|
import {
|
||||||
|
MenuItemKeysUser,
|
||||||
|
menuKeysUser
|
||||||
|
} from '@components/UserMenu/user-menu.type.ts'
|
||||||
|
|
||||||
import { getConfigProperty } from '@utils/configUtils.ts'
|
import { getConfigProperty } from '@utils/configUtils.ts'
|
||||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||||
@@ -15,56 +19,81 @@ import { useAppSelector } from '@hooks/redux.ts'
|
|||||||
|
|
||||||
import { routePaths } from '@routes/routePaths.ts'
|
import { routePaths } from '@routes/routePaths.ts'
|
||||||
|
|
||||||
import './user.scss'
|
const UserMenu = () => {
|
||||||
|
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||||
const items: MenuProps['items'] = [
|
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeysUser[]>(
|
||||||
{
|
[]
|
||||||
label: 'Профиль',
|
)
|
||||||
key: 'profile',
|
|
||||||
icon: <ProfileOutlined />
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Выход',
|
|
||||||
key: 'logout',
|
|
||||||
icon: <LogoutOutlined />
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function UserMenu() {
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { logout } = useAuth()
|
const { logout } = useAuth()
|
||||||
const headerName = LocalStorage.get(localStorageKeys.HEADER_NAME)
|
|
||||||
const {
|
const {
|
||||||
profile: { firstName }
|
profile: { firstName }
|
||||||
} = useAppSelector((state) => state.profileReducer)
|
} = useAppSelector((state) => state.profileReducer)
|
||||||
const handlerDropDownClick = (e: any) => {
|
|
||||||
if ((e.key as UserMenuKeys) === 'logout') {
|
const headerName = LocalStorage.get(localStorageKeys.HEADER_NAME)
|
||||||
logout(apiPaths.logout, {
|
|
||||||
'X-APPLICATION-TOKEN': getConfigProperty(
|
useEffect(() => {
|
||||||
'APP_TOKEN',
|
const menuKey = location.pathname.split('/')[1] as MenuItemKeysUser
|
||||||
import.meta.env.VITE_APP_TOKEN
|
|
||||||
),
|
const menuItem = menuKeysUser[menuKey]
|
||||||
[headerName]: LocalStorage.get(localStorageKeys.USER_TOKEN)
|
|
||||||
})
|
if (menuItem) {
|
||||||
.then(() => {
|
setSelectedMenuKeys([menuItem.key])
|
||||||
LocalStorage.remove(localStorageKeys.USER_TOKEN)
|
setOpenKeys(menuItem.parent)
|
||||||
LocalStorage.remove(localStorageKeys.HEADER_NAME)
|
}
|
||||||
navigate(routePaths.login, { replace: true })
|
}, [location])
|
||||||
|
|
||||||
|
const userItems: MenuProps['items'] = [
|
||||||
|
{
|
||||||
|
label: firstName || 'Анастасия',
|
||||||
|
key: 'userManagement',
|
||||||
|
icon: <img src="/src/assets/icon/default-user.svg" alt="" />,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
label: 'Профиль',
|
||||||
|
key: 'profile',
|
||||||
|
icon: <ProfileOutlined />
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Выход',
|
||||||
|
key: 'logout',
|
||||||
|
icon: <LogoutOutlined />
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const handlerOnClickMenuUser = ({ key }: any): void => {
|
||||||
|
switch (key) {
|
||||||
|
case MenuItemKeysUser.logout:
|
||||||
|
logout(apiPaths.logout, {
|
||||||
|
'X-APPLICATION-TOKEN': getConfigProperty(
|
||||||
|
'APP_TOKEN',
|
||||||
|
import.meta.env.VITE_APP_TOKEN
|
||||||
|
),
|
||||||
|
[headerName]: LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.then(() => {
|
||||||
|
LocalStorage.remove(localStorageKeys.USER_TOKEN)
|
||||||
|
LocalStorage.remove(localStorageKeys.HEADER_NAME)
|
||||||
|
navigate(routePaths.login, { replace: true })
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
break
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<div className="user-menu">
|
||||||
trigger={['click']}
|
<Menu
|
||||||
menu={{ items, onClick: handlerDropDownClick }}
|
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||||
className="user"
|
openKeys={openKeys}
|
||||||
>
|
selectedKeys={selectedMenuKeys}
|
||||||
<div role="presentation" onClick={(e) => e.preventDefault()}>
|
onClick={handlerOnClickMenuUser}
|
||||||
<span className="user__avatar" />
|
theme="light"
|
||||||
<span className="user__name">{firstName || ''}</span>
|
mode="inline"
|
||||||
</div>
|
items={userItems}
|
||||||
</Dropdown>
|
/>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export default UserMenu
|
||||||
@@ -1 +1,13 @@
|
|||||||
export type UserMenuKeys = 'logout' | 'profile'
|
export enum MenuItemKeysUser {
|
||||||
|
logout = 'logout'
|
||||||
|
}
|
||||||
|
type MenuItemUser = {
|
||||||
|
key: MenuItemKeysUser
|
||||||
|
parent: string[]
|
||||||
|
}
|
||||||
|
export const menuKeysUser: Record<MenuItemKeysUser, MenuItemUser> = {
|
||||||
|
[MenuItemKeysUser.logout]: {
|
||||||
|
key: MenuItemKeysUser.logout,
|
||||||
|
parent: ['']
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
@import "src/constants/styleConstants";
|
|
||||||
.user {
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
&__avatar {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
background: url("/src/assets/icon/default-user.svg") no-repeat, center left;
|
|
||||||
}
|
|
||||||
&__name {
|
|
||||||
margin-left: $basic-margin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user