ExternalAccountTable.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React, { useCallback } from 'react';
  2. import { 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/apiNotification';
  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. <table className={`${styles['ea-table']} table table-bordered table-user-list`}>
  26. <thead>
  27. <tr>
  28. <th style={{ width: '140px' }}>{t('user_management.authentication_provider')}</th>
  29. <th style={{ width: '390px' }}><code>accountId</code></th>
  30. <th style={{ width: '390px' }}>{t('user_management.related_username')}<code>username</code></th>
  31. <th style={{ width: '160px' }}>
  32. {t('user_management.password_setting')}
  33. {/* TODO: Enable popper */}
  34. <span
  35. role="button"
  36. className="text-muted px-2"
  37. data-toggle="popper"
  38. data-placement="top"
  39. data-trigger="hover"
  40. data-html="true"
  41. title={t('user_management.password_setting_help')}
  42. >
  43. <small><i className="icon-question" aria-hidden="true"></i></small>
  44. </span>
  45. </th>
  46. <th style={{ width: '140px' }}>{t('Created')}</th>
  47. <th style={{ width: '70px' }}></th>
  48. </tr>
  49. </thead>
  50. <tbody>
  51. { adminExternalAccountsContainer.state.externalAccounts.map((ea: IAdminExternalAccount) => {
  52. return (
  53. <tr key={ea._id}>
  54. <td><span>{ea.providerType}</span></td>
  55. <td><strong>{ea.accountId}</strong></td>
  56. <td><strong>{ea.user.username}</strong></td>
  57. <td>
  58. {ea.user.password
  59. ? (<span className="badge badge-info">{t('user_management.set')}</span>)
  60. : (<span className="badge badge-warning">{t('user_management.unset')}</span>)
  61. }
  62. </td>
  63. <td><span>{dateFnsFormat(new Date(ea.createdAt), 'yyyy-MM-dd')}</span></td>
  64. <td>
  65. <div className="btn-group admin-user-menu">
  66. <button type="button" className="btn btn-outline-secondary btn-sm dropdown-toggle" data-toggle="dropdown">
  67. <i className="icon-settings"></i> <span className="caret"></span>
  68. </button>
  69. <ul className="dropdown-menu" role="menu">
  70. <li className="dropdown-header">{t('user_management.user_table.edit_menu')}</li>
  71. <button
  72. className="dropdown-item"
  73. type="button"
  74. role="button"
  75. onClick={() => removeExtenalAccount(ea._id)}
  76. >
  77. <i className="icon-fw icon-fire text-danger"></i> {t('Delete')}
  78. </button>
  79. </ul>
  80. </div>
  81. </td>
  82. </tr>
  83. );
  84. }) }
  85. </tbody>
  86. </table>
  87. );
  88. };
  89. const ExternalAccountTableWrapper = withUnstatedContainers(ExternalAccountTable, [AdminExternalAccountsContainer]);
  90. export default ExternalAccountTableWrapper;