<commit_before>import React, {Component} from 'react'
import Dialog from 'react-toolbox/lib/dialog/Dialog'
import Input from 'react-toolbox/lib/input/Input'
import Dropdown from 'react-toolbox/lib/dropdown/Dropdown'
import Button from 'react-toolbox/lib/button/Button'
import { browserHistory } from 'react-router'
import { connect } from 'react-redux'
import {
  fetchSingleClient,
  resetClient,
  updateClientField,
  saveClient,
  createClient
} from '../reducers/clients.reducer'

class EditClient extends Component {
  state = {
    active: true
  }
  componentDidMount() {
    const { routeParams, dispatch } = this.props;
    const id = parseInt(routeParams.id, 10);
    if(!isNaN(id)) {
      dispatch(fetchSingleClient(id))
    }
  }
  componentWillUnmount() {
    this.props.dispatch(resetClient())
  }

  onCancel = () => {
    browserHistory.push('/users')
  }
  onSubmit = (ev) => {
    ev.preventDefault()
    const { client, dispatch, routeParams } = this.props
    let action = null
    if(isNaN(routeParams.id)) {
      action = createClient
    } else {
      action = saveClient
    }
    dispatch(action(client))
  }
  onChange = (text, ev) => {
    const name = ev.target.name;
    this.props.dispatch(updateClientField(name, text))
  }
  render() {
    const statusOptions = [
      {value: "INTERNAL", label: "Interno"},
      {value: "CONTACT", label: "Contacto"},
    ]
    const dialogActions = [
      {label: "Cancelar", onClick: this.onCancel},
      {label: "Guardar", primary: true, onClick: this.onSubmit}
    ]
    const {client, loading, error, routeParams} = this.props;
    return (
      <div className="edit-client">
        <Dialog
          active={this.state.active}
          onEscKeyDown={this.onCancel}
          onOverlayClick={this.onCancel}
          title={isNaN(routeParams.id) ? 'Nuevo cliente':'Editar cliente'}
        >
          {loading && <p className="color-primary">Cargando ...</p>}
          {error && <p className="color-error">{error}</p>}
          <form onSubmit={this.onSubmit}
                style={{
                  display: loading ? 'none':'block'
                }}>
            <Input
              name="name"
              label="Nombre"
              value={client.name || ''}
              onChange={this.onChange}
            />
            <Dropdown
              name="typeUser"
              label="Tipo de usuario"
              icon="info"
              source={statusOptions}
              value={client.typeCompany || ''}
              onChange={this.onChange}
            />
            <Input
              icon="location_on"
              name="address"
              label="Dirección"
              value={client.address || ''}
              onChange={this.onChange}
            />
            <Button
              primary raised
              label="Guardar"
              type="submit"
            />
          </form>
        </Dialog>
      </div>
    );
  }
}

const mapStateToProps = (state, ownProps) => {
  return {
    error: state.clients.error,
    loading: state.clients.loading,
    client: state.clients.activeClient || {}
  }
}

export default connect(mapStateToProps)(EditClient);
<commit_msg>fix: client edit type field<commit_after>import React, {Component} from 'react'
import Dialog from 'react-toolbox/lib/dialog/Dialog'
import Input from 'react-toolbox/lib/input/Input'
import Dropdown from 'react-toolbox/lib/dropdown/Dropdown'
import Button from 'react-toolbox/lib/button/Button'
import { browserHistory } from 'react-router'
import { connect } from 'react-redux'
import {
  fetchSingleClient,
  resetClient,
  updateClientField,
  saveClient,
  createClient
} from '../reducers/clients.reducer'

class EditClient extends Component {
  state = {
    active: true
  }
  componentDidMount() {
    const { routeParams, dispatch } = this.props;
    const id = parseInt(routeParams.id, 10);
    if(!isNaN(id)) {
      dispatch(fetchSingleClient(id))
    }
  }
  componentWillUnmount() {
    this.props.dispatch(resetClient())
  }

  onCancel = () => {
    browserHistory.push('/clients')
  }
  onSubmit = (ev) => {
    ev.preventDefault()
    const { client, dispatch, routeParams } = this.props
    let action = null
    if(isNaN(routeParams.id)) {
      action = createClient
    } else {
      action = saveClient
    }
    dispatch(action(client))
  }
  onChange = (text, ev) => {
    const name = ev.target.name;
    this.props.dispatch(updateClientField(name, text))
  }
  render() {
    const statusOptions = [
      {value: "INTERNAL", label: "Interno"},
      {value: "CONTACT", label: "Contacto"},
    ]
    const dialogActions = [
      {label: "Cancelar", onClick: this.onCancel},
      {label: "Guardar", primary: true, onClick: this.onSubmit}
    ]
    const {client, loading, error, routeParams} = this.props;
    return (
      <div className="edit-client">
        <Dialog
          active={this.state.active}
          onEscKeyDown={this.onCancel}
          onOverlayClick={this.onCancel}
          title={isNaN(routeParams.id) ? 'Nuevo cliente':'Editar cliente'}
        >
          {loading && <p className="color-primary">Cargando ...</p>}
          {error && <p className="color-error">{error}</p>}
          <form onSubmit={this.onSubmit}
                style={{
                  display: loading ? 'none':'block'
                }}>
            <Input
              name="name"
              label="Nombre"
              value={client.name || ''}
              onChange={this.onChange}
            />
            <Dropdown
              name="typeCompany"
              label="Tipo de cliente"
              icon="info"
              source={statusOptions}
              value={client.typeCompany || ''}
              onChange={this.onChange}
            />
            <Input
              icon="location_on"
              name="address"
              label="Dirección"
              value={client.address || ''}
              onChange={this.onChange}
            />
            <Button
              primary raised
              label="Guardar"
              type="submit"
            />
          </form>
        </Dialog>
      </div>
    );
  }
}

const mapStateToProps = (state, ownProps) => {
  return {
    error: state.clients.error,
    loading: state.clients.loading,
    client: state.clients.activeClient || {}
  }
}

export default connect(mapStateToProps)(EditClient);

{'fraction_non_alphanumeric': 0.13222239526553498, 'fraction_numerical': 0.0006229559258682448, 'mean_word_length': 2.0860163382988945, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, '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': '6691816', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1869, 'n_words': 364}