<commit_before>import app from 'ampersand-app';
import { connect } from 'react-redux';
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import { logout } from '../state/ducks/auth';
import UserAccount from './user-account';


class UserAccountController extends Component {
  constructor(props) {
    super(props);
    this.logout = this.logout.bind(this);
  }

  logout(evt) {
    const { dispatch } = this.props;
    const { router } = this.context;

    evt.preventDefault();

    dispatch(logout())
    .then(() => {
      router.push('/login');
      app.notify({
        level: 'success',
        message: 'Successfully logged out',
      });
    })
    .catch(err => {
      app.logger.error(err);
      app.notify({
        level: 'error',
        message: 'Error logging out',
      });
    });
  }

  render() {
    return (
      <UserAccount logout={this.logout} {...this.props} />
    );
  }

}

UserAccountController.contextTypes = {
  router: PropTypes.object.isRequired,
};

UserAccountController.displayName = 'UserAccountController';

UserAccountController.propTypes = {
  push: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
};

function select(state) {
  return {
    auth: state.auth,
    // if auth is gone, we're probably logging out, use prev state
    user: app.core.auth ? app.core.auth.getUser() : state.auth.user,
  };
}

export default connect(select)(UserAccountController);<commit_msg>Modify user account's `mapStateToProps` function.<commit_after>import app from 'ampersand-app';
import { connect } from 'react-redux';
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import { logout } from '../state/ducks/auth';
import UserAccount from './user-account';


class UserAccountController extends Component {
  constructor(props) {
    super(props);
    this.logout = this.logout.bind(this);
  }

  logout(evt) {
    const { dispatch } = this.props;
    const { router } = this.context;

    evt.preventDefault();

    dispatch(logout())
    .then(() => {
      router.push('/login');
      app.notify({
        level: 'success',
        message: 'Successfully logged out',
      });
    })
    .catch(err => {
      app.logger.error(err);
      app.notify({
        level: 'error',
        message: 'Error logging out',
      });
    });
  }

  render() {
    return (
      <UserAccount logout={this.logout} {...this.props} />
    );
  }

}

UserAccountController.contextTypes = {
  router: PropTypes.object.isRequired,
};

UserAccountController.displayName = 'UserAccountController';

UserAccountController.propTypes = {
  push: PropTypes.func.isRequired,
  dispatch: PropTypes.func.isRequired,
};

const mapStateToProps = ({ auth }) => {
  let user = auth.user;

  // if auth is gone, we're probably logging out, use prev state
  if (typeof app.core.auth === 'object') {
    if ('getUser' in app.core.auth) {
      if (app.core.auth.getUser instanceof Function) {
        user = app.core.auth.getUser();
      }
    }
  }

  return {
    auth,
    user,
  };
};

export default connect(mapStateToProps)(UserAccountController);
{'fraction_non_alphanumeric': 0.14659018483110262, 'fraction_numerical': 0.0, 'mean_word_length': 2.9633838383838382, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '7321960', 'n_tokens_mistral': 970, 'n_tokens_neox': 968, 'n_words': 213}