import React, { PropTypes, Component } from 'react'

import { connect } from 'react-redux'

import Card from './../atoms/Card'

import {
  fetchUser
} from './../../redux/actions/admin-actions'

class EditUserForm extends Component {

  constructor(props) {
    super(props)
  }

  componentDidMount() {
    this.props.dispatch(fetchUser(this.props.params.id))
  }

  render() {

    const editId = this.props.admin.users.currentlyEditing

    const user = editId ?
    this.props.admin.users.results.find(user => {
      return user.id === editId
    }) :
    {}

    return (
      <section className="container">
        <Card>
          <pre>Edit User</pre>
          <form
            action={"/api/v1/user/edit/" + user.id}
            method="POST">

            {
              this.props.error &&
              <label>{this.props.error}</label>
            }

            <fieldset>

              <label htmlFor="name">Name</label>
              <input
                type="text"
                name="name"
                value={user.name ? user.name : ""} />

              <label htmlFor="emailAddress">Email Address</label>
              <input
                type="text"
                name="emailAddress"
                value={user.emailAddress ? user.emailAddress : ""} />

              <label htmlFor="password">Password</label>
              <input
                type="password"
                name="password"
                placeholder="hunter2" />

              <button type="submit">Update</button>

            </fieldset>

          </form>
        </Card>
      </section>
    )
  }

}

EditUserForm.propTypes = {
  id: PropTypes.number,
  name: PropTypes.string,
  emailAddress: PropTypes.string,
  error: PropTypes.string,
  admin: PropTypes.object,
  user: PropTypes.object,
  ui: PropTypes.object,
  dispatch: PropTypes.func
}

export default connect(
  state => ({
    admin: state.admin
  })
)(EditUserForm)

@@ -359,16 +359,93 @@
 ))%0A  %7D%0A%0A
+  handleChange(event) %7B%0A    this.setState(%7Bvalue: event.target.value%7D);%0A  %7D%0A%0A
   render
@@ -1135,24 +1135,69 @@
 r.name : %22%22%7D
+%0A                onChange=%7Bthis.handleChange%7D
  /%3E%0A%0A       
@@ -1406,16 +1406,61 @@
 ss : %22%22%7D
+%0A                onChange=%7Bthis.handleChange%7D
  /%3E%0A%0A   

fix bug with edit form input fields