Pass updates up from project updater to top-level redux store

This commit is contained in:
Paul Kaplan 2019-01-25 13:35:39 -05:00
parent db99c12d89
commit 8e57bb5493

View file

@ -1,11 +1,13 @@
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
const React = require('react'); const React = require('react');
const bindAll = require('lodash.bindall'); const bindAll = require('lodash.bindall');
const api = require('../../lib/api');
const connect = require('react-redux').connect; const connect = require('react-redux').connect;
const injectIntl = require('react-intl').injectIntl; const injectIntl = require('react-intl').injectIntl;
const intlShape = require('react-intl').intlShape; const intlShape = require('react-intl').intlShape;
const api = require('../../lib/api');
const previewActions = require('../../redux/preview');
class FormsyProjectUpdater extends React.Component { class FormsyProjectUpdater extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
@ -41,6 +43,7 @@ class FormsyProjectUpdater extends React.Component {
}, (err, body, res) => { }, (err, body, res) => {
if (res.statusCode === 200) { if (res.statusCode === 200) {
this.setState({value: body[this.props.field], error: false}); this.setState({value: body[this.props.field], error: false});
this.props.onUpdate(jsonData);
} else { } else {
this.setState({error: res.statusCode}); this.setState({error: res.statusCode});
} }
@ -63,6 +66,7 @@ FormsyProjectUpdater.propTypes = {
field: PropTypes.string, field: PropTypes.string,
initialValue: PropTypes.string, initialValue: PropTypes.string,
intl: intlShape, intl: intlShape,
onUpdate: PropTypes.func,
projectInfo: PropTypes.shape({ projectInfo: PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
}), }),
@ -76,4 +80,12 @@ const mapStateToProps = state => ({
user: state.session.session.user user: state.session.session.user
}); });
module.exports = connect(mapStateToProps)(injectIntl(FormsyProjectUpdater)); const mapDispatchToProps = dispatch => ({
onUpdate: info => {
dispatch(previewActions.updateProjectInfo(info));
}
});
module.exports = connect(mapStateToProps, mapDispatchToProps)(
injectIntl(FormsyProjectUpdater)
);