ExternalAccountTable.tsx 4.7 KB

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