UserGroupUserTable.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { type JSX } from 'react';
  2. import { UserPicture } from '@growi/ui/dist/components';
  3. import { format as dateFnsFormat } from 'date-fns/format';
  4. import { useTranslation } from 'next-i18next';
  5. import type { IUserGroupRelationHasIdPopulatedUser } from '~/interfaces/user-group-response';
  6. type Props = {
  7. userGroupRelations: IUserGroupRelationHasIdPopulatedUser[] | undefined,
  8. onClickRemoveUserBtn: (username: string) => Promise<void>,
  9. onClickPlusBtn: () => void,
  10. isExternalGroup?: boolean
  11. }
  12. export const UserGroupUserTable = (props: Props): JSX.Element => {
  13. const { t } = useTranslation('admin');
  14. return (
  15. <table className="table table-bordered table-user-list mb-5">
  16. <thead>
  17. <tr>
  18. <th style={{ width: '100px' }}>#</th>
  19. <th>
  20. {t('username')}
  21. </th>
  22. <th>{t('Name')}</th>
  23. <th style={{ width: '100px' }}>{t('Created')}</th>
  24. <th style={{ width: '160px' }}>{t('last_login')}</th>
  25. {!props.isExternalGroup && <th style={{ width: '70px' }}></th>}
  26. </tr>
  27. </thead>
  28. <tbody>
  29. {props.userGroupRelations != null && props.userGroupRelations.map((relation) => {
  30. const { relatedUser } = relation;
  31. return (
  32. <tr key={relation._id}>
  33. <td>
  34. <UserPicture user={relatedUser} />
  35. </td>
  36. <td>
  37. <strong>{relatedUser.username}</strong>
  38. </td>
  39. <td>{relatedUser.name}</td>
  40. <td>{relatedUser.createdAt ? dateFnsFormat(new Date(relatedUser.createdAt), 'yyyy-MM-dd') : ''}</td>
  41. <td>{relatedUser.lastLoginAt ? dateFnsFormat(new Date(relatedUser.lastLoginAt), 'yyyy-MM-dd HH:mm:ss') : ''}</td>
  42. {!props.isExternalGroup && (
  43. <td>
  44. <div className="btn-group admin-user-menu">
  45. <button
  46. type="button"
  47. id={`admin-group-menu-button-${relatedUser._id}`}
  48. className="btn btn-outline-secondary btn-sm dropdown-toggle"
  49. data-bs-toggle="dropdown"
  50. >
  51. <span className="material-symbols-outlined fs-5">settings</span>
  52. </button>
  53. <div className="dropdown-menu" role="menu" aria-labelledby={`admin-group-menu-button-${relatedUser._id}`}>
  54. <button
  55. className="dropdown-item"
  56. type="button"
  57. onClick={() => props.onClickRemoveUserBtn(relatedUser.username)}
  58. >
  59. <span className="material-symbols-outlined me-1">person_remove</span>{t('admin:user_group_management.remove_from_group')}
  60. </button>
  61. </div>
  62. </div>
  63. </td>
  64. )}
  65. </tr>
  66. );
  67. })}
  68. {!props.isExternalGroup && (
  69. <tr>
  70. <td></td>
  71. <td className="text-center">
  72. <button className="btn btn-outline-secondary" type="button" onClick={props.onClickPlusBtn}>
  73. <span className="material-symbols-outlined">add</span>
  74. </button>
  75. </td>
  76. <td></td>
  77. <td></td>
  78. <td></td>
  79. <td></td>
  80. </tr>
  81. )}
  82. </tbody>
  83. </table>
  84. );
  85. };