client/src/components/Sessions.js
changeset 29 4cfeabef7d5e
parent 12 48ddaa42b810
child 58 f16a080e0bc4
--- a/client/src/components/Sessions.js	Mon Jun 12 18:09:13 2017 +0200
+++ b/client/src/components/Sessions.js	Mon Jun 12 18:12:38 2017 +0200
@@ -9,10 +9,14 @@
 
 class Sessions extends Component {
 
-  createNewSession = () => {
-    const result = this.props.actions.createNewSession();
-    // FIXME Feels ugly, change location after state has changed?
-    this.props.history.push('/sessions/' + result.session.id)
+  createSession = () => {
+    this.props.sessionsActions.createSession();
+  }
+
+  componentDidUpdate = () => {
+    if (this.props.currentSession) {
+      this.props.history.push('/sessions/' + this.props.currentSession._id)
+    }
   }
 
   render() {
@@ -25,13 +29,13 @@
               <ListGroup>
                 {this.props.sessions.map((session) =>
                   <ListGroupItem
-                    key={session.id}
-                    onClick={() => this.props.history.push('/sessions/' + session.id)}>
-                    {session.title || 'No title'} {session.id} {moment(session.date).format('DD/MM/YYYY')}
+                    key={session._id}
+                    onClick={() => this.props.history.push('/sessions/' + session._id)}>
+                    {session.title || 'No title'} {session._id} {moment(session.date).format('DD/MM/YYYY')}
                   </ListGroupItem>
                 )}
               </ListGroup>
-              <Button bsStyle="success" onClick={this.createNewSession}>Create new session</Button>
+              <Button bsStyle="success" onClick={this.createSession}>Create new session</Button>
             </Col>
           </Row>
         </Grid>
@@ -49,7 +53,7 @@
 
 function mapDispatchToProps(dispatch) {
   return {
-    actions: bindActionCreators(sessionsActions, dispatch)
+    sessionsActions: bindActionCreators(sessionsActions, dispatch)
   }
 }