UserTable.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, { Fragment } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import dateFnsFormat from 'date-fns/format';
  5. import UserPicture from '../../User/UserPicture';
  6. import { createSubscribedElement } from '../../UnstatedUtils';
  7. import AppContainer from '../../../services/AppContainer';
  8. class UserTable extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. };
  13. }
  14. render() {
  15. const { t } = this.props;
  16. return (
  17. <Fragment>
  18. <h2>{ t('User_Management') }</h2>
  19. <table className="table table-default table-bordered table-user-list">
  20. <thead>
  21. <tr>
  22. <th width="100px">#</th>
  23. <th>{ t('status') }</th>
  24. <th><code>{ t('User') }</code></th>
  25. <th>{ t('Name') }</th>
  26. <th>{ t('Email') }</th>
  27. <th width="100px">{ t('Created') }</th>
  28. <th width="150px">{ t('Last_Login') }</th>
  29. <th width="70px"></th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. {this.props.users.map((user) => {
  34. return (
  35. <tr key={user._id}>
  36. <td>
  37. <UserPicture user={user} className="picture img-circle" />
  38. </td>
  39. <td>{user.admin && <span className="label label-inverse label-admin">{ t('administrator') }</span>}</td>
  40. <td>
  41. <strong>{user.username}</strong>
  42. </td>
  43. <td>{user.name}</td>
  44. <td>{user.email}</td>
  45. <td>{dateFnsFormat(new Date(user.createdAt), 'YYYY-MM-DD')}</td>
  46. <td>
  47. { user.lastLoginAt && <span>{dateFnsFormat(new Date(user.lastLoginAt), 'YYYY-MM-DD HH:mm')}</span> }
  48. </td>
  49. <td>
  50. <div className="btn-group admin-user-menu">
  51. <button type="button" className="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
  52. <i className="icon-settings"></i> <span className="caret"></span>
  53. </button>
  54. </div>
  55. </td>
  56. </tr>
  57. );
  58. })}
  59. </tbody>
  60. </table>
  61. </Fragment>
  62. );
  63. }
  64. }
  65. const UserTableWrapper = (props) => {
  66. return createSubscribedElement(UserTable, props, [AppContainer]);
  67. };
  68. UserTable.propTypes = {
  69. t: PropTypes.func.isRequired, // i18next
  70. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  71. users: PropTypes.array.isRequired,
  72. };
  73. export default withTranslation()(UserTableWrapper);