Merge branch 'MSP-3104-profile-screen' into 'main'
Resolve MSP-3104 "Profile screen" Closes MSP-3104 See merge request isp/isp-admin-ui!8
This commit is contained in:
commit
23d2610b35
41 files changed
+10476
-5606
No files matched your search
@@ -0,0 +1,2 @@
|
||||
PROXY_URL=
|
||||
VITE_APP_TOKEN=
|
||||
@@ -33,7 +33,7 @@
|
||||
],
|
||||
"rules": {
|
||||
"import/no-named-as-default":"off",
|
||||
"prettier/prettier": "error",
|
||||
"prettier/prettier": "off",
|
||||
"quotes": ["error", "single"],
|
||||
"react/jsx-filename-extension": [
|
||||
1,
|
||||
@@ -41,6 +41,7 @@
|
||||
"extensions": [".js", ".jsx", ".tsx"]
|
||||
}
|
||||
],
|
||||
"react/jsx-one-expression-per-line": "off",
|
||||
"react/prop-types": 0,
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"semi": ["error", "never"],
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
## 0.3.0
|
||||
- Добавлен экран Профиля
|
||||
- Добавлено хранилище ролей
|
||||
- Изменен пакетный менеджер на npm
|
||||
- Улучшения стилей приложения
|
||||
## 0.2.6
|
||||
- Добавлено модальное окно
|
||||
## 0.2.5
|
||||
|
||||
Generated
+9866
File diff suppressed because it is too large.
Load diff
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "unsubscribe_landing",
|
||||
"name": "isp-admin-ui",
|
||||
"private": true,
|
||||
"version": "0.2.6",
|
||||
"version": "0.3.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export type ChangePasswordModalType = {
|
||||
oldPassword: string
|
||||
newPassword: string
|
||||
confirmPassword: string
|
||||
}
|
||||
|
||||
export type ChangePasswordModalProps = {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { FormComponents } from 'isp-ui-kit'
|
||||
import { FC } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
|
||||
import Modal from '@widgets/Modal'
|
||||
|
||||
import {
|
||||
ChangePasswordModalProps,
|
||||
ChangePasswordModalType
|
||||
} from '@components/ChangePasswordModal/change-password-modal.type.ts'
|
||||
|
||||
|
||||
const { FormInputPassword } = FormComponents
|
||||
const ChangePasswordModal: FC<ChangePasswordModalProps> = ({
|
||||
open,
|
||||
onClose
|
||||
}) => {
|
||||
const { control, handleSubmit } = useForm<ChangePasswordModalType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const onSubmit = (formValue: ChangePasswordModalType) => {
|
||||
//TODO добавить бэк, как появится
|
||||
console.log(formValue)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title="Сменить пароль"
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
onOk={handleSubmit(onSubmit)}
|
||||
footer={{ onOkText: 'Изменить пароль', onCanselText: 'Отмена' }}
|
||||
>
|
||||
<form key="change-pass-modal">
|
||||
<FormInputPassword
|
||||
rules={{
|
||||
required: { value: true, message: 'Поле не может быть пустым' }
|
||||
}}
|
||||
label="Старый пароль"
|
||||
control={control}
|
||||
name="oldPassword"
|
||||
/>
|
||||
<FormInputPassword
|
||||
rules={{
|
||||
required: { value: true, message: 'Поле не может быть пустым' }
|
||||
}}
|
||||
label="Новый пароль"
|
||||
control={control}
|
||||
name="newPassword"
|
||||
/>
|
||||
<FormInputPassword
|
||||
rules={{
|
||||
required: { value: true, message: 'Поле не может быть пустым' },
|
||||
validate: (value, formValues) => {
|
||||
const { newPassword } = formValues
|
||||
return value !== newPassword ? 'Пароли не совпадают' : true
|
||||
}
|
||||
}}
|
||||
label="Подтвердите пароль"
|
||||
control={control}
|
||||
name="confirmPassword"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
export default ChangePasswordModal
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ProfileOutlined } from '@ant-design/icons'
|
||||
import { Layout, Menu, Spin } from 'antd'
|
||||
import { Divider, Layout, Menu, Spin } from 'antd'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom'
|
||||
|
||||
@@ -26,6 +26,7 @@ import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import './layout.scss'
|
||||
|
||||
|
||||
const { Content, Sider } = Layout
|
||||
|
||||
const LayoutComponent = () => {
|
||||
@@ -107,6 +108,7 @@ const LayoutComponent = () => {
|
||||
onCollapse={(value) => setCollapsed(value)}
|
||||
>
|
||||
<UserMenu />
|
||||
<Divider />
|
||||
<Menu
|
||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||
openKeys={openKeys}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@import 'src/constants/style/styleConst';
|
||||
|
||||
.layout {
|
||||
min-height: 100vh !important;
|
||||
@@ -12,6 +13,7 @@
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -19,12 +21,14 @@
|
||||
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");
|
||||
@@ -35,35 +39,55 @@
|
||||
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: $basic-padding * 2;
|
||||
}
|
||||
|
||||
.ant-menu-title-content {
|
||||
color: #1B1B1B;
|
||||
padding-left: 15px;
|
||||
|
||||
}
|
||||
|
||||
.site-layout {
|
||||
|
||||
&__content {
|
||||
padding: $basic-padding * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.user-menu {
|
||||
padding-top: 20px;
|
||||
padding-bottom: 100px;
|
||||
margin-bottom: 100px;
|
||||
|
||||
& ul {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
& .ant-menu-submenu-arrow {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Descriptions, Spin } from 'antd'
|
||||
|
||||
import { RoleListProps } from '@components/RoleList/role-list.type.ts'
|
||||
|
||||
import roleApi from '@services/roleService.ts'
|
||||
|
||||
import './role-list.scss'
|
||||
|
||||
|
||||
const RoleList = ({ userRoles }: RoleListProps) => {
|
||||
const { data: roles = [], isLoading, isError } = roleApi.useGetAllRolesQuery()
|
||||
const roleIds = new Set(userRoles)
|
||||
|
||||
if (isError) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Descriptions layout="vertical" className="role-list">
|
||||
<Descriptions.Item label="Список ролей">
|
||||
{isLoading ? (
|
||||
<Spin className="spin" />
|
||||
) : (
|
||||
<ul>
|
||||
{roles.map((roleData) => {
|
||||
if (roleIds.has(roleData.id) && roleData.name) {
|
||||
return <li key={roleData.id}>{roleData.name}</li>
|
||||
}
|
||||
return null
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)
|
||||
}
|
||||
|
||||
export default RoleList
|
||||
@@ -0,0 +1,19 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.role-list {
|
||||
.ant-descriptions-item-label {
|
||||
font-size: $text-size-header2;
|
||||
}
|
||||
|
||||
.spin {
|
||||
position: initial;
|
||||
}
|
||||
|
||||
ul, li {
|
||||
list-style-position: inside
|
||||
}
|
||||
|
||||
li {
|
||||
font-size: $text-size
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export type RoleListProps = {
|
||||
userRoles: number[]
|
||||
}
|
||||
@@ -1,37 +1,31 @@
|
||||
import { LogoutOutlined, ProfileOutlined } from '@ant-design/icons'
|
||||
import { Menu, MenuProps } from 'antd'
|
||||
import { useAuth } from 'isp-ui-kit'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
|
||||
import {
|
||||
MenuItemKeysUser,
|
||||
menuKeysUser
|
||||
} from '@components/UserMenu/user-menu.type.ts'
|
||||
|
||||
import { getConfigProperty } from '@utils/configUtils.ts'
|
||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { useAppSelector } from '@hooks/redux.ts'
|
||||
import useLogout from '@hooks/useLogout.tsx'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
|
||||
const UserMenu = () => {
|
||||
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeysUser[]>(
|
||||
[]
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
const { logout } = useAuth()
|
||||
|
||||
const { logoutUser } = useLogout()
|
||||
const {
|
||||
profile: { firstName }
|
||||
} = useAppSelector((state) => state.profileReducer)
|
||||
|
||||
const headerName = LocalStorage.get(localStorageKeys.HEADER_NAME)
|
||||
|
||||
useEffect(() => {
|
||||
const menuKey = location.pathname.split('/')[1] as MenuItemKeysUser
|
||||
|
||||
@@ -45,7 +39,7 @@ const UserMenu = () => {
|
||||
|
||||
const userItems: MenuProps['items'] = [
|
||||
{
|
||||
label: firstName || 'Анастасия',
|
||||
label: firstName,
|
||||
key: 'userManagement',
|
||||
icon: <img src="/src/assets/icon/default-user.svg" alt="" />,
|
||||
children: [
|
||||
@@ -64,21 +58,14 @@ const UserMenu = () => {
|
||||
]
|
||||
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)
|
||||
})
|
||||
.then(() => {
|
||||
LocalStorage.remove(localStorageKeys.USER_TOKEN)
|
||||
LocalStorage.remove(localStorageKeys.HEADER_NAME)
|
||||
navigate(routePaths.login, { replace: true })
|
||||
})
|
||||
.catch(() => {})
|
||||
case MenuItemKeysUser.logout: {
|
||||
logoutUser()
|
||||
break
|
||||
}
|
||||
case MenuItemKeysUser.profile: {
|
||||
navigate(routePaths.profile)
|
||||
break
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export enum MenuItemKeysUser {
|
||||
logout = 'logout'
|
||||
logout = 'logout',
|
||||
profile = 'profile'
|
||||
}
|
||||
|
||||
type MenuItemUser = {
|
||||
key: MenuItemKeysUser
|
||||
parent: string[]
|
||||
@@ -9,5 +11,9 @@ export const menuKeysUser: Record<MenuItemKeysUser, MenuItemUser> = {
|
||||
[MenuItemKeysUser.logout]: {
|
||||
key: MenuItemKeysUser.logout,
|
||||
parent: ['']
|
||||
},
|
||||
[MenuItemKeysUser.profile]: {
|
||||
key: MenuItemKeysUser.profile,
|
||||
parent: ['']
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@import "src/constants/styleConstants";
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
*, html {
|
||||
margin:0;
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
type PathKeys = 'baseUrl' | 'login' | 'logout'
|
||||
|
||||
type PathKeys =
|
||||
| 'baseUrl'
|
||||
| 'getAllRoles'
|
||||
| 'createRole'
|
||||
| 'updateRole'
|
||||
| 'deleteRole'
|
||||
| 'login'
|
||||
| 'logout'
|
||||
| 'getProfile'
|
||||
export const apiPaths: Record<PathKeys, string> = {
|
||||
baseUrl: '/',
|
||||
baseUrl: '/api/admin',
|
||||
// ======= ROLES ======
|
||||
getAllRoles: '/role/all',
|
||||
createRole: '/role/create',
|
||||
updateRole: '/role/update',
|
||||
deleteRole: '/role/delete',
|
||||
// ======= AUTH ======
|
||||
login: '/api/admin/auth/login',
|
||||
logout: '/api/admin/auth/logout'
|
||||
logout: '/api/admin/auth/logout',
|
||||
// ======= PROFILE ======
|
||||
getProfile: '/api/admin/user/get_profile'
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
$basic-margin: 8px;
|
||||
$basic-padding: 8px;
|
||||
|
||||
$text-size: 1rem;
|
||||
$text-size-header1: 1.7rem;
|
||||
$text-size-header2: 1.25rem;
|
||||
|
||||
$text-color-gray: var(--ant-primary-color);
|
||||
$background-color: #F0F2F5;
|
||||
$grey:#606060;
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
$background-color: #F0F2F5;
|
||||
$text-color-gray: var(--ant-primary-color);
|
||||
$text-color-blue: #1890FF;
|
||||
|
||||
$basic-margin: 8px;
|
||||
$basic-padding: 8px;
|
||||
|
||||
$text-size: 14px;
|
||||
|
||||
$border-color: #F0F0F0;
|
||||
|
||||
$blue-color: #40A9FF;
|
||||
$blue-light: #E6F7FF;
|
||||
|
||||
$grey:#606060;
|
||||
$red: #FF4D4F;
|
||||
$green: #52C41A;
|
||||
$yellow: #FAAD14;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useAuth } from 'isp-ui-kit'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
|
||||
import { getConfigProperty } from '@utils/configUtils.ts'
|
||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
|
||||
const useLogout = () => {
|
||||
const { logout, isLoading } = useAuth()
|
||||
const navigate = useNavigate()
|
||||
const headerName = LocalStorage.get(localStorageKeys.HEADER_NAME)
|
||||
|
||||
const logoutUser = () =>
|
||||
logout(apiPaths.logout, {
|
||||
'X-APPLICATION-TOKEN': getConfigProperty(
|
||||
'APP_TOKEN',
|
||||
import.meta.env.VITE_APP_TOKEN
|
||||
),
|
||||
[headerName]: LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||
})
|
||||
.then(() => {
|
||||
LocalStorage.remove(localStorageKeys.USER_TOKEN)
|
||||
LocalStorage.remove(localStorageKeys.HEADER_NAME)
|
||||
navigate(routePaths.login, { replace: true })
|
||||
})
|
||||
.catch(() => {})
|
||||
return { isLoading, logoutUser }
|
||||
}
|
||||
|
||||
export default useLogout
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Layout } from 'antd'
|
||||
|
||||
import UserMenu from '@components/UserMenu/UserMenu.tsx'
|
||||
|
||||
import './header.scss'
|
||||
|
||||
|
||||
const { Header: AntdHeader } = Layout
|
||||
|
||||
const Header = () => {
|
||||
return (
|
||||
<AntdHeader className="header">
|
||||
<UserMenu />
|
||||
</AntdHeader>
|
||||
)
|
||||
}
|
||||
|
||||
export default Header
|
||||
@@ -1,42 +1,5 @@
|
||||
import { Button, theme } from 'antd'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { useRole } from '@hooks/useRole.tsx'
|
||||
|
||||
import { PermissionKeys } from '@type/roles.type.ts'
|
||||
|
||||
import Modal from 'src/widgets/Modal'
|
||||
|
||||
import './home-page.scss'
|
||||
|
||||
const HomePages = () => {
|
||||
const { hasPermission } = useRole()
|
||||
const { useToken } = theme
|
||||
const { token } = useToken()
|
||||
const [isOpenModal, setIsOpenModal] = useState(false)
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeys.user_view)
|
||||
|
||||
return (
|
||||
<main className="main" style={{ backgroundColor: token.colorBgLayout }}>
|
||||
{isPageAvailable && (
|
||||
<Button ghost type="primary">
|
||||
Border
|
||||
</Button>
|
||||
)}
|
||||
<div>Проверка шрифтов</div>
|
||||
|
||||
{isOpenModal && (
|
||||
<Modal setIsOpenModal={setIsOpenModal} title="modal title">
|
||||
<div>modal content</div>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
<Button type="primary" onClick={() => setIsOpenModal(true)}>
|
||||
Open Modal
|
||||
</Button>
|
||||
</main>
|
||||
)
|
||||
export default function HomePage() {
|
||||
return <div className="home-page">Добро пожаловать!</div>
|
||||
}
|
||||
|
||||
export default HomePages
|
||||
@@ -1,4 +1,4 @@
|
||||
@import "src/constants/styleConstants";
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.login-page {
|
||||
height: 100vh;
|
||||
@@ -32,7 +32,7 @@
|
||||
&__title {
|
||||
text-align: center;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 14px;
|
||||
font-size: $text-size;
|
||||
line-height: 20px;
|
||||
color: $text-color-gray;
|
||||
}
|
||||
@@ -40,6 +40,7 @@
|
||||
&__submit-sudir-btn {
|
||||
background: #0000000f;
|
||||
margin-top: 4 * $basic-margin;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.09) !important;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Button, Descriptions } from 'antd'
|
||||
import { useState } from 'react'
|
||||
|
||||
import PermissionList from '@widgets/PermissionList'
|
||||
|
||||
import ChangePasswordModal from '@components/ChangePasswordModal'
|
||||
import RoleList from '@components/RoleList'
|
||||
|
||||
import { useAppSelector } from '@hooks/redux.ts'
|
||||
import useLogout from '@hooks/useLogout.tsx'
|
||||
|
||||
import './profile-page.scss'
|
||||
|
||||
|
||||
const ProfilePage = () => {
|
||||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false)
|
||||
const { profile } = useAppSelector((state) => state.profileReducer)
|
||||
const { logoutUser, isLoading } = useLogout()
|
||||
|
||||
return (
|
||||
<section className="profile-page">
|
||||
<ChangePasswordModal
|
||||
onClose={() => setIsModalOpen(false)}
|
||||
open={isModalOpen}
|
||||
/>
|
||||
<h1 className="profile-page__title">{`${profile.lastName} ${profile.firstName}`}</h1>
|
||||
<div className="profile-page__user-info">
|
||||
<div className="profile-page__user-info__email-wrapper">
|
||||
<Descriptions>
|
||||
<Descriptions.Item label="Email">{profile.email}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</div>
|
||||
</div>
|
||||
<RoleList userRoles={profile.roles} />
|
||||
<PermissionList permissions={profile.permissions} />
|
||||
<div className="profile-page__actions">
|
||||
<Button
|
||||
loading={isLoading}
|
||||
disabled={isLoading}
|
||||
className="profile-page__actions__exit-btn"
|
||||
type="primary"
|
||||
onClick={logoutUser}
|
||||
>
|
||||
Выход
|
||||
</Button>
|
||||
<Button
|
||||
className="profile-page__actions__change-pass-btn"
|
||||
type="primary"
|
||||
onClick={() => setIsModalOpen(true)}
|
||||
>
|
||||
Сменить пароль
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProfilePage
|
||||
@@ -0,0 +1,24 @@
|
||||
@import '../../constants/style/styleConst';
|
||||
|
||||
.profile-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: start;
|
||||
|
||||
&__title {
|
||||
font-size: $text-size-header1;
|
||||
}
|
||||
|
||||
&__user-info {
|
||||
margin-top: $basic-padding;
|
||||
|
||||
span {
|
||||
font-size: $text-size !important;
|
||||
}
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
gap: $basic-margin
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StateProfileStatus } from '../stores/redusers/ProfileSlice.ts'
|
||||
import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts'
|
||||
|
||||
export type ProfileDataType = {
|
||||
email: string
|
||||
@@ -13,6 +13,9 @@ const LoginPage = lazy(() => import('@pages/LoginPage'))
|
||||
|
||||
const ErrorPage = lazy(() => import('@components/ErrorPage'))
|
||||
|
||||
|
||||
const ProfilePage = lazy(() => import('@pages/ProfilePage'))
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
<Routes>
|
||||
@@ -26,10 +29,17 @@ const Routers = () => {
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.profile}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ProfilePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.error}
|
||||
<Route path={routePaths.error}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ErrorPage />
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
type RoutePaths = 'home' | 'notFound' | 'error' | 'login'
|
||||
type RoutePaths = 'home' | 'notFound' | 'error' | 'login' | 'profile'
|
||||
|
||||
export const routePaths: Record<RoutePaths, string> = {
|
||||
home: '/',
|
||||
error: '/error',
|
||||
notFound: '*',
|
||||
login: '/login'
|
||||
login: '/login',
|
||||
profile: '/profile'
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export const apiService = axios.create({
|
||||
|
||||
apiService.defaults.headers.post['X-APPLICATION-TOKEN'] = getConfigProperty(
|
||||
'APP_TOKEN',
|
||||
import.meta.env.APP_TOKEN
|
||||
import.meta.env.VITE_APP_TOKEN
|
||||
)
|
||||
|
||||
apiService.interceptors.request.use(
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import { NewRoleType, RoleType } from '@type/roles.type.ts'
|
||||
|
||||
|
||||
const roleApi = createApi({
|
||||
reducerPath: 'roleApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['Roles'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getAllRoles: builder.query<RoleType[], void>({
|
||||
query: () => ({ url: apiPaths.getAllRoles }),
|
||||
providesTags: () => ['Roles']
|
||||
}),
|
||||
createRole: builder.mutation<RoleType, NewRoleType>({
|
||||
query: (newRole) => ({
|
||||
url: apiPaths.createRole,
|
||||
data: newRole
|
||||
}),
|
||||
invalidatesTags: ['Roles']
|
||||
}),
|
||||
updateRole: builder.mutation<void, RoleType>({
|
||||
query: (role) => ({
|
||||
url: apiPaths.updateRole,
|
||||
data: role
|
||||
}),
|
||||
invalidatesTags: ['Roles']
|
||||
}),
|
||||
removeRole: builder.mutation<void, number>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.deleteRole,
|
||||
data: { id }
|
||||
}),
|
||||
invalidatesTags: ['Roles']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default roleApi
|
||||
@@ -3,8 +3,11 @@ import { theme } from 'antd'
|
||||
import { MapToken, SeedToken } from 'antd/es/theme/interface'
|
||||
import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
|
||||
import roleApi from '@services/roleService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
|
||||
|
||||
export interface ContextProps {
|
||||
setTheme: Dispatch<
|
||||
SetStateAction<{ algorithm: (token: SeedToken) => MapToken }>
|
||||
@@ -16,12 +19,15 @@ export const Context = createContext<ContextProps>({
|
||||
})
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer
|
||||
profileReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
configureStore({
|
||||
reducer: rootReducer
|
||||
reducer: rootReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat([roleApi.middleware])
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
|
||||
@@ -2,15 +2,18 @@ import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { ProfileDataType } from '@pages/ProfilePage/profile-page.type.ts'
|
||||
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
|
||||
import { ProfileDataType } from '@type/profile.type.ts'
|
||||
|
||||
export const fetchProfile = createAsyncThunk(
|
||||
'profile/fetchProfile',
|
||||
async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const response = await apiService.post<ProfileDataType>(apiPaths.baseUrl)
|
||||
const response = await apiService.post<ProfileDataType>(
|
||||
apiPaths.getProfile
|
||||
)
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return rejectWithValue(error)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import {
|
||||
ActionReducerMapBuilder,
|
||||
PayloadAction,
|
||||
createSlice
|
||||
createSlice,
|
||||
PayloadAction
|
||||
} from '@reduxjs/toolkit'
|
||||
|
||||
import { ProfileDataType, ProfileType } from '@type/profile.type.ts'
|
||||
import {
|
||||
ProfileDataType,
|
||||
ProfileType
|
||||
} from '@pages/ProfilePage/profile-page.type.ts'
|
||||
|
||||
import { fetchProfile } from './ActionCreators.ts'
|
||||
|
||||
|
||||
export enum StateProfileStatus {
|
||||
resolved = 'resolved',
|
||||
pending = 'pending',
|
||||
|
||||
@@ -11,15 +11,6 @@ export enum PermissionKeys {
|
||||
role_view = 'role_view', // Просмотр экрана ролей
|
||||
}
|
||||
|
||||
export type ConfigRoles = {
|
||||
operator: string[]
|
||||
supervisor: string[]
|
||||
ontologist: string[]
|
||||
businessMonitoring: string[]
|
||||
technicalMonitoring: string[]
|
||||
administratorIS: string[]
|
||||
}
|
||||
|
||||
export type RoleType = {
|
||||
changeMessage?: string
|
||||
createdAt: string
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { BaseQueryFn, retry } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
import { apiService } from '@services/apiService.ts'
|
||||
import { MSPError } from '@type/index.ts'
|
||||
|
||||
export const axiosBaseQuery =
|
||||
(
|
||||
{ baseUrl }: { baseUrl: string } = { baseUrl: '' },
|
||||
): BaseQueryFn<
|
||||
{
|
||||
url: string;
|
||||
method?: AxiosRequestConfig['method'];
|
||||
data?: AxiosRequestConfig['data'];
|
||||
params?: AxiosRequestConfig['params'];
|
||||
},
|
||||
unknown,
|
||||
unknown
|
||||
> =>
|
||||
async ({ url, method = 'post', data, params }) => {
|
||||
try {
|
||||
const result = await apiService({
|
||||
url: baseUrl + url,
|
||||
method,
|
||||
data,
|
||||
params,
|
||||
});
|
||||
return { data: result.data };
|
||||
} catch (axiosError) {
|
||||
const err = axiosError as AxiosError<MSPError>;
|
||||
return {
|
||||
error: { ...err.response },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const staggeredBaseQueryWithBailOut = (baseUrl: string) =>
|
||||
retry(
|
||||
async (args: string | AxiosRequestConfig['data'], api, extraOptions) => {
|
||||
const result = await axiosBaseQuery({ baseUrl })(args, api, extraOptions);
|
||||
const error = result.error as AxiosError<MSPError>;
|
||||
if (error && error?.status === 400) {
|
||||
retry.fail(result.error);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
{
|
||||
maxRetries: 5,
|
||||
},
|
||||
);
|
||||
+31
-16
@@ -1,35 +1,50 @@
|
||||
import { Button } from 'antd'
|
||||
import { Dispatch, MouseEvent, ReactNode, SetStateAction } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import CloseBtn from 'src/ui/CloseBtn'
|
||||
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
|
||||
import './modal.scss'
|
||||
|
||||
interface ModalPropsType {
|
||||
onOk?: () => void
|
||||
title: string
|
||||
children: ReactNode
|
||||
setIsOpenModal: Dispatch<SetStateAction<boolean>>
|
||||
footer?: { onOkText: string; onCanselText: string }
|
||||
}
|
||||
|
||||
const Modal = ({
|
||||
onOk,
|
||||
open,
|
||||
onOk = () => {},
|
||||
footer,
|
||||
title,
|
||||
children,
|
||||
setIsOpenModal
|
||||
onClose = () => {}
|
||||
}: ModalPropsType) => {
|
||||
const closeModal = () => {
|
||||
setIsOpenModal(false)
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
const handleModalClick = (event: MouseEvent<HTMLDivElement>) => {
|
||||
event.stopPropagation()
|
||||
const closeModal = () => {
|
||||
onClose()
|
||||
document.body.classList.remove('modal-open')
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', handleKeyDown)
|
||||
|
||||
if (open) {
|
||||
document.body.classList.add('modal-open')
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
if (!open) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="modal" onClick={closeModal}>
|
||||
<div className="modal__wrap" onClick={handleModalClick}>
|
||||
<div className="modal__wrap" onClick={(event) => event.stopPropagation()}>
|
||||
<h1 className="modal__title">{title}</h1>
|
||||
<div className="modal__content">{children}</div>
|
||||
{footer && (
|
||||
@@ -37,7 +52,7 @@ const Modal = ({
|
||||
<Button type="default" onClick={closeModal}>
|
||||
{footer.onCanselText}
|
||||
</Button>
|
||||
<Button type="default" onClick={onOk}>
|
||||
<Button type="primary" onClick={onOk}>
|
||||
{footer.onOkText}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
@@ -13,12 +15,19 @@
|
||||
&__wrap {
|
||||
min-width: 310px;
|
||||
min-height: 170px;
|
||||
max-height: 90vh;
|
||||
max-width: 90%;
|
||||
background: white;
|
||||
color: white;
|
||||
z-index: 10;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.04);
|
||||
position: relative;
|
||||
padding: $basic-padding * 1.5;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
&__header {
|
||||
@@ -28,20 +37,28 @@
|
||||
border-top-left-radius: 16px;
|
||||
border-top-right-radius: 16px;
|
||||
}
|
||||
&__title {
|
||||
color: $grey;
|
||||
}
|
||||
&__content {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
color: #2c3e50;
|
||||
text-align: center;
|
||||
overflow: auto;
|
||||
}
|
||||
&__footer {
|
||||
position: absolute;
|
||||
bottom: 8px;
|
||||
right: 16px;
|
||||
button:first-child {
|
||||
margin-right: 8px;
|
||||
}
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
margin-top: $basic-margin;
|
||||
button:first-child {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.modal-open {
|
||||
overflow: hidden;
|
||||
padding-right: 14px;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ReactNode } from 'react'
|
||||
|
||||
export interface ModalPropsType {
|
||||
open: boolean
|
||||
onOk?: () => void
|
||||
onClose?: () => void
|
||||
title: string
|
||||
children: ReactNode
|
||||
footer?: { onOkText: string; onCanselText: string }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Descriptions } from 'antd'
|
||||
import { FC } from 'react'
|
||||
|
||||
import { PermissionListProps } from './permisiion-list.type.ts'
|
||||
|
||||
import './permission-list.scss'
|
||||
|
||||
|
||||
const PermissionList: FC<PermissionListProps> = ({ permissions }) => {
|
||||
return (
|
||||
<Descriptions layout="vertical" className="permission-list">
|
||||
<Descriptions.Item
|
||||
label="Список разрешений"
|
||||
>
|
||||
<ul>
|
||||
{permissions.map((permission, index) => {
|
||||
return <li key={`${permission}-${index}`}>{permission}</li>
|
||||
})}
|
||||
</ul>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)
|
||||
}
|
||||
|
||||
export default PermissionList
|
||||
@@ -0,0 +1,3 @@
|
||||
export type PermissionListProps = {
|
||||
permissions:string[];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.permission-list {
|
||||
.ant-descriptions-item-label {
|
||||
font-size: $text-size-header2;
|
||||
}
|
||||
|
||||
ul, li {
|
||||
list-style-position: inside
|
||||
}
|
||||
|
||||
li {
|
||||
font-size: $text-size;
|
||||
margin-bottom: $basic-margin * 1.5;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user