<commit_before>import Immutable from 'immutable';
import PropTypes from 'prop-types';
import moment from 'moment';
import ImmutablePropTypes from 'react-immutable-proptypes';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Button, Container, Row, Col } from 'reactstrap';
import { connect } from 'react-redux';

import { fetchUser, updateUser } from '../store/users/actions';
import { getUser, getUserErrors } from '../store/users/selectors';

import { getAccount } from '../store/account/selectors';
import ControlledForm from './controlled-form';


const EDIT_PROFILE_FIELDS = new Immutable.OrderedSet([
  new Immutable.Map({
    name: 'name',
    title: 'Name',
    type: 'text',
  }),
  new Immutable.Map({
    name: 'bio',
    title: 'Bio',
    type: 'textarea',
  }),
  new Immutable.Map({
    name: 'website',
    title: 'Website',
    type: 'text',
  }),
]);


class EditProfilePage extends Component {
  static propTypes = {
    account: ImmutablePropTypes.map.isRequired,
    profileError: ImmutablePropTypes.map.isRequired,
    fetchUser: PropTypes.func.isRequired,
    match: PropTypes.object.isRequired,
    updateUser: PropTypes.func.isRequired,
  };

  static defaultProps = {
    account: null,
  };

  componentWillMount() {
    this.props.fetchUser({ id: this.props.match.params.userId });
  }

  handleSubmit = (data) => {
    const updatedData = this.props.account.reduce((result, value, key) => {
      if (data[key] === value) {
        return result;
      }
      result[key] = data[key];
      return result;
    }, {});

    this.props.updateUser({ id: this.props.account.get('id'), ...updatedData });
  }

  renderForm() {
    return (
      <ControlledForm
        actionTitle="Edit profile"
        fields={EDIT_PROFILE_FIELDS}
        errors={new Immutable.Map()}
        values={this.props.account}
        onSubmit={this.handleSubmit}
      />
    );
  }

  render() {
    if (!this.props.account) {
      return <div>Loading...</div>;
    }

    return (
      <div className="edit-account-page">
        <Container>
          <Row>
            <Col sm={12}>
              <Link to={`/users/${this.props.account.get('id')}`}>
                Back to profile page
              </Link>
            </Col>
          </Row>
          <Row>
            <Col sm={12}>
              <h2>Edit {this.props.account.get('name')}</h2>
            </Col>
          </Row>
          <Row>
            <Col sm={12}>
              {this.renderForm()}
            </Col>
          </Row>
        </Container>
      </div>
    );
  }
}

const mapStateToProps = (state, props) => ({
  account: getAccount(state),
  userErrors: getUserErrors(state),
});

const mapDispatchToProps = {
  updateUser,
  fetchUser,
};
<commit_msg>Fix back to profile link url.<commit_after>import Immutable from 'immutable';
import PropTypes from 'prop-types';
import moment from 'moment';
import ImmutablePropTypes from 'react-immutable-proptypes';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Button, Container, Row, Col } from 'reactstrap';
import { connect } from 'react-redux';

import { fetchUser, updateUser } from '../store/users/actions';
import { getUser, getUserErrors } from '../store/users/selectors';

import { getAccount } from '../store/account/selectors';
import ControlledForm from './controlled-form';


const EDIT_PROFILE_FIELDS = new Immutable.OrderedSet([
  new Immutable.Map({
    name: 'name',
    title: 'Name',
    type: 'text',
  }),
  new Immutable.Map({
    name: 'bio',
    title: 'Bio',
    type: 'textarea',
  }),
  new Immutable.Map({
    name: 'website',
    title: 'Website',
    type: 'text',
  }),
]);


class EditProfilePage extends Component {
  static propTypes = {
    account: ImmutablePropTypes.map.isRequired,
    profileError: ImmutablePropTypes.map.isRequired,
    fetchUser: PropTypes.func.isRequired,
    match: PropTypes.object.isRequired,
    updateUser: PropTypes.func.isRequired,
  };

  static defaultProps = {
    account: null,
  };

  componentWillMount() {
    this.props.fetchUser({ id: this.props.match.params.userId });
  }

  handleSubmit = (data) => {
    const updatedData = this.props.account.reduce((result, value, key) => {
      if (data[key] === value) {
        return result;
      }
      result[key] = data[key];
      return result;
    }, {});

    this.props.updateUser({ id: this.props.account.get('id'), ...updatedData });
  }

  renderForm() {
    return (
      <ControlledForm
        actionTitle="Edit profile"
        fields={EDIT_PROFILE_FIELDS}
        errors={new Immutable.Map()}
        values={this.props.account}
        onSubmit={this.handleSubmit}
      />
    );
  }

  render() {
    if (!this.props.account) {
      return <div>Loading...</div>;
    }

    return (
      <div className="edit-account-page">
        <Container>
          <Row>
            <Col sm={12}>
              <Link to={`/people/${this.props.account.get('id')}`}>
                Back to profile page
              </Link>
            </Col>
          </Row>
          <Row>
            <Col sm={12}>
              <h2>Edit {this.props.account.get('name')}</h2>
            </Col>
          </Row>
          <Row>
            <Col sm={12}>
              {this.renderForm()}
            </Col>
          </Row>
        </Container>
      </div>
    );
  }
}

const mapStateToProps = (state, props) => ({
  account: getAccount(state),
  userErrors: getUserErrors(state),
});

const mapDispatchToProps = {
  updateUser,
  fetchUser,
};

{'fraction_non_alphanumeric': 0.153088630259624, 'fraction_numerical': 0.002864816472694718, 'mean_word_length': 2.4165137614678898, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 55, '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': '354654', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1731, 'n_words': 373}