Кнопка ОК переименована в Сохранить, добавлено блокирование кнопки до валидации формы

This commit is contained in:
Александр Сироткин 2021-12-29 12:21:57 +05:00
parent 278ebeb573
commit f6f5fa15be

View File

@ -23,9 +23,14 @@ const fieldRules = [...passwordRules, ...createPasswordRules]
export const ChangePassword = memo<ChangePasswordProps>(({ user, visible, onCancel, onOk }) => {
const [showLoader, setShowLoader] = useState<boolean>(false)
const [password, setPassword] = useState<string>('')
const [isDisabled, setIsDisabled] = useState(true)
const [form] = useForm()
const onFormChange = async () => await form.validateFields()
.then(() => setIsDisabled(false))
.catch(() => setIsDisabled(true))
const onModalCancel = () => {
form.resetFields()
onCancel?.()
@ -52,6 +57,10 @@ export const ChangePassword = memo<ChangePasswordProps>(({ user, visible, onCanc
visible={visible}
onCancel={onModalCancel}
onOk={() => form.submit()}
okText={'Сохранить'}
okButtonProps={{
disabled: isDisabled
}}
>
<LoaderPortal show={showLoader}>
<Form
@ -59,6 +68,7 @@ export const ChangePassword = memo<ChangePasswordProps>(({ user, visible, onCanc
form={form}
name={'change-password'}
onFinish={onFormFinish}
onChange={onFormChange}
>
<Form.Item
label={'Новый пароль'}