ExternalAccountTable.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React, { Fragment } from 'react';
  2. import dateFnsFormat from 'date-fns/format';
  3. import { useTranslation } from 'next-i18next';
  4. import PropTypes from 'prop-types';
  5. import AdminExternalAccountsContainer from '~/client/services/AdminExternalAccountsContainer';
  6. import { toastSuccess, toastError } from '~/client/util/apiNotification';
  7. import { withUnstatedContainers } from '../../UnstatedUtils';
  8. class ExternalAccountTable extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. };
  13. this.removeExtenalAccount = this.removeExtenalAccount.bind(this);
  14. }
  15. // remove external-account
  16. async removeExtenalAccount(externalAccountId) {
  17. const { t } = this.props;
  18. try {
  19. const accountId = await this.props.adminExternalAccountsContainer.removeExternalAccountById(externalAccountId);
  20. toastSuccess(t('toaster.remove_external_user_success', { accountId }));
  21. }
  22. catch (err) {
  23. toastError(err);
  24. }
  25. }
  26. render() {
  27. const { t, adminExternalAccountsContainer } = this.props;
  28. return (
  29. <Fragment>
  30. <table className="table table-bordered table-user-list">
  31. <thead>
  32. <tr>
  33. <th width="120px">{t('admin:user_management.authentication_provider')}</th>
  34. <th><code>accountId</code></th>
  35. <th>{t('admin:user_management.related_username')}<code>username</code></th>
  36. <th>
  37. {t('admin:user_management.password_setting')}
  38. <div
  39. className="text-muted"
  40. data-toggle="popover"
  41. data-placement="top"
  42. data-trigger="hover focus"
  43. tabIndex="0"
  44. role="button"
  45. data-animation="false"
  46. data-html="true"
  47. data-content={t('admin:user_management.password_setting_help')}
  48. >
  49. <small>
  50. <i className="icon-question" aria-hidden="true"></i>
  51. </small>
  52. </div>
  53. </th>
  54. <th width="100px">{t('Created')}</th>
  55. <th width="70px"></th>
  56. </tr>
  57. </thead>
  58. <tbody>
  59. {adminExternalAccountsContainer.state.externalAccounts.map((ea) => {
  60. return (
  61. <tr key={ea._id}>
  62. <td>{ea.providerType}</td>
  63. <td>
  64. <strong>{ea.accountId}</strong>
  65. </td>
  66. <td>
  67. <strong>{ea.user.username}</strong>
  68. </td>
  69. <td>
  70. {ea.user.password
  71. ? (
  72. <span className="badge badge-info">
  73. {t('admin:user_management.set')}
  74. </span>
  75. )
  76. : (
  77. <span className="badge badge-warning">
  78. {t('admin:user_management.unset')}
  79. </span>
  80. )
  81. }
  82. </td>
  83. <td>{dateFnsFormat(new Date(ea.createdAt), 'yyyy-MM-dd')}</td>
  84. <td>
  85. <div className="btn-group admin-user-menu">
  86. <button type="button" className="btn btn-outline-secondary btn-sm dropdown-toggle" data-toggle="dropdown">
  87. <i className="icon-settings"></i> <span className="caret"></span>
  88. </button>
  89. <ul className="dropdown-menu" role="menu">
  90. <li className="dropdown-header">{t('admin:user_management.user_table.edit_menu')}</li>
  91. <button className="dropdown-item" type="button" role="button" onClick={() => { return this.removeExtenalAccount(ea._id) }}>
  92. <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
  93. </button>
  94. </ul>
  95. </div>
  96. </td>
  97. </tr>
  98. );
  99. })}
  100. </tbody>
  101. </table>
  102. </Fragment>
  103. );
  104. }
  105. }
  106. ExternalAccountTable.propTypes = {
  107. t: PropTypes.func.isRequired, // i18next
  108. adminExternalAccountsContainer: PropTypes.instanceOf(AdminExternalAccountsContainer).isRequired,
  109. };
  110. const ExternalAccountTableWrapperFC = (props) => {
  111. const { t } = useTranslation();
  112. return <ExternalAccountTable t={t} {...props} />;
  113. };
  114. const ExternalAccountTableWrapper = withUnstatedContainers(ExternalAccountTableWrapperFC, [AdminExternalAccountsContainer]);
  115. export default ExternalAccountTableWrapper;