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; + } + + } +}