diff --git a/CHANGELOG.md b/CHANGELOG.md index 89465ac..d3e6efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.9.0 +-Добавлена страница приложений ## 0.8.1 - Перенос UserMenu в список главного меню в Layout ## 0.8.0 diff --git a/package-lock.json b/package-lock.json index 2b2868a..b7f65f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "isp-admin-ui", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "isp-admin-ui", - "version": "0.8.0", + "version": "0.8.1", "dependencies": { "@reduxjs/toolkit": "^2.2.3", "@types/react-router-dom": "^5.3.3", "axios": "^1.6.8", - "isp-ui-kit": "https://github.com/txix-open/isp-ui-kit", + "isp-ui-kit": "github:txix-open/isp-ui-kit", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", @@ -7055,8 +7055,8 @@ "dev": true }, "node_modules/isp-ui-kit": { - "version": "0.3.3", - "resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#508a5bd9cb4efac0e9389ad2f9f8c60683d1712e", + "version": "0.3.4", + "resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#ee517a533f9e4934d08bf6d70cdfda31198cba4c", "license": "ISC", "dependencies": { "@codemirror/lang-javascript": "^6.2.1", @@ -7430,7 +7430,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -7810,7 +7809,6 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "dev": true, "dependencies": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", diff --git a/package.json b/package.json index 97da8fc..4c7381c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.8.1", + "version": "0.9.0", "type": "module", "scripts": { "start": "vite", @@ -17,7 +17,7 @@ "@reduxjs/toolkit": "^2.2.3", "@types/react-router-dom": "^5.3.3", "axios": "^1.6.8", - "isp-ui-kit": "https://github.com/txix-open/isp-ui-kit", + "isp-ui-kit": "github:txix-open/isp-ui-kit", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", diff --git a/src/components/ApplicationsContent/applications-content.scss b/src/components/ApplicationsContent/applications-content.scss new file mode 100644 index 0000000..ed9183c --- /dev/null +++ b/src/components/ApplicationsContent/applications-content.scss @@ -0,0 +1,19 @@ +@import "src/constants/style/styleConst"; + +.applications-content { + padding: $basic-padding *2 $basic-padding; + display: flex; + flex-direction: column; + &__add-btn { + max-width: 240px; + margin-left: auto; + margin-bottom: $basic-margin * 2; + } + &__update-btn { + margin-right: $basic-margin; + } + &__addToken-btn { + display: flex; + margin: 0 auto; + } +} \ No newline at end of file diff --git a/src/components/ApplicationsContent/index.tsx b/src/components/ApplicationsContent/index.tsx new file mode 100644 index 0000000..941472f --- /dev/null +++ b/src/components/ApplicationsContent/index.tsx @@ -0,0 +1,360 @@ +import { + EditOutlined, + DeleteOutlined, + PlusSquareOutlined +} from '@ant-design/icons' +import { Button, message, Spin, Table } from 'antd' +import { ColumnsType } from 'antd/es/table' +import { FormComponents } from 'isp-ui-kit' +import { EmptyData } from 'isp-ui-kit/dist/Layout' +import { FC, useState } from 'react' +import { useForm } from 'react-hook-form' + +import { ValidationRules } from '@constants/form/validationRules.ts' + +import Modal from '@widgets/Modal' + +import CanEdit from '@components/CanEdit' + +import { + ApplicationAppType, + ApplicationsServiceType, + ApplicationTokenType, + NewApplicationAppType, + NewApplicationTokenType, + UpdateApplicationAppType +} from '@pages/ApplicationsPage/applications.type.ts' + +import applicationsApi from '@services/applicationsService.ts' +import tokensApi from '@services/tokensService.ts' + +import './applications-content.scss' + +const { FormInput, FormSelect } = FormComponents + +interface ApplicationsContentPropTypes { + id: number +} + +const ApplicationsContent: FC = (id) => { + const { data: applications, isLoading: isLoadingApplicationsContent = [] } = + applicationsApi.useGetApplicationsByServiceIdQuery(id) + + const [createApplicationService] = + applicationsApi.useCreateApplicationServiceMutation() + const [updateApplication] = + applicationsApi.useUpdateApplicationsServiceMutation() + const [removeApplicationsService] = + applicationsApi.useRemoveApplicationsServiceMutation() + const [createToken] = tokensApi.useCreateTokenMutation() + const [showApplicationsModal, setShowApplicationsModal] = useState({ + addModal: false, + updateModal: false, + addToken: false + }) + const [currentApplicationsApp, setCurrentApplicationsApp] = + useState() + + const { + handleSubmit, + control: controlApplicationApp, + reset + } = useForm({ + mode: 'onChange' + }) + + const { handleSubmit: handleSubmitTokens, control: controlTokens } = + useForm({ + mode: 'onChange' + }) + + const handleShowUpdateModalApplicationApp = (data: ApplicationAppType) => { + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: true + }) + setCurrentApplicationsApp(data) + } + const handleShowCreateModalApplicationApp = () => { + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: true + }) + } + const handleShowAddModalToken = (data: ApplicationAppType) => { + setShowApplicationsModal({ + ...showApplicationsModal, + addToken: true + }) + setCurrentApplicationsApp(data) + } + + const handleUpdateApplicationApp = (data: UpdateApplicationAppType) => { + if (currentApplicationsApp) { + const updateApplications: UpdateApplicationAppType = { + id: currentApplicationsApp.id, + name: data.name, + description: data.description + ? data.description + : currentApplicationsApp.description, + serviceId: id.id, + type: 'SYSTEM' + } + updateApplication({ ...currentApplicationsApp, ...updateApplications }) + .unwrap() + .then(() => { + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: false + }) + reset() + message.info('Элемент сохранен') + }) + .catch(() => message.error('Ошибка обновления элемента')) + } + } + + const handleCreateApplicationApp = (data: NewApplicationAppType) => { + const newApplicationApp: NewApplicationAppType = { + name: data.name, + description: data.description, + serviceId: id.id, + type: 'SYSTEM' + } + + createApplicationService(newApplicationApp) + .unwrap() + .then(message.info('Элемент сохранен')) + .catch((e) => message.error(e)) + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: false + }) + reset() + } + const handleRemoveApplicationApp = (id: number) => + removeApplicationsService([id]) + .then(() => { + message.info('Элемент удален') + }) + .catch(message.error('Ошибка добавления элемента')) + + const handleCreateToken = (data: NewApplicationTokenType) => { + if (currentApplicationsApp) { + const newToken: NewApplicationTokenType = { + expireTimeMs: data.expireTimeMs, + appId: currentApplicationsApp.id + } + + createToken(newToken) + .then(() => { + setShowApplicationsModal({ + ...showApplicationsModal, + addToken: false + }) + reset() + message.info('Элемент добавлен') + }) + .catch(() => { + message.error('Ошибка добавления элемента') + }) + } + } + + const columns: ColumnsType = [ + { + title: 'id', + dataIndex: ['app', 'id'], + key: 'id' + }, + { + title: 'Наименование', + dataIndex: ['app', 'name'], + key: 'name' + }, + { + title: 'Описание', + dataIndex: ['app', 'description'], + key: 'description' + }, + { + title: 'Type', + dataIndex: ['app', 'type'], + key: 'Type' + }, + { + title: 'Количество токенов', + dataIndex: 'tokens', + key: 'tokensAmount', + render: (value) => { + return value.length + } + }, + { + title: 'Действия', + dataIndex: 'app', + key: 'actions', + render: (record) => { + return ( + + + + ( + + + + ) + }} + className="appliactions-content__table" + rowKey={(record) => record.app.id} + pagination={false} + dataSource={applications} + columns={columns} + /> + + + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: false + }) + } + > +
+ + + +
+ + + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: false + }) + } + > +
+ + + +
+ + + setShowApplicationsModal({ + ...showApplicationsModal, + addToken: false + }) + } + > +
+ + +
+ + ) +} + +export default ApplicationsContent diff --git a/src/components/AdminPermission/index.tsx b/src/components/CanEdit/index.tsx similarity index 62% rename from src/components/AdminPermission/index.tsx rename to src/components/CanEdit/index.tsx index 557861f..a2c9993 100644 --- a/src/components/AdminPermission/index.tsx +++ b/src/components/CanEdit/index.tsx @@ -4,13 +4,13 @@ import { useRole } from '@hooks/useRole.tsx' import { PermissionKeysType } from '@type/roles.type.ts' -const AdminPermission = ({ children }: PropsWithChildren) => { +const CanEdit = ({ children }: PropsWithChildren) => { const { hasPermission } = useRole() - if (hasPermission(PermissionKeysType.read)) { + if (hasPermission(PermissionKeysType.write)) { return <>{children} } return null } -export default AdminPermission +export default CanEdit diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index cb4d411..78b0218 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -1,7 +1,8 @@ import { LockOutlined, LogoutOutlined, - ProfileOutlined + ProfileOutlined, + AppstoreAddOutlined } from '@ant-design/icons' import { ConfigProvider, Layout, Menu, Spin } from 'antd' import { useContext, useEffect, useState } from 'react' @@ -81,6 +82,12 @@ const LayoutComponent = () => { } ] }, + { + label: 'Группа приложений', + key: 'applications', + className: hideItem([PermissionKeysType.read]), + icon: + }, { label: 'Доступы приложений', key: 'appAccess', @@ -169,6 +176,9 @@ const LayoutComponent = () => { case MenuItemKeysType.roles: navigate(routePaths.roles) break + case MenuItemKeysType.applications: + navigate(routePaths.applications) + break default: } } diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index 4e7f612..93a4422 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -7,7 +7,8 @@ export enum MenuItemKeysType { appAccess = 'appAccess', roles = 'roles', logout = 'logout', - profile = 'profile' + profile = 'profile', + applications = 'applications', } interface MenuItem { @@ -42,6 +43,10 @@ export const menuKeys: Record = { [MenuItemKeysType.profile]: { key: MenuItemKeysType.profile, parent: [''] + }, + [MenuItemKeysType.applications]: { + key: MenuItemKeysType.applications, + parent: [''] } } diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index 1149e8c..68f1761 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -28,6 +28,20 @@ type PathKeys = | 'setList' | 'setOne' | 'getAllRoutes' + | 'createUpdateService' + | 'deleteService' + | 'getAllService' + | 'getServiceById' + | 'getServicesByDomainId' + | 'createUpdateApplication' + | 'deleteApplication' + | 'getApplicationById' + | 'getAllApplications' + | 'getApplicationsByServiceId' + | 'createToken' + | 'getTokensByAppId' + | 'revokeTokens' + | 'revokeTokensForApp' export const apiPaths: Record = { baseUrl: '/api/kkd-configuration-service', @@ -62,9 +76,25 @@ export const apiPaths: Record = { setLogEvents: '/log/set_events', // ======= APPLICATIONS ====== getSystemTree: '/application/get_system_tree', + getAllApplications: '/application/get_applications', + createUpdateApplication: '/application/create_update_application', + getApplicationsByServiceId: '/application/get_applications_by_service_id', + deleteApplication: '/application/delete_applications', + getApplicationById: '/application/get_application_by_id', // ======= ACCESS_LIST ====== getById: '/access_list/get_by_id', setList: '/access_list/set_list', setOne: '/access_list/set_one', - getAllRoutes: '/routing/get_routes' + getAllRoutes: '/routing/get_routes', + // ======= SERVICE ====== + getServiceById: '/service/get_service_by_id', + getAllService: '/service/get_service', + deleteService: '/service/delete_service', + createUpdateService: '/service/create_update_service', + getServicesByDomainId: '/service/get_services_by_domain_id', + // ======= TOKENS ====== + createToken: '/token/create_token', + getTokensByAppId: '/token/get_tokens_by_app_id', + revokeTokens: '/token/revoke_tokens', + revokeTokensForApp: '/token/revoke_tokens_for_app' } diff --git a/src/pages/ApplicationsPage/applications-page.scss b/src/pages/ApplicationsPage/applications-page.scss new file mode 100644 index 0000000..d8ace88 --- /dev/null +++ b/src/pages/ApplicationsPage/applications-page.scss @@ -0,0 +1,69 @@ +@import "src/constants/style/styleConst"; + +.applications-page { + height: 100vh; + .three-columns { + display: flex; + background: #fff; + box-shadow: inset -1px 0px 0px $border-color; + + height: 100%; + + .column__header { + padding: $basic-padding * 2 $basic-padding; + + svg { + fill: $blue-color; + } + } + + .ant-input-affix-wrapper { + .ant-input-prefix { + margin-left: auto; + position: absolute; + right: 5px; + top: 50%; + transform: translateY(-50%); + z-index: 10; + cursor: pointer; + } + } + + .ant-input-affix-wrapper-focused { + .ant-input-prefix { + .anticon-search { + svg { + display: none; + } + } + } + } + + .ant-list-items { + .column__items__item { + .ant-list-item-meta-title { + font-family: 'Roboto', sans-serif; + font-size: 14px; + line-height: 22px; + font-weight: 400; + color: $text-color-gray; + margin-left: 5px; + } + + &.active { + background: $blue-light !important; + + .ant-list-item-meta-title { + color: $text-color-blue; + } + + svg { + path { + fill: $text-color-blue; + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/pages/ApplicationsPage/applications.type.ts b/src/pages/ApplicationsPage/applications.type.ts new file mode 100644 index 0000000..b0500c4 --- /dev/null +++ b/src/pages/ApplicationsPage/applications.type.ts @@ -0,0 +1,39 @@ +export interface ApplicationsGroupType { + createdAt: string, + description: string, + domainId: number, + id: number, + name: string, + updatedAt: string +} + +export type NewApplicationsGroupType = Omit +export type UpdateApplicationsGroupType = Omit + +export interface ApplicationsServiceType { + app:ApplicationAppType + tokens: ApplicationTokenType[] +} + +export type NewApplicationTokenType = Omit +export interface ApplicationAppType { + createdAt: string, + description: string, + id: number, + name: string, + serviceId: number, + type: string, + updatedAt: string +} + + +export type UpdateApplicationAppType = Omit +export type NewApplicationAppType = Omit + +export interface ApplicationTokenType { + appId: number, + createdAt: string, + expireTimeMs: number, + token: string +} + diff --git a/src/pages/ApplicationsPage/index.tsx b/src/pages/ApplicationsPage/index.tsx new file mode 100644 index 0000000..81f983f --- /dev/null +++ b/src/pages/ApplicationsPage/index.tsx @@ -0,0 +1,219 @@ +import { message, Spin } from 'antd' +import { Layout, FormComponents } from 'isp-ui-kit' +import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import { useNavigate, useParams, useSearchParams } from 'react-router-dom' + +import { ValidationRules } from '@constants/form/validationRules.ts' + +import ListItem from '@widgets/ListItem' +import Modal from '@widgets/Modal' + +import ApplicationsContent from '@components/ApplicationsContent' + +import { + NewApplicationsGroupType, + ApplicationsGroupType, + UpdateApplicationsGroupType +} from '@pages/ApplicationsPage/applications.type.ts' + +import { setSearchValue, setSelectedItemId } from '@utils/columnLayoutUtils.ts' +import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts' + +import useRole from '@hooks/useRole.tsx' + +import applicationsGroupApi from '@services/applicationsGroupService.ts' + +import { routePaths } from '@routes/routePaths.ts' + +import { PermissionKeysType } from '@type/roles.type.ts' + +import './applications-page.scss' + +const { Column, ContentColumn, EmptyData } = Layout +const { FormInput } = FormComponents + +const ApplicationsPage = () => { + const navigate = useNavigate() + const { id: selectedItemId = '' } = useParams() + const [searchParams, setSearchParams] = useSearchParams('') + const { hasPermission } = useRole() + + const { + data: applicationsGroup = [], + isError: isErrorApplicationsGroup, + isLoading: isLoadingApplicationsGroup + } = applicationsGroupApi.useGetApplicationsGroupByDomainIdQuery({ id: 2 }) + + const [createApplicationsGroup] = + applicationsGroupApi.useCreateApplicationsGroupMutation() + const [updateApplicationsGroup] = + applicationsGroupApi.useUpdateApplicationsGroupMutation() + + const [deleteApplicationsGroup] = + applicationsGroupApi.useRemoveApplicationsGroupMutation() + + const isPageAvailable = hasPermission(PermissionKeysType.read) + const hasRevokePermission = hasPermission(PermissionKeysType.write) + + useEffect(() => { + if (!isPageAvailable) { + navigate(routePaths.home) + } + }, [isPageAvailable]) + + const [showApplicationsModal, setShowApplicationsModal] = useState({ + addModal: false, + updateModal: false + }) + const searchValue = searchParams.get('search') || '' + const { handleSubmit, control, reset } = useForm({ + mode: 'onChange' + }) + + if (isErrorApplicationsGroup) { + return + } + + if (isLoadingApplicationsGroup) { + return + } + + const renderColumnItems = (item: ColumnItem) => + + const addApplicationModal = () => { + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: true + }) + } + + const updateApplicationModal = () => { + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: true + }) + } + + const handleAddApplicationGroup = (data: any) => { + const newService: NewApplicationsGroupType = { + name: data.name, + description: data.description, + domainId: 2 + } + createApplicationsGroup(newService) + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: false + }) + reset() + message.info('Сервис успешно создан') + } + + const handleUpdateApplicationsGroup = (data: NewApplicationsGroupType) => { + const updateService: UpdateApplicationsGroupType = { + name: data.name, + description: data.description, + domainId: 2, + id: Number(selectedItemId) + } + + updateApplicationsGroup(updateService) + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: false + }) + + reset() + message.info('Сервис успешно отредактирован') + } + + const renderMainContent = () => { + if (!selectedItemId) { + return + } + return + } + + return ( +
+
+ deleteApplicationsGroup([Number(selectedItemId)])} + items={filterFirstColumnItems( + applicationsGroup as unknown as ColumnItem[], + searchValue + )} + renderItems={renderColumnItems} + searchValue={searchValue} + selectedItemId={selectedItemId} + setSelectedItemId={(itemId) => { + setSelectedItemId( + `${routePaths.applications}`, + itemId, + searchValue, + navigate + ) + }} + onChangeSearchValue={(value) => + setSearchValue(value, setSearchParams) + } + /> + + {renderMainContent()} + + + setShowApplicationsModal({ + ...showApplicationsModal, + addModal: false + }) + } + > +
+ + + +
+ + + setShowApplicationsModal({ + ...showApplicationsModal, + updateModal: false + }) + } + > +
+ + + +
+
+
+ ) +} + +export default ApplicationsPage diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index 08083e1..23ea7ad 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -18,6 +18,7 @@ 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')) +const ApplicationsPage = lazy(() => import('@pages/ApplicationsPage')) const Routers = () => { return ( @@ -73,6 +74,23 @@ const Routers = () => { } /> + }> + + + } + > + }> + + + } + /> + = { home: '/', @@ -20,5 +21,6 @@ export const routePaths: Record = { sessions: '/sessions', securityLog: '/securityLog', roles: '/roles', - appAccess: '/appAccess' + appAccess: '/appAccess', + applications: '/applications' } diff --git a/src/services/appService.ts b/src/services/appService.ts index eec1c33..f4d6200 100644 --- a/src/services/appService.ts +++ b/src/services/appService.ts @@ -10,7 +10,7 @@ import { AppApiResponseType, DomainType } from '@type/app.type.ts' const appApi = createApi({ reducerPath: 'appService', refetchOnFocus: true, - tagTypes: ['SystemTreeApps'], + tagTypes: ['SystemTreeApps' , 'Application'], baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }), endpoints: (builder) => ({ getSystemTree: builder.query({ diff --git a/src/services/applicationsGroupService.ts b/src/services/applicationsGroupService.ts new file mode 100644 index 0000000..420a814 --- /dev/null +++ b/src/services/applicationsGroupService.ts @@ -0,0 +1,81 @@ +import { createApi } from '@reduxjs/toolkit/query/react' + +import { apiPaths } from '@constants/api/apiPaths.ts' + +import { + ApplicationsGroupType, + NewApplicationsGroupType, + UpdateApplicationsGroupType +} from '@pages/ApplicationsPage/applications.type.ts' + +import { axiosBaseQuery } from '@utils/apiUtils.ts' + +const applicationsGroupApi = createApi({ + reducerPath: 'applicationsGroupApi', + refetchOnFocus: true, + tagTypes: ['ApplicationsGroup'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }), + endpoints: (builder) => ({ + getApplicationsGroupByDomainId: builder.query< + ApplicationsGroupType, + { id: number } + >({ + query: (id) => ({ + url: apiPaths.getServicesByDomainId, + data: id + }), + providesTags: () => ['ApplicationsGroup'] + }), + + getApplicationsGroupByServiceId: builder.query< + ApplicationsGroupType[], + { id: number } + >({ + query: (id) => ({ + url: apiPaths.getServiceById, + data: id + }), + providesTags: () => ['ApplicationsGroup'] + }), + + getAllApplicationsGroup: builder.query< + ApplicationsGroupType[], + { id: string } + >({ + query: () => ({ url: apiPaths.getAllService }), + providesTags: () => ['ApplicationsGroup'] + }), + + createApplicationsGroup: builder.mutation< + ApplicationsGroupType, + NewApplicationsGroupType + >({ + query: (newApplicationsGroup) => ({ + url: apiPaths.createUpdateService, + data: newApplicationsGroup + }), + invalidatesTags: ['ApplicationsGroup'] + }), + + updateApplicationsGroup: builder.mutation< + void, + UpdateApplicationsGroupType + >({ + query: (updateApplicationsGroup) => ({ + url: apiPaths.createUpdateService, + data: updateApplicationsGroup + }), + invalidatesTags: ['ApplicationsGroup'] + }), + + removeApplicationsGroup: builder.mutation({ + query: ([id]) => ({ + url: apiPaths.deleteService, + data: [id] + }), + invalidatesTags: ['ApplicationsGroup'] + }) + }) +}) + +export default applicationsGroupApi diff --git a/src/services/applicationsService.ts b/src/services/applicationsService.ts new file mode 100644 index 0000000..a6ec56b --- /dev/null +++ b/src/services/applicationsService.ts @@ -0,0 +1,70 @@ +import { createApi } from '@reduxjs/toolkit/query/react' +import { apiPaths } from '@constants/api/apiPaths.ts' + +import { + ApplicationAppType, + ApplicationsServiceType, NewApplicationAppType, + UpdateApplicationAppType +} from '@pages/ApplicationsPage/applications.type.ts' + +import { axiosBaseQuery } from '@utils/apiUtils.ts' + +const applicationsApi = createApi({ + reducerPath: 'applicationsApi', + refetchOnFocus: true, + tagTypes: ['Applications'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }), + endpoints: (builder) => ({ + + getAllApplicationsService: builder.query< + ApplicationsServiceType[], + { id: string } + >({ + query: () => ({ url: apiPaths.getAllApplications }), + providesTags: () => ['Applications'] + }), + + createApplicationService: builder.mutation< + ApplicationAppType, + NewApplicationAppType + >({ + query: ( NewApplicationsService) => ({ + url: apiPaths.createUpdateApplication, + data: NewApplicationsService + }), + invalidatesTags: ['Applications'] + }), + + getApplicationsServiceById: builder.query({ + query: (id) => ({ + url: apiPaths.getApplicationById, + data: id + }), + }), + + getApplicationsByServiceId: builder.query({ + query: (id) => ({ + url: apiPaths.getApplicationsByServiceId, + data: id + }), + }), + + updateApplicationsService: builder.mutation({ + query: (updateApplications) => ({ + url: apiPaths.createUpdateApplication, + data: updateApplications + }), + invalidatesTags: ['Applications'] + }), + + removeApplicationsService: builder.mutation({ + query: ([id]) => ({ + url: apiPaths.deleteApplication, + data: [ id] + }), + invalidatesTags: ['Applications'] + }) + }) +}) + +export default applicationsApi \ No newline at end of file diff --git a/src/services/tokensService.ts b/src/services/tokensService.ts new file mode 100644 index 0000000..a29fbd0 --- /dev/null +++ b/src/services/tokensService.ts @@ -0,0 +1,30 @@ +import { createApi } from '@reduxjs/toolkit/query/react' +import { apiPaths } from '@constants/api/apiPaths.ts' + +import { + ApplicationTokenType, + NewApplicationTokenType, +} from '@pages/ApplicationsPage/applications.type.ts' + +import { axiosBaseQuery } from '@utils/apiUtils.ts' + +const tokensApi = createApi({ + reducerPath: 'tokensApi', + refetchOnFocus: true, + tagTypes: ['Tokens'], + baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }), + endpoints: (builder) => ({ + createToken: builder.mutation< + ApplicationTokenType, + NewApplicationTokenType + >({ + query: ( NewApplicationTokenType) => ({ + url: apiPaths.createToken, + data: NewApplicationTokenType + }), + invalidatesTags: ['Tokens'] + }), + }) +}) + +export default tokensApi \ No newline at end of file diff --git a/src/stores/index.tsx b/src/stores/index.tsx index 2e37302..7b8403f 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -12,6 +12,8 @@ import userServiceApi from '@services/userService.ts' import routeApi from '@services/routeService.ts' import profileReducer from './redusers/ProfileSlice.ts' +import applicationsGroupApi from '@services/applicationsGroupService.ts' +import applicationsApi from '@services/applicationsService.ts' export interface ContextProps { setTheme: Dispatch< @@ -31,7 +33,9 @@ const rootReducer = combineReducers({ [securityLogServiceApi.reducerPath]: securityLogServiceApi.reducer, [appApi.reducerPath]: appApi.reducer, [accessListApi.reducerPath]: accessListApi.reducer, - [routeApi.reducerPath]: routeApi.reducer + [routeApi.reducerPath]: routeApi.reducer, + [applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer, + [applicationsApi.reducerPath]: applicationsApi.reducer, }) export const setupStore = () => @@ -46,7 +50,9 @@ export const setupStore = () => accessListApi.middleware, routeApi.middleware, userServiceApi.middleware, - sessionServiceApi.middleware + sessionServiceApi.middleware, + applicationsGroupApi.middleware, + applicationsApi.middleware ) })