From 031a92db3f6b21173a28d58f6780bc4bb09927e1 Mon Sep 17 00:00:00 2001 From: txix Date: Thu, 6 Jun 2024 13:58:58 +0300 Subject: [PATCH] 2024-06-06 13:58:58: merge [main:94936000280c72ce43ef30f2a36a36333115dd62]; --- CHANGELOG.md | 11 +++ package-lock.json | 20 +++--- package.json | 2 +- .../active-configurations-table.scss | 4 -- .../ActiveConfigurationsTable/index.tsx | 1 + src/components/ApplicationsContent/index.tsx | 24 ++++--- src/components/Layout/index.tsx | 4 +- src/components/RolesContent/index.tsx | 6 +- .../RolesContent/roles-content.type.ts | 7 +- src/components/TokenContent/index.tsx | 33 ++++----- src/components/TokenContent/tokens.scss | 11 ++- src/components/app.scss | 1 + src/pages/LoginPage/index.tsx | 4 +- src/pages/RolesPage/index.tsx | 33 +++++++-- src/pages/UserEditor/index.tsx | 24 +++++-- src/pages/UsersPage/index.tsx | 71 +++++++++++-------- src/routes/Routers/index.tsx | 12 +++- 17 files changed, 171 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5053a67..e995e48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.11.5 +- Обновлена библиотека isp-ui-kit +- Убраны лишние столбцы на странице токенов +- Исправлено поведение модального окна на странице Группы приложений +- Убран лишний скролл +- Различные улучшения дизайна страницы Приложений +- Убран Ховер в таблицах на экране Модули +- Улучшена ui-логика блокировки/разблокировки пользователя +- Добавлена обработка ошибок с существующими значения на экране "Пользователи", "Роли" +- Исправлена обработки ошибки 401 на экране логина +- Исправлено моргание страницы Модулей ## 0.11.4 - Правки для прода ## 0.11.3 diff --git a/package-lock.json b/package-lock.json index c3e9994..5bd6d1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isp-admin-ui", - "version": "0.11.3", + "version": "0.11.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isp-admin-ui", - "version": "0.11.3", + "version": "0.11.5", "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "@codemirror/lang-json": "^6.0.1", @@ -2934,9 +2934,9 @@ } }, "node_modules/@lezer/javascript": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.4.14.tgz", - "integrity": "sha512-GEdUyspTRgc5dwIGebUk+f3BekvqEWVIYsIuAC3pA8e8wcikGwBZRWRa450L0s8noGWuULwnmi4yjxTnYz9PpA==", + "version": "1.4.16", + "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.4.16.tgz", + "integrity": "sha512-84UXR3N7s11MPQHWgMnjb9571fr19MmXnr5zTv2XX0gHXXUvW3uPJ8GCjKrfTXmSdfktjRK0ayKklw+A13rk4g==", "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.1.3", @@ -7844,8 +7844,8 @@ } }, "node_modules/isp-ui-kit": { - "version": "0.5.5", - "resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#e63795caeb38900e8ca4787eaf0ba6ea606d935c", + "version": "0.5.6", + "resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#894f639391c367af3909c8e5feb5873d25ff9132", "license": "ISC", "dependencies": { "@codemirror/lang-javascript": "^6.2.1", @@ -10812,9 +10812,9 @@ } }, "node_modules/ua-parser-js": { - "version": "1.0.37", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.37.tgz", - "integrity": "sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==", + "version": "1.0.38", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.38.tgz", + "integrity": "sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ==", "funding": [ { "type": "opencollective", diff --git a/package.json b/package.json index 861dced..8f7b369 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.11.4", + "version": "0.11.5", "type": "module", "scripts": { "start": "vite", diff --git a/src/components/ActiveConfigurationsTable/active-configurations-table.scss b/src/components/ActiveConfigurationsTable/active-configurations-table.scss index abe6085..3c34169 100644 --- a/src/components/ActiveConfigurationsTable/active-configurations-table.scss +++ b/src/components/ActiveConfigurationsTable/active-configurations-table.scss @@ -36,10 +36,6 @@ tr { background: $blue-light; } - - .ant-table-cell-row-hover { - background: $blue-color-2 !important; - } } &__buttons { diff --git a/src/components/ActiveConfigurationsTable/index.tsx b/src/components/ActiveConfigurationsTable/index.tsx index 673abef..0920e17 100644 --- a/src/components/ActiveConfigurationsTable/index.tsx +++ b/src/components/ActiveConfigurationsTable/index.tsx @@ -207,6 +207,7 @@ const ActiveConfigurationsTable: FC = } record.id} pagination={false} diff --git a/src/components/ApplicationsContent/index.tsx b/src/components/ApplicationsContent/index.tsx index 2c84842..c061d49 100644 --- a/src/components/ApplicationsContent/index.tsx +++ b/src/components/ApplicationsContent/index.tsx @@ -1,4 +1,4 @@ -import { LinkOutlined } from '@ant-design/icons' +import { FileProtectOutlined } from '@ant-design/icons' import { List, message, Spin, Tooltip } from 'antd' import { Layout } from 'isp-ui-kit' import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type' @@ -120,12 +120,14 @@ const ApplicationsContent: FC = ({ createApplicationService(newApplicationApp) .unwrap() - .then(() => message.success('Элемент сохранен')) - .catch(() => message.error('Ошибка добавления элемента')).finally(()=> setShowApplicationsModal({ - ...showApplicationsModal, - addModal: false - })) - + .then(() => { + message.success('Элемент сохранен') + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: false + }) + }) + .catch(() => message.error('Ошибка добавления элемента')) } const handleRemoveApplicationApp = (id: number) => removeApplicationsService([id]) @@ -139,8 +141,8 @@ const ApplicationsContent: FC = ({ const renderColumnItems = (item: ColumnItem) => { return ( - - + +
{ @@ -148,7 +150,9 @@ const ApplicationsContent: FC = ({ navigate(`/appAccess/${item.id}`) }} > - + + +
diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 10f0f79..6656cd4 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -1,6 +1,6 @@ import { AppstoreAddOutlined, - LockOutlined, + FileProtectOutlined, ProductOutlined, ProfileOutlined } from '@ant-design/icons' @@ -81,7 +81,7 @@ const LayoutComponent = () => { label: 'Доступы приложений', key: 'appAccess', className: hideItem([PermissionKeysType.read]), - icon: + icon: }, { label: 'Модули', diff --git a/src/components/RolesContent/index.tsx b/src/components/RolesContent/index.tsx index b181427..dfa5403 100644 --- a/src/components/RolesContent/index.tsx +++ b/src/components/RolesContent/index.tsx @@ -1,4 +1,4 @@ -import { Divider, Table, message } from 'antd' +import { Divider, message, Table } from 'antd' import { ColumnsType } from 'antd/es/table' import { FormComponents } from 'isp-ui-kit' import { useEffect, useState } from 'react' @@ -19,6 +19,7 @@ import { PermissionKeysType, RoleType } from '@type/roles.type.ts' import './roles-content.scss' + const newRole: Partial = { externalGroup: '', name: '', @@ -46,6 +47,7 @@ const RolesContent = ({ const { control, formState: { isDirty }, + setError, getValues, reset } = useForm({ @@ -79,7 +81,7 @@ const RolesContent = ({ } const formValue = getValues() formValue.changeMessage = changeMessage - saveRole(formValue) + saveRole(formValue, setError) setOpenModal(false) } diff --git a/src/components/RolesContent/roles-content.type.ts b/src/components/RolesContent/roles-content.type.ts index 68835d2..8f4780d 100644 --- a/src/components/RolesContent/roles-content.type.ts +++ b/src/components/RolesContent/roles-content.type.ts @@ -1,3 +1,5 @@ +import { UseFormSetError } from 'react-hook-form' + import { NewRoleType, PermissionType, RoleType } from '@type/roles.type.ts' export interface RolesContentPropsType { @@ -5,5 +7,8 @@ export interface RolesContentPropsType { title?: string immutable?: boolean permissions: PermissionType[] - saveRole: (formValue: RoleType | NewRoleType) => void + saveRole: ( + formValue: RoleType | NewRoleType, + setError: UseFormSetError + ) => void } diff --git a/src/components/TokenContent/index.tsx b/src/components/TokenContent/index.tsx index fbfe515..6461118 100644 --- a/src/components/TokenContent/index.tsx +++ b/src/components/TokenContent/index.tsx @@ -113,11 +113,6 @@ const TokenContent = ({ id }: TokenPropTypes) => { } const columns: ColumnsType = [ - { - title: 'ID', - dataIndex: 'appId', - key: 'appId' - }, { title: 'Токен', dataIndex: 'token', @@ -135,28 +130,24 @@ const TokenContent = ({ id }: TokenPropTypes) => { return
{formatTime}
} }, - { - title: 'Срок действия', - dataIndex: 'expireTime', - key: 'expireTime', - render: (value) => { - const time = dayjs.duration(value).humanize() - if (value > 0) { - return
{time}
- } - return
Отсутствует
- } - }, { title: 'Истекает', dataIndex: 'expireTime', key: 'expireTime', render: (value, record) => { - const formatTime = dayjs(record.createdAt) - .add(record.expireTime) - .format(dateFormats.fullFormat) - return value > 0 ? {formatTime} : Никогда + if (value === -1) { + return Никогда + } + + const dateNow = dayjs() + const expireTime = dayjs(record.createdAt).add(value) + if (expireTime.isBefore(dateNow)) { + return Просрочен + } + + const formatTime = expireTime.format(dateFormats.fullFormat) + return {formatTime} } }, { diff --git a/src/components/TokenContent/tokens.scss b/src/components/TokenContent/tokens.scss index c837b6b..fbf7f3d 100644 --- a/src/components/TokenContent/tokens.scss +++ b/src/components/TokenContent/tokens.scss @@ -10,13 +10,20 @@ } &__wrap { - padding: $basic-padding*2 $basic-padding*3; - min-width: 700px; + padding: $basic-padding*1.25 $basic-padding*3; } &__header { display: flex; justify-content: space-between; + + h3 { + font-size: 19px; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + font-weight: 500; + } } .copy-btn { diff --git a/src/components/app.scss b/src/components/app.scss index 8947f80..025b2fd 100644 --- a/src/components/app.scss +++ b/src/components/app.scss @@ -4,6 +4,7 @@ margin:0; padding:0; box-sizing: border-box; + font-family: PT Sans, sans-serif; } .app{ diff --git a/src/pages/LoginPage/index.tsx b/src/pages/LoginPage/index.tsx index d6aa488..01570c8 100644 --- a/src/pages/LoginPage/index.tsx +++ b/src/pages/LoginPage/index.tsx @@ -38,8 +38,8 @@ const LoginPage = () => { } const handleError = (err: AxiosError): 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) diff --git a/src/pages/RolesPage/index.tsx b/src/pages/RolesPage/index.tsx index 5493f9c..547cb04 100644 --- a/src/pages/RolesPage/index.tsx +++ b/src/pages/RolesPage/index.tsx @@ -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 + ) => { 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 + ) => { 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('') }) } diff --git a/src/pages/UserEditor/index.tsx b/src/pages/UserEditor/index.tsx index 932d959..8e2bab1 100644 --- a/src/pages/UserEditor/index.tsx +++ b/src/pages/UserEditor/index.tsx @@ -52,7 +52,7 @@ const UserEditor = () => { getValues, setValue, watch, - reset + setError } = useForm({ 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 && ( <> Последняя сессия   - {dayjs(state.lastSessionCreatedAt).format(dateFormats.fullFormat)} + {dayjs(state.lastSessionCreatedAt).format( + dateFormats.fullFormat + )} )} diff --git a/src/pages/UsersPage/index.tsx b/src/pages/UsersPage/index.tsx index 2c05acb..ca1e268 100644 --- a/src/pages/UsersPage/index.tsx +++ b/src/pages/UsersPage/index.tsx @@ -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 ? : + + return ( + handleBlockUser(id)}> + +