import React from 'react';

import {FormsyDate, FormsyText} from 'formsy-material-ui';
import {Form} from 'formsy-react';
import RaisedButton from 'material-ui/lib/raised-button';

import {createBook} from '../actions/crudActions';

export default class BookComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
          canSubmit: false
        };
    }

    submit(_data) {
      this.props.onAddBook(_data);
    }

    render() {
      return (
        <Form onValidSubmit={(data) => {this.submit(data)}}
            onValid={() => {this.setState({canSubmit: true})}}
            onInvalid={() => {this.setState({canSubmit: false})}}
        >
          <FormsyText
            name='book-title'
            required
            floatingLabelText='Title'
          />
          <FormsyText
            name='book-author-name'
            required
            floatingLabelText='Author'
          />
          <div>
            <FormsyText
              name='book-nb-pages-read'
              value='0'
              validations='isInt'
            />
            <span>of</span>
            <FormsyText
              name='book-nb-pages'
              required
              validations='isInt'
            />
          </div>
          <RaisedButton
            type="submit"
            label="Submit"
            disabled={!this.state.canSubmit}
          />
        </Form>
      );
    }
}

@@ -737,17 +737,17 @@
 me='book
--
+_
 title'%0A 
@@ -865,16 +865,16 @@
 book
--
+_
 author
--
+_
 name
@@ -1016,18 +1016,18 @@
 book
--nb-
+_nb_
 pages
--
+_
 read
@@ -1181,12 +1181,12 @@
 book
--nb-
+_nb_
 page
@@ -1322,16 +1322,16 @@
 ype=
-%22
+'
 submit
-%22
+'
 %0A   
@@ -1349,16 +1349,16 @@
 bel=
-%22
+'
 Submit
-%22
+'
 %0A   

use single quotes only