Skip to content

Commit

Permalink
fix-alert-instance-state-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Dec 22, 2023
1 parent 7a9988f commit 4eac60a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const InstanceForm: React.FC<InstanceFormProps> = (props) => {

const [alertType, setAlertType] = useState<string>(values.type ?? ALERT_TYPE.DINGTALK);

const [formValues, setFormValues] = useState<Partial<Alert.AlertInstance>>(values);


const renderPreForm = () => {
return (
<>
Expand Down Expand Up @@ -87,10 +90,16 @@ const InstanceForm: React.FC<InstanceFormProps> = (props) => {

return (
<>
<ProForm form={form} submitter={false}>
<ProForm
form={form}
onValuesChange={(changedValues, allValues) =>
setFormValues((prevState) => ({ ...prevState, ...allValues, ...changedValues }))
}
submitter={false}
>
<ProForm.Group>
{renderPreForm()}
{renderFormByType(values, alertType)}
{renderFormByType(formValues, alertType)}
</ProForm.Group>
</ProForm>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const AlertTypeChoose: React.FC<UpdateFormProps> = (props) => {
loading
} = props;

const [formValues, setFormValues] = useState<Partial<Alert.AlertInstance>>(values);

/**
* init form
Expand Down Expand Up @@ -81,17 +80,17 @@ const AlertTypeChoose: React.FC<UpdateFormProps> = (props) => {
* when modalVisible or values changed, set form values
*/
useEffect(() => {
form.setFieldsValue(formValues);
}, [modalVisible, formValues, form]);
form.setFieldsValue(values);
}, [modalVisible, values, form]);

const testSend = async () => {
const validateFields = await form.validateFields();
handleTest({ ...formValues, ...validateFields });
handleTest({ ...values, ...validateFields });
};

const submit = async () => {
const validateFields = await form.validateFields();
handleSubmit({ ...formValues, ...validateFields });
handleSubmit({ ...values, ...validateFields });
handleCancel();
};

Expand Down Expand Up @@ -120,18 +119,15 @@ const AlertTypeChoose: React.FC<UpdateFormProps> = (props) => {
<>
<ModalForm<Alert.AlertInstance>
{...NORMAL_MODAL_OPTIONS}
title={formValues?.id ? l('rc.ai.modify') : l('rc.ai.create')}
title={values?.id ? l('rc.ai.modify') : l('rc.ai.create')}
open={modalVisible}
form={form}
initialValues={formValues}
onValuesChange={(changedValues, allValues) =>
setFormValues((prevState) => ({ ...prevState, ...allValues, ...changedValues }))
}
initialValues={values}
modalProps={{ onCancel: handleCancel, ...NORMAL_MODAL_OPTIONS }}
submitter={{ render: () => [...renderFooter()] }}
syncToInitialValues
>
<InstanceForm form={form} values={formValues} />
<InstanceForm form={form} values={values} />
</ModalForm>
</>
);
Expand Down

0 comments on commit 4eac60a

Please sign in to comment.