mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -05:00
Pass updates up from project updater to top-level redux store
This commit is contained in:
parent
db99c12d89
commit
8e57bb5493
1 changed files with 14 additions and 2 deletions
|
@ -1,11 +1,13 @@
|
|||
const PropTypes = require('prop-types');
|
||||
const React = require('react');
|
||||
const bindAll = require('lodash.bindall');
|
||||
const api = require('../../lib/api');
|
||||
const connect = require('react-redux').connect;
|
||||
const injectIntl = require('react-intl').injectIntl;
|
||||
const intlShape = require('react-intl').intlShape;
|
||||
|
||||
const api = require('../../lib/api');
|
||||
const previewActions = require('../../redux/preview');
|
||||
|
||||
class FormsyProjectUpdater extends React.Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
|
@ -41,6 +43,7 @@ class FormsyProjectUpdater extends React.Component {
|
|||
}, (err, body, res) => {
|
||||
if (res.statusCode === 200) {
|
||||
this.setState({value: body[this.props.field], error: false});
|
||||
this.props.onUpdate(jsonData);
|
||||
} else {
|
||||
this.setState({error: res.statusCode});
|
||||
}
|
||||
|
@ -63,6 +66,7 @@ FormsyProjectUpdater.propTypes = {
|
|||
field: PropTypes.string,
|
||||
initialValue: PropTypes.string,
|
||||
intl: intlShape,
|
||||
onUpdate: PropTypes.func,
|
||||
projectInfo: PropTypes.shape({
|
||||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
||||
}),
|
||||
|
@ -76,4 +80,12 @@ const mapStateToProps = state => ({
|
|||
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)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue