<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { push } from 'connected-react-router'
import queryString from 'query-string'

import LoadingIndicator from '../progress/dots.jsx'
import RaisedButton from '../material/raised-button.jsx'
import { retrieveUsername, startPasswordReset, resetPassword } from './auther'
import form from '../forms/form.jsx'
import SubmitOnEnter from '../forms/submit-on-enter.jsx'
import {
  AuthContentContainer,
  AuthContent,
  AuthTitle,
  AuthBody,
  LoadingArea,
  ErrorsContainer,
  SuccessContainer,
  AuthBottomAction,
  BottomActionButton,
  FieldRow,
  AuthTextField,
  AuthPasswordTextField,
} from './auth-content.jsx'

import {
  composeValidators,
  minLength,
  maxLength,
  matchesOther,
  regex,
  required,
} from '../forms/validators'
import {
  EMAIL_MINLENGTH,
  EMAIL_MAXLENGTH,
  EMAIL_PATTERN,
  PASSWORD_MINLENGTH,
  USERNAME_MINLENGTH,
  USERNAME_MAXLENGTH,
  USERNAME_PATTERN,
} from '../../common/constants'

const emailValidator = composeValidators(
  required('Enter an email address'),
  minLength(EMAIL_MINLENGTH, `Use at least ${EMAIL_MINLENGTH} characters`),
  maxLength(EMAIL_MAXLENGTH, `Use at most ${EMAIL_MAXLENGTH} characters`),
  regex(EMAIL_PATTERN, 'Enter a valid email address'),
)
const usernameValidator = composeValidators(
  required('Enter a username'),
  minLength(USERNAME_MINLENGTH, `Enter at least ${USERNAME_MINLENGTH} characters`),
  maxLength(USERNAME_MAXLENGTH, `Enter at most ${USERNAME_MAXLENGTH} characters`),
  regex(USERNAME_PATTERN, 'Username contains invalid characters'),
)

@connect(state => ({ auth: state.auth }))
class ForgotFormHolder extends React.Component {
  static propTypes = {
    // The Form component class to render
    form: PropTypes.func.isRequired,
    title: PropTypes.string.isRequired,
    model: PropTypes.object,
    doSubmit: PropTypes.func.isRequired,
    successMessage: PropTypes.string,
  }

  state = {
    reqId: null,
    success: false,
  }
  _form = null
  _setForm = elem => {
    this._form = elem
  }

  componentWillUpdate(nextProps, nextState) {
    if (this.props.auth.authChangeInProgress && !nextProps.auth.authChangeInProgress) {
      if (this.state.reqId && !nextProps.auth.lastFailure) {
        this._form.reset()
        this.setState({ success: true })
      }
    }
  }

  render() {
    const {
      auth: { authChangeInProgress, lastFailure },
      form: FormComponent,
      model,
      title,
      successMessage,
    } = this.props
    let loadingContents
    if (authChangeInProgress) {
      loadingContents = (
        <LoadingArea>
          <LoadingIndicator /><commit_msg>Move forgot.jsx componentWillUpdate -> componentDidUpdate. (#562)<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { push } from 'connected-react-router'
import queryString from 'query-string'

import LoadingIndicator from '../progress/dots.jsx'
import RaisedButton from '../material/raised-button.jsx'
import { retrieveUsername, startPasswordReset, resetPassword } from './auther'
import form from '../forms/form.jsx'
import SubmitOnEnter from '../forms/submit-on-enter.jsx'
import {
  AuthContentContainer,
  AuthContent,
  AuthTitle,
  AuthBody,
  LoadingArea,
  ErrorsContainer,
  SuccessContainer,
  AuthBottomAction,
  BottomActionButton,
  FieldRow,
  AuthTextField,
  AuthPasswordTextField,
} from './auth-content.jsx'

import {
  composeValidators,
  minLength,
  maxLength,
  matchesOther,
  regex,
  required,
} from '../forms/validators'
import {
  EMAIL_MINLENGTH,
  EMAIL_MAXLENGTH,
  EMAIL_PATTERN,
  PASSWORD_MINLENGTH,
  USERNAME_MINLENGTH,
  USERNAME_MAXLENGTH,
  USERNAME_PATTERN,
} from '../../common/constants'

const emailValidator = composeValidators(
  required('Enter an email address'),
  minLength(EMAIL_MINLENGTH, `Use at least ${EMAIL_MINLENGTH} characters`),
  maxLength(EMAIL_MAXLENGTH, `Use at most ${EMAIL_MAXLENGTH} characters`),
  regex(EMAIL_PATTERN, 'Enter a valid email address'),
)
const usernameValidator = composeValidators(
  required('Enter a username'),
  minLength(USERNAME_MINLENGTH, `Enter at least ${USERNAME_MINLENGTH} characters`),
  maxLength(USERNAME_MAXLENGTH, `Enter at most ${USERNAME_MAXLENGTH} characters`),
  regex(USERNAME_PATTERN, 'Username contains invalid characters'),
)

@connect(state => ({ auth: state.auth }))
class ForgotFormHolder extends React.Component {
  static propTypes = {
    // The Form component class to render
    form: PropTypes.func.isRequired,
    title: PropTypes.string.isRequired,
    model: PropTypes.object,
    doSubmit: PropTypes.func.isRequired,
    successMessage: PropTypes.string,
  }

  state = {
    reqId: null,
    success: false,
  }
  _form = null
  _setForm = elem => {
    this._form = elem
  }

  componentDidUpdate(prevProps) {
    if (prevProps.auth.authChangeInProgress && !this.props.auth.authChangeInProgress) {
      if (this.state.reqId && !this.props.auth.lastFailure) {
        this._form.reset()
        this.setState({ success: true })
      }
    }
  }

  render() {
    const {
      auth: { authChangeInProgress, lastFailure },
      form: FormComponent,
      model,
      title,
      successMessage,
    } = this.props
    let loadingContents
    if (authChangeInProgress) {
      loadingContents = (
        <LoadingArea>
          <LoadingIndicator />
{'fraction_non_alphanumeric': 0.10886726638516615, 'fraction_numerical': 0.0005507618872774004, 'mean_word_length': 3.9303167420814478, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '78386', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1653, 'n_words': 383}