client/src/components/SessionList.js
changeset 137 279e1dffa213
parent 133 6f3078f7fd47
child 143 cfcbf4bc66f1
equal deleted inserted replaced
136:1a3be12af395 137:279e1dffa213
     5 import moment from 'moment';
     5 import moment from 'moment';
     6 import '../App.css';
     6 import '../App.css';
     7 import Navbar from './Navbar';
     7 import Navbar from './Navbar';
     8 import * as sessionsActions from '../actions/sessionsActions';
     8 import * as sessionsActions from '../actions/sessionsActions';
     9 import uuidV1 from 'uuid/v1';
     9 import uuidV1 from 'uuid/v1';
    10 import { ActionEnum } from '../constants';
    10 import { getActiveSessions } from '../selectors/coreSelectors';
       
    11 import { getCurrentUser, getGroups, getCurrentGroup } from '../selectors/authSelectors';
    11 
    12 
    12 class SessionList extends Component {
    13 class SessionList extends Component {
    13 
    14 
    14   state = {
    15   state = {
    15     showModal: false,
    16     showModal: false,
    16     sessionToDelete: null
    17     sessionToDelete: null
    17   }
    18   }
    18 
    19 
    19   createSession = () => {
    20   createSession = () => {
    20     const sessionId = uuidV1();
    21     const sessionId = uuidV1();
    21     const groupName = (this.props.currentUser)?this.props.currentUser.get('default_group'):null;
    22     let groupName = null;
    22     let protocol = null;
    23     let protocol = null;
    23     if(groupName != null) {
    24     if(this.props.currentGroup) {
    24       const group = this.props.groups.find((g) => g.name === groupName);
    25       groupName = this.props.currentGroup.get('name');
    25       if(group) {
    26       protocol = this.props.currentGroup.get('protocol');
    26         protocol = group.get('protocol');
    27     }
       
    28     if(groupName === null) {
       
    29       groupName = (this.props.currentUser)?this.props.currentUser.get('default_group'):null;
       
    30       if(groupName != null) {
       
    31         const group = this.props.groups.find((g) => g.name === groupName);
       
    32         if(group) {
       
    33           protocol = group.get('protocol');
       
    34         }
    27       }
    35       }
    28     }
    36     }
       
    37 
    29     this.props.sessionsActions.createSession(sessionId, groupName, protocol);
    38     this.props.sessionsActions.createSession(sessionId, groupName, protocol);
    30     this.props.history.push('/sessions/' + sessionId);
    39     this.props.history.push('/sessions/' + sessionId);
    31   }
    40   }
    32 
    41 
    33   onClickDelete(session, e) {
    42   onClickDelete(session, e) {
    92   }
   101   }
    93 }
   102 }
    94 
   103 
    95 function mapStateToProps(state, props) {
   104 function mapStateToProps(state, props) {
    96   return {
   105   return {
    97     sessions: state.get('sessions').filter(session => session.get('action') !== ActionEnum.DELETED),
   106     sessions: getActiveSessions(state),
    98     currentUser: state.getIn(['authStatus', 'currentUser']),
   107     currentUser: getCurrentUser(state),
    99     groups: state.get('groups')
   108     groups: getGroups(state),
       
   109     currentGroup: getCurrentGroup(state)
   100   };
   110   };
   101 }
   111 }
   102 
   112 
   103 function mapDispatchToProps(dispatch) {
   113 function mapDispatchToProps(dispatch) {
   104   return {
   114   return {