MSP-3289 create appModal
This commit is contained in:
1 parent
2d7bc6aeb9
commit
9a0f85e434
2 files changed
+59
No files matched your search
@@ -0,0 +1,8 @@
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
|
||||
import { ApplicationAppType } from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
export type AppModalType = Omit<ModalPropsType, 'onOk' | 'children'> & {
|
||||
app?: ApplicationAppType
|
||||
onOk: (data: ApplicationAppType) => void
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { FormComponents } from 'isp-ui-kit'
|
||||
import { FC, useEffect } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
|
||||
import Modal from '@widgets/Modal'
|
||||
|
||||
import { AppModalType } from '@components/AppModal/app-group-modal.type.ts'
|
||||
|
||||
import { ApplicationAppType } from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
|
||||
const { FormInput, FormTextArea } = FormComponents
|
||||
|
||||
const AppModal: FC<AppModalType> = ({ title,onOk, onClose, open, app }) => {
|
||||
const { handleSubmit, control, reset } = useForm<ApplicationAppType>({
|
||||
mode: 'onChange',
|
||||
defaultValues: app
|
||||
})
|
||||
useEffect(() => {
|
||||
reset(app)
|
||||
}, [open])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
onOk={handleSubmit(onOk)}
|
||||
title={title}
|
||||
open={open}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={onClose}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={control}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormTextArea
|
||||
autoSize={{ minRows: 2, maxRows: 6 }}
|
||||
control={control}
|
||||
label="Описание"
|
||||
name="description"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default AppModal
|
||||
Reference in new issue
Block a user