ExternalAccountTable.jsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 { createSubscribedElement } from '../../UnstatedUtils';
  6. import AppContainer from '../../../services/AppContainer';
  7. import AdminExternalAccountsContainer from '../../../services/AdminExternalAccountsContainer';
  8. import { toastSuccess, toastError } from '../../../util/apiNotification';
  9. class ExternalAccountTable extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. };
  14. this.getUserStatusLabel = this.getUserStatusLabel.bind(this);
  15. this.removeExtenalAccount = this.removeExtenalAccount.bind(this);
  16. }
  17. // remove external-account
  18. async removeExtenalAccount(externalAccountId) {
  19. try {
  20. await this.props.adminExternalAccountsContainer.removeExternal(externalAccountId);
  21. toastSuccess(`Removed "${this.xss.process(externalAccountId)}"`);
  22. }
  23. catch (err) {
  24. toastError(new Error(`Unable to remove "${this.xss.process(externalAccountId)}"`));
  25. }
  26. }
  27. /**
  28. * user.statusをみてステータスのラベルを返す
  29. * @param {string} userStatus
  30. * @return ステータスラベル
  31. */
  32. getUserStatusLabel(userStatus) {
  33. let additionalClassName;
  34. let text;
  35. switch (userStatus) {
  36. case 1:
  37. additionalClassName = 'label-info';
  38. text = 'Approval Pending';
  39. break;
  40. case 2:
  41. additionalClassName = 'label-success';
  42. text = 'Active';
  43. break;
  44. case 3:
  45. additionalClassName = 'label-warning';
  46. text = 'Suspended';
  47. break;
  48. case 4:
  49. additionalClassName = 'label-danger';
  50. text = 'Deleted';
  51. break;
  52. case 5:
  53. additionalClassName = 'label-info';
  54. text = 'Invited';
  55. break;
  56. }
  57. return (
  58. <span className={`label ${additionalClassName}`}>
  59. {text}
  60. </span>
  61. );
  62. }
  63. render() {
  64. const { t, adminExternalAccountsContainer } = this.props;
  65. return (
  66. <Fragment>
  67. <table className="table table-bordered table-user-list">
  68. <thead>
  69. <tr>
  70. <th width="120px">{ t('user_management.authentication_provider') }</th>
  71. <th><code>accountId</code></th>
  72. <th>{ t('user_management.related_username', 'username') }</th>
  73. <th>
  74. { t('user_management.password_setting') }
  75. <div
  76. className="text-muted"
  77. data-toggle="popover"
  78. data-placement="top"
  79. data-trigger="hover focus"
  80. tabIndex="0"
  81. role="button"
  82. data-animation="false"
  83. data-html="true"
  84. data-content={t('user_management.password_setting_help')}
  85. >
  86. <small>
  87. <i className="icon-question" aria-hidden="true"></i>
  88. </small>
  89. </div>
  90. </th>
  91. <th width="100px">{ t('Created') }</th>
  92. <th width="70px"></th>
  93. </tr>
  94. </thead>
  95. <tbody>
  96. {adminExternalAccountsContainer.state.exteranalAccounts.map((ea) => {
  97. const { externalAccount } = ea;
  98. return (
  99. <tr>
  100. <td>{externalAccount.providerType}</td>
  101. <td>
  102. <strong>{externalAccount.accountId}</strong>
  103. </td>
  104. <td>
  105. <strong>{externalAccount.user.username}</strong>
  106. </td>
  107. <td>
  108. { externalAccount.password
  109. ? (
  110. <span className="label label-info">
  111. { t('user_management.set') }
  112. </span>
  113. )
  114. : (
  115. <span className="label label-warning">
  116. { t('user_management.unset') }
  117. </span>
  118. )
  119. }
  120. </td>
  121. <td>{dateFnsFormat(new Date(externalAccount.createdAt), 'yyyy-MM-dd')}</td>
  122. <td>
  123. <div className="btn-group admin-user-menu">
  124. <button type="button" className="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
  125. <i className="icon-settings"></i> <span className="caret"></span>
  126. </button>
  127. <ul className="dropdown-menu" role="menu">
  128. <li className="dropdown-header">{ t('user_management.edit_menu') }</li>
  129. <li>
  130. <a onClick={() => { return this.removeExtenalAccount(externalAccount.accountId) }}>
  131. <i className="icon-fw icon-fire text-danger"></i> { t('Delete') }
  132. </a>
  133. </li>
  134. </ul>
  135. </div>
  136. </td>
  137. </tr>
  138. );
  139. })}
  140. </tbody>
  141. </table>
  142. </Fragment>
  143. );
  144. }
  145. }
  146. ExternalAccountTable.propTypes = {
  147. t: PropTypes.func.isRequired, // i18next
  148. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  149. adminExternalAccountsContainer: PropTypes.instanceOf(AdminExternalAccountsContainer).isRequired,
  150. };
  151. const ExternalAccountTableWrapper = (props) => {
  152. return createSubscribedElement(ExternalAccountTable, props, [AppContainer, AdminExternalAccountsContainer]);
  153. };
  154. export default withTranslation()(ExternalAccountTableWrapper);