UserTable.jsx 3.5 KB

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