use dva to encounter the add function. Here is the form that clicks the add button to display the modal box, but the closing time cannot be judged by the returned result if you use state, in the component (some fields cannot be added when duplicated). Now that the logic of displaying and closing is written into model, is it okay to do so?
part of the code:
component:
function handleAdd() {
dispatch({ type: "user/saveAddModalVisible", payload: true });
}
function handleCancel() {
dispatch({ type: "user/saveAddModalVisible", payload: false });
}
<Button onClick={handleAdd}></Button>
<Modal
title=""
visible={addModalVisible}
onCancel={handleCancel}
>
<div>
<Form>
// ...
</Form>
</div>
</Modal>
in model:
*addChannel({ payload }, { call, put }) {
const res = yield call(addChannelReq, payload);
if (res.code === 200) {
yield put({ type: "saveAddModalVisible", payload: false });
message.success("");
} else {
message.destroy();
message.warning(res.msg);
}
},