const mapDispatchToProps = (dispatch, { FORM_NAME = FIELD_FORM_NAME }) => ({ onChange: composedOf => { dispatch(change(FORM_NAME, 'composedOf', composedOf)); }, })
const resetFields = (props, formName, fieldsObj) => { Object.keys(fieldsObj).forEach(fieldKey => { //reset the field's value props.dispatch(change(formName, fieldKey, fieldsObj[fieldKey])); //reset the field's error props.dispatch(untouch(formName, fieldKey)); }); }
export function fetchTodo(id) { return dispatch => fetch(`${ // "typeof window === 'object'" is to decide wheher we are running in server // or browser. // In pages/_document.js, we put process.env.UISVR_APISERVER into // window.__APISERVER__. typeof window === 'object' ? window.__APISERVER__ : process.env.UISVR_APISERVER }todos/${ id }`) .then(response => response.json()) .then(todo => { // save to redux-form state dispatch(change(constants.REDUX_FORM_NAME, 'todo', todo)); }); }
clearField(field) { this.props.dispatch(change(this.props.formInstanceId, field, null)); this.props.dispatch(untouch(this.props.formInstanceId, field)); }
const mapDispatchToProps = (dispatch) => { return { encryptBody: (data) => { dispatch(encryptBody(data)).then((response) => { if (response.type === actionTypes.encryptionMessageSuccess) { let text = JSON.stringify(response.response.data); text = text.replace(/{|}|"|/g, ''); text = text.replace(':', '=""'); dispatch(change('decryptionForm', 'encryptedText', text)); } }); }, decryptBody: (data) => { dispatch(decryptBody(data)).then((response) => { if (response.type === actionTypes.decryptionMessageSuccess) { let text = JSON.parse(response.response.data); debugger dispatch(change('decryptionForm', 'decryptedText', text.plainText)); } }); } }; }