|
| 1 | +import React, {Component} from "react"; |
| 2 | +import Container from 'react-bootstrap/Container'; |
| 3 | +import Row from 'react-bootstrap/Row'; |
| 4 | +import Col from 'react-bootstrap/Col'; |
| 5 | +import Breadcrumb from 'react-bootstrap/Breadcrumb'; |
| 6 | +import SideMenu from '../components/SideMenu.js'; |
| 7 | +import Loading from '../components/Loading.js'; |
| 8 | +import {connect} from 'react-redux'; |
| 9 | +import {getUserDetails} from '../actions'; |
| 10 | +import { |
| 11 | + faUser, |
| 12 | + faChartBar |
| 13 | +} from '@fortawesome/free-solid-svg-icons'; |
| 14 | +import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 15 | + |
| 16 | +class UserView extends Component { |
| 17 | + |
| 18 | + constructor(props) { |
| 19 | + super(props); |
| 20 | + } |
| 21 | + |
| 22 | + componentDidMount() { |
| 23 | + this.props.getUserDetails(this.props.match.params.id); |
| 24 | + } |
| 25 | + |
| 26 | + render() { |
| 27 | + if(this.props.isLoading) { |
| 28 | + return<Loading />; |
| 29 | + } |
| 30 | + if(!this.props.user) { |
| 31 | + return <span>User not found</span>; |
| 32 | + } |
| 33 | + return ( |
| 34 | + <div> |
| 35 | + <Container fluid> |
| 36 | + <Row> |
| 37 | + <Col lg={3} xl={2} style={{backgroundColor: '#f7f7f7', borderRight: '1px solid #ececec'}} > |
| 38 | + <SideMenu /> |
| 39 | + </Col> |
| 40 | + <Col lg={9} xl={10} style={{paddingTop: '1em'}}> |
| 41 | + <Breadcrumb> |
| 42 | + <Breadcrumb.Item href="#/dashboard">Dashboard</Breadcrumb.Item> |
| 43 | + <Breadcrumb.Item href="#/users">Users</Breadcrumb.Item> |
| 44 | + <Breadcrumb.Item active>{this.props.user.account.displayName} ({this.props.user.account.username})</Breadcrumb.Item> |
| 45 | + </Breadcrumb> |
| 46 | + <div className="card"> |
| 47 | + <div className="card-header"> |
| 48 | + <FontAwesomeIcon size="lg" icon={faUser} /> <strong>Account</strong> |
| 49 | + </div> |
| 50 | + <ul className="list-group list-group-flush"> |
| 51 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 52 | + User name <span className="badge badge-primary badge-pill">{this.props.user.account.username}</span> |
| 53 | + </li> |
| 54 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 55 | + Display name <span className="badge badge-primary badge-pill">{this.props.user.account.displayName}</span> |
| 56 | + </li> |
| 57 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 58 | + Provider <span className="badge badge-primary badge-pill">{this.props.user.account.provider}</span> |
| 59 | + </li> |
| 60 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 61 | + Email <span className="badge badge-primary badge-pill">{this.props.user.account.email}</span> |
| 62 | + </li> |
| 63 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 64 | + Status <span className="badge badge-primary badge-pill">{this.props.user.account.registered ? 'Registered' : 'Unregistered'}</span> |
| 65 | + </li> |
| 66 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 67 | + Role <span className="badge badge-primary badge-pill">{this.props.user.account.role}</span> |
| 68 | + </li> |
| 69 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 70 | + Joined at <span className="badge badge-primary badge-pill">{new Date(this.props.user.account.createdAt).toLocaleString()}</span> |
| 71 | + </li> |
| 72 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 73 | + Last login <span className="badge badge-primary badge-pill">{new Date(this.props.user.account.lastLoginAt).toLocaleString()}</span> |
| 74 | + </li> |
| 75 | + </ul> |
| 76 | + </div> |
| 77 | + <hr /> |
| 78 | + <div className="card"> |
| 79 | + <div className="card-header"> |
| 80 | + <FontAwesomeIcon size="lg" icon={faChartBar} /> <strong>Stats</strong> |
| 81 | + </div> |
| 82 | + <ul className="list-group list-group-flush"> |
| 83 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 84 | + Challenges Completed <span className="badge badge-primary badge-pill">{this.props.user.challenges.length}</span> |
| 85 | + </li> |
| 86 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 87 | + Scripts stored <span className="badge badge-primary badge-pill">{this.props.user.scripts.length}</span> |
| 88 | + </li> |
| 89 | + <li className="list-group-item d-flex justify-content-between align-items-center"> |
| 90 | + Battles stored <span className="badge badge-primary badge-pill">{this.props.user.battles.length}</span> |
| 91 | + </li> |
| 92 | + </ul> |
| 93 | + </div> |
| 94 | + </Col> |
| 95 | + </Row> |
| 96 | + </Container> |
| 97 | + </div> |
| 98 | + ); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +// eslint-disable-next-line no-unused-vars |
| 103 | +const mapStateToProps = (state) => ({ |
| 104 | + user: state.users.selected, |
| 105 | + isLoading: state.loading.USER_VIEW |
| 106 | +}); |
| 107 | + |
| 108 | +const mapDispatchToProps = (dispatch) => ({ |
| 109 | + getUserDetails: (id) => dispatch(getUserDetails(id)) |
| 110 | +}); |
| 111 | +export default connect( |
| 112 | + mapStateToProps, |
| 113 | + mapDispatchToProps |
| 114 | +)(UserView); |
0 commit comments