This commit is contained in:
mikheykinnv committed 2024-04-26 15:24:10 +08:00
1 parent 7a0137e3f7
commit ca3de4ee36
1 file changed
+158 -158
+158 -158
View File
@@ -3,10 +3,9 @@ import {
DeleteOutlined, DeleteOutlined,
PlusSquareOutlined PlusSquareOutlined
} from '@ant-design/icons' } from '@ant-design/icons'
import { Button, message, Spin, Table } from 'antd' import {Button, message, Spin, Table} from 'antd'
import { ColumnsType } from 'antd/es/table' import { ColumnsType } from 'antd/es/table'
import { FormComponents } from 'isp-ui-kit' import { FormComponents, Layout } from 'isp-ui-kit'
import { EmptyData } from 'isp-ui-kit/dist/Layout'
import { FC, useState } from 'react' import { FC, useState } from 'react'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
@@ -31,6 +30,7 @@ import tokensApi from '@services/tokensService.ts'
import './applications-content.scss' import './applications-content.scss'
const { FormInput, FormSelect } = FormComponents const { FormInput, FormSelect } = FormComponents
const { EmptyData } = Layout
interface ApplicationsContentPropTypes { interface ApplicationsContentPropTypes {
id: number id: number
@@ -38,14 +38,14 @@ interface ApplicationsContentPropTypes {
const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => { const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
const { data: applications, isLoading: isLoadingApplicationsContent = [] } = const { data: applications, isLoading: isLoadingApplicationsContent = [] } =
applicationsApi.useGetApplicationsByServiceIdQuery(id) applicationsApi.useGetApplicationsByServiceIdQuery(id)
const [createApplicationService] = const [createApplicationService] =
applicationsApi.useCreateApplicationServiceMutation() applicationsApi.useCreateApplicationServiceMutation()
const [updateApplication] = const [updateApplication] =
applicationsApi.useUpdateApplicationsServiceMutation() applicationsApi.useUpdateApplicationsServiceMutation()
const [removeApplicationsService] = const [removeApplicationsService] =
applicationsApi.useRemoveApplicationsServiceMutation() applicationsApi.useRemoveApplicationsServiceMutation()
const [createToken] = tokensApi.useCreateTokenMutation() const [createToken] = tokensApi.useCreateTokenMutation()
const [showApplicationsModal, setShowApplicationsModal] = useState({ const [showApplicationsModal, setShowApplicationsModal] = useState({
addModal: false, addModal: false,
@@ -53,7 +53,7 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
addToken: false addToken: false
}) })
const [currentApplicationsApp, setCurrentApplicationsApp] = const [currentApplicationsApp, setCurrentApplicationsApp] =
useState<ApplicationAppType>() useState<ApplicationAppType>()
const { const {
handleSubmit, handleSubmit,
@@ -64,9 +64,9 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
}) })
const { handleSubmit: handleSubmitTokens, control: controlTokens } = const { handleSubmit: handleSubmitTokens, control: controlTokens } =
useForm<ApplicationTokenType>({ useForm<ApplicationTokenType>({
mode: 'onChange' mode: 'onChange'
}) })
const handleShowUpdateModalApplicationApp = (data: ApplicationAppType) => { const handleShowUpdateModalApplicationApp = (data: ApplicationAppType) => {
setShowApplicationsModal({ setShowApplicationsModal({
@@ -95,22 +95,22 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
id: currentApplicationsApp.id, id: currentApplicationsApp.id,
name: data.name, name: data.name,
description: data.description description: data.description
? data.description ? data.description
: currentApplicationsApp.description, : currentApplicationsApp.description,
serviceId: id.id, serviceId: id.id,
type: 'SYSTEM' type: 'SYSTEM'
} }
updateApplication({ ...currentApplicationsApp, ...updateApplications }) updateApplication({ ...currentApplicationsApp, ...updateApplications })
.unwrap() .unwrap()
.then(() => { .then(() => {
setShowApplicationsModal({ setShowApplicationsModal({
...showApplicationsModal, ...showApplicationsModal,
updateModal: false updateModal: false
})
reset()
message.info('Элемент сохранен')
}) })
reset() .catch(() => message.error('Ошибка обновления элемента'))
message.info('Элемент сохранен')
})
.catch(() => message.error('Ошибка обновления элемента'))
} }
} }
@@ -123,9 +123,9 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
} }
createApplicationService(newApplicationApp) createApplicationService(newApplicationApp)
.unwrap() .unwrap()
.then(message.info('Элемент сохранен')) .then(message.info('Элемент сохранен'))
.catch((e) => message.error(e)) .catch((e) => message.error(e))
setShowApplicationsModal({ setShowApplicationsModal({
...showApplicationsModal, ...showApplicationsModal,
addModal: false addModal: false
@@ -133,11 +133,11 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
reset() reset()
} }
const handleRemoveApplicationApp = (id: number) => const handleRemoveApplicationApp = (id: number) =>
removeApplicationsService([id]) removeApplicationsService([id])
.then(() => { .then(() => {
message.info('Элемент удален') message.info('Элемент удален')
}) })
.catch(message.error('Ошибка добавления элемента')) .catch(message.error('Ошибка добавления элемента'))
const handleCreateToken = (data: NewApplicationTokenType) => { const handleCreateToken = (data: NewApplicationTokenType) => {
if (currentApplicationsApp) { if (currentApplicationsApp) {
@@ -147,17 +147,17 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
} }
createToken(newToken) createToken(newToken)
.then(() => { .then(() => {
setShowApplicationsModal({ setShowApplicationsModal({
...showApplicationsModal, ...showApplicationsModal,
addToken: false addToken: false
})
reset()
message.info('Элемент добавлен')
})
.catch(() => {
message.error('Ошибка добавления элемента')
}) })
reset()
message.info('Элемент добавлен')
})
.catch(() => {
message.error('Ошибка добавления элемента')
})
} }
} }
@@ -196,20 +196,20 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
key: 'actions', key: 'actions',
render: (record) => { render: (record) => {
return ( return (
<CanEdit> <CanEdit>
<Button <Button
danger danger
className="applications-content__update-btn" className="applications-content__update-btn"
onClick={() => { onClick={() => {
handleShowUpdateModalApplicationApp(record) handleShowUpdateModalApplicationApp(record)
}} }}
icon={<EditOutlined />} icon={<EditOutlined />}
/> />
<Button <Button
onClick={() => handleRemoveApplicationApp(record.id)} onClick={() => handleRemoveApplicationApp(record.id)}
icon={<DeleteOutlined />} icon={<DeleteOutlined />}
/> />
</CanEdit> </CanEdit>
) )
} }
} }
@@ -247,113 +247,113 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
} }
return ( return (
<section className="applications-content"> <section className="applications-content">
<CanEdit> <CanEdit>
<Button <Button
className="applications-content__add-btn" className="applications-content__add-btn"
type="primary" type="primary"
onClick={handleShowCreateModalApplicationApp} onClick={handleShowCreateModalApplicationApp}
>
Добавить
</Button>
</CanEdit>
<Table
expandable={{
expandedRowRender: (record) => (
<CanEdit>
<Button
className="applications-content__addToken-btn"
onClick={() => handleShowAddModalToken(record.app)}
>
<PlusSquareOutlined /> Добавить токен
</Button>
</CanEdit>
)
}}
className="appliactions-content__table"
rowKey={(record) => record.app.id}
pagination={false}
dataSource={applications}
columns={columns}
/>
<Modal
onOk={handleSubmit(handleUpdateApplicationApp)}
title="Редактировать"
open={showApplicationsModal.updateModal}
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
onClose={() =>
setShowApplicationsModal({
...showApplicationsModal,
updateModal: false
})
}
> >
Добавить <form>
</Button> <FormInput
</CanEdit> control={controlApplicationApp}
<Table name="name"
expandable={{ label="Наименование"
expandedRowRender: (record) => ( rules={{ required: ValidationRules.required }}
<CanEdit> />
<Button <FormInput
className="applications-content__addToken-btn" control={controlApplicationApp}
onClick={() => handleShowAddModalToken(record.app)} label="Описание"
> name="description"
<PlusSquareOutlined /> Добавить токен />
</Button> </form>
</CanEdit> </Modal>
)
}}
className="appliactions-content__table"
rowKey={(record) => record.app.id}
pagination={false}
dataSource={applications}
columns={columns}
/>
<Modal <Modal
onOk={handleSubmit(handleUpdateApplicationApp)} onOk={handleSubmit(handleCreateApplicationApp)}
title="Редактировать" title="Добавить"
open={showApplicationsModal.updateModal} open={showApplicationsModal.addModal}
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }} footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
onClose={() => onClose={() =>
setShowApplicationsModal({ setShowApplicationsModal({
...showApplicationsModal, ...showApplicationsModal,
updateModal: false addModal: false
}) })
} }
> >
<form> <form>
<FormInput <FormInput
control={controlApplicationApp} control={controlApplicationApp}
name="name" name="name"
label="Наименование" label="Наименование"
rules={{ required: ValidationRules.required }} rules={{ required: ValidationRules.required }}
/> />
<FormInput <FormInput
control={controlApplicationApp} control={controlApplicationApp}
label="Описание" label="Описание"
name="description" name="description"
/> />
</form> </form>
</Modal> </Modal>
<Modal <Modal
onOk={handleSubmit(handleCreateApplicationApp)} onOk={handleSubmitTokens(handleCreateToken)}
title="Добавить" title="Добавить"
open={showApplicationsModal.addModal} open={showApplicationsModal.addToken}
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }} footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
onClose={() => onClose={() =>
setShowApplicationsModal({ setShowApplicationsModal({
...showApplicationsModal, ...showApplicationsModal,
addModal: false addToken: false
}) })
} }
> >
<form> <form>
<FormInput <FormSelect
control={controlApplicationApp} options={tokensOptions}
name="name" name="expireTimeMs"
label="Наименование" control={controlTokens}
rules={{ required: ValidationRules.required }} label="Время действия"
/> rules={{ required: ValidationRules.required }}
<FormInput />
control={controlApplicationApp} </form>
label="Описание" </Modal>
name="description" </section>
/>
</form>
</Modal>
<Modal
onOk={handleSubmitTokens(handleCreateToken)}
title="Добавить"
open={showApplicationsModal.addToken}
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
onClose={() =>
setShowApplicationsModal({
...showApplicationsModal,
addToken: false
})
}
>
<form>
<FormSelect
options={tokensOptions}
name="expireTimeMs"
control={controlTokens}
label="Время действия"
rules={{ required: ValidationRules.required }}
/>
</form>
</Modal>
</section>
) )
} }