From 07b8a0478260042ce54b961098dbdea2770b643f Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 12 Apr 2024 14:39:10 +0300 Subject: [PATCH 01/39] MSP-3105 add getUserFullName in utils/userUtils --- src/type/user.type.ts | 28 ++++++++++++++++++++++++++ src/utils/userUtils/getFullNameUtil.ts | 4 ++++ 2 files changed, 32 insertions(+) create mode 100644 src/type/user.type.ts create mode 100644 src/utils/userUtils/getFullNameUtil.ts diff --git a/src/type/user.type.ts b/src/type/user.type.ts new file mode 100644 index 0000000..64c8c1c --- /dev/null +++ b/src/type/user.type.ts @@ -0,0 +1,28 @@ +export interface UserType { + id: number + blocked: boolean + createdAt: string + email: string + password: string + firstName: string + lastName: string + roleId: number + roleName: string + roles: number[] + updatedAt: string + description: string + lastSessionCreatedAt?: string +} + +export interface UserResponseType { + items: UserType[] +} + +export interface NewUserType { + description: string + email: string + firstName: string + lastName: string + password: string + roles: number[] +} diff --git a/src/utils/userUtils/getFullNameUtil.ts b/src/utils/userUtils/getFullNameUtil.ts new file mode 100644 index 0000000..e7f5f71 --- /dev/null +++ b/src/utils/userUtils/getFullNameUtil.ts @@ -0,0 +1,4 @@ +import { UserType } from '@type/user.type.ts' + +export const getUserFullName = (user: UserType): string => + user ? `${user.lastName} ${user.firstName}` : '' From 67691c58f2a200c9bf1471dd327daa2fe37f17f7 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 12 Apr 2024 16:19:19 +0300 Subject: [PATCH 02/39] MSP-3105 add endpoints in apiPaths and routes in routePaths --- src/constants/api/apiPaths.ts | 22 +++++++++++++++++++++- src/routes/routePaths.ts | 8 ++++++++ src/services/roleService.ts | 3 +-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index 97f220e..0246857 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -9,13 +9,25 @@ type PathKeys = | 'login' | 'logout' | 'getProfile' + | 'getUsers' + | 'createUser' + | 'updateUser' + | 'blockUser' + | 'deleteUser' + | 'getRoles' + | 'getAllPermissions' + | 'baseUserUrl' + | 'baseAdminUrl' | 'getSystemTree' | 'getById' | 'setList' | 'setOne' | 'getAllRoutes' + export const apiPaths: Record = { - baseUrl: '/api/admin', + baseUrl: '/api/kkd-configuration-service', + baseAdminUrl: '/api/admin', + baseUserUrl: '/api/admin/user', baseSystemUrl: '/api/system', baseConfigUrl: '/api/config', // ======= ROLES ====== @@ -28,6 +40,14 @@ export const apiPaths: Record = { logout: '/api/admin/auth/logout', // ======= PROFILE ====== getProfile: '/api/admin/user/get_profile', + // ======= USERS ====== + getUsers: '/get_users', + createUser: '/create_user', + updateUser: '/update_user', + blockUser: '/block_user', + deleteUser: '/delete_user', + getRoles: '/get_roles', + getAllPermissions: '/get_permissions', // ======= APPLICATIONS ====== getSystemTree: '/application/get_system_tree', // ======= ACCESS_LIST ====== diff --git a/src/routes/routePaths.ts b/src/routes/routePaths.ts index b46d0f1..6a61849 100644 --- a/src/routes/routePaths.ts +++ b/src/routes/routePaths.ts @@ -4,6 +4,10 @@ type RoutePaths = | 'error' | 'login' | 'profile' + | 'users' + | 'sessions' + | 'securityLog' + | 'roles' | 'appAccess' export const routePaths: Record = { @@ -12,5 +16,9 @@ export const routePaths: Record = { notFound: '*', login: '/login', profile: '/profile', + users: '/users', + sessions: '/sessions', + securityLog: '/securityLog', + roles: '/roles', appAccess: '/appAccess' } diff --git a/src/services/roleService.ts b/src/services/roleService.ts index 1d7075c..9c13f32 100644 --- a/src/services/roleService.ts +++ b/src/services/roleService.ts @@ -6,12 +6,11 @@ import { axiosBaseQuery } from '@utils/apiUtils.ts' import { NewRoleType, RoleType } from '@type/roles.type.ts' - const roleApi = createApi({ reducerPath: 'roleApi', refetchOnFocus: true, tagTypes: ['Roles'], - baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseUrl }), + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseAdminUrl }), endpoints: (builder) => ({ getAllRoles: builder.query({ query: () => ({ url: apiPaths.getAllRoles }), From a38006790801ffcffa2ac5c69fb7f11d5f31b94c Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 12 Apr 2024 14:55:50 +0300 Subject: [PATCH 03/39] MSP-3105 fix eslint and add constants in styleConst --- src/constants/style/styleConst.scss | 4 +++ src/pages/HomePage/index.tsx | 4 ++- src/pages/LoginPage/index.tsx | 4 +-- src/services/apiService.ts | 14 ++++++---- src/utils/apiUtils.ts | 43 +++++++++++++++-------------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/constants/style/styleConst.scss b/src/constants/style/styleConst.scss index 870ffa5..9b32063 100644 --- a/src/constants/style/styleConst.scss +++ b/src/constants/style/styleConst.scss @@ -11,3 +11,7 @@ $grey: #606060; $border-color: #d9d9d9; $error-red: #cf1322; +$border-color: #F0F0F0; + +$blue-color: #40A9FF; +$blue-light: #E6F7FF; \ No newline at end of file diff --git a/src/pages/HomePage/index.tsx b/src/pages/HomePage/index.tsx index 7e844ac..7943ce5 100644 --- a/src/pages/HomePage/index.tsx +++ b/src/pages/HomePage/index.tsx @@ -1,5 +1,7 @@ import './home-page.scss' -export default function HomePage() { +const HomePage = () => { return
Добро пожаловать!
} + +export default HomePage diff --git a/src/pages/LoginPage/index.tsx b/src/pages/LoginPage/index.tsx index 891d6c8..f4826df 100644 --- a/src/pages/LoginPage/index.tsx +++ b/src/pages/LoginPage/index.tsx @@ -105,7 +105,7 @@ const LoginPage = () => { } return ( -
+

Вход в систему @@ -113,7 +113,7 @@ const LoginPage = () => { {renderInternalAuthForm()} -

+ ) } diff --git a/src/services/apiService.ts b/src/services/apiService.ts index 1c76946..9124a01 100644 --- a/src/services/apiService.ts +++ b/src/services/apiService.ts @@ -33,16 +33,18 @@ apiService.interceptors.request.use( apiService.interceptors.response.use( async (response: any) => response, (error: AxiosError) => { - console.error(error) + console.error(error) if (error.response && error.response.status === 401) { - LocalStorage.clear() - message.error('Ваша сессия истекла"').then() - LocalStorage.set('redirectUrl', location.pathname) - window.location.href = routePaths.login + LocalStorage.clear() + message.error('Ваша сессия истекла"').then() + LocalStorage.set('redirectUrl', location.pathname) + window.location.href = routePaths.login } if (error.response && error.response.status >= 500) { - message.error('Внутренняя ошибка сервиса, попробуйте повторить запрос').then() + message + .error('Внутренняя ошибка сервиса, попробуйте повторить запрос') + .then() } return Promise.reject(error) diff --git a/src/utils/apiUtils.ts b/src/utils/apiUtils.ts index a99d880..dd5f6ee 100644 --- a/src/utils/apiUtils.ts +++ b/src/utils/apiUtils.ts @@ -1,18 +1,19 @@ -import { BaseQueryFn, retry } from '@reduxjs/toolkit/query/react'; +import { BaseQueryFn, retry } from '@reduxjs/toolkit/query/react' +import { AxiosError, AxiosRequestConfig } from 'axios' -import { AxiosError, AxiosRequestConfig } from 'axios'; import { apiService } from '@services/apiService.ts' + import { MSPError } from '@type/index.ts' export const axiosBaseQuery = ( - { baseUrl }: { baseUrl: string } = { baseUrl: '' }, + { baseUrl }: { baseUrl: string } = { baseUrl: '' } ): BaseQueryFn< { - url: string; - method?: AxiosRequestConfig['method']; - data?: AxiosRequestConfig['data']; - params?: AxiosRequestConfig['params']; + url: string + method?: AxiosRequestConfig['method'] + data?: AxiosRequestConfig['data'] + params?: AxiosRequestConfig['params'] }, unknown, unknown @@ -23,29 +24,29 @@ export const axiosBaseQuery = url: baseUrl + url, method, data, - params, - }); - return { data: result.data }; + params + }) + return { data: result.data } } catch (axiosError) { - const err = axiosError as AxiosError; + const err = axiosError as AxiosError return { - error: { ...err.response }, - }; + error: { ...err.response } + } } - }; + } export const staggeredBaseQueryWithBailOut = (baseUrl: string) => retry( async (args: string | AxiosRequestConfig['data'], api, extraOptions) => { - const result = await axiosBaseQuery({ baseUrl })(args, api, extraOptions); - const error = result.error as AxiosError; + const result = await axiosBaseQuery({ baseUrl })(args, api, extraOptions) + const error = result.error as AxiosError if (error && error?.status === 400) { - retry.fail(result.error); + retry.fail(result.error) } - return result; + return result }, { - maxRetries: 5, - }, - ); + maxRetries: 5 + } + ) From 42ee1697c4dd95dce52a85343e45e6bda5434db6 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Wed, 17 Apr 2024 18:19:41 +0300 Subject: [PATCH 04/39] MSP-3105 change layout.type.ts and roles.type.ts --- src/components/AdminPermission/index.tsx | 4 ++-- src/components/AppAccessContent/index.tsx | 4 ++-- src/components/Layout/index.tsx | 22 +++++++++++----------- src/components/Layout/layout.type.ts | 16 ++++++++-------- src/hooks/useRole.tsx | 4 ++-- src/pages/AppAccessPage/index.tsx | 4 ++-- src/type/roles.type.ts | 15 +++++---------- src/widgets/AccessListTree/index.tsx | 4 ++-- 8 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/components/AdminPermission/index.tsx b/src/components/AdminPermission/index.tsx index 310f505..557861f 100644 --- a/src/components/AdminPermission/index.tsx +++ b/src/components/AdminPermission/index.tsx @@ -2,12 +2,12 @@ import { PropsWithChildren } from 'react' import { useRole } from '@hooks/useRole.tsx' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' const AdminPermission = ({ children }: PropsWithChildren) => { const { hasPermission } = useRole() - if (hasPermission(PermissionKeys.read)) { + if (hasPermission(PermissionKeysType.read)) { return <>{children} } return null diff --git a/src/components/AppAccessContent/index.tsx b/src/components/AppAccessContent/index.tsx index b62d59a..c4f09a1 100644 --- a/src/components/AppAccessContent/index.tsx +++ b/src/components/AppAccessContent/index.tsx @@ -18,7 +18,7 @@ import routeApi from '@services/routeService.ts' import { routePaths } from '@routes/routePaths.ts' import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' import './app-access-content.scss' @@ -32,7 +32,7 @@ const AppAccessContent: FC = ({ const [messageApi, contextHolder] = message.useMessage() const { hasPermission } = useRole() - const canWrite = hasPermission(PermissionKeys.write) + const canWrite = hasPermission(PermissionKeysType.write) const { data: methods = [], diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index fdffbf5..fbaaaeb 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -6,7 +6,7 @@ import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom' import { localStorageKeys } from '@constants/localStorageKeys.ts' import { - MenuItemKeys, + MenuItemKeysType, MenuItemType, menuKeys } from '@components/Layout/layout.type.ts' @@ -22,7 +22,7 @@ import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts' import { routePaths } from '@routes/routePaths.ts' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' import './layout.scss' @@ -32,16 +32,16 @@ const LayoutComponent = () => { const navigate = useNavigate() const [collapsed, setCollapsed] = useState(false) - const [selectedMenuKeys, setSelectedMenuKeys] = useState([]) + const [selectedMenuKeys, setSelectedMenuKeys] = useState([]) const [openKeys, setOpenKeys] = useState([]) const dispatch = useAppDispatch() const { status } = useAppSelector((state) => state.profileReducer) const location = useLocation() - const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN) - const { hasPermission } = useRole() - const hideItem = (permission: PermissionKeys | PermissionKeys[]) => { + const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN) + + const hideItem = (permission: PermissionKeysType | PermissionKeysType[]) => { if (Array.isArray(permission)) { const result = permission.reduce((acc, currentValue) => { const hasPermissionFunc = hasPermission(currentValue) @@ -55,19 +55,19 @@ const LayoutComponent = () => { { label: 'Доступы приложений', key: 'appAccess', - className: hideItem([PermissionKeys.read]), + className: hideItem([PermissionKeysType.read]), icon: }, { label: 'Пользователи и роли', key: 'sessionManagement', - className: hideItem([PermissionKeys.read]), + className: hideItem([PermissionKeysType.read]), icon: , children: [ { label: 'Пользователи', key: 'users', - className: hideItem(PermissionKeys.read) + className: hideItem(PermissionKeysType.read) } ] } @@ -80,7 +80,7 @@ const LayoutComponent = () => { }, []) useEffect(() => { - const menuKey = location.pathname.split('/')[1] as MenuItemKeys + const menuKey = location.pathname.split('/')[1] as MenuItemKeysType const menuItem = menuKeys[menuKey] @@ -92,7 +92,7 @@ const LayoutComponent = () => { const handlerOnClickMenu = ({ key }: any): void => { switch (key) { - case MenuItemKeys.appAccess: + case MenuItemKeysType.appAccess: navigate(routePaths.appAccess) break default: diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index c3027ad..bcd5b94 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -1,21 +1,21 @@ import { MenuProps } from 'antd' -export enum MenuItemKeys { +export enum MenuItemKeysType { users = 'users', appAccess = 'appAccess' } -type MenuItem = { - key: MenuItemKeys +interface MenuItem { + key: MenuItemKeysType parent: string[] } -export const menuKeys: Record = { - [MenuItemKeys.users]: { - key: MenuItemKeys.users, +export const menuKeys: Record = { + [MenuItemKeysType.users]: { + key: MenuItemKeysType.users, parent: ['sessionManagement'] }, - [MenuItemKeys.appAccess]: { - key: MenuItemKeys.appAccess, + [MenuItemKeysType.appAccess]: { + key: MenuItemKeysType.appAccess, parent: [] } } diff --git a/src/hooks/useRole.tsx b/src/hooks/useRole.tsx index b17c70e..da69254 100644 --- a/src/hooks/useRole.tsx +++ b/src/hooks/useRole.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' import { useAppSelector } from './redux.ts' @@ -8,7 +8,7 @@ export const useRole = () => { const { profile } = useAppSelector((state: any) => state.profileReducer) const role: string = useMemo(() => profile && profile.role, [profile]) - const hasPermission = (permission: PermissionKeys) => { + const hasPermission = (permission: PermissionKeysType) => { const userPermission = profile.permissions || [] return userPermission.includes(permission) } diff --git a/src/pages/AppAccessPage/index.tsx b/src/pages/AppAccessPage/index.tsx index fd00d4d..77f8292 100644 --- a/src/pages/AppAccessPage/index.tsx +++ b/src/pages/AppAccessPage/index.tsx @@ -24,7 +24,7 @@ import appApi from '@services/appService.ts' import { routePaths } from '@routes/routePaths.ts' import { SystemTreeAppType } from '@type/app.type.ts' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' import './app-access-page.scss' @@ -48,7 +48,7 @@ const AppAccessPage = () => { const { id: selectedItemId = '' } = useParams() const [searchParams, setSearchParams] = useSearchParams() const searchValue = searchParams.get(firstColumnSearchParam) || '' - const canRead = hasPermission(PermissionKeys.read) + const canRead = hasPermission(PermissionKeysType.read) useEffect(() => { if (!canRead) { diff --git a/src/type/roles.type.ts b/src/type/roles.type.ts index ce617ac..05df90b 100644 --- a/src/type/roles.type.ts +++ b/src/type/roles.type.ts @@ -1,21 +1,16 @@ -export enum RoleKeys { - user = 'user', - admin = 'admin' -} - -export enum PermissionKeys { +export enum PermissionKeysType { read = 'read', // Просмотр страниц write = 'write', // Редактирование страниц } -export type RoleType = { +export interface RoleType { changeMessage?: string createdAt: string description: string externalGroup: string id: number name: string - permissions: PermissionKeys[] + permissions: PermissionKeysType[] updatedAt: string immutable: boolean exclusive: boolean @@ -23,7 +18,7 @@ export type RoleType = { export type NewRoleType = Omit -export type PermissionType = { - key: PermissionKeys +export interface PermissionType { + key: PermissionKeysType name: string } diff --git a/src/widgets/AccessListTree/index.tsx b/src/widgets/AccessListTree/index.tsx index bac898d..62dd993 100644 --- a/src/widgets/AccessListTree/index.tsx +++ b/src/widgets/AccessListTree/index.tsx @@ -7,7 +7,7 @@ import { AccessListTreePropsType } from '@widgets/AccessListTree/access-list-tre import useRole from '@hooks/useRole.tsx' import { EndpointType } from '@type/accessList.type.ts' -import { PermissionKeys } from '@type/roles.type.ts' +import { PermissionKeysType } from '@type/roles.type.ts' import './access-list-tree.scss' @@ -123,7 +123,7 @@ const AccessListTree: FC = ({
setExpandedKeys(keys as string[])} From 4901e036eed35971228b95072aeccd8f6273113d Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Thu, 18 Apr 2024 10:53:50 +0300 Subject: [PATCH 05/39] MSP-3105 add holderRender for theme in Layout for message --- src/components/Layout/index.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index fbaaaeb..9a5aa6e 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -1,6 +1,6 @@ import { LockOutlined, ProfileOutlined } from '@ant-design/icons' -import { Divider, Layout, Menu, Spin } from 'antd' -import { useEffect, useState } from 'react' +import { ConfigProvider, Divider, 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' @@ -38,6 +38,7 @@ const LayoutComponent = () => { const { status } = useAppSelector((state) => state.profileReducer) const location = useLocation() const { hasPermission } = useRole() + const { theme } = useContext(ConfigProvider.ConfigContext) const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN) @@ -73,6 +74,16 @@ const LayoutComponent = () => { } ] + useEffect(() => { + ConfigProvider.config({ + holderRender: (children) => ( + + {children} + + ), + }) + }, [theme]) + useEffect(() => { if (userToken) { dispatch(fetchProfile()) From a288b18ea87e28cb3565b80a16d1d5a63f35f372 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Wed, 17 Apr 2024 17:33:41 +0300 Subject: [PATCH 06/39] MSP-3105 add userServiceApi and add it in store --- src/services/userService.ts | 54 +++++++++++++++++++++++++++++++++++++ src/stores/index.tsx | 5 +++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/services/userService.ts diff --git a/src/services/userService.ts b/src/services/userService.ts new file mode 100644 index 0000000..9f69730 --- /dev/null +++ b/src/services/userService.ts @@ -0,0 +1,54 @@ +import { createApi } from '@reduxjs/toolkit/query/react' + +import { apiPaths } from '@constants/api/apiPaths.ts' + +import { axiosBaseQuery } from '@utils/apiUtils.ts' + +import { PermissionType } from '@type/roles.type.ts' +import { NewUserType, UserResponseType, UserType } from '@type/user.type.ts' + +const userServiceApi = createApi({ + reducerPath: 'userServiceApi', + refetchOnFocus: true, + tagTypes: ['users', 'permissions'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseUserUrl }), + endpoints: (builder) => ({ + getAllUsers: builder.query({ + query: () => ({ url: apiPaths.getUsers, data: { limit: 1000 } }), + transformResponse: (response: UserResponseType) => response.items, + providesTags: () => ['users'] + }), + getAllPermissions: builder.query({ + query: () => ({ url: apiPaths.getAllPermissions, data: {} }), + providesTags: () => ['permissions'] + }), + blockUser: builder.mutation({ + query: (userId) => ({ url: apiPaths.blockUser, data: { userId } }), + invalidatesTags: () => ['users'] + }), + deleteUser: builder.mutation({ + query: (userId) => ({ + url: apiPaths.deleteUser, + data: { ids: [userId] } + }), + invalidatesTags: () => ['users'] + }), + createUser: builder.mutation({ + query: (newUser) => ({ + url: apiPaths.createUser, + data: newUser + }), + invalidatesTags: ['users'] + }), + + updateUser: builder.mutation>({ + query: (user) => ({ + url: apiPaths.updateUser, + data: user + }), + invalidatesTags: ['users'] + }) + }) +}) + +export default userServiceApi diff --git a/src/stores/index.tsx b/src/stores/index.tsx index 65be389..fb7f3b8 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -6,6 +6,7 @@ import { createContext, Dispatch, SetStateAction } from 'react' import accessListApi from '@services/accessListService.ts' import appApi from '@services/appService.ts' import roleApi from '@services/roleService.ts' +import userServiceApi from '@services/userService.ts' import routeApi from '@services/routeService.ts' import profileReducer from './redusers/ProfileSlice.ts' @@ -24,6 +25,7 @@ export const Context = createContext({ const rootReducer = combineReducers({ profileReducer, [roleApi.reducerPath]: roleApi.reducer, + [userServiceApi.reducerPath]: userServiceApi.reducer, [appApi.reducerPath]: appApi.reducer, [accessListApi.reducerPath]: accessListApi.reducer, [routeApi.reducerPath]: routeApi.reducer @@ -37,7 +39,8 @@ export const setupStore = () => roleApi.middleware, appApi.middleware, accessListApi.middleware, - routeApi.middleware + routeApi.middleware, + userServiceApi.middleware ) }) From f908f2c7ebc0a754cbd48d3b249d584dd97dedf2 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 12 Apr 2024 15:46:49 +0300 Subject: [PATCH 07/39] MSP-3105 add UsersPage --- src/pages/UsersPage/index.tsx | 222 ++++++++++++++++++++++++++++ src/pages/UsersPage/users-page.scss | 70 +++++++++ 2 files changed, 292 insertions(+) create mode 100644 src/pages/UsersPage/index.tsx create mode 100644 src/pages/UsersPage/users-page.scss diff --git a/src/pages/UsersPage/index.tsx b/src/pages/UsersPage/index.tsx new file mode 100644 index 0000000..3aa2508 --- /dev/null +++ b/src/pages/UsersPage/index.tsx @@ -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 + } + + const columns: ColumnsType = [ + { + 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) => ( +
+ {label} +
+ )) + } + }, + { + title: 'Последняя сессия', + dataIndex: 'lastSessionCreatedAt', + key: 'lastSessionCreatedAt', + render: (value: string) => + value ? new Date(value).toLocaleDateString() : '' + }, + { + dataIndex: 'actions', + key: 'actions', + render: (_, record) => { + const blockTitle = record.blocked + ? 'Вы действительно хотите разблокировать этого пользователя?' + : 'Вы действительно хотите заблокировать этого пользователя?' + return ( +
+ {hasBlockUserPermission && ( + handleBlockUser(record.id)} + > +
+ ) + } + } + ] + + return ( +
+
+ + Пользователи + + +
+
+
+ record.id} + pagination={false} + dataSource={allUsers} + columns={columns} + /> + + + + ) +} + +export default UsersPage diff --git a/src/pages/UsersPage/users-page.scss b/src/pages/UsersPage/users-page.scss new file mode 100644 index 0000000..b9e9a36 --- /dev/null +++ b/src/pages/UsersPage/users-page.scss @@ -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; + } + } +} From 58075955dc1f1b2e519542bca702847dfd79a74b Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Wed, 17 Apr 2024 18:30:39 +0300 Subject: [PATCH 08/39] MSP-3105 add navigate in menu in LayoutComponent and add Route in Routers --- src/components/Layout/index.tsx | 6 ++++-- src/routes/Routers/index.tsx | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 9a5aa6e..0ea7e94 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -29,14 +29,13 @@ import './layout.scss' const { Content, Sider } = Layout const LayoutComponent = () => { - const navigate = useNavigate() - const [collapsed, setCollapsed] = useState(false) const [selectedMenuKeys, setSelectedMenuKeys] = useState([]) const [openKeys, setOpenKeys] = useState([]) const dispatch = useAppDispatch() const { status } = useAppSelector((state) => state.profileReducer) const location = useLocation() + const navigate = useNavigate() const { hasPermission } = useRole() const { theme } = useContext(ConfigProvider.ConfigContext) @@ -103,6 +102,9 @@ const LayoutComponent = () => { const handlerOnClickMenu = ({ key }: any): void => { switch (key) { + case MenuItemKeysType.users: + navigate(routePaths.users) + break case MenuItemKeysType.appAccess: navigate(routePaths.appAccess) break diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index c5f233d..b007043 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -12,6 +12,7 @@ import { routePaths } from '@routes/routePaths.ts' const LoginPage = lazy(() => import('@pages/LoginPage')) const ErrorPage = lazy(() => import('@components/ErrorPage')) const ProfilePage = lazy(() => import('@pages/ProfilePage')) +const UsersPage = lazy(() => import('@pages/UsersPage')) const AppAccessPage = lazy(() => import('@pages/AppAccessPage')) const Routers = () => { @@ -52,6 +53,14 @@ const Routers = () => { } /> + }> + + + } + /> Date: Mon, 15 Apr 2024 09:22:33 +0300 Subject: [PATCH 09/39] MSP-3105 add roleUtils in utils --- src/utils/roleUtils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/utils/roleUtils.ts diff --git a/src/utils/roleUtils.ts b/src/utils/roleUtils.ts new file mode 100644 index 0000000..e785958 --- /dev/null +++ b/src/utils/roleUtils.ts @@ -0,0 +1,16 @@ +import { RoleType } from '@type/roles.type.ts' + +export const findExclusiveRole = ( + roles: RoleType[], + watchRoles: number[] = [] +) => { + let firstExclusiveElement = null + for (let i = 0; i < roles.length; i++) { + const item = roles[i] + if (item.exclusive === true && watchRoles.includes(item.id)) { + firstExclusiveElement = item + break + } + } + return firstExclusiveElement +} From 8cd3b86a2c71486a1173d4dadc12d6fee9e81467 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 09:23:40 +0300 Subject: [PATCH 10/39] MSP-3105 create UserEditor --- src/pages/UserEditor/index.tsx | 230 ++++++++++++++++++++++++++ src/pages/UserEditor/user-editor.scss | 66 ++++++++ 2 files changed, 296 insertions(+) create mode 100644 src/pages/UserEditor/index.tsx create mode 100644 src/pages/UserEditor/user-editor.scss diff --git a/src/pages/UserEditor/index.tsx b/src/pages/UserEditor/index.tsx new file mode 100644 index 0000000..7f3227c --- /dev/null +++ b/src/pages/UserEditor/index.tsx @@ -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({ + 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( + <> + Роль: {exclusiveRole.name} несовместима с + другими ролями + + ) + } + 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 + } + return ( +
+
+
+ +
+ + {isNew ? ( + '' + ) : ( + + {state.lastSessionCreatedAt && ( + <> + Последняя сессия   + {new Date(state.lastSessionCreatedAt).toLocaleDateString()} +   + {new Date(state.lastSessionCreatedAt).toLocaleTimeString()} + + )} + + )} +
+ +
+
+
+ +
+
+ +
+
+ +
+ + {isNew && ( +
+ +
+ )} + +
+ +
+
+ +
+ ) +} +export default UserEditor diff --git a/src/pages/UserEditor/user-editor.scss b/src/pages/UserEditor/user-editor.scss new file mode 100644 index 0000000..2b5f2a4 --- /dev/null +++ b/src/pages/UserEditor/user-editor.scss @@ -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 + } + } + } +} From d719e2207f597eff82f4baa8b98c2be8fb2d379f Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 09:24:37 +0300 Subject: [PATCH 11/39] MSP-3105 add Route in Routers --- src/routes/Routers/index.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index b007043..bee770e 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -13,6 +13,7 @@ const LoginPage = lazy(() => import('@pages/LoginPage')) const ErrorPage = lazy(() => import('@components/ErrorPage')) const ProfilePage = lazy(() => import('@pages/ProfilePage')) const UsersPage = lazy(() => import('@pages/UsersPage')) +const UserEditor = lazy(() => import('src/pages/UserEditor')) const AppAccessPage = lazy(() => import('@pages/AppAccessPage')) const Routers = () => { @@ -36,6 +37,22 @@ const Routers = () => { } /> + }> + + + } + /> + }> + + + } + /> { } /> - }> - - - } - /> Date: Mon, 15 Apr 2024 09:26:32 +0300 Subject: [PATCH 12/39] MSP-3105 up version to 0.5.0 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1fb188..70f5b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.5.0 +- Добавлена страница 'Пользователи' и страница редактирования пользователя ## 0.4.0 - Добавлен экран управления доступами приложений - Исправлены корневые стили приложения diff --git a/package.json b/package.json index 34396f7..672ea0a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.4.0", + "version": "0.5.0", "type": "module", "scripts": { "start": "vite", From 89d719e8ebf0f9b9b407208ae124c6c2878056cd Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:09:48 +0300 Subject: [PATCH 13/39] MSP-3174 add paths in apiPaths --- src/constants/api/apiPaths.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index 0246857..14a32e4 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -18,6 +18,9 @@ type PathKeys = | 'getAllPermissions' | 'baseUserUrl' | 'baseAdminUrl' + | 'getAllLogs' + | 'getLogEvents' + | 'setLogEvents' | 'getSystemTree' | 'getById' | 'setList' @@ -48,6 +51,10 @@ export const apiPaths: Record = { deleteUser: '/delete_user', getRoles: '/get_roles', getAllPermissions: '/get_permissions', + // ======= LOGS ====== + getAllLogs: '/log/all', + getLogEvents: '/log/events', + setLogEvents: '/log/set_events', // ======= APPLICATIONS ====== getSystemTree: '/application/get_system_tree', // ======= ACCESS_LIST ====== From 99ee80a57921f2b44c0849d2fc45eb041d86cd5e Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Wed, 17 Apr 2024 18:22:15 +0300 Subject: [PATCH 14/39] MSP-3174 add types --- src/components/Layout/layout.type.ts | 5 +++++ src/type/index.ts | 5 +++++ src/type/log.type.ts | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/type/log.type.ts diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index bcd5b94..d7ca27a 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -2,6 +2,7 @@ import { MenuProps } from 'antd' export enum MenuItemKeysType { users = 'users', + securityLog = 'securityLog', appAccess = 'appAccess' } @@ -14,6 +15,10 @@ export const menuKeys: Record = { key: MenuItemKeysType.users, parent: ['sessionManagement'] }, + [MenuItemKeysType.securityLog]: { + key: MenuItemKeysType.securityLog, + parent: ['sessionManagement'] + }, [MenuItemKeysType.appAccess]: { key: MenuItemKeysType.appAccess, parent: [] diff --git a/src/type/index.ts b/src/type/index.ts index d3c4f4c..1acd4ac 100644 --- a/src/type/index.ts +++ b/src/type/index.ts @@ -3,3 +3,8 @@ export interface MSPError { errorCode: string errorMessage: string } + +export interface LimitOffsetRequestType { + limit: number + offset: number +} diff --git a/src/type/log.type.ts b/src/type/log.type.ts new file mode 100644 index 0000000..568bf04 --- /dev/null +++ b/src/type/log.type.ts @@ -0,0 +1,25 @@ +export interface LogResponseType { + totalCount: number + items: LogType[] +} + +export interface LogType { + id: string + userId: string + createdAt: string + message: string +} + +export type LogEventKeyType = + | 'login_logout' + | 'role_changed' + | 'user_changed' + | 'user_blocked' + +export interface LogEventType { + event: LogEventKeyType + name: string + enabled: boolean +} + +export type SetEventType = Omit From 97d878fafb14726910487bbf8ee6046c30c04c58 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:12:14 +0300 Subject: [PATCH 15/39] MSP-3174 add securityLogServiceApi --- src/services/securityLogService.ts | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/services/securityLogService.ts diff --git a/src/services/securityLogService.ts b/src/services/securityLogService.ts new file mode 100644 index 0000000..8f25bbe --- /dev/null +++ b/src/services/securityLogService.ts @@ -0,0 +1,31 @@ +import { createApi } from '@reduxjs/toolkit/query/react' + +import { apiPaths } from '@constants/api/apiPaths' + +import { axiosBaseQuery } from '@utils/apiUtils' + +import { LimitOffsetRequestType } from '@type/index.ts' +import { LogEventType, LogResponseType, SetEventType } from '@type/log.type' + +const securityLogServiceApi = createApi({ + reducerPath: 'securityLogService', + refetchOnFocus: true, + tagTypes: ['logs', 'events'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseAdminUrl }), + endpoints: (builder) => ({ + getAllLogs: builder.mutation({ + query: (request) => ({ url: apiPaths.getAllLogs, data: request }), + invalidatesTags: () => ['logs'] + }), + getLogEvents: builder.query({ + query: () => ({ url: apiPaths.getLogEvents }), + providesTags: () => ['events'] + }), + setLogEvents: builder.mutation({ + query: (request) => ({ url: apiPaths.setLogEvents, data: request }), + invalidatesTags: () => ['events'] + }) + }) +}) + +export default securityLogServiceApi From bdb2805844b461a717f7a42e838110b54580b15d Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:13:19 +0300 Subject: [PATCH 16/39] MSP-3174 add SecurityLogPage --- src/pages/SecurityLogPage/index.tsx | 126 ++++++++++++++++++ .../SecurityLogPage/security-log-page.scss | 36 +++++ 2 files changed, 162 insertions(+) create mode 100644 src/pages/SecurityLogPage/index.tsx create mode 100644 src/pages/SecurityLogPage/security-log-page.scss diff --git a/src/pages/SecurityLogPage/index.tsx b/src/pages/SecurityLogPage/index.tsx new file mode 100644 index 0000000..d1b70c1 --- /dev/null +++ b/src/pages/SecurityLogPage/index.tsx @@ -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 + } + + const columns: ColumnsType = [ + { + 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) =>

{line}

) + } + ] + + const { totalCount, items } = data + + return ( +
+
+ + Просмотр журналов ИБ + +
+
+
+
record.id} + pagination={false} + dataSource={items} + columns={columns} + /> + +
+ +
+ + + ) +} + +export default SecurityLogPage diff --git a/src/pages/SecurityLogPage/security-log-page.scss b/src/pages/SecurityLogPage/security-log-page.scss new file mode 100644 index 0000000..078a3f5 --- /dev/null +++ b/src/pages/SecurityLogPage/security-log-page.scss @@ -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; + } + + } +} From 2977dfdce7cc1af0e13382a49b1d73975dde54b3 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:14:16 +0300 Subject: [PATCH 17/39] MSP-3174 add securityLogServiceApi in store --- src/stores/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stores/index.tsx b/src/stores/index.tsx index fb7f3b8..7ab020d 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -6,12 +6,12 @@ import { createContext, Dispatch, SetStateAction } from 'react' import accessListApi from '@services/accessListService.ts' import appApi from '@services/appService.ts' import roleApi from '@services/roleService.ts' +import securityLogServiceApi from '@services/securityLogService.ts' import userServiceApi from '@services/userService.ts' import routeApi from '@services/routeService.ts' import profileReducer from './redusers/ProfileSlice.ts' - export interface ContextProps { setTheme: Dispatch< SetStateAction<{ algorithm: (token: SeedToken) => MapToken }> @@ -26,6 +26,7 @@ const rootReducer = combineReducers({ profileReducer, [roleApi.reducerPath]: roleApi.reducer, [userServiceApi.reducerPath]: userServiceApi.reducer, + [securityLogServiceApi.reducerPath]: securityLogServiceApi.reducer, [appApi.reducerPath]: appApi.reducer, [accessListApi.reducerPath]: accessListApi.reducer, [routeApi.reducerPath]: routeApi.reducer @@ -37,6 +38,8 @@ export const setupStore = () => middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat( roleApi.middleware, + userServiceApi.middleware, + securityLogServiceApi.middleware, appApi.middleware, accessListApi.middleware, routeApi.middleware, From 5a16c69e54808a7484b050affd8d3b4d3464c4b2 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:14:59 +0300 Subject: [PATCH 18/39] MSP-3174 add Route in Routers --- src/routes/Routers/index.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index bee770e..f7d2bea 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -14,6 +14,7 @@ const ErrorPage = lazy(() => import('@components/ErrorPage')) const ProfilePage = lazy(() => import('@pages/ProfilePage')) const UsersPage = lazy(() => import('@pages/UsersPage')) const UserEditor = lazy(() => import('src/pages/UserEditor')) +const SecurityLogPage = lazy(() => import('@pages/SecurityLogPage')) const AppAccessPage = lazy(() => import('@pages/AppAccessPage')) const Routers = () => { @@ -70,6 +71,14 @@ const Routers = () => { } /> + }> + + + } + /> Date: Wed, 17 Apr 2024 18:07:50 +0300 Subject: [PATCH 19/39] MSP-3174 add securityLog in menu in LayoutComponent --- src/components/Layout/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 0ea7e94..2fd1b37 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -68,6 +68,11 @@ const LayoutComponent = () => { label: 'Пользователи', key: 'users', className: hideItem(PermissionKeysType.read) + }, + { + label: 'Просмотр журналов ИБ', + key: 'securityLog', + className: hideItem(PermissionKeysType.read) } ] } @@ -105,6 +110,9 @@ const LayoutComponent = () => { case MenuItemKeysType.users: navigate(routePaths.users) break + case MenuItemKeysType.securityLog: + navigate(routePaths.securityLog) + break case MenuItemKeysType.appAccess: navigate(routePaths.appAccess) break From f7a39dfd1c3f6718b0f93098e8734cf049058ae0 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 20:16:57 +0300 Subject: [PATCH 20/39] MSP-3174 up version to 0.6.0 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f5b2b..124d170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.6.0 +- Добавлена страница 'Просмотр журналов ИБ' ## 0.5.0 - Добавлена страница 'Пользователи' и страница редактирования пользователя ## 0.4.0 diff --git a/package.json b/package.json index 672ea0a..5af6367 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.5.0", + "version": "0.6.0", "type": "module", "scripts": { "start": "vite", From ba16e7a35d8b1f186c3e9c0b1addaa6c1163b2a0 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 10:55:37 +0300 Subject: [PATCH 21/39] MSP-3173 add statuses in type --- src/constants/statuses.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/constants/statuses.ts diff --git a/src/constants/statuses.ts b/src/constants/statuses.ts new file mode 100644 index 0000000..2720611 --- /dev/null +++ b/src/constants/statuses.ts @@ -0,0 +1,11 @@ +export enum SessionStatusKeysType { + allowed = 'ALLOWED', + revoked = 'REVOKED', + expired = 'EXPIRED' +} + +export const sessionStatuses: Record = { + [SessionStatusKeysType.allowed]: 'Активная', + [SessionStatusKeysType.revoked]: 'Отмененная', + [SessionStatusKeysType.expired]: 'Истекшая' +} From 859ed3b2d08f56f4569515cd58de171a35c43573 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 10:59:15 +0300 Subject: [PATCH 22/39] MSP-3173 add paths in apiPaths --- src/constants/api/apiPaths.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index 14a32e4..1149e8c 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -18,6 +18,8 @@ type PathKeys = | 'getAllPermissions' | 'baseUserUrl' | 'baseAdminUrl' + | 'getAllSession' + | 'revokeSession' | 'getAllLogs' | 'getLogEvents' | 'setLogEvents' @@ -51,6 +53,9 @@ export const apiPaths: Record = { deleteUser: '/delete_user', getRoles: '/get_roles', getAllPermissions: '/get_permissions', + // ======= SESSIONS ====== + getAllSession: '/session/all', + revokeSession: '/session/revoke', // ======= LOGS ====== getAllLogs: '/log/all', getLogEvents: '/log/events', From ca4975dee76706a641fe5a7d39d3b5671e624b2b Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:06:07 +0300 Subject: [PATCH 23/39] MSP-3173 add types --- src/components/Layout/layout.type.ts | 5 +++++ src/type/session.type.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/type/session.type.ts diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index d7ca27a..e74d286 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -2,6 +2,7 @@ import { MenuProps } from 'antd' export enum MenuItemKeysType { users = 'users', + sessions = 'sessions', securityLog = 'securityLog', appAccess = 'appAccess' } @@ -15,6 +16,10 @@ export const menuKeys: Record = { key: MenuItemKeysType.users, parent: ['sessionManagement'] }, + [MenuItemKeysType.sessions]: { + key: MenuItemKeysType.sessions, + parent: ['sessionManagement'] + }, [MenuItemKeysType.securityLog]: { key: MenuItemKeysType.securityLog, parent: ['sessionManagement'] diff --git a/src/type/session.type.ts b/src/type/session.type.ts new file mode 100644 index 0000000..4cab19e --- /dev/null +++ b/src/type/session.type.ts @@ -0,0 +1,14 @@ +import { SessionStatusKeysType } from '@constants/statuses' + +export interface SessionType { + userId: string + createdAt: string + expiredAt: string + id: number + status: SessionStatusKeysType +} + +export interface SessionResponseType { + totalCount: number + items: SessionType[] +} From 65e61988076ee3ebe4e7e0bad6c4a4dd34b47f83 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:07:38 +0300 Subject: [PATCH 24/39] MSP-3173 add sessionServiceApi --- src/services/sessionService.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/services/sessionService.ts diff --git a/src/services/sessionService.ts b/src/services/sessionService.ts new file mode 100644 index 0000000..cece62e --- /dev/null +++ b/src/services/sessionService.ts @@ -0,0 +1,27 @@ +import { createApi } from '@reduxjs/toolkit/query/react' + +import { apiPaths } from '@constants/api/apiPaths' + +import { axiosBaseQuery } from '@utils/apiUtils' + +import { LimitOffsetRequestType } from '@type/index.ts' +import { SessionResponseType } from '@type/session.type' + +const sessionServiceApi = createApi({ + reducerPath: 'sessionService', + refetchOnFocus: true, + tagTypes: ['sessions'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseAdminUrl }), + endpoints: (builder) => ({ + getAllSessions: builder.query({ + query: (request) => ({ url: apiPaths.getAllSession, data: request }), + providesTags: () => ['sessions'] + }), + revokeSession: builder.mutation({ + query: (id) => ({ url: apiPaths.revokeSession, data: { id } }), + invalidatesTags: () => ['sessions'] + }) + }) +}) + +export default sessionServiceApi From ddf4388250170ec243fbcdff9f94f40da19dd7b9 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:11:52 +0300 Subject: [PATCH 25/39] MSP-3173 add style for SessionsPage --- src/pages/SessionsPage/sessions-page.scss | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/pages/SessionsPage/sessions-page.scss diff --git a/src/pages/SessionsPage/sessions-page.scss b/src/pages/SessionsPage/sessions-page.scss new file mode 100644 index 0000000..3978107 --- /dev/null +++ b/src/pages/SessionsPage/sessions-page.scss @@ -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; + } + } +} From 1916bac98b4d811c338263ae9b87170734e5db09 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:13:11 +0300 Subject: [PATCH 26/39] MSP-3173 add SessionsPage --- src/pages/SessionsPage/index.tsx | 172 +++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 src/pages/SessionsPage/index.tsx diff --git a/src/pages/SessionsPage/index.tsx b/src/pages/SessionsPage/index.tsx new file mode 100644 index 0000000..882fd91 --- /dev/null +++ b/src/pages/SessionsPage/index.tsx @@ -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(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 + } + + const columns: ColumnsType = [ + { + 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 && ( + handleRevokeSessions(record.id)} + > +
record.id} + pagination={false} + dataSource={items} + columns={columns} + /> + +
+ +
+ + + ) +} + +export default SessionsPage From d9499fe5d0cc55b182d1c660a60e7160d3ee13a3 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:13:37 +0300 Subject: [PATCH 27/39] MSP-3173 add sessionServiceApi in store --- src/stores/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stores/index.tsx b/src/stores/index.tsx index 7ab020d..2e37302 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -3,6 +3,7 @@ import { theme } from 'antd' import { MapToken, SeedToken } from 'antd/es/theme/interface' import { createContext, Dispatch, SetStateAction } from 'react' +import sessionServiceApi from '@services/sessionService.ts' import accessListApi from '@services/accessListService.ts' import appApi from '@services/appService.ts' import roleApi from '@services/roleService.ts' @@ -26,6 +27,7 @@ const rootReducer = combineReducers({ profileReducer, [roleApi.reducerPath]: roleApi.reducer, [userServiceApi.reducerPath]: userServiceApi.reducer, + [sessionServiceApi.reducerPath]: sessionServiceApi.reducer, [securityLogServiceApi.reducerPath]: securityLogServiceApi.reducer, [appApi.reducerPath]: appApi.reducer, [accessListApi.reducerPath]: accessListApi.reducer, @@ -43,7 +45,8 @@ export const setupStore = () => appApi.middleware, accessListApi.middleware, routeApi.middleware, - userServiceApi.middleware + userServiceApi.middleware, + sessionServiceApi.middleware ) }) From 88da3bb572a8a5001d3d12c05a9869b4d8b39eee Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:14:00 +0300 Subject: [PATCH 28/39] MSP-3173 add Route in Routers --- src/routes/Routers/index.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index f7d2bea..a0151c6 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -14,6 +14,7 @@ const ErrorPage = lazy(() => import('@components/ErrorPage')) const ProfilePage = lazy(() => import('@pages/ProfilePage')) const UsersPage = lazy(() => import('@pages/UsersPage')) const UserEditor = lazy(() => import('src/pages/UserEditor')) +const SessionsPage = lazy(() => import('@pages/SessionsPage')) const SecurityLogPage = lazy(() => import('@pages/SecurityLogPage')) const AppAccessPage = lazy(() => import('@pages/AppAccessPage')) @@ -54,6 +55,22 @@ const Routers = () => { } /> + }> + + + } + /> + }> + + + } + /> { } /> - }> - - - } - /> Date: Mon, 15 Apr 2024 11:14:49 +0300 Subject: [PATCH 29/39] MSP-3173 add sessions in menu in LayoutComponent --- src/components/Layout/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 2fd1b37..9dd4b90 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -69,6 +69,11 @@ const LayoutComponent = () => { key: 'users', className: hideItem(PermissionKeysType.read) }, + { + label: 'Пользовательские сессии', + key: 'sessions', + className: hideItem(PermissionKeysType.read) + }, { label: 'Просмотр журналов ИБ', key: 'securityLog', @@ -110,6 +115,9 @@ const LayoutComponent = () => { case MenuItemKeysType.users: navigate(routePaths.users) break + case MenuItemKeysType.sessions: + navigate(routePaths.sessions) + break case MenuItemKeysType.securityLog: navigate(routePaths.securityLog) break From 507da4b30dbcbcdd6944eb50b7ac7b10c84f33ce Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Mon, 15 Apr 2024 11:26:46 +0300 Subject: [PATCH 30/39] MSP-3173 up version to 0.7.0 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 124d170..b36679b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.7.0 +- Добавлена страница 'Сессии' ## 0.6.0 - Добавлена страница 'Просмотр журналов ИБ' ## 0.5.0 diff --git a/package.json b/package.json index 5af6367..0902f78 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.6.0", + "version": "0.7.0", "type": "module", "scripts": { "start": "vite", From 43cfa9392e798f5507602d3ab1dd86c011e06cd7 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 19 Apr 2024 09:57:16 +0300 Subject: [PATCH 31/39] MSP-3172 add react-resizable and simplebar-react in package.json --- package-lock.json | 64 +++++++++++++++++++++++++++++++++++++++++++---- package.json | 6 ++++- src/index.tsx | 2 +- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 759fb9c..2b2868a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isp-admin-ui", - "version": "0.3.1", + "version": "0.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isp-admin-ui", - "version": "0.3.1", + "version": "0.8.0", "dependencies": { "@reduxjs/toolkit": "^2.2.3", "@types/react-router-dom": "^5.3.3", @@ -16,13 +16,17 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", "react-redux": "^9.1.0", - "react-router-dom": "^6.22.3" + "react-resizable": "^3.0.5", + "react-router-dom": "^6.22.3", + "simplebar": "^6.2.5", + "simplebar-react": "^3.2.4" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/node": "^20.12.4", "@types/react": "^18.2.74", "@types/react-dom": "^18.2.24", + "@types/react-resizable": "^3.0.7", "@typescript-eslint/eslint-plugin": "^7.5.0", "@typescript-eslint/parser": "^7.5.0", "@vitejs/plugin-legacy": "^5.3.2", @@ -3916,6 +3920,15 @@ "@types/react": "*" } }, + "node_modules/@types/react-resizable": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/@types/react-resizable/-/react-resizable-3.0.7.tgz", + "integrity": "sha512-V4N7/xDUME+cxKya/A73MmFrHofTupVdE45boRxeA8HL4Q5pJh3AuG0FWCEy2GB84unIMSRISyEAS/GHWum9EQ==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/react-router": { "version": "5.1.20", "resolved": "https://registry.npmjs.org/@types/react-router/-/react-router-5.1.20.tgz", @@ -4902,6 +4915,14 @@ "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" }, + "node_modules/clsx": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz", + "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==", + "engines": { + "node": ">=6" + } + }, "node_modules/codemirror": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.1.tgz", @@ -8438,6 +8459,19 @@ "react": "^18.2.0" } }, + "node_modules/react-draggable": { + "version": "4.4.6", + "resolved": "https://registry.npmjs.org/react-draggable/-/react-draggable-4.4.6.tgz", + "integrity": "sha512-LtY5Xw1zTPqHkVmtM3X8MUOxNDOUhv/khTgBgrUvwaS064bwVvxT+q5El0uUFNx5IEPKXuRejr7UqLwBIg5pdw==", + "dependencies": { + "clsx": "^1.1.1", + "prop-types": "^15.8.1" + }, + "peerDependencies": { + "react": ">= 16.3.0", + "react-dom": ">= 16.3.0" + } + }, "node_modules/react-hook-form": { "version": "7.51.2", "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.2.tgz", @@ -8456,8 +8490,7 @@ "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "node_modules/react-redux": { "version": "9.1.0", @@ -8494,6 +8527,18 @@ "node": ">=0.10.0" } }, + "node_modules/react-resizable": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/react-resizable/-/react-resizable-3.0.5.tgz", + "integrity": "sha512-vKpeHhI5OZvYn82kXOs1bC8aOXktGU5AmKAgaZS4F5JPburCtbmDPqE7Pzp+1kN4+Wb81LlF33VpGwWwtXem+w==", + "dependencies": { + "prop-types": "15.x", + "react-draggable": "^4.0.3" + }, + "peerDependencies": { + "react": ">= 16.3" + } + }, "node_modules/react-router": { "version": "6.22.3", "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.22.3.tgz", @@ -8968,6 +9013,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/simplebar": { + "version": "6.2.5", + "resolved": "https://registry.npmjs.org/simplebar/-/simplebar-6.2.5.tgz", + "integrity": "sha512-vfxKR6KNBsPx7+sZnqO7T8VuCvi4px6OlycrrkNgyjvoHhRW7LIyVkHhUfXxbz33Gw99Wb9UMMsnEZv35wtLSw==", + "dependencies": { + "can-use-dom": "^0.1.0", + "simplebar-core": "^1.2.4" + } + }, "node_modules/simplebar-core": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/simplebar-core/-/simplebar-core-1.2.4.tgz", diff --git a/package.json b/package.json index 0902f78..7508482 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,17 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", "react-redux": "^9.1.0", - "react-router-dom": "^6.22.3" + "react-resizable": "^3.0.5", + "react-router-dom": "^6.22.3", + "simplebar": "^6.2.5", + "simplebar-react": "^3.2.4" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/node": "^20.12.4", "@types/react": "^18.2.74", "@types/react-dom": "^18.2.24", + "@types/react-resizable": "^3.0.7", "@typescript-eslint/eslint-plugin": "^7.5.0", "@typescript-eslint/parser": "^7.5.0", "@vitejs/plugin-legacy": "^5.3.2", diff --git a/src/index.tsx b/src/index.tsx index 17e575d..4b578e6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,9 +7,9 @@ import App from './components/App.tsx' import { setupStore } from './stores' +import 'react-resizable/css/styles.css' import 'simplebar-react/dist/simplebar.min.css' - const store = setupStore() setupListeners(store.dispatch) const root = createRoot(document.getElementById('root') as HTMLElement) From 45e7cf96dab06bb7341124dad3a910481293a150 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 19 Apr 2024 10:02:06 +0300 Subject: [PATCH 32/39] MSP-3172 add className wrap in app.scss --- src/components/Layout/layout.scss | 7 ------- src/components/app.scss | 5 +++++ src/pages/ProfilePage/index.tsx | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/Layout/layout.scss b/src/components/Layout/layout.scss index 3094efe..d13f3a9 100644 --- a/src/components/Layout/layout.scss +++ b/src/components/Layout/layout.scss @@ -72,13 +72,6 @@ padding-left: 15px; } - - .site-layout { - - &__content { - padding: $basic-padding * 2; - } - } } .user-menu { diff --git a/src/components/app.scss b/src/components/app.scss index 7f1477f..6095f4b 100644 --- a/src/components/app.scss +++ b/src/components/app.scss @@ -13,3 +13,8 @@ min-height: 0; min-width: 500px; } + +.wrap { + padding: 2 * $basic-padding; + border: 1px solid #F0F0F0; +} diff --git a/src/pages/ProfilePage/index.tsx b/src/pages/ProfilePage/index.tsx index d6d792d..0ae9f02 100644 --- a/src/pages/ProfilePage/index.tsx +++ b/src/pages/ProfilePage/index.tsx @@ -18,7 +18,7 @@ const ProfilePage = () => { const { logoutUser, isLoading } = useLogout() return ( -
+
setIsModalOpen(false)} open={isModalOpen} From c7c56e8e7b45bb0c838361784e94e7c69428a1b1 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 19 Apr 2024 10:09:08 +0300 Subject: [PATCH 33/39] MSP-3172 add constant in styleConst --- src/constants/style/styleConst.scss | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/constants/style/styleConst.scss b/src/constants/style/styleConst.scss index 9b32063..b3322d9 100644 --- a/src/constants/style/styleConst.scss +++ b/src/constants/style/styleConst.scss @@ -14,4 +14,5 @@ $error-red: #cf1322; $border-color: #F0F0F0; $blue-color: #40A9FF; -$blue-light: #E6F7FF; \ No newline at end of file +$blue-light: #E6F7FF; +$text-color-blue: #1890FF; \ No newline at end of file From 9d3c39befd5fae9b20a0a4db01c348b1995772f7 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Fri, 19 Apr 2024 10:18:25 +0300 Subject: [PATCH 34/39] MSP-3172 add AgreementModal --- .../AgreementModal/agreement-modal.scss | 8 +++ .../AgreementModal/agreement-modal.type.ts | 7 +++ src/widgets/AgreementModal/index.tsx | 51 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/widgets/AgreementModal/agreement-modal.scss create mode 100644 src/widgets/AgreementModal/agreement-modal.type.ts create mode 100644 src/widgets/AgreementModal/index.tsx diff --git a/src/widgets/AgreementModal/agreement-modal.scss b/src/widgets/AgreementModal/agreement-modal.scss new file mode 100644 index 0000000..b4a5050 --- /dev/null +++ b/src/widgets/AgreementModal/agreement-modal.scss @@ -0,0 +1,8 @@ +@import "../../constants/style/styleConst"; + +.agreement-modal { + &__description { + display: inline-block; + margin-bottom: $basic-margin; + } +} diff --git a/src/widgets/AgreementModal/agreement-modal.type.ts b/src/widgets/AgreementModal/agreement-modal.type.ts new file mode 100644 index 0000000..e2ba3d6 --- /dev/null +++ b/src/widgets/AgreementModal/agreement-modal.type.ts @@ -0,0 +1,7 @@ +import { ModalProps } from 'antd' + +export type AgreementModalPropsType = ModalProps & { + description: string + showTextArea?: boolean + onConfirm: (message: string) => void +} diff --git a/src/widgets/AgreementModal/index.tsx b/src/widgets/AgreementModal/index.tsx new file mode 100644 index 0000000..1f813b2 --- /dev/null +++ b/src/widgets/AgreementModal/index.tsx @@ -0,0 +1,51 @@ +import { Input, Modal } from 'antd' +import { ChangeEvent, useState } from 'react' + +import { AgreementModalPropsType } from '@widgets/AgreementModal/agreement-modal.type.ts' + +import './agreement-modal.scss' + +const { TextArea } = Input + +const AgreementModal = ({ + description, + onConfirm, + showTextArea = true, + ...rest +}: AgreementModalPropsType) => { + const [message, setMessage] = useState('') + + const handleOnChange = (e: ChangeEvent) => { + setMessage(e.target.value) + } + + const handleOnOk = () => { + onConfirm(message) + } + + return ( + + + {description} + + {showTextArea && ( +