2024-06-06 13:58:58: merge [main:94936000280c72ce43ef30f2a36a36333115dd62];

This commit is contained in:
txix committed 2024-06-06 13:58:58 +03:00
1 parent e8dfc2e552
commit 031a92db3f
17 files changed
+171 -97

No files matched your search

+2 -2
View File
@@ -38,8 +38,8 @@ const LoginPage = () => {
}
const handleError = (err: AxiosError<MSPError>): void => {
const { response } = err
if (response && response.status === 401) {
const { response,status } = err
if (response && status === 401) {
setFormError(response.statusText, messages.loginError)
} else {
setFormError('serverError', messages.serverError)
+27 -6
View File
@@ -1,6 +1,7 @@
import { List, Spin, message, Tooltip } from 'antd'
import { List, message, Spin, Tooltip } from 'antd'
import { Layout } from 'isp-ui-kit'
import { useEffect } from 'react'
import { UseFormSetError } from 'react-hook-form'
import {
createSearchParams,
useLocation,
@@ -24,6 +25,7 @@ import { NewRoleType, PermissionKeysType, RoleType } from '@type/roles.type.ts'
import './roles-page.scss'
const { Column, EmptyData, NoData } = Layout
const RolesPage = () => {
@@ -89,25 +91,44 @@ const RolesPage = () => {
const handeOnAddItem = () => setSelectedItemId('new')
const handleUpdateRole = (formValue: RoleType | NewRoleType) => {
const handleUpdateRole = (
formValue: RoleType | NewRoleType,
setError: UseFormSetError<RoleType>
) => {
updateRole(formValue as RoleType)
.unwrap()
.then(() => {
message.success('Элемент успешно добавлен').then()
})
.catch(() => message.error('Не удалось сохранить роль'))
.catch((error) => {
const { status } = error
if (status === 409) {
setError('name', {
message: 'Роль с таким названием уже существует'
})
}
message.error('Не удалось сохранить роль')
})
}
const handleCreateRole = (formValue: NewRoleType) => {
const handleCreateRole = (
formValue: NewRoleType,
setError: UseFormSetError<NewRoleType>
) => {
createRole(formValue)
.unwrap()
.then((res) => {
message.success('Элемент успешно добавлен').then()
setSelectedItemId(res.id.toString())
})
.catch(() => {
.catch((error) => {
const { status } = error
if (status === 409) {
setError('name', {
message: 'Роль с таким названием уже существует'
})
}
message.error('Не удалось добавить роль').then()
setSelectedItemId('')
})
}
+19 -5
View File
@@ -52,7 +52,7 @@ const UserEditor = () => {
getValues,
setValue,
watch,
reset
setError
} = useForm<UserType>({
defaultValues: isNew
? {
@@ -108,7 +108,13 @@ const UserEditor = () => {
message.success('Пользователь успешно создан')
navigate(routePaths.users)
})
.catch(() => {
.catch((error) => {
const { status } = error
if (status === 409) {
setError('email', {
message: 'Пользователь с таким Email уже существует'
})
}
message.error('Произошла ошибка создания пользователя')
})
} else {
@@ -118,9 +124,15 @@ const UserEditor = () => {
.unwrap()
.then(() => {
message.success('Пользователь успешно изменен')
reset({}, { keepValues: true })
navigate(routePaths.users)
})
.catch(() => {
.catch((error) => {
const { status } = error
if (status === 409) {
setError('email', {
message: 'Пользователь с таким Email уже существует'
})
}
message.error('Произошла ошибка обновления пользователя')
})
}
@@ -169,7 +181,9 @@ const UserEditor = () => {
{state.lastSessionCreatedAt && (
<>
Последняя сессия &nbsp;
{dayjs(state.lastSessionCreatedAt).format(dateFormats.fullFormat)}
{dayjs(state.lastSessionCreatedAt).format(
dateFormats.fullFormat
)}
</>
)}
</span>
+43 -28
View File
@@ -2,14 +2,17 @@ import {
DeleteOutlined,
EditOutlined,
LockOutlined,
UnlockOutlined,
PlusSquareOutlined
PlusSquareOutlined,
UnlockOutlined
} from '@ant-design/icons'
import { Button, Popconfirm, Spin, Table, message, Tooltip } from 'antd'
import { Button, message, Popconfirm, Spin, Table, Tag, Tooltip } from 'antd'
import { ColumnsType } from 'antd/es/table'
import dayjs from 'dayjs'
import { useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { dateFormats } from '@constants/date.ts'
import CanEdit from '@components/CanEdit'
import { getUserFullName } from '@utils/userUtils/getFullNameUtil.ts'
@@ -25,8 +28,7 @@ import { PermissionKeysType } from '@type/roles.type.ts'
import { UserType } from '@type/user.type.ts'
import './users-page.scss'
import dayjs from 'dayjs'
import { dateFormats } from '@constants/date.ts'
const UsersPage = () => {
const { data: allUsers = [], isLoading: isUsersLoading } =
@@ -76,6 +78,32 @@ const UsersPage = () => {
.catch(() => message.error(<>{errorMessage}</>))
}
const renderBlockButton = (userData: UserType) => {
const { blocked, id } = userData
const popConfirmTitle = blocked
? 'Вы действительно хотите разблокировать этого пользователя?'
: 'Вы действительно хотите заблокировать этого пользователя?'
const tooltipTitle = blocked
? 'Разблокировать пользователя'
: 'Заблокировать пользователя'
const icon = blocked ? <UnlockOutlined /> : <LockOutlined />
return (
<Popconfirm title={popConfirmTitle} onConfirm={() => handleBlockUser(id)}>
<Tooltip key="LockOutlined" title={tooltipTitle}>
<Button
data-cy={`users-page__content__table__actions__lock-btn ${id}`}
className="users-page__content__table__actions__lock-btn"
icon={icon}
/>
</Tooltip>
</Popconfirm>
)
}
if (isLoading) {
return <Spin />
}
@@ -100,7 +128,14 @@ const UsersPage = () => {
{
title: 'Email',
dataIndex: 'email',
key: 'email'
key: 'email',
render: (value, record) => {
if(record.blocked){
return <div>{value} <Tag color="red">Заблокирован</Tag></div>
}
return value
}
},
{
title: 'Роль',
@@ -126,37 +161,17 @@ const UsersPage = () => {
dataIndex: 'lastSessionCreatedAt',
key: 'lastSessionCreatedAt',
render: (value: string) =>
value ? dayjs(value).format(dateFormats.fullFormat) : ''
value ? dayjs(value).format(dateFormats.fullFormat) : ''
},
{
dataIndex: 'actions',
key: 'actions',
render: (_, record) => {
const blockTitle = record.blocked
? 'Вы действительно хотите разблокировать этого пользователя?'
: 'Вы действительно хотите заблокировать этого пользователя?'
return (
<div className="users-page__content__table__actions">
<CanEdit>
<Button.Group className="button_group">
<Popconfirm
title={blockTitle}
onConfirm={() => handleBlockUser(record.id)}
>
<Tooltip
key="LockOutlined"
title="Заблокировать пользователя"
>
<Button
data-cy={`users-page__content__table__actions__lock-btn ${record.id}`}
className="users-page__content__table__actions__lock-btn"
danger={record.blocked}
icon={
record.blocked ? <LockOutlined /> : <UnlockOutlined />
}
/>
</Tooltip>
</Popconfirm>
{renderBlockButton(record)}
<Tooltip key="EditOutlined" title="Редактировать пользователя">
<Button
data-cy={`users-page__content__table__actions__edit-btn ${record.id}`}