ExternalAccountTable.tsx 4.8 KB

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