2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];
This commit is contained in:
1 parent
5a5f104174
commit
a31c44eb7b
121 files changed
+14802
-84
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import { PropsWithChildren } from 'react'
|
||||
|
||||
import { useRole } from '@hooks/useRole.tsx'
|
||||
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
const AdminPermission = ({ children }: PropsWithChildren) => {
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
if (hasPermission(PermissionKeysType.read)) {
|
||||
return <>{children}</>
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export default AdminPermission
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ConfigProvider } from 'antd'
|
||||
import ruRu from 'antd/locale/ru_RU'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { lightTheme } from '@constants/theme.ts'
|
||||
|
||||
import { Context } from '@stores/index.tsx'
|
||||
|
||||
import Routers from '@routes/Routers'
|
||||
|
||||
import './app.scss'
|
||||
|
||||
const App = () => {
|
||||
const [themes, setTheme] = useState(lightTheme)
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<Context.Provider value={{ setTheme }}>
|
||||
<ConfigProvider theme={themes} locale={ruRu}>
|
||||
<Routers />
|
||||
</ConfigProvider>
|
||||
</Context.Provider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,36 @@
|
||||
@import 'src/constants/style/styleConst';
|
||||
|
||||
.app-access-content {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
min-width: 760px;
|
||||
|
||||
padding: $basic-padding * 2;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: $basic-margin * 2;
|
||||
|
||||
&__action-buttons {
|
||||
display: flex;
|
||||
gap: $basic-margin * 2;
|
||||
}
|
||||
}
|
||||
|
||||
&__main {
|
||||
display: grid;
|
||||
grid-template-columns:1fr 1fr;
|
||||
|
||||
|
||||
&__tree-search-input {
|
||||
width: 350px;
|
||||
margin-bottom: $basic-margin * 2;
|
||||
}
|
||||
}
|
||||
|
||||
.unknown-label {
|
||||
color: $error-red
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface AppAccessContentPropsType {
|
||||
id: number
|
||||
paramPrefix: string
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import { SearchOutlined } from '@ant-design/icons'
|
||||
import { Button, Input, message, Spin, TreeProps } from 'antd'
|
||||
import { ChangeEvent, FC, memo, useEffect, useState } from 'react'
|
||||
import { Navigate, useSearchParams } from 'react-router-dom'
|
||||
|
||||
import AccessListTree from '@widgets/AccessListTree'
|
||||
import SelectedAccessMethod from '@widgets/SelectedAccessMethod'
|
||||
|
||||
import { AppAccessContentPropsType } from '@components/AppAccessContent/app-access-content.type.ts'
|
||||
|
||||
import { setSearchValue } from '@utils/columnLayoutUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import accessListApi from '@services/accessListService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
import './app-access-content.scss'
|
||||
|
||||
|
||||
const unknownMethodKey = 'неизвестные методы'
|
||||
|
||||
const AppAccessContent: FC<AppAccessContentPropsType> = ({
|
||||
id,
|
||||
paramPrefix
|
||||
}) => {
|
||||
const [messageApi, contextHolder] = message.useMessage()
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const canWrite = hasPermission(PermissionKeysType.write)
|
||||
|
||||
const {
|
||||
data: methods = [],
|
||||
isLoading: isMethodsLoading,
|
||||
isError: isMethodsError,
|
||||
isSuccess: isMethodsSuccess
|
||||
} = accessListApi.useGetByIdQuery({ id })
|
||||
const [setList] = accessListApi.useSetListMutation()
|
||||
const [setOne] = accessListApi.useSetOneMutation()
|
||||
|
||||
const {
|
||||
data: routes = {
|
||||
originalResponse: [],
|
||||
moduleEndpoints: {},
|
||||
allRouteMap: {}
|
||||
},
|
||||
isLoading: isRouteLoading,
|
||||
isError: isRouteError,
|
||||
isSuccess: isRouteSuccess
|
||||
} = routeApi.useGetAllRoutesQuery()
|
||||
const { moduleEndpoints, allRouteMap } = routes
|
||||
const [defaultAllRoutes, setDefaultAllRoutes] = useState<
|
||||
Record<string, EndpointType[]>
|
||||
>({})
|
||||
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const searchValue = searchParams.get(paramPrefix) || ''
|
||||
|
||||
const isLoading = isMethodsLoading || isRouteLoading
|
||||
const isError = isMethodsError || isRouteError
|
||||
const isSuccess = isMethodsSuccess && isRouteSuccess
|
||||
|
||||
const openSuccessMessage = (body: string) => {
|
||||
messageApi.success(body)
|
||||
}
|
||||
|
||||
const openErrorMessage = (body: string) => {
|
||||
messageApi.error(body)
|
||||
}
|
||||
|
||||
const createAllMethodList = (status: boolean) => {
|
||||
return Object.keys(allRouteMap).map((key) => {
|
||||
return {
|
||||
method: key,
|
||||
value: status
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onCheck: TreeProps['onCheck'] = (_, info): void | never[] => {
|
||||
const { node } = info
|
||||
if (!node.children) {
|
||||
const sendData = {
|
||||
appId: id,
|
||||
method: node.key as string,
|
||||
value: !node.checked
|
||||
}
|
||||
setOne(sendData)
|
||||
.then(() => {
|
||||
openSuccessMessage('Статус метода успешно изменен')
|
||||
})
|
||||
.catch(() => {
|
||||
openErrorMessage('Не удалось изменить статус метода')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const newCheckedKeys = node.children.map((child) => ({
|
||||
method: child.key as string,
|
||||
value: !node.checked
|
||||
}))
|
||||
setListMethods(newCheckedKeys)
|
||||
}
|
||||
|
||||
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const { value } = e.target
|
||||
setSearchValue(value.trim().toLowerCase(), setSearchParams, paramPrefix)
|
||||
}
|
||||
|
||||
const setListMethods = (methods: AccessListMethodType[]) => {
|
||||
setList({
|
||||
appId: id,
|
||||
methods: methods
|
||||
})
|
||||
.then(() => {
|
||||
openSuccessMessage('Статус методов успешно изменен')
|
||||
})
|
||||
.catch(() => {
|
||||
openErrorMessage('Не удалось изменить статус методов')
|
||||
})
|
||||
}
|
||||
|
||||
const setAllMethods = (status: boolean) => {
|
||||
const methods = createAllMethodList(status)
|
||||
setListMethods(methods)
|
||||
}
|
||||
|
||||
const getAllRoutes = () => {
|
||||
const missingRoute: EndpointType[] = []
|
||||
const copyAllRoutes = { ...moduleEndpoints }
|
||||
|
||||
methods.forEach((item) => {
|
||||
if (!allRouteMap[item.method]) {
|
||||
missingRoute.push({ path: item.method } as EndpointType)
|
||||
}
|
||||
})
|
||||
|
||||
if (missingRoute.length) {
|
||||
copyAllRoutes[unknownMethodKey] = missingRoute
|
||||
}
|
||||
return copyAllRoutes
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const allRoutes = getAllRoutes()
|
||||
setDefaultAllRoutes(allRoutes)
|
||||
}, [isSuccess])
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <Navigate to={routePaths.error} />
|
||||
}
|
||||
return (
|
||||
<div className="app-access-content">
|
||||
{contextHolder}
|
||||
<div className="app-access-content__header">
|
||||
<Input
|
||||
prefix={<SearchOutlined />}
|
||||
allowClear
|
||||
className="app-access-content__main__tree-search-input"
|
||||
value={searchValue}
|
||||
placeholder="Найти метод"
|
||||
onChange={onChange}
|
||||
/>
|
||||
<div className="app-access-content__header__action-buttons">
|
||||
<Button disabled={!canWrite}
|
||||
onClick={() => {
|
||||
setAllMethods(false)
|
||||
}}
|
||||
>
|
||||
Запретить все
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!canWrite}
|
||||
onClick={() => {
|
||||
setAllMethods(true)
|
||||
}}
|
||||
>
|
||||
Выбрать все
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="app-access-content__main">
|
||||
<AccessListTree
|
||||
searchValue={searchValue}
|
||||
onCheck={onCheck}
|
||||
defaultAllRoutes={defaultAllRoutes}
|
||||
methods={methods}
|
||||
/>
|
||||
<SelectedAccessMethod
|
||||
unknownMethodKey={unknownMethodKey}
|
||||
methods={methods}
|
||||
allRoutes={defaultAllRoutes}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AppAccessContent)
|
||||
@@ -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
|
||||
@@ -0,0 +1,5 @@
|
||||
.error-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const ErrorPage = () => {
|
||||
return (
|
||||
<section className="error-page">
|
||||
<p>Извините, ошибка</p>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default ErrorPage
|
||||
@@ -0,0 +1,35 @@
|
||||
const DefaultUser = () => {
|
||||
return (
|
||||
<span role="img" className="anticon ant-menu-item-icon">
|
||||
<svg
|
||||
data-icon="appstore"
|
||||
width="1.5em"
|
||||
height="1.5em"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||
>
|
||||
<rect width="24" height="24" fill="url(#pattern0)" />
|
||||
<defs>
|
||||
<pattern
|
||||
id="pattern0"
|
||||
patternContentUnits="objectBoundingBox"
|
||||
width="1"
|
||||
height="1"
|
||||
>
|
||||
<use xlinkHref="#image0_121_5920" transform="scale(0.0025)" />
|
||||
</pattern>
|
||||
<image
|
||||
id="image0_121_5920"
|
||||
width="400"
|
||||
height="400"
|
||||
xlinkHref="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAgAElEQVR4Ae29e9AcVbnvn7JqV/mP5w/PH5YQuQgYRcIlBaRAkmACKBQ3cQPyCwUGs1Pctv5gi8IBIWhSapAtAmfDO+/7GhRPwQbMBSFbSDCH24YYCJDpSZBggSGFsnETiVwUjM+pT/N26PS7Vt+mu2d19zNVUzPTM9O91tNrfb/rua4JE/ShEmiQBBa/IB8c3iQTf7xBpoz0ZNZIT04d9uSCoa7MH+7K9UM9ubXjyYqOJw91urKm05WnO55s6HTl+SFPNg958sqQJ1s7PXmr05V3/WdP3uLY2Heb+e3Yf572z8G5PFnBuf1rcC1PLuDatIG20Cba1iBRa1dUAioBlUC9JHDHS/LhMXI4dcSTi4Y3yI1jhAAJvDHUFXH5SRt98vFkBW2nDxANfaJv9bob2lqVgEpAJeCYBOaLfOAnG+UTACuaQ6crSzs9WT/kyTaXyaGQtnmyjb7SZ/qODJAFMnHsNmlzVAIqAZXAYCXAqts3NXlyUacnI8OerMV8VAgYO66NZOkjMhmTzciY1jJLNZbBjl29ukpAJVChBFhF+/4AfBI9ud33OTQI5LMQQmG/xW/Tk9vxuSBb1VQqHNB6KZWASqA8CYy+Kh8a7coxvgPbk1V18FEUBuwDIkZkPOzJKmSO7LkH5d1hPbNKQCWgEihIAkQZAVqdnlxDdFPdwbgp7fcjzXpyDfdGI8EKGux6GpWASqB/CdyySfbCfOJHQqnvwukIMAjRD08mAsyTC7h3/Y8APYNKQCWgEkgpAV/L6Mmx5Dt0PNnUlFV6W/vBPeRejvbkWNVOUk4C/ZlKQCWQXgIAy8gGORlnrfox3M4z6YcI/Xvbk9u510om6eeH/lIloBKISAAA6fTkRLKrW5F/MSCndz+AX+p/ybkha78nJyqZRCaHflQJqATGS2BI5B8wZYyRxtZSAUoB23l/yY77TxmXntz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6bwZF8hrx/zYgNx3H2V1EvsBlS16LvTYVZfNOFv1fMgBy7033l2OqASbLr45jzMcq3dnQHRZpwja0ADmbFNnAJHycmklFkEcw+eJ26SMMWFfC5QEZ0Vbhext+n7dwY3Bf9bW8+9avbMEsdxC0xS0Z6sr8fm+mK/8HqMnjMJUaR0NhBzwc4EW3FzNVXFFBdaiXC0Q27VPlXq7ci55HWc833JNLWwzdg+/68LNyZtabVpffo2GglfDElFG2LyIuIgwtpOzr1+W+lNFOm+ZJMmgZ19NzukNMYNjgkbSFLfCzzB0tUVLXCUrmetiEEn6vRRfLAx1bQunnLlmnBFJRZYBBzVlKnmi2esUENpbr4Xyi4KAGZd7roumESSP8/tCzH2osmKFdDXJ3Rzb+Css6eA+h572X+r/yCL9w2XqyVXNEKiIRP1zXkw2F38SGr3TSystWIZiwUsqdpz1PWb/DtEfoM6Y9dvkjDwZfAaXxWbEDugAy+TX4dYKdGglXJmmPkGl8DuS5mDLyOcb37B7I74MdHqkTRuQb5+X8BDJwPa6L3+rcoZf8UvBX3vMnX05ZTH62TcX6DdMu6x7oeYsnp44nGzS8twIS6XRlqQ7g4gdwIFMif4IVcPSVnIXgd2W9QlKQA4B82sKNPkgDpAC4zdkcbacLnyEifEcQDgQRFLskCCJKxBCRqc2YtsqSs563vDmUV7ZgWwUQ2t5LELWQ9+bo/9JNGEw5tjInRVaJJXwVMGLine truncated
|
||||
/>
|
||||
</defs>
|
||||
</svg>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default DefaultUser
|
||||
@@ -0,0 +1,215 @@
|
||||
import {
|
||||
LockOutlined,
|
||||
LogoutOutlined,
|
||||
ProfileOutlined
|
||||
} from '@ant-design/icons'
|
||||
import { ConfigProvider, Layout, Menu, Spin } from 'antd'
|
||||
import { useContext, useEffect, useState } from 'react'
|
||||
import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
|
||||
import DefaultUser from '@components/Icons/DefaultUser.tsx'
|
||||
import {
|
||||
MenuItemKeysType,
|
||||
MenuItemType,
|
||||
menuKeys
|
||||
} from '@components/Layout/layout.type.ts'
|
||||
|
||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { useAppDispatch, useAppSelector } from '@hooks/redux.ts'
|
||||
import useLogout from '@hooks/useLogout.tsx'
|
||||
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 { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
import './layout.scss'
|
||||
|
||||
const { Content, Sider } = Layout
|
||||
|
||||
const LayoutComponent = () => {
|
||||
const [collapsed, setCollapsed] = useState<boolean>(false)
|
||||
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeysType[]>(
|
||||
[]
|
||||
)
|
||||
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||
const dispatch = useAppDispatch()
|
||||
const {
|
||||
status,
|
||||
profile: { firstName }
|
||||
} = useAppSelector((state) => state.profileReducer)
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const { hasPermission } = useRole()
|
||||
const { theme } = useContext(ConfigProvider.ConfigContext)
|
||||
|
||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||
const { logoutUser } = useLogout()
|
||||
|
||||
const hideItem = (permission: PermissionKeysType | PermissionKeysType[]) => {
|
||||
if (Array.isArray(permission)) {
|
||||
const result = permission.reduce((acc, currentValue) => {
|
||||
const hasPermissionFunc = hasPermission(currentValue)
|
||||
return hasPermissionFunc || acc
|
||||
}, false)
|
||||
return result ? '' : 'hide-item'
|
||||
}
|
||||
return hasPermission(permission) ? '' : 'hide-item'
|
||||
}
|
||||
const menuItems: MenuItemType[] = [
|
||||
{
|
||||
label: firstName || '',
|
||||
key: 'userManagement',
|
||||
className: 'user-item',
|
||||
icon: <DefaultUser />,
|
||||
children: [
|
||||
{
|
||||
label: 'Профиль',
|
||||
key: 'profile',
|
||||
icon: <ProfileOutlined />
|
||||
},
|
||||
{
|
||||
label: 'Выход',
|
||||
key: 'logout',
|
||||
icon: <LogoutOutlined />
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Доступы приложений',
|
||||
key: 'appAccess',
|
||||
className: hideItem([PermissionKeysType.read]),
|
||||
icon: <LockOutlined />
|
||||
},
|
||||
{
|
||||
label: 'Пользователи и роли',
|
||||
key: 'sessionManagement',
|
||||
className: hideItem([PermissionKeysType.read]),
|
||||
icon: <ProfileOutlined />,
|
||||
children: [
|
||||
{
|
||||
label: 'Пользователи',
|
||||
key: 'users',
|
||||
className: hideItem(PermissionKeysType.read)
|
||||
},
|
||||
{
|
||||
label: 'Пользовательские сессии',
|
||||
key: 'sessions',
|
||||
className: hideItem(PermissionKeysType.read)
|
||||
},
|
||||
{
|
||||
label: 'Просмотр журналов ИБ',
|
||||
key: 'securityLog',
|
||||
className: hideItem(PermissionKeysType.read)
|
||||
},
|
||||
{
|
||||
label: 'Роли',
|
||||
key: 'roles',
|
||||
className: hideItem(PermissionKeysType.read)
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
useEffect(() => {
|
||||
ConfigProvider.config({
|
||||
holderRender: (children) => (
|
||||
<ConfigProvider prefixCls="static" theme={theme}>
|
||||
{children}
|
||||
</ConfigProvider>
|
||||
)
|
||||
})
|
||||
}, [theme])
|
||||
|
||||
useEffect(() => {
|
||||
if (userToken) {
|
||||
dispatch(fetchProfile())
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const menuKey = location.pathname.split('/')[1] as MenuItemKeysType
|
||||
|
||||
const menuItem = menuKeys[menuKey]
|
||||
|
||||
if (menuItem) {
|
||||
setSelectedMenuKeys([menuItem.key])
|
||||
setOpenKeys(menuItem.parent)
|
||||
}
|
||||
}, [location])
|
||||
|
||||
const handlerOnClickMenu = ({ key }: any): void => {
|
||||
switch (key) {
|
||||
case MenuItemKeysType.logout: {
|
||||
logoutUser()
|
||||
break
|
||||
}
|
||||
case MenuItemKeysType.profile: {
|
||||
navigate(routePaths.profile)
|
||||
break
|
||||
}
|
||||
case MenuItemKeysType.users:
|
||||
navigate(routePaths.users)
|
||||
break
|
||||
case MenuItemKeysType.sessions:
|
||||
navigate(routePaths.sessions)
|
||||
break
|
||||
case MenuItemKeysType.securityLog:
|
||||
navigate(routePaths.securityLog)
|
||||
break
|
||||
case MenuItemKeysType.appAccess:
|
||||
navigate(routePaths.appAccess)
|
||||
break
|
||||
case MenuItemKeysType.roles:
|
||||
navigate(routePaths.roles)
|
||||
break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
if (status === StateProfileStatus.rejected) {
|
||||
return <Navigate to={routePaths.error} replace />
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout className="layout" data-cy="homePage">
|
||||
{status === StateProfileStatus.pending ? (
|
||||
<Spin size="large" />
|
||||
) : (
|
||||
<>
|
||||
<Sider
|
||||
width="250px"
|
||||
data-cy="aside"
|
||||
theme="light"
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
onCollapse={(value) => setCollapsed(value)}
|
||||
>
|
||||
<Menu
|
||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||
openKeys={openKeys}
|
||||
selectedKeys={selectedMenuKeys}
|
||||
onClick={handlerOnClickMenu}
|
||||
theme="light"
|
||||
mode="inline"
|
||||
items={menuItems}
|
||||
/>
|
||||
</Sider>
|
||||
<Layout className="site-layout">
|
||||
<Content className="site-layout__content">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</>
|
||||
)}
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export default LayoutComponent
|
||||
@@ -0,0 +1,95 @@
|
||||
@import 'src/constants/style/styleConst';
|
||||
|
||||
.layout {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu {
|
||||
border-inline-end: none !important;
|
||||
}
|
||||
|
||||
.ant-menu-title-content {
|
||||
color: #1B1B1B;
|
||||
padding-left: 10px
|
||||
}
|
||||
}
|
||||
|
||||
.user-item {
|
||||
padding: $basic-padding 0 $basic-padding * 3;
|
||||
|
||||
& .ant-menu-submenu-arrow {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
border-bottom: 1px solid lightgray;
|
||||
border-radius: 0 !important;
|
||||
|
||||
& .ant-menu-submenu-title {
|
||||
padding-left: 21px !important;
|
||||
}
|
||||
|
||||
& .ant-menu-title-content {
|
||||
margin: 0 !important;
|
||||
padding-left: 17px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-menu-inline-collapsed {
|
||||
& .user-item {
|
||||
& .ant-menu-submenu-title {
|
||||
padding-left: 24px !important;
|
||||
padding-top: 5px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { MenuProps } from 'antd'
|
||||
|
||||
export enum MenuItemKeysType {
|
||||
users = 'users',
|
||||
sessions = 'sessions',
|
||||
securityLog = 'securityLog',
|
||||
appAccess = 'appAccess',
|
||||
roles = 'roles',
|
||||
logout = 'logout',
|
||||
profile = 'profile'
|
||||
}
|
||||
|
||||
interface MenuItem {
|
||||
key: MenuItemKeysType
|
||||
parent: string[]
|
||||
}
|
||||
export const menuKeys: Record<MenuItemKeysType, MenuItem> = {
|
||||
[MenuItemKeysType.users]: {
|
||||
key: MenuItemKeysType.users,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeysType.sessions]: {
|
||||
key: MenuItemKeysType.sessions,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeysType.securityLog]: {
|
||||
key: MenuItemKeysType.securityLog,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeysType.appAccess]: {
|
||||
key: MenuItemKeysType.appAccess,
|
||||
parent: []
|
||||
},
|
||||
[MenuItemKeysType.roles]: {
|
||||
key: MenuItemKeysType.roles,
|
||||
parent: ['sessionManagement']
|
||||
},
|
||||
[MenuItemKeysType.logout]: {
|
||||
key: MenuItemKeysType.logout,
|
||||
parent: ['']
|
||||
},
|
||||
[MenuItemKeysType.profile]: {
|
||||
key: MenuItemKeysType.profile,
|
||||
parent: ['']
|
||||
}
|
||||
}
|
||||
|
||||
export type MenuItemType = Required<MenuProps>['items'][number]
|
||||
@@ -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[]
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import { Divider, Table, message } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { FormComponents } from 'isp-ui-kit'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Controller, useForm } from 'react-hook-form'
|
||||
import { useParams } from 'react-router-dom'
|
||||
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
|
||||
import SaveButton from '@ui/SaveButton'
|
||||
|
||||
import AgreementModal from '@widgets/AgreementModal'
|
||||
|
||||
import { RolesContentPropsType } from '@components/RolesContent/roles-content.type.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import { PermissionKeysType, RoleType } from '@type/roles.type.ts'
|
||||
|
||||
import './roles-content.scss'
|
||||
|
||||
const newRole: Partial<RoleType> = {
|
||||
externalGroup: '',
|
||||
name: '',
|
||||
permissions: []
|
||||
}
|
||||
|
||||
const columns: ColumnsType = [
|
||||
{
|
||||
title: 'Действие',
|
||||
dataIndex: 'name'
|
||||
},
|
||||
{
|
||||
title: 'Ключ в системе',
|
||||
dataIndex: 'key'
|
||||
}
|
||||
]
|
||||
const { FormInput } = FormComponents
|
||||
const RolesContent = ({
|
||||
role,
|
||||
permissions,
|
||||
saveRole,
|
||||
title = 'Редактировать',
|
||||
immutable = false
|
||||
}: RolesContentPropsType) => {
|
||||
const {
|
||||
control,
|
||||
formState: { isDirty },
|
||||
getValues,
|
||||
reset
|
||||
} = useForm<RoleType>({
|
||||
defaultValues: role,
|
||||
mode: 'onChange'
|
||||
})
|
||||
const { hasPermission } = useRole()
|
||||
const { id: selectedItemId } = useParams()
|
||||
|
||||
const [openModal, setOpenModal] = useState<boolean>(false)
|
||||
const isUpdateRole = hasPermission(PermissionKeysType.write)
|
||||
const isCreateRole = hasPermission(PermissionKeysType.write)
|
||||
|
||||
const isSaveBtnAvailable =
|
||||
selectedItemId === 'new' ? isCreateRole : isUpdateRole
|
||||
|
||||
const isExternalGroup = hasPermission(PermissionKeysType.write)
|
||||
|
||||
useEffect(() => {
|
||||
if (!role) {
|
||||
reset(newRole)
|
||||
} else {
|
||||
reset(role)
|
||||
}
|
||||
}, [role])
|
||||
|
||||
const handleSubmitForm = (changeMessage: string) => {
|
||||
if (!changeMessage) {
|
||||
message.error('Поле не может быть пустым')
|
||||
return
|
||||
}
|
||||
const formValue = getValues()
|
||||
formValue.changeMessage = changeMessage
|
||||
saveRole(formValue)
|
||||
setOpenModal(false)
|
||||
}
|
||||
|
||||
const renderFormTable = () => (
|
||||
<Controller
|
||||
control={control}
|
||||
name="permissions"
|
||||
render={({ field: { value, onChange } }) => (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={permissions}
|
||||
pagination={{ pageSize: 10 }}
|
||||
scroll={{
|
||||
y: 'calc(100vh - 450px)',
|
||||
}}
|
||||
rowSelection={{
|
||||
selectedRowKeys: value,
|
||||
type: 'checkbox',
|
||||
onChange: (selectedRowKeys) => {
|
||||
onChange(selectedRowKeys)
|
||||
},
|
||||
getCheckboxProps: () => ({
|
||||
disabled: immutable
|
||||
})
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
{openModal && (
|
||||
<AgreementModal
|
||||
open
|
||||
destroyOnClose
|
||||
onCancel={() => setOpenModal(false)}
|
||||
okText="Сохранить"
|
||||
title="Для подтверждения изменений укажите причину"
|
||||
description="Основание для измений"
|
||||
onConfirm={handleSubmitForm}
|
||||
/>
|
||||
)}
|
||||
<form className="roles-content">
|
||||
<div className="roles-content__header">
|
||||
<h2
|
||||
data-cy="roles-content__header__title"
|
||||
className="roles-content__header__title"
|
||||
>
|
||||
{title}
|
||||
</h2>
|
||||
<SaveButton
|
||||
disabled={!isDirty || !isSaveBtnAvailable}
|
||||
type="primary"
|
||||
data-cy="roles-content__header__save-button"
|
||||
onClick={() => setOpenModal(true)}
|
||||
className="roles-content__header__save-button"
|
||||
/>
|
||||
</div>
|
||||
<Divider />
|
||||
<FormInput
|
||||
data-cy="roles-content__input__name"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
label="Наименование роли"
|
||||
name="name"
|
||||
control={control}
|
||||
/>
|
||||
<FormInput
|
||||
data-cy="roles-content__input__external-group"
|
||||
disabled={!isExternalGroup}
|
||||
label="Группы ЕСК"
|
||||
name="externalGroup"
|
||||
control={control}
|
||||
/>
|
||||
{renderFormTable()}
|
||||
</form>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default RolesContent
|
||||
@@ -0,0 +1,11 @@
|
||||
@import "../../constants/style/styleConst";
|
||||
|
||||
.roles-content {
|
||||
padding: $basic-padding*3;
|
||||
min-width: 400px;
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NewRoleType, PermissionType, RoleType } from '@type/roles.type.ts'
|
||||
|
||||
export interface RolesContentPropsType {
|
||||
role?: Partial<RoleType>
|
||||
title?: string
|
||||
immutable?: boolean
|
||||
permissions: PermissionType[]
|
||||
saveRole: (formValue: RoleType | NewRoleType) => void
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
*, html {
|
||||
margin:0;
|
||||
padding:0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.app{
|
||||
overflow: hidden;
|
||||
height: 100vh;
|
||||
padding: 0 $basic-padding;
|
||||
min-height: 0;
|
||||
min-width: 500px;
|
||||
}
|
||||
|
||||
.wrap {
|
||||
padding: 2 * $basic-padding;
|
||||
border: 1px solid #F0F0F0;
|
||||
}
|
||||
Reference in new issue
Block a user