Merge pull request #739 from mewtaylor/issue/gh-698

Fix GH-698: refresh session on successful registration
This commit is contained in:
Matthew Taylor 2016-07-21 13:44:15 -04:00 committed by GitHub
commit bf28fae97c

View file

@ -1,8 +1,10 @@
var connect = require('react-redux').connect;
var defaults = require('lodash.defaultsdeep');
var React = require('react');
var render = require('../../lib/render.jsx');
var api = require('../../lib/api');
var sessionActions = require('../../redux/session.js');
var Deck = require('../../components/deck/deck.jsx');
var Progression = require('../../components/progression/progression.jsx');
@ -67,12 +69,16 @@ var TeacherRegistration = React.createClass({
}, function (err, res) {
this.setState({waiting: false});
if (err) return this.setState({registrationError: err});
if (res[0].success) return this.advanceStep(formData);
if (res[0].success) {
this.props.dispatch(sessionActions.refreshSession());
return this.advanceStep(formData);
}
this.setState({registrationError: res[0].msg});
}.bind(this));
},
render: function () {
var permissions = this.props.session.permissions || {};
return (
<Deck className="teacher-registration">
{this.state.registrationError ?
@ -101,7 +107,10 @@ var TeacherRegistration = React.createClass({
waiting={this.state.waiting} />
<Steps.EmailStep onNextStep={this.register}
waiting={this.state.waiting} />
<Steps.TeacherApprovalStep email={this.state.formData.user && this.state.formData.user.email} />
<Steps.TeacherApprovalStep email={this.state.formData.user && this.state.formData.user.email}
confirmed={permissions.social}
invited={permissions.educator_invitee}
educator={permissions.educator} />
</Progression>
}
</Deck>
@ -109,4 +118,12 @@ var TeacherRegistration = React.createClass({
}
});
render(<TeacherRegistration />, document.getElementById('app'));
var mapStateToProps = function (state) {
return {
session: state.session.session
};
};
var ConnectedTeacherRegistration = connect(mapStateToProps)(TeacherRegistration);
render(<ConnectedTeacherRegistration />, document.getElementById('app'));