ExternalAccountTable.tsx 4.2 KB

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