UserTable.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 UserMenu from './UserMenu';
  7. import { createSubscribedElement } from '../../UnstatedUtils';
  8. import AppContainer from '../../../services/AppContainer';
  9. class UserTable extends React.Component {
  10. render() {
  11. const { t } = this.props;
  12. let userStatusLabel;
  13. let additionalClassName;
  14. let text;
  15. this.props.users.forEach((user) => {
  16. userStatusLabel = (
  17. <span className={`label ${additionalClassName}`}>
  18. {text}
  19. </span>
  20. );
  21. switch (user.status) {
  22. case 1:
  23. additionalClassName = 'label-info';
  24. text = 'Approval Pending';
  25. break;
  26. case 2:
  27. additionalClassName = 'label-success';
  28. text = 'Active';
  29. break;
  30. case 3:
  31. additionalClassName = 'label-warning';
  32. text = 'Suspended';
  33. break;
  34. case 4:
  35. additionalClassName = 'label-danger';
  36. text = 'Deleted';
  37. break;
  38. case 5:
  39. additionalClassName = 'label-info';
  40. text = 'Invited';
  41. break;
  42. }
  43. });
  44. return (
  45. <Fragment>
  46. <h2>{ t('User_Management') }</h2>
  47. <table className="table table-default table-bordered table-user-list">
  48. <thead>
  49. <tr>
  50. <th width="100px">#</th>
  51. <th>{ t('status') }</th>
  52. <th><code>{ t('User') }</code></th>
  53. <th>{ t('Name') }</th>
  54. <th>{ t('Email') }</th>
  55. <th width="100px">{ t('Created') }</th>
  56. <th width="150px">{ t('Last_Login') }</th>
  57. <th width="70px"></th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. {this.props.users.map((user) => {
  62. return (
  63. <tr key={user._id}>
  64. <td>
  65. <UserPicture user={user} className="picture img-circle" />
  66. {user.admin && <span className="label label-inverse label-admin ml-2">{ t('administrator') }</span>}
  67. </td>
  68. <td>{userStatusLabel}</td>
  69. <td>
  70. <strong>{user.username}</strong>
  71. </td>
  72. <td>{user.name}</td>
  73. <td>{user.email}</td>
  74. <td>{dateFnsFormat(new Date(user.createdAt), 'YYYY-MM-DD')}</td>
  75. <td>
  76. { user.lastLoginAt && <span>{dateFnsFormat(new Date(user.lastLoginAt), 'YYYY-MM-DD HH:mm')}</span> }
  77. </td>
  78. <td>
  79. <UserMenu user={user} />
  80. </td>
  81. </tr>
  82. );
  83. })}
  84. </tbody>
  85. </table>
  86. </Fragment>
  87. );
  88. }
  89. }
  90. const UserTableWrapper = (props) => {
  91. return createSubscribedElement(UserTable, props, [AppContainer]);
  92. };
  93. UserTable.propTypes = {
  94. t: PropTypes.func.isRequired, // i18next
  95. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  96. users: PropTypes.array.isRequired,
  97. };
  98. export default withTranslation()(UserTableWrapper);