<commit_before>import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'

import { initializeForm, createNewConversation } from '../actions/inbox'
import { MessageForm } from '../forms'
import { replaceTo } from '../actions/redirect'
import { translate } from '../../../common/services/i18n'

class ConversationsNew extends Component {
  static propTypes = {
    createNewConversation: PropTypes.func.isRequired,
    errorMessage: PropTypes.string.isRequired,
    initializeForm: PropTypes.func.isRequired,
    isLoading: PropTypes.bool.isRequired,
    receiverAnimals: PropTypes.array,
    replaceTo: PropTypes.func.isRequired,
  }

  static defaultProps = {
    receiverAnimals: [],
  }

  componentWillMount() {
    if (this.props.receiverAnimals.length === 0) {
      this.props.replaceTo('/inbox')
      return
    }

    this.props.initializeForm()
  }

  onSubmit(values) {
    const { text, title } = values
    const animalIds = this.props.receiverAnimals.map(animal => animal.id)

    this.props.createNewConversation(animalIds, title, text)
  }

  renderReceiverNames() {
    const names = this.props.receiverAnimals.map(animal => animal.name)

    return (
      <p>
        <strong>
          { translate('views.inbox.messageTo') }
        </strong>
        &nbsp;
        { names.join(', ') }
      </p>
    )
  }

  render() {
    return (
      <section>
        <h1>{ translate('views.inbox.conversationNewTitle') }</h1>
        <Link className="button" to="/inbox">
          { translate('views.inbox.backToConversations') }
        </Link>
        <hr />
        { this.renderReceiverNames() }
        <MessageForm
          errorMessage={this.props.errorMessage}
          isLoading={this.props.isLoading}
          onSubmit={this.onSubmit}
        />
      </section>
    )
  }

  constructor(props) {
    super(props)

    this.onSubmit = this.onSubmit.bind(this)
  }
}

function mapStateToProps(state) {
  const { errorMessage, isLoading } = state.inbox
  const location = state.routing.location

  let receiverAnimals = []
  if (location.query && location.query.receiverAnimals) {
    receiverAnimals = location.query.receiverAnimals
  }

  return {
    errorMessage,
    isLoading,
    receiverAnimals,
  }
}

export default connect(
  mapStateToProps, {
    createNewConversation,
    initializeForm,
    replaceTo,
  }
)(ConversationsNew)<commit_msg>Fix incorrect reducer name for router<commit_after>import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'

import { initializeForm, createNewConversation } from '../actions/inbox'
import { MessageForm } from '../forms'
import { replaceTo } from '../actions/redirect'
import { translate } from '../../../common/services/i18n'

class ConversationsNew extends Component {
  static propTypes = {
    createNewConversation: PropTypes.func.isRequired,
    errorMessage: PropTypes.string.isRequired,
    initializeForm: PropTypes.func.isRequired,
    isLoading: PropTypes.bool.isRequired,
    receiverAnimals: PropTypes.array,
    replaceTo: PropTypes.func.isRequired,
  }

  static defaultProps = {
    receiverAnimals: [],
  }

  componentWillMount() {
    if (this.props.receiverAnimals.length === 0) {
      this.props.replaceTo('/inbox')
      return
    }

    this.props.initializeForm()
  }

  onSubmit(values) {
    const { text, title } = values
    const animalIds = this.props.receiverAnimals.map(animal => animal.id)

    this.props.createNewConversation(animalIds, title, text)
  }

  renderReceiverNames() {
    const names = this.props.receiverAnimals.map(animal => animal.name)

    return (
      <p>
        <strong>
          { translate('views.inbox.messageTo') }
        </strong>
        &nbsp;
        { names.join(', ') }
      </p>
    )
  }

  render() {
    return (
      <section>
        <h1>{ translate('views.inbox.conversationNewTitle') }</h1>
        <Link className="button" to="/inbox">
          { translate('views.inbox.backToConversations') }
        </Link>
        <hr />
        { this.renderReceiverNames() }
        <MessageForm
          errorMessage={this.props.errorMessage}
          isLoading={this.props.isLoading}
          onSubmit={this.onSubmit}
        />
      </section>
    )
  }

  constructor(props) {
    super(props)

    this.onSubmit = this.onSubmit.bind(this)
  }
}

function mapStateToProps(state) {
  const { errorMessage, isLoading } = state.inbox
  const location = state.router.location

  let receiverAnimals = []
  if (location.query && location.query.receiverAnimals) {
    receiverAnimals = location.query.receiverAnimals
  }

  return {
    errorMessage,
    isLoading,
    receiverAnimals,
  }
}

export default connect(
  mapStateToProps, {
    createNewConversation,
    initializeForm,
    replaceTo,
  }
)(ConversationsNew)
{'fraction_non_alphanumeric': 0.12477359629704166, 'fraction_numerical': 0.002012477359629704, 'mean_word_length': 2.852713178294574, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '5379245', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1514, 'n_words': 278}