import React, { PropTypes } from 'react';
import { reduxForm } from 'redux-form';
import validator from 'validator';

import { Button } from 'react-bootstrap';

import * as api from '../api';
import Icon from '../components/icon';
import { FormGroup } from '../components/form';

const validateChangeEmail = values => {
  return values.email && validator.isEmail(values.email) ? {} :
    { email: 'Please provide a valid email address' };
};

class ChangeEmailForm extends React.Component {

  constructor(props) {
    super(props);
    this.handleSubmit = this.props.handleSubmit(this.handleSubmit.bind(this));
  }

  handleSubmit(values) {
    console.log("HOWDY")
    return new Promise((resolve, reject) => {
      const { email } = values;
      api.changeEmail(values.email)
      .then(() => {
        this.props.onComplete(email);
        resolve();
      }, error => {
        reject(error.data);
      });
    });
  }

  render() {
    const {
      submitting,
      fields: { email },
    } = this.props;

    return (
      <form className="form form-vertical" onSubmit={this.handleSubmit}>
            <FormGroup field={email}>
            <input type="email" className="form-control" {...email} />
          </FormGroup>

          <Button
            bsStyle="primary"
            className="form-control"
            disabled={submitting}
            type="submit"
          >
            <Icon icon="save"/> Save new email address
          </Button>
      </form>
    );
  }
}

ChangeEmailForm.propTypes = {
  onComplete: PropTypes.func.isRequired,
  handleSubmit: PropTypes.func.isRequired,
  submitting: PropTypes.bool.isRequired,
  fields: PropTypes.object.isRequired,
};

export default reduxForm({
  form: 'change-email',
  fields: ['email'],
  validate: validateChangeEmail,
}, state => ({
  initialValues: state.auth,
}))(ChangeEmailForm);

@@ -554,32 +554,8 @@
 t = 
-this.props.handleSubmit(
 this
@@ -578,17 +578,16 @@
 nd(this)
-)
 ;%0A  %7D%0A%0A 
@@ -614,33 +614,8 @@
 ) %7B%0A
-    console.log(%22HOWDY%22)%0A
     
@@ -897,16 +897,36 @@
 const %7B%0A
+      handleSubmit,%0A
       su
@@ -1047,16 +1047,29 @@
 Submit=%7B
+handleSubmit(
 this.han
@@ -1077,23 +1077,20 @@
 leSubmit
+)
 %7D%3E%0A
-    
         
@@ -1115,18 +1115,16 @@
 email%7D%3E%0A
-  
         
@@ -1192,18 +1192,16 @@
         
-  
 %3C/FormGr
@@ -1205,19 +1205,16 @@
 mGroup%3E%0A
-%0A  
         
@@ -1231,18 +1231,16 @@
         
-  
 bsStyle=
@@ -1249,18 +1249,16 @@
 rimary%22%0A
-  
         
@@ -1294,18 +1294,16 @@
         
- 
- 
 disabled
@@ -1326,18 +1326,16 @@
         
-  
 type=%22su
@@ -1340,18 +1340,16 @@
 submit%22%0A
-  
         
@@ -1360,18 +1360,16 @@
         
-  
 %3CIcon ic
@@ -1403,18 +1403,16 @@
 address%0A
-  
         

Fix change forms