Skip to content

Commit

Permalink
fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Dec 24, 2023
1 parent 8e951e8 commit 7e9380a
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { NORMAL_MODAL_OPTIONS } from '@/services/constants';
import { Document } from '@/types/RegCenter/data';
import { l } from '@/utils/intl';
import { Form, Modal } from 'antd';
import React from 'react';
import React, {useEffect} from 'react';

type DocumentModalProps = {
onCancel: (flag?: boolean) => void;
Expand All @@ -50,11 +50,18 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
* init props
*/
const { onSubmit: handleSubmit, onCancel: handleModalVisible, modalVisible, values } = props;
/**
* when modalVisible or values changed, set form values
*/
useEffect(() => {
if (modalVisible) form.resetFields();
form.setFieldsValue(values);
}, [modalVisible, values, form]);

/**
* handle cancel
*/
const handleCancel = () => {
const handleCancel = async () => {
handleModalVisible();
formContext.resetForm();
};
Expand All @@ -64,7 +71,7 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
const submitForm = async () => {
const fieldsValue = await form.validateFields();
handleSubmit({ ...values, ...fieldsValue });
handleCancel();
await handleCancel();
};

return (
Expand All @@ -77,7 +84,7 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
autoFocus: true
}}
onOk={() => submitForm()}
onCancel={() => handleModalVisible()}
onCancel={() => handleCancel()}
>
<DocumentForm values={values} form={form} />
</Modal>
Expand Down

0 comments on commit 7e9380a

Please sign in to comment.