diff -r adad5563603c -r 906a6c7c7943 client/src/components/SessionForm.js
--- a/client/src/components/SessionForm.js Mon Jul 31 23:18:38 2017 +0200
+++ b/client/src/components/SessionForm.js Tue Aug 01 12:20:14 2017 +0200
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
-import { Panel, FormGroup, ControlLabel, FormControl, Button, InputGroup, HelpBlock, Glyphicon } from 'react-bootstrap';
+import { Panel, FormGroup, ControlLabel, FormControl } from 'react-bootstrap';
+import GroupForm from './GroupForm';
import '../App.css';
import * as sessionsActions from '../actions/sessionsActions';
import * as authActions from '../actions/authActions';
@@ -13,18 +14,6 @@
createGroup: false
}
- toggleCreateGroup = (e) => {
- e.preventDefault();
- const { createGroup } = this.state;
- this.setState({ createGroup: !createGroup });
- }
-
- onClickCreateGroup = (e) => {
- e.preventDefault();
- const groupName = this.groupName.value;
- this.props.sessionsActions.createGroupAndUpdateSession(this.props.currentSession, groupName);
- }
-
onChange = (e) => {
const { name, value } = e.target;
const changes = { [name]: value }
@@ -36,10 +25,9 @@
}, 750)
onGroupChange = (e) => {
- const groupId = parseInt(this.group.value, 10);
- const group = this.props.groups.find(group => group.id === groupId);
+ const groupName = e.target.value;
- this.props.sessionsActions.updateSession(this.props.currentSession, { group });
+ this.props.sessionsActions.updateSession(this.props.currentSession, { group: groupName });
}
componentWillUpdate = (nextProps, nextState) => {
@@ -48,48 +36,6 @@
}
}
- renderCreateGroup = () => {
- const { createGroup } = this.props;
- const hasErrors = true === createGroup.get('error') && createGroup.get('errorMessages').has('name');
-
- let errors = [];
- if (hasErrors) {
- const errorMessages = createGroup.get('errorMessages').toArray();
- errors = errorMessages.map((message, key) => {
- return (
- { message }
- )
- })
- }
-
- if (this.state.createGroup) {
- return (
-
-
- { this.groupName = ref; } } />
-
-
-
-
- { errors }
-
-
-
- )
- }
-
- return (
-
-
-
- )
- }
-
render() {
if (!this.props.currentSession) {
@@ -109,7 +55,6 @@
onChange={ this.onChange }
type="text"
placeholder="Enter a title"
- inputRef={ ref => { this.title = ref; } }
/>
@@ -120,7 +65,6 @@
defaultValue={ this.props.currentSession.description }
onChange={ this.onChange }
placeholder="Enter a description"
- inputRef={ ref => { this.description = ref; } }
/>
@@ -128,17 +72,15 @@
{ this.group = ref; } }>
-
+ value={ this.props.group ? this.props.group.get('name') : '' }
+ onChange={ this.onGroupChange }>
{ this.props.groups.map((group, key) =>
-
+
) }
- { this.renderCreateGroup() }
+
@@ -149,8 +91,8 @@
function mapStateToProps(state, props) {
let group;
- if (props.session && props.session.group) {
- group = state.groups.find(group => props.session.group.get('id') === group.id)
+ if (props.session && props.session.get('group')) {
+ group = state.get('groups').find(group => props.session.get('group') === group.get('name'))
}
return {