<commit_before>import React, { Component } from 'react';
import Redirect from 'react-router/Redirect';
import { isEmail } from 'validator';
import PropTypes from 'prop-types';
import ErrorList from './ErrorList';
import Client from '../Client';
import PageTitle from './PageTitle';
import Button from './Button';
import ViewContainer from './ViewContainer';

const contextTypes = {
  language: PropTypes.object,
};

class RecoverView extends Component {
  constructor() {
    super();

    this.onInputChange = this.onInputChange.bind(this);
    this.onFormSubmit = this.onFormSubmit.bind(this);
  }
  state = {
    fields: {
      email: '',
    },
    fieldErrors: [],
    redirect: false,
  }


  onFormSubmit(event) {
    event.preventDefault();
    let fieldErrors = this.validate(this.state.fields);
    this.setState({ fieldErrors });

    // Return on error.
    if (fieldErrors.length) return;

    const uri = '/api/visitor/request_password_recovery';

    Client.post(this.state.fields, uri)
      .then(() => {
        fieldErrors = ['Email sent!'];
        this.setState({ fieldErrors, fields: {} });
      });


    this.setState({ fields: {}, redirect: true });
  }

  onInputChange(event) {
    const fields = this.state.fields;
    fields[event.target.name] = event.target.value;
    this.setState({ fields });
  }<commit_msg>remove unnecessary setState<commit_after>import React, { Component } from 'react';
import Redirect from 'react-router/Redirect';
import { isEmail } from 'validator';
import PropTypes from 'prop-types';
import ErrorList from './ErrorList';
import Client from '../Client';
import PageTitle from './PageTitle';
import Button from './Button';
import ViewContainer from './ViewContainer';

const contextTypes = {
  language: PropTypes.object,
};

class RecoverView extends Component {
  constructor() {
    super();

    this.onInputChange = this.onInputChange.bind(this);
    this.onFormSubmit = this.onFormSubmit.bind(this);
  }
  state = {
    fields: {
      email: '',
    },
    fieldErrors: [],
    redirect: false,
  }


  onFormSubmit(event) {
    event.preventDefault();
    let fieldErrors = this.validate(this.state.fields);
    this.setState({ fieldErrors });

    // Return on error.
    if (fieldErrors.length) return;

    const uri = '/api/visitor/request_password_recovery';

    Client.post(this.state.fields, uri)
      .then(() => {
        fieldErrors = ['Email sent!'];
        this.setState({ fieldErrors, fields: {}, redirect: true });
      });
  }

  onInputChange(event) {
    const fields = this.state.fields;
    fields[event.target.name] = event.target.value;
    this.setState({ fields });
  }
{'fraction_non_alphanumeric': 0.1438227562898986, 'fraction_numerical': 0.0, 'mean_word_length': 3.324675324675325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350521', 'n_tokens_mistral': 778, 'n_tokens_neox': 775, 'n_words': 188}