<commit_before>import React from 'react'
import { reduxForm } from 'redux-form'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import { translate } from 'react-i18next'
import { Link } from 'react-router'

import { register, requestInvitation } from '../../state/users/current_user/effects'
import {
  renderAllUserFields, submitButton,
  validatePasswordRepeat
} from './UserFormFields'
import ThirdPartyAuthList from './ThirdPartyAuthList'
import Notification from '../Utils/Notification'
import Message from '../Utils/Message'
import InvitationRequestForm from './InvitationRequestForm'
import { errorToFlash } from '../../state/flashes/reducer'
import { handleFormEffectResponse } from '../../lib/handle_effect_response'



const SignupForm = ({location, t}) => {
  if (location.query.invitation_token)
    return <RealSignupForm initialValues={{invitation_token: location.query.invitation_token}}/>
  else
    return (
      <div className="user-form">
        <Message
          type="warning"
          header={t('invitationOnlyTitle')}
          body={
            <div>
              {t('invitationOnlyBody')}
              <hr/>
              <InvitationRequestForm/>
            </div>
          }
        />
      </div>
    )
}

export default withRouter(translate('user')(SignupForm))

@withRouter
@translate('user')
@reduxForm({form: 'signupForm', validate: validatePasswordRepeat})
@connect(
  ({CurrentUser: {data}}) => ({CurrentUser: data}),
  {register, requestInvitation, errorToFlash}
)
class RealSignupForm extends React.PureComponent {
  componentWillReceiveProps(props) {
    // Redirect to user profile when logged in
    if (props.CurrentUser.id)
      this.props.router.push(`/u/${props.CurrentUser.username}`)
  }

  submit({invitation_token, ...user}) {
    return this.props.register({invitation_token, user})
      .then(handleFormEffectResponse({
        onError: msg => typeof(msg) === 'string' ? this.props.errorToFlash(msg) : null
      }))
  }

  render() {
    const { valid, error, t } = this.props

    return (
      <form className="form user-form"
            onSubmit={this.props.handleSubmit(this.submit.bind(this))}>
        {error && <Notification type="danger">{error}</Notification>}
        {renderAllUserFields(valid, t)}
        {submitButton(t('signup'), valid)}
        <div>
          {t('alreadyHaveAccountQuestion')} <Link to="login">{t('login')}</Link>.
        </div>
        <ThirdPartyAuthList/>
      </form>
    )}
}<commit_msg>Record user locale on register<commit_after>import React from 'react'
import { reduxForm } from 'redux-form'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import { translate } from 'react-i18next'
import { Link } from 'react-router'

import { register, requestInvitation } from '../../state/users/current_user/effects'
import {
  renderAllUserFields, submitButton,
  validatePasswordRepeat
} from './UserFormFields'
import ThirdPartyAuthList from './ThirdPartyAuthList'
import Notification from '../Utils/Notification'
import Message from '../Utils/Message'
import InvitationRequestForm from './InvitationRequestForm'
import { errorToFlash } from '../../state/flashes/reducer'
import { handleFormEffectResponse } from '../../lib/handle_effect_response'



const SignupForm = ({location, t}) => {
  if (location.query.invitation_token)
    return <RealSignupForm initialValues={{invitation_token: location.query.invitation_token}}/>
  else
    return (
      <div className="user-form">
        <Message
          type="warning"
          header={t('invitationOnlyTitle')}
          body={
            <div>
              {t('invitationOnlyBody')}
              <hr/>
              <InvitationRequestForm/>
            </div>
          }
        />
      </div>
    )
}

export default withRouter(translate('user')(SignupForm))

@withRouter
@translate('user')
@reduxForm({form: 'signupForm', validate: validatePasswordRepeat})
@connect(
  ({CurrentUser: {data}, UserPreferences: {locale}}) => ({CurrentUser: data, locale}),
  {register, requestInvitation, errorToFlash}
)
class RealSignupForm extends React.PureComponent {
  componentWillReceiveProps(props) {
    // Redirect to user profile when logged in
    if (props.CurrentUser.id)
      this.props.router.push(`/u/${props.CurrentUser.username}`)
  }

  submit({invitation_token, ...user}) {
    return this.props.register({invitation_token, user: {...user, locale: this.props.locale}})
      .then(handleFormEffectResponse({
        onError: msg => typeof(msg) === 'string' ? this.props.errorToFlash(msg) : null
      }))
  }

  render() {
    const { valid, error, t } = this.props

    return (
      <form className="form user-form"
            onSubmit={this.props.handleSubmit(this.submit.bind(this))}>
        {error && <Notification type="danger">{error}</Notification>}
        {renderAllUserFields(valid, t)}
        {submitButton(t('signup'), valid)}
        <div>
          {t('alreadyHaveAccountQuestion')} <Link to="login">{t('login')}</Link>.
        </div>
        <ThirdPartyAuthList/>
      </form>
    )}
}
{'fraction_non_alphanumeric': 0.14544392523364486, 'fraction_numerical': 0.000778816199376947, 'mean_word_length': 3.2737104825291183, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, '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': '1539216', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1483, 'n_words': 314}