<commit_before>import React from 'react';
import { compose, graphql } from 'react-apollo';
import { pick } from 'lodash';

import UserAddView from '../components/UserAddView';
import ADD_USER from '../graphql/AddUser.graphql';
import settings from '../../../../../../settings';
import UserFormatter from '../helpers/UserFormatter';

class UserAdd extends React.Component {
  constructor(props) {
    super(props);
  }

  onSubmit = async values => {
    const { addUser, t } = this.props;

    let userValues = pick(values, ['username', 'email', 'role', 'isActive', 'password']);

    userValues['profile'] = pick(values.profile, ['firstName', 'lastName']);

    userValues = UserFormatter.trimExtraSpaces(userValues);

    if (settings.user.auth.certificate.enabled) {
      userValues['auth'] = { certificate: pick(values.auth.certificate, 'serial') };
    }

    const result = await addUser(userValues);

    if (result && result.errors) {
      throw result.errors.reduce(
        (res, error) => {
          res[error.field] = error.message;
          return res;
        },
        { _error: t('userEdit.errorMsg') }
      );
    }
  };

  render() {
    return <UserAddView onSubmit={this.onSubmit} {...this.props} />;
  }
}

export default compose(
  graphql(ADD_USER, {
    props: ({ ownProps: { history, navigation }, mutate }) => ({
      addUser: async input => {
        try {
          const {
            data: { addUser }
          } = await mutate({
            variables: { input }<commit_msg>Define missing 't' prop in UserAdd<commit_after>import React from 'react';
import { compose, graphql } from 'react-apollo';
import { pick } from 'lodash';

import UserAddView from '../components/UserAddView';
import ADD_USER from '../graphql/AddUser.graphql';
import settings from '../../../../../../settings';
import translate from '../../../i18n';
import UserFormatter from '../helpers/UserFormatter';

class UserAdd extends React.Component {
  constructor(props) {
    super(props);
  }

  onSubmit = async values => {
    const { addUser, t } = this.props;

    let userValues = pick(values, ['username', 'email', 'role', 'isActive', 'password']);

    userValues['profile'] = pick(values.profile, ['firstName', 'lastName']);

    userValues = UserFormatter.trimExtraSpaces(userValues);

    if (settings.user.auth.certificate.enabled) {
      userValues['auth'] = { certificate: pick(values.auth.certificate, 'serial') };
    }

    const result = await addUser(userValues);

    if (result && result.errors) {
      throw result.errors.reduce(
        (res, error) => {
          res[error.field] = error.message;
          return res;
        },
        { _error: t('userEdit.errorMsg') }
      );
    }
  };

  render() {
    return <UserAddView onSubmit={this.onSubmit} {...this.props} />;
  }
}

export default compose(
  translate('user'),
  graphql(ADD_USER, {
    props: ({ ownProps: { history, navigation }, mutate }) => ({
      addUser: async input => {
        try {
          const {
            data: { addUser }
          } = await mutate({
            variables: { input }
{'fraction_non_alphanumeric': 0.16135265700483092, 'fraction_numerical': 0.0006441223832528181, 'mean_word_length': 2.742168674698795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5447666', 'n_tokens_mistral': 925, 'n_tokens_neox': 905, 'n_words': 218}