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,15 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.app-access-page {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
|
||||
.ant-tree {
|
||||
background: none;
|
||||
}
|
||||
|
||||
&__content-wrap{
|
||||
width: 100%;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,111 @@
|
||||
import { Spin } from 'antd'
|
||||
import { Layout } from 'isp-ui-kit'
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
import { memo, useEffect } from 'react'
|
||||
import {
|
||||
createSearchParams,
|
||||
Navigate,
|
||||
useNavigate,
|
||||
useParams,
|
||||
useSearchParams
|
||||
} from 'react-router-dom'
|
||||
|
||||
import ListItem from '@widgets/ListItem'
|
||||
|
||||
import AppAccessContent from '@components/AppAccessContent'
|
||||
|
||||
import { setSearchValue, setSelectedItemId } from '@utils/columnLayoutUtils.ts'
|
||||
import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import appApi from '@services/appService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { SystemTreeAppType } from '@type/app.type.ts'
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
import './app-access-page.scss'
|
||||
|
||||
|
||||
const { Column, EmptyData } = Layout
|
||||
|
||||
const firstColumnSearchParam = 'search'
|
||||
const findMethodParam = 'method'
|
||||
|
||||
const AppAccessPage = () => {
|
||||
const {
|
||||
data = { originalResponse: [], appList: [] },
|
||||
isLoading,
|
||||
isError
|
||||
} = appApi.useGetSystemTreeQuery()
|
||||
|
||||
const { appList } = data
|
||||
const navigate = useNavigate()
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const { id: selectedItemId = '' } = useParams()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const searchValue = searchParams.get(firstColumnSearchParam) || ''
|
||||
const canRead = hasPermission(PermissionKeysType.read)
|
||||
|
||||
useEffect(() => {
|
||||
if (!canRead) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [canRead])
|
||||
|
||||
const handleOnChangeSearchValue = (value: string): void => {
|
||||
setSearchValue(value, setSearchParams)
|
||||
}
|
||||
|
||||
const onSelectedItemId = (id: string): void => {
|
||||
setSearchValue('', setSearchParams, findMethodParam)
|
||||
setSelectedItemId(
|
||||
routePaths.appAccess,
|
||||
id,
|
||||
createSearchParams(searchParams).toString(),
|
||||
navigate
|
||||
)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <Navigate to={routePaths.error} />
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="app-access-page">
|
||||
<Column
|
||||
showAddBtn={false}
|
||||
showRemoveBtn={false}
|
||||
items={filterFirstColumnItems(
|
||||
appList as ColumnItem<SystemTreeAppType>,
|
||||
searchValue
|
||||
)}
|
||||
renderItems={(item) => <ListItem item={item} />}
|
||||
searchValue={searchValue}
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={onSelectedItemId}
|
||||
onChangeSearchValue={handleOnChangeSearchValue}
|
||||
/>
|
||||
<div className="app-access-page__content-wrap">
|
||||
{selectedItemId ? (
|
||||
<AppAccessContent
|
||||
paramPrefix={findMethodParam}
|
||||
key={`content-${selectedItemId}`}
|
||||
id={Number(selectedItemId)}
|
||||
/>
|
||||
) : (
|
||||
<EmptyData />
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AppAccessPage)
|
||||
@@ -0,0 +1,13 @@
|
||||
.home-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
background-image: url("/src/assets/images/home-background.png");
|
||||
font-size: calc(1.5vw + 1.5vh);
|
||||
font-family: 'Roboto',sans-serif;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
line-height: 56px;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import './home-page.scss'
|
||||
|
||||
const HomePage = () => {
|
||||
return <div className="home-page">Добро пожаловать!</div>
|
||||
}
|
||||
|
||||
export default HomePage
|
||||
@@ -0,0 +1,120 @@
|
||||
import { LockOutlined, UserOutlined } from '@ant-design/icons'
|
||||
import { Button, Divider } from 'antd'
|
||||
import { AxiosError } from 'axios'
|
||||
import { FormComponents, useAuth } from 'isp-ui-kit'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
import { messages } from '@constants/messages.ts'
|
||||
|
||||
import { getConfigProperty } from '@utils/configUtils.ts'
|
||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { MSPError } from '@type/index.ts'
|
||||
import { LoginRequest } from '@type/login.type.ts'
|
||||
|
||||
import './login-page.scss'
|
||||
|
||||
const passwordLoginEnabled = getConfigProperty('ENABLE_PASSWORD_LOGIN', true)
|
||||
|
||||
const LoginPage = () => {
|
||||
const { login, isLoading } = useAuth()
|
||||
const { handleSubmit, control, setError } = useForm<LoginRequest>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
const navigate = useNavigate()
|
||||
|
||||
const setFormError = (statusText: string, message: string): void => {
|
||||
setError('email', {})
|
||||
setError('password', {
|
||||
message,
|
||||
type: statusText
|
||||
})
|
||||
}
|
||||
|
||||
const handleError = (err: AxiosError<MSPError>): void => {
|
||||
const { response } = err
|
||||
if (response && response.status === 401) {
|
||||
setFormError(response.statusText, messages.loginError)
|
||||
} else {
|
||||
setFormError('serverError', messages.serverError)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmitForm = (data: LoginRequest): void => {
|
||||
login(apiPaths.login, data, {
|
||||
'X-APPLICATION-TOKEN': getConfigProperty(
|
||||
'APP_TOKEN',
|
||||
import.meta.env.VITE_APP_TOKEN
|
||||
)
|
||||
})
|
||||
.then((response) => {
|
||||
LocalStorage.set(localStorageKeys.HEADER_NAME, response.headerName)
|
||||
LocalStorage.set(localStorageKeys.USER_TOKEN, response.token)
|
||||
const redirectUrl =
|
||||
localStorage.getItem('redirectUrl') || routePaths.home
|
||||
navigate(redirectUrl, { replace: true })
|
||||
localStorage.removeItem('redirectUrl')
|
||||
})
|
||||
.catch((err: any) => handleError(err))
|
||||
}
|
||||
|
||||
const renderInternalAuthForm = () => {
|
||||
if (!passwordLoginEnabled) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<FormComponents.FormInput
|
||||
data-cy="email-input"
|
||||
control={control}
|
||||
name="email"
|
||||
className="login-page__content__email-field"
|
||||
prefix={<UserOutlined className="color" />}
|
||||
placeholder="Логин"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormComponents.FormInput
|
||||
data-cy="password-input"
|
||||
control={control}
|
||||
name="password"
|
||||
className="login-page__content__password-field"
|
||||
prefix={<LockOutlined className="color" />}
|
||||
type="password"
|
||||
placeholder="Пароль"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<Button
|
||||
data-cy="submit-btn"
|
||||
disabled={isLoading}
|
||||
loading={isLoading}
|
||||
type="primary"
|
||||
className="login-page__content__submit-btn"
|
||||
onClick={handleSubmit(handleSubmitForm)}
|
||||
>
|
||||
Войти
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="login-page">
|
||||
<form className="login-page__content">
|
||||
<h1 data-cy="login-title" className="login-page__content__title">
|
||||
Вход в систему
|
||||
</h1>
|
||||
<Divider />
|
||||
{renderInternalAuthForm()}
|
||||
</form>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
@@ -0,0 +1,53 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.login-page {
|
||||
height: 100vh;
|
||||
background: $background-color;
|
||||
|
||||
display: flex;
|
||||
|
||||
.ant-input {
|
||||
width: 300px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ant-divider-horizontal {
|
||||
margin-top: $basic-margin !important;
|
||||
}
|
||||
|
||||
.ant-form-item-explain-error {
|
||||
margin-bottom: $basic-margin;
|
||||
}
|
||||
|
||||
.color {
|
||||
color: $text-color-gray;
|
||||
}
|
||||
|
||||
&__content {
|
||||
max-width: 360px;
|
||||
margin: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&__title {
|
||||
text-align: center;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: $text-size;
|
||||
line-height: 20px;
|
||||
color: $text-color-gray;
|
||||
}
|
||||
|
||||
&__submit-sudir-btn {
|
||||
background: #0000000f;
|
||||
margin-top: 4 * $basic-margin;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.09) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.requiredInput::after {
|
||||
content: "";
|
||||
}
|
||||
}
|
||||
@@ -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 wrap">
|
||||
<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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts'
|
||||
|
||||
export type ProfileDataType = {
|
||||
email: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
role: string
|
||||
roles: number[]
|
||||
permissions: string[]
|
||||
idleTimeoutMs: number
|
||||
}
|
||||
|
||||
export type ProfileType = {
|
||||
profile: ProfileDataType
|
||||
status: StateProfileStatus
|
||||
error: string
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import { List, Spin, message } from 'antd'
|
||||
import { Layout } from 'isp-ui-kit'
|
||||
import { useEffect } from 'react'
|
||||
import {
|
||||
createSearchParams,
|
||||
useLocation,
|
||||
useNavigate,
|
||||
useParams,
|
||||
useSearchParams
|
||||
} from 'react-router-dom'
|
||||
|
||||
import RolesContent from '@components/RolesContent'
|
||||
|
||||
import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { NewRoleType, PermissionKeysType, RoleType } from '@type/roles.type.ts'
|
||||
|
||||
import './roles-page.scss'
|
||||
|
||||
const { Column, EmptyData, NoData } = Layout
|
||||
|
||||
const RolesPage = () => {
|
||||
const { id: selectedItemId = '' } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const fromApp = location.state?.fromApp || false
|
||||
const { role, hasPermission } = useRole()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const searchValue = searchParams.get('search') || ''
|
||||
const { data: permissionList = [], isLoading: isPermissionLoading } =
|
||||
userServiceApi.useGetAllPermissionsQuery()
|
||||
const { data = [], isLoading: isRolesLoading } = roleApi.useGetAllRolesQuery()
|
||||
const [createRole] = roleApi.useCreateRoleMutation()
|
||||
const [updateRole] = roleApi.useUpdateRoleMutation()
|
||||
const [removeRole] = roleApi.useRemoveRoleMutation()
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
const isAddRolePermissions = hasPermission(PermissionKeysType.write)
|
||||
const isRemoveRolePermissions = hasPermission(PermissionKeysType.write)
|
||||
const isLoading = isPermissionLoading || isRolesLoading
|
||||
|
||||
const isNew = selectedItemId === 'new'
|
||||
|
||||
useEffect(() => {
|
||||
if (!fromApp) {
|
||||
navigate(routePaths.roles)
|
||||
}
|
||||
}, [fromApp])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [isPageAvailable])
|
||||
|
||||
useEffect(() => {
|
||||
if (!role) {
|
||||
navigate(routePaths.error)
|
||||
}
|
||||
}, [role])
|
||||
|
||||
const setSelectedItemId = (id: string): void => {
|
||||
navigate(
|
||||
{
|
||||
pathname: `${routePaths.roles}/${id}`,
|
||||
search: createSearchParams(searchParams).toString()
|
||||
},
|
||||
{ replace: true, state: { fromApp: true } }
|
||||
)
|
||||
}
|
||||
|
||||
const handleOnChangeSearchValue = (value: string): void => {
|
||||
setSearchParams((prev) => {
|
||||
if (!value) {
|
||||
prev.delete('search')
|
||||
} else {
|
||||
prev.set('search', value)
|
||||
}
|
||||
return prev
|
||||
})
|
||||
}
|
||||
|
||||
const handeOnAddItem = () => setSelectedItemId('new')
|
||||
|
||||
const handleUpdateRole = (formValue: RoleType | NewRoleType) => {
|
||||
updateRole(formValue as RoleType)
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
message.success('Элемент успешно добавлен').then()
|
||||
})
|
||||
.catch(() => message.error('Не удалось сохранить роль'))
|
||||
}
|
||||
|
||||
const handleCreateRole = (formValue: NewRoleType) => {
|
||||
createRole(formValue)
|
||||
.unwrap()
|
||||
.then((res) => {
|
||||
message.success('Элемент успешно добавлен').then()
|
||||
setSelectedItemId(res.id.toString())
|
||||
})
|
||||
.catch(() => {
|
||||
message.error('Не удалось добавить роль').then()
|
||||
setSelectedItemId('')
|
||||
})
|
||||
}
|
||||
|
||||
const handleRemoveRole = (id: any) => {
|
||||
const idAsNumber = parseInt(id, 10)
|
||||
removeRole(idAsNumber)
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
message.success('Элемент успешно удален').then()
|
||||
setSelectedItemId('')
|
||||
})
|
||||
.catch(() => message.error('Не удалось удалить роль'))
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin />
|
||||
}
|
||||
|
||||
const currentRole = data
|
||||
? data.find((item) => item.id.toString() === selectedItemId)
|
||||
: null
|
||||
const renderItems = (item: RoleType) => (
|
||||
<List.Item data-cy="role-item">
|
||||
<div className="role-item">
|
||||
<span className="role-item__name">{item.name}</span>
|
||||
<span className="role-item__id">id: {item.id}</span>
|
||||
</div>
|
||||
</List.Item>
|
||||
)
|
||||
|
||||
const renderMainContent = () => {
|
||||
if (isNew) {
|
||||
return (
|
||||
<RolesContent
|
||||
saveRole={handleCreateRole}
|
||||
permissions={permissionList}
|
||||
title="Добавить"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (!selectedItemId) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
if (!currentRole) {
|
||||
return <NoData />
|
||||
}
|
||||
|
||||
return (
|
||||
<RolesContent
|
||||
immutable={currentRole.immutable}
|
||||
saveRole={handleUpdateRole}
|
||||
permissions={permissionList}
|
||||
role={currentRole}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="roles-page three-columns">
|
||||
<Column
|
||||
items={filterFirstColumnItems(data, searchValue)}
|
||||
showAddBtn={isAddRolePermissions}
|
||||
showRemoveBtn={isRemoveRolePermissions}
|
||||
onAddItem={handeOnAddItem}
|
||||
onRemoveItem={handleRemoveRole}
|
||||
onChangeSearchValue={handleOnChangeSearchValue}
|
||||
renderItems={renderItems}
|
||||
searchValue={searchValue}
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={setSelectedItemId}
|
||||
/>
|
||||
<div className="roles-page__content">{renderMainContent()}</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default RolesPage
|
||||
@@ -0,0 +1,81 @@
|
||||
@import "../../constants/style/styleConst";
|
||||
|
||||
.roles-page {
|
||||
height: 100%;
|
||||
|
||||
.role-item {
|
||||
&__id {
|
||||
color: $grey;
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
overflow-x: scroll;
|
||||
width: 100%
|
||||
}
|
||||
}
|
||||
|
||||
.three-columns {
|
||||
display: flex;
|
||||
background: #fff;
|
||||
box-shadow: inset -1px 0px 0px $border-color;
|
||||
|
||||
height: 100%;
|
||||
|
||||
.column__header {
|
||||
padding: $basic-padding * 2 $basic-padding;
|
||||
|
||||
svg {
|
||||
fill: $blue-color;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper {
|
||||
.ant-input-prefix {
|
||||
margin-left: auto;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
z-index: 10;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper-focused {
|
||||
.ant-input-prefix {
|
||||
.anticon-search {
|
||||
svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list-items {
|
||||
.column__items__item {
|
||||
.ant-list-item-meta-title {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
font-weight: 400;
|
||||
color: $text-color-gray;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: $blue-light !important;
|
||||
|
||||
.ant-list-item-meta-title {
|
||||
color: $text-color-blue;
|
||||
}
|
||||
|
||||
svg {
|
||||
path {
|
||||
fill: $text-color-blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Pagination, Spin, Table } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { getUserFullName } from '@utils/userUtils/getFullNameUtil'
|
||||
|
||||
import useRole from '@hooks/useRole'
|
||||
|
||||
import securityLogServiceApi from '@services/securityLogService'
|
||||
import userServiceApi from '@services/userService'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { LogType } from '@type/log.type'
|
||||
import { PermissionKeysType } from '@type/roles.type'
|
||||
|
||||
import './security-log-page.scss'
|
||||
|
||||
const limit = 10
|
||||
|
||||
const SecurityLogPage = () => {
|
||||
const [getAllLogs, { data, isLoading: isLoadingLogs }] =
|
||||
securityLogServiceApi.useGetAllLogsMutation()
|
||||
|
||||
const { data: allUsers = [], isLoading: isUsersLoading } =
|
||||
userServiceApi.useGetAllUsersQuery()
|
||||
const { role, hasPermission } = useRole()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
|
||||
const isLoading = isUsersLoading || isLoadingLogs
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
|
||||
useEffect(() => {
|
||||
getAllLogs({ limit, offset: 0 })
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [isPageAvailable])
|
||||
|
||||
useEffect(() => {
|
||||
if (!role) {
|
||||
navigate(routePaths.error)
|
||||
}
|
||||
}, [role])
|
||||
|
||||
const handleChangePagination = (page: number) => {
|
||||
setCurrentPage(page)
|
||||
getAllLogs({ limit, offset: (page - 1) * limit })
|
||||
}
|
||||
|
||||
if (isLoading || !data) {
|
||||
return <Spin />
|
||||
}
|
||||
|
||||
const columns: ColumnsType<LogType> = [
|
||||
{
|
||||
title: 'Пользователь',
|
||||
dataIndex: 'userId',
|
||||
key: 'userId',
|
||||
render: (value) => {
|
||||
const user = allUsers.find((el) => el.id === value)
|
||||
if (user) {
|
||||
return getUserFullName(user)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Время события',
|
||||
dataIndex: 'createdAt',
|
||||
key: 'createdAt',
|
||||
render: (value) => {
|
||||
const date = new Date(value)
|
||||
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Действие',
|
||||
dataIndex: 'message',
|
||||
key: 'message',
|
||||
render: (value: string) =>
|
||||
value.split('\n').map((line) => <p key={line}>{line}</p>)
|
||||
}
|
||||
]
|
||||
|
||||
const { totalCount, items } = data
|
||||
|
||||
return (
|
||||
<section className="security-log-page">
|
||||
<header className="security-log-page__header">
|
||||
<span
|
||||
data-cy="security-log-page__header__title"
|
||||
className="security-log-page__header__title"
|
||||
>
|
||||
Просмотр журналов ИБ
|
||||
</span>
|
||||
</header>
|
||||
<section className="security-log-page__content">
|
||||
<div className="security-log-page__content__wrap-table">
|
||||
<Table
|
||||
rowKey={(record) => record.id}
|
||||
pagination={false}
|
||||
dataSource={items}
|
||||
columns={columns}
|
||||
/>
|
||||
</div>
|
||||
<div className="security-log-page__content__pagination">
|
||||
<Pagination
|
||||
showSizeChanger={false}
|
||||
current={currentPage}
|
||||
total={totalCount}
|
||||
pageSize={limit}
|
||||
onChange={handleChangePagination}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default SecurityLogPage
|
||||
@@ -0,0 +1,36 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.security-log-page {
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
&__header {
|
||||
border-bottom: 1px solid $border-color;
|
||||
padding: 0 3 * $basic-padding;
|
||||
|
||||
&__title {
|
||||
padding: 3 * $basic-padding 0;
|
||||
display: inline-block;
|
||||
font-weight: 500;
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
padding: 2 * $basic-padding 3 * $basic-padding;
|
||||
|
||||
&__wrap-table {
|
||||
overflow-x: scroll;
|
||||
height: calc(100vh - 200px);
|
||||
}
|
||||
|
||||
&__pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
import { LogoutOutlined } from '@ant-design/icons'
|
||||
import { Button, Popconfirm, Spin, Table, message, Pagination } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { SessionStatusKeysType, sessionStatuses } from '@constants/statuses'
|
||||
|
||||
import { getUserFullName } from '@utils/userUtils/getFullNameUtil'
|
||||
|
||||
import useRole from '@hooks/useRole'
|
||||
|
||||
import sessionServiceApi from '@services/sessionService'
|
||||
import userServiceApi from '@services/userService'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
import { SessionType } from '@type/session.type'
|
||||
|
||||
import './sessions-page.scss'
|
||||
|
||||
const limit = 10
|
||||
|
||||
const SessionsPage = () => {
|
||||
const [offset, setOffset] = useState<number>(0)
|
||||
const { data, isLoading: isLoadingSession } =
|
||||
sessionServiceApi.useGetAllSessionsQuery({ limit, offset })
|
||||
const [revokeSession] = sessionServiceApi.useRevokeSessionMutation()
|
||||
const { data: allUsers = [], isLoading: isUsersLoading } =
|
||||
userServiceApi.useGetAllUsersQuery()
|
||||
const { role, hasPermission } = useRole()
|
||||
const navigate = useNavigate()
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
|
||||
const isLoading = isUsersLoading || isLoadingSession
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
const hasRevokePermission = hasPermission(PermissionKeysType.write)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [isPageAvailable])
|
||||
|
||||
useEffect(() => {
|
||||
if (!role) {
|
||||
navigate(routePaths.error)
|
||||
}
|
||||
}, [role])
|
||||
|
||||
const handleChangePagination = (page: number) => {
|
||||
setCurrentPage(page)
|
||||
const currentOffset = (page - 1) * limit
|
||||
setOffset(currentOffset)
|
||||
}
|
||||
|
||||
const handleRevokeSessions = (id: number) => {
|
||||
revokeSession(id)
|
||||
.unwrap()
|
||||
.then(() => message.success('Сессия успешно завершена'))
|
||||
.catch(() => message.info('Не удалось завершить сессию'))
|
||||
}
|
||||
|
||||
if (isLoading || !data) {
|
||||
return <Spin />
|
||||
}
|
||||
|
||||
const columns: ColumnsType<SessionType> = [
|
||||
{
|
||||
title: 'Пользователь',
|
||||
dataIndex: 'userId',
|
||||
key: 'userId',
|
||||
render: (value) => {
|
||||
const user = allUsers.find((el) => el.id === value)
|
||||
return user && getUserFullName(user)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Идентификатор',
|
||||
dataIndex: 'id',
|
||||
key: 'id'
|
||||
},
|
||||
{
|
||||
title: 'Дата начала сессии',
|
||||
dataIndex: 'createdAt',
|
||||
key: 'createdAt',
|
||||
render: (value) => {
|
||||
const date = new Date(value)
|
||||
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Дата окончания сессии',
|
||||
dataIndex: 'expiredAt',
|
||||
key: 'expiredAt',
|
||||
render: (value) => {
|
||||
const date = new Date(value)
|
||||
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Статус',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
render: (value: SessionStatusKeysType) => sessionStatuses[value]
|
||||
},
|
||||
{
|
||||
dataIndex: 'actions',
|
||||
key: 'actions',
|
||||
render: (_, record) => {
|
||||
if (record.status !== SessionStatusKeysType.allowed) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{hasRevokePermission && (
|
||||
<Popconfirm
|
||||
title="Закончить эту сессию?"
|
||||
onConfirm={() => handleRevokeSessions(record.id)}
|
||||
>
|
||||
<Button
|
||||
data-cy="sessions-page__content__table__logout-btn"
|
||||
type="primary"
|
||||
className="sessions-page__content__table__logout-btn"
|
||||
icon={<LogoutOutlined />}
|
||||
/>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const { totalCount, items } = data
|
||||
return (
|
||||
<section className="sessions-page">
|
||||
<header className="sessions-page__header">
|
||||
<span
|
||||
data-cy="sessions-page__header__title"
|
||||
className="sessions-page__header__title"
|
||||
>
|
||||
Пользовательские сессии
|
||||
</span>
|
||||
</header>
|
||||
<section className="sessions-page__content">
|
||||
<div className="sessions-page__content__wrap-table">
|
||||
<Table
|
||||
className="sessions-page__content__table"
|
||||
rowKey={(record) => record.id}
|
||||
pagination={false}
|
||||
dataSource={items}
|
||||
columns={columns}
|
||||
/>
|
||||
</div>
|
||||
<div className="sessions-page__content__pagination">
|
||||
<Pagination
|
||||
showSizeChanger={false}
|
||||
current={currentPage}
|
||||
total={totalCount}
|
||||
pageSize={limit}
|
||||
onChange={handleChangePagination}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default SessionsPage
|
||||
@@ -0,0 +1,42 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.sessions-page {
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
&__header {
|
||||
border-bottom: 1px solid $border-color;
|
||||
padding: 0 3 * $basic-padding;
|
||||
|
||||
&__title {
|
||||
padding: 3 * $basic-padding 0;
|
||||
display: inline-block;
|
||||
font-weight: 500;
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
padding: 2 * $basic-padding 3 * $basic-padding;
|
||||
|
||||
&__wrap-table {
|
||||
overflow-x: scroll;
|
||||
height: calc(100vh - 200px);
|
||||
}
|
||||
|
||||
&__table {
|
||||
&__logout-btn {
|
||||
color: $blue-color;
|
||||
background: $blue-light;
|
||||
}
|
||||
}
|
||||
|
||||
&__pagination {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons'
|
||||
import { Button, message, Spin } from 'antd'
|
||||
import { FormComponents } from 'isp-ui-kit'
|
||||
import { useEffect } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
|
||||
import { findExclusiveRole } from '@utils/roleUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { PermissionKeysType, RoleType } from '@type/roles.type.ts'
|
||||
import { UserType } from '@type/user.type.ts'
|
||||
|
||||
import { LabelItem } from 'isp-ui-kit/dist/FormComponents/formTypes'
|
||||
|
||||
import './user-editor.scss'
|
||||
|
||||
const UserEditor = () => {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const state = location.state as UserType
|
||||
const isNew = location.pathname.includes('new')
|
||||
const fromApp = location.state?.fromApp || false
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const hasCreateUserPermission = hasPermission(PermissionKeysType.write)
|
||||
const hasUpdateUserPermission = hasPermission(PermissionKeysType.write)
|
||||
|
||||
const [createUser] = userServiceApi.useCreateUserMutation()
|
||||
const { data: roles = [], isLoading } = roleApi.useGetAllRolesQuery()
|
||||
|
||||
const [updateUser] = userServiceApi.useUpdateUserMutation()
|
||||
|
||||
const isSaveBtnAvailable = isNew
|
||||
? hasCreateUserPermission
|
||||
: hasUpdateUserPermission
|
||||
|
||||
const {
|
||||
control,
|
||||
formState: { isDirty },
|
||||
getValues,
|
||||
setValue,
|
||||
watch,
|
||||
reset
|
||||
} = useForm<UserType>({
|
||||
defaultValues: isNew
|
||||
? {
|
||||
description: '',
|
||||
email: '',
|
||||
firstName: '',
|
||||
password: '',
|
||||
roles: []
|
||||
}
|
||||
: state,
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (isNew && !fromApp) {
|
||||
navigate(routePaths.users)
|
||||
}
|
||||
}, [fromApp])
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch((value, { name, type }) => {
|
||||
if (name === 'roles' && type === 'change') {
|
||||
const exclusiveRole = findExclusiveRole(roles, value.roles as number[])
|
||||
if (exclusiveRole) {
|
||||
if (value.roles && value.roles.length > 1) {
|
||||
message.info(
|
||||
<>
|
||||
Роль: <strong>{exclusiveRole.name}</strong> несовместима с
|
||||
другими ролями
|
||||
</>
|
||||
)
|
||||
}
|
||||
setValue('roles', [exclusiveRole.id])
|
||||
}
|
||||
}
|
||||
})
|
||||
return () => subscription.unsubscribe()
|
||||
}, [watch])
|
||||
|
||||
const sendForm = () => {
|
||||
if (isNew) {
|
||||
const newUser = {
|
||||
email: getValues().email,
|
||||
password: getValues().password,
|
||||
description: getValues().description,
|
||||
firstName: getValues().firstName,
|
||||
lastName: getValues().lastName,
|
||||
roles: getValues().roles
|
||||
}
|
||||
createUser(newUser)
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
message.success('Пользователь успешно создан')
|
||||
navigate(routePaths.users)
|
||||
})
|
||||
.catch(() => {
|
||||
message.error('Произошла ошибка создания пользователя')
|
||||
})
|
||||
} else {
|
||||
const formData = getValues()
|
||||
delete formData.lastSessionCreatedAt
|
||||
updateUser(formData)
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
message.success('Пользователь успешно изменен')
|
||||
reset({}, { keepValues: true })
|
||||
})
|
||||
.catch(() => {
|
||||
message.error('Произошла ошибка обновления пользователя')
|
||||
})
|
||||
}
|
||||
}
|
||||
const createSelectOptions = (role: RoleType[]) => {
|
||||
const options: LabelItem[] = role.map((r) => ({
|
||||
value: r.id,
|
||||
label: r.name
|
||||
}))
|
||||
return options
|
||||
}
|
||||
if (isLoading) {
|
||||
return <Spin />
|
||||
}
|
||||
return (
|
||||
<section className="user-editor">
|
||||
<header className="user-editor__header">
|
||||
<div className="user-editor__header__nav">
|
||||
<Button
|
||||
data-cy="user-editor__header__nav__backBtn"
|
||||
className="user-editor__header__nav__backBtn"
|
||||
type="text"
|
||||
onClick={() => navigate(routePaths.users)}
|
||||
icon={<ArrowLeftOutlined />}
|
||||
/>
|
||||
|
||||
<h2 className="user-editor__header__name">
|
||||
{isNew ? 'Новый пользователь' : `${state.firstName}`}
|
||||
</h2>
|
||||
<Button
|
||||
disabled={!isDirty || !isSaveBtnAvailable}
|
||||
data-cy="user-editor__header__btn"
|
||||
className="user-editor__header__btn"
|
||||
onClick={() => sendForm()}
|
||||
type="primary"
|
||||
icon={<SaveOutlined />}
|
||||
>
|
||||
Сохранить
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{isNew ? (
|
||||
''
|
||||
) : (
|
||||
<span data-cy="user-editor__status" className="user-editor__status">
|
||||
{state.lastSessionCreatedAt && (
|
||||
<>
|
||||
Последняя сессия
|
||||
{new Date(state.lastSessionCreatedAt).toLocaleDateString()}
|
||||
|
||||
{new Date(state.lastSessionCreatedAt).toLocaleTimeString()}
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<form className="user-editor__content">
|
||||
<div className="user-editor__content__wrap">
|
||||
<div className="user-editor__content__name">
|
||||
<FormComponents.FormInput
|
||||
label="Пользователь"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
control={control}
|
||||
name="firstName"
|
||||
/>
|
||||
</div>
|
||||
<div className="user-editor__content__description">
|
||||
<FormComponents.FormInput
|
||||
label="Описание"
|
||||
control={control}
|
||||
name="description"
|
||||
/>
|
||||
</div>
|
||||
<div className="user-editor__content__email">
|
||||
<FormComponents.FormInput
|
||||
label="Email"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
control={control}
|
||||
name="email"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{isNew && (
|
||||
<div className="user-editor__content__password">
|
||||
<FormComponents.FormInputPassword
|
||||
label="Пароль"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
control={control}
|
||||
name="password"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="user-editor__content__roles">
|
||||
<FormComponents.FormSelect
|
||||
label="Добавить роль"
|
||||
optionFilterProp="label"
|
||||
disabled={!hasPermission(PermissionKeysType.write)}
|
||||
control={control}
|
||||
name="roles"
|
||||
options={createSelectOptions(roles)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
export default UserEditor
|
||||
@@ -0,0 +1,66 @@
|
||||
@import "../../constants/style/styleConst";
|
||||
|
||||
.user-editor {
|
||||
background: #fff;
|
||||
height: 100%;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
&__header {
|
||||
border-bottom: 1px solid $border-color;
|
||||
padding: $basic-padding *4 $basic-padding*3;
|
||||
|
||||
&__nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: $basic-margin* 2.5;
|
||||
|
||||
&__backBtn {
|
||||
margin-left: -$basic-margin;
|
||||
margin-right: $basic-margin;
|
||||
}
|
||||
}
|
||||
|
||||
&__name {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
color: #000;
|
||||
|
||||
}
|
||||
|
||||
&__btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
&__status {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
&__content {
|
||||
&__wrap {
|
||||
overflow-x: scroll;
|
||||
height: calc(100vh - 200px);
|
||||
}
|
||||
|
||||
.ant-form-item {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
&__name, &__description, &__email, &__roles, &__password {
|
||||
padding: $basic-padding*1.5 $basic-padding*3;
|
||||
|
||||
h3 {
|
||||
padding-bottom: $basic-padding*1;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-weight: 400;
|
||||
font-size: 14px;
|
||||
line-height: 22px
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditTwoTone,
|
||||
LockOutlined,
|
||||
UnlockOutlined,
|
||||
PlusSquareOutlined
|
||||
} from '@ant-design/icons'
|
||||
import { Button, Popconfirm, Spin, Table, message } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
import { getUserFullName } from '@utils/userUtils/getFullNameUtil.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import roleApi from '@services/roleService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
import { UserType } from '@type/user.type.ts'
|
||||
|
||||
import './users-page.scss'
|
||||
|
||||
const UsersPage = () => {
|
||||
const { data: allUsers = [], isLoading: isUsersLoading } =
|
||||
userServiceApi.useGetAllUsersQuery()
|
||||
const { data: roles, isLoading: isRolesLoading } =
|
||||
roleApi.useGetAllRolesQuery()
|
||||
const [blockUser] = userServiceApi.useBlockUserMutation()
|
||||
const [deleteUser] = userServiceApi.useDeleteUserMutation()
|
||||
const { role, hasPermission } = useRole()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const isLoading = isRolesLoading || isUsersLoading
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
const hasBlockUserPermission = hasPermission(PermissionKeysType.write)
|
||||
const hasDeleteUserPermission = hasPermission(PermissionKeysType.write)
|
||||
const hasUpdateUserPermission = hasPermission(PermissionKeysType.write)
|
||||
const hasCreateUserPermission = hasPermission(PermissionKeysType.write)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [isPageAvailable])
|
||||
|
||||
useEffect(() => {
|
||||
if (!role) {
|
||||
navigate(routePaths.error)
|
||||
}
|
||||
}, [role])
|
||||
|
||||
const handleDeleteUser = (userId: number) => {
|
||||
deleteUser(userId)
|
||||
.unwrap()
|
||||
.then(() => message.success('Пользователь успешно удален'))
|
||||
.catch(() => message.error('Не удалось удалить пользователя'))
|
||||
}
|
||||
|
||||
const handleBlockUser = (userId: number) => {
|
||||
const currentUser = allUsers.find((el) => el.id === userId)
|
||||
const successMessage = currentUser?.blocked
|
||||
? `Пользователь ${currentUser.lastName} ${currentUser.firstName} успешно разблокирован`
|
||||
: `Пользователь ${currentUser?.lastName} ${currentUser?.firstName} успешно заблокирован`
|
||||
const errorMessage = currentUser?.blocked
|
||||
? `Не удалось разблокировать пользователя ${currentUser.lastName} ${currentUser.firstName}`
|
||||
: `Не удалось заблокировать пользователя ${currentUser?.lastName} ${currentUser?.firstName}`
|
||||
blockUser(userId)
|
||||
.unwrap()
|
||||
.then(() => message.success(successMessage))
|
||||
.catch(() => message.error(<>{errorMessage}</>))
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin />
|
||||
}
|
||||
|
||||
const columns: ColumnsType<UserType> = [
|
||||
{
|
||||
title: 'id',
|
||||
dataIndex: 'id',
|
||||
key: 'id'
|
||||
},
|
||||
{
|
||||
title: 'Пользователь',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
render: (_, record) => getUserFullName(record)
|
||||
},
|
||||
{
|
||||
title: 'Описание',
|
||||
dataIndex: 'description',
|
||||
key: 'description'
|
||||
},
|
||||
{
|
||||
title: 'Email',
|
||||
dataIndex: 'email',
|
||||
key: 'email'
|
||||
},
|
||||
{
|
||||
title: 'Роль',
|
||||
dataIndex: 'roles',
|
||||
key: 'roles',
|
||||
render: (values: number[]) => {
|
||||
const labels: any[] = []
|
||||
values.forEach((value: number) => {
|
||||
const roleLabel = roles?.find((el) => el.id === value)
|
||||
if (roleLabel) {
|
||||
labels.push(roleLabel.name)
|
||||
}
|
||||
})
|
||||
return labels.map((label) => (
|
||||
<div key={label} className="role-item">
|
||||
{label}
|
||||
</div>
|
||||
))
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Последняя сессия',
|
||||
dataIndex: 'lastSessionCreatedAt',
|
||||
key: 'lastSessionCreatedAt',
|
||||
render: (value: string) =>
|
||||
value ? new Date(value).toLocaleDateString() : ''
|
||||
},
|
||||
{
|
||||
dataIndex: 'actions',
|
||||
key: 'actions',
|
||||
render: (_, record) => {
|
||||
const blockTitle = record.blocked
|
||||
? 'Вы действительно хотите разблокировать этого пользователя?'
|
||||
: 'Вы действительно хотите заблокировать этого пользователя?'
|
||||
return (
|
||||
<div className="users-page__content__table__actions">
|
||||
{hasBlockUserPermission && (
|
||||
<Popconfirm
|
||||
title={blockTitle}
|
||||
onConfirm={() => handleBlockUser(record.id)}
|
||||
>
|
||||
<Button
|
||||
data-cy={`users-page__content__table__actions__lock-btn ${record.id}`}
|
||||
className="users-page__content__table__actions__lock-btn"
|
||||
type="primary"
|
||||
danger={record.blocked}
|
||||
icon={record.blocked ? <LockOutlined /> : <UnlockOutlined />}
|
||||
/>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{hasUpdateUserPermission && (
|
||||
<div
|
||||
data-cy={`users-page__content__table__actions__edit-btn ${record.id}`}
|
||||
className="users-page__content__table__actions__edit-btn"
|
||||
onClick={() => {
|
||||
navigate(`${routePaths.users}/${record.id}`, {
|
||||
state: { ...record }
|
||||
})
|
||||
}}
|
||||
>
|
||||
<EditTwoTone />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasDeleteUserPermission && (
|
||||
<Popconfirm
|
||||
title="Вы действительно хотите удалить этого пользователя?"
|
||||
onConfirm={() => handleDeleteUser(record.id)}
|
||||
>
|
||||
<Button
|
||||
data-cy={`users-page__content__table__actions__delete-btn ${record.id}`}
|
||||
className="users-page__content__table__actions__delete-btn"
|
||||
type="primary"
|
||||
icon={<DeleteOutlined />}
|
||||
/>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
return (
|
||||
<section className="users-page">
|
||||
<header className="users-page__header">
|
||||
<span
|
||||
data-cy="users-page__header__title"
|
||||
className="users-page__header__title"
|
||||
>
|
||||
Пользователи
|
||||
</span>
|
||||
<Button
|
||||
disabled={!hasCreateUserPermission}
|
||||
onClick={() =>
|
||||
navigate(`${routePaths.users}/new`, { state: { fromApp: true } })
|
||||
}
|
||||
data-cy="users-page__header__addButton"
|
||||
type="primary"
|
||||
icon={<PlusSquareOutlined />}
|
||||
>
|
||||
Добавить
|
||||
</Button>
|
||||
</header>
|
||||
<section className="users-page__content">
|
||||
<div className="users-page__content__wrap-table">
|
||||
<Table
|
||||
data-cy="users-page__content__table"
|
||||
rowKey={(record) => record.id}
|
||||
pagination={false}
|
||||
dataSource={allUsers}
|
||||
columns={columns}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default UsersPage
|
||||
@@ -0,0 +1,70 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.users-page {
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
border: 1px solid $border-color;
|
||||
|
||||
|
||||
&__header {
|
||||
border-bottom: 1px solid $border-color;
|
||||
padding: 0 3 * $basic-padding;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
&__title {
|
||||
padding: 3 * $basic-padding 0;
|
||||
display: inline-block;
|
||||
font-weight: 500;
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
padding: 2 * $basic-padding 3 * $basic-padding;
|
||||
overflow-x: scroll;
|
||||
|
||||
&__wrap-table {
|
||||
overflow-x: scroll;
|
||||
height: calc(100vh - 200px);
|
||||
}
|
||||
|
||||
&__table {
|
||||
&__actions {
|
||||
justify-content: flex-end;
|
||||
display: flex;
|
||||
gap: $basic-margin;
|
||||
|
||||
&__delete-btn {
|
||||
color: $blue-color;
|
||||
background: $blue-light;
|
||||
}
|
||||
|
||||
&__edit-btn {
|
||||
cursor: pointer;
|
||||
background: $blue-light;
|
||||
padding: 4px 10px;
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
path:first-child {
|
||||
fill: $blue-color;
|
||||
}
|
||||
|
||||
path:last-child {
|
||||
fill: #fff;
|
||||
}
|
||||
|
||||
background: $blue-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__pagination {
|
||||
margin-top: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user