{"size": 1317, "ext": "js", "max_stars_repo_path": "client/components/resetPassword.js", "max_stars_repo_name": "graceful-shoppers/Grace-Shopper", "max_stars_repo_stars_event_min_datetime": "2019-07-30T13:11:54.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-09T23:13:30.000Z", "max_issues_repo_path": "client/components/resetPassword.js", "max_issues_repo_name": "Graceful-Shoppers/grace-shopper", "max_issues_repo_issues_event_min_datetime": "2018-04-16T20:25:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-20T13:35:37.000Z", "max_forks_repo_path": "client/components/resetPassword.js", "max_forks_repo_name": "graceful-shoppers/Grace-Shopper", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 26, "max_forks_count": null, "avg_line_length": 21.2419354839, "max_line_length": 79, "alphanum_fraction": 0.6233864844}
import React from 'react'
import {connect} from 'react-redux'
import {editSelfPassword} from '../store/user'

class ResetPassword extends React.Component {
  constructor() {
    super()

    this.state = {
      newPassword: ''
    }

    this.handleChange = this.handleChange.bind(this)
    this.changePassword = this.changePassword.bind(this)
  }

  async handleChange(event) {
    await this.setState({
      [event.target.name]: event.target.value
    })
  }

  changePassword(user) {
    let updatedUser = user
    updatedUser.password = this.state.newPassword
    updatedUser.needPasswordReset = false
    this.props.editSelfPassword(updatedUser)
    console.log(updatedUser)
  }

  render() {
    return (
      <div>
        Looks like it is time to reset your password!
        <div>
          <input type="text" name="newPassword" onChange={this.handleChange} />
          <button
            type="button"
            onClick={() => this.changePassword(this.props.user)}
          >
            Submit
          </button>
        </div>
      </div>
    )
  }
}

const mapState = state => {
  return {
    user: state.user
  }
}

const mapDispatch = dispatch => {
  return {
    editSelfPassword: user => dispatch(editSelfPassword(user))
  }
}

export default connect(mapState, mapDispatch)(ResetPassword)
