{"size": 1616, "ext": "js", "max_stars_repo_path": "src/admin/containers/UserProfile/Index.js", "max_stars_repo_name": "jovanidash21/nodejs-express-react-event-registration-system", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/admin/containers/UserProfile/Index.js", "max_issues_repo_name": "jovanidash21/nodejs-express-react-event-registration-system", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/admin/containers/UserProfile/Index.js", "max_forks_repo_name": "jovanidash21/nodejs-express-react-event-registration-system", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.1194029851, "max_line_length": 73, "alphanum_fraction": 0.6101485149}
import React, { Component } from 'react';
import { connect } from 'react-refetch';
import { browserHistory } from 'react-router';
import LoadingAnimation from '../LoadingAnimation/Index';
import Error from '../Error/Index';
import Menu from './Menu';
import Header from './Header';
import Body from './Body';

class UserProfile extends Component {
  constructor(props) {
    super(props);

    this.handleDeleteUserSubmit = this.handleDeleteUserSubmit.bind(this);
  }
  handleDeleteUserSubmit(userID) {
    const { deleteUser } = this.props;

    deleteUser(userID);
    browserHistory.push('/admin/users');
  }

  render() {
    const { userProfileDataFetch } = this.props;

    if (userProfileDataFetch.pending) {
      return <LoadingAnimation />
    }
    else if (userProfileDataFetch.rejected) {
      return <Error error={userProfileDataFetch.reason} />
    }
    else if (userProfileDataFetch.fulfilled) {
      const [user] = userProfileDataFetch.value;
      const { handleDeleteUserSubmit } = this;

      return(
        <div>
          <Menu
            user={user}
            handleDeleteUserSubmit={handleDeleteUserSubmit}
          />
          <Header user={user} />
          <Body user={user} />
        </div>
      )
    }
  }
}

export default connect((props) => {
  return {
    userProfileDataFetch: {
      url: `/api/user/${props.userID}`,
      force: true,
      refreshing: true
    },
    deleteUser: (userID) => ({
      deleteUserFetch: {
        url: `/api/user/${userID}`,
        method: 'DELETE',
        force: true,
        refreshing: true
      }
    })
  }
})(UserProfile);
