import React, { Component } from 'react';
import { Button, Input, Col, Row } from 'react-materialize';
import { reduxForm, reset } from 'redux-form';
import { addRoom } from '../actions/rooms.action.js';

class AddRoomForm extends Component {
  addRoom(newRoomObj) {
    console.log(newRoomObj, this);
    const {addRoom, dispatch} = this.props;
    addRoom(newRoomObj);
    dispatch(reset('AddRoomForm'));
  }

  render() {
    const { fields: { roomName, size, notes }, handleSubmit } = this.props;

    return (
      <form onSubmit={ handleSubmit(this.addRoom.bind(this)) } >
        <Col s={12}>
          <Row>
            <Input type="text" placeholder="Room Name" s={6} label="Room Name" { ...roomName } />
            <Input type="text" placeholder="Size" s={6} label="Size" { ...size } />
          </Row>
          <Row>
            <div class="input-field col s12">
              <label for="textarea1">Notes</label>
              <textarea id="textarea1" className="materialize-textarea" placeholder="Notes" { ...notes }></textarea>
            </div>
          </Row>
        </Col>
        <Button type="submit">Submit</Button>
      </form>
    );
  }
}

export default reduxForm({
  form: 'AddRoomForm',
  fields: ['roomName', 'size', 'notes'],
}, null, { addRoom })(AddRoomForm);

function mapDispatchToProps(dispatch) {
  return bindActionCreators(null, dispatch);
}

import React, { Component } from 'react';
import { Button, Input, Col, Row } from 'react-materialize';
import { reduxForm } from 'redux-form';
import { addRoom } from '../actions/rooms.action.js';

class AddRoomForm extends Component {
  render() {
    const { fields: { roomName, size, notes }, handleSubmit } = this.props;

    return (
      <form onSubmit={ handleSubmit(this.props.addRoom) } >
        <Col s={12}>
          <Row>
            <Input type="text" placeholder="Room Name" s={6} label="Room Name" { ...roomName } />
            <Input type="text" placeholder="Size" s={6} label="Size" { ...size } />
          </Row>
          <Row>
            <div class="input-field col s12">
              <label for="textarea1">Notes</label>
              <textarea id="textarea1" className="materialize-textarea" placeholder="Notes" { ...notes }></textarea>
            </div>
          </Row>
        </Col>
        <Button type="submit">Submit</Button>
      </form>
    );
  }
}

export default reduxForm({
  form: 'AddRoomForm',
  fields: ['roomName', 'size', 'notes'],
}, null, { addRoom })(AddRoomForm);

Revert "fix(add room form): submit now clears form"
Revert "fix(add room form): submit now clears form"

This reverts commit 993c8f795e746ecc17bb31ca473d586ca4c4f98f.
