UserGroupUserTable.tsx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. import { UserPicture } from '@growi/ui/dist/components/User/UserPicture';
  3. import 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. }
  11. export const UserGroupUserTable = (props: Props): JSX.Element => {
  12. const { t } = useTranslation('admin');
  13. const {
  14. userGroupRelations, onClickRemoveUserBtn, onClickPlusBtn,
  15. } = props;
  16. return (
  17. <table className="table table-bordered table-user-list">
  18. <thead>
  19. <tr>
  20. <th style={{ width: '100px' }}>#</th>
  21. <th>
  22. {t('username')}
  23. </th>
  24. <th>{t('Name')}</th>
  25. <th style={{ width: '100px' }}>{t('Created')}</th>
  26. <th style={{ width: '160px' }}>{t('last_login')}</th>
  27. <th style={{ width: '70px' }}></th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. {userGroupRelations != null && userGroupRelations.map((relation) => {
  32. const { relatedUser } = relation;
  33. return (
  34. <tr key={relation._id}>
  35. <td>
  36. <UserPicture user={relatedUser} />
  37. </td>
  38. <td>
  39. <strong>{relatedUser.username}</strong>
  40. </td>
  41. <td>{relatedUser.name}</td>
  42. <td>{relatedUser.createdAt ? dateFnsFormat(new Date(relatedUser.createdAt), 'yyyy-MM-dd') : ''}</td>
  43. <td>{relatedUser.lastLoginAt ? dateFnsFormat(new Date(relatedUser.lastLoginAt), 'yyyy-MM-dd HH:mm:ss') : ''}</td>
  44. <td>
  45. <div className="btn-group admin-user-menu">
  46. <button
  47. type="button"
  48. id={`admin-group-menu-button-${relatedUser._id}`}
  49. className="btn btn-outline-secondary btn-sm dropdown-toggle"
  50. data-toggle="dropdown"
  51. >
  52. <i className="icon-settings"></i>
  53. </button>
  54. <div className="dropdown-menu" role="menu" aria-labelledby={`admin-group-menu-button-${relatedUser._id}`}>
  55. <button
  56. className="dropdown-item"
  57. type="button"
  58. onClick={() => onClickRemoveUserBtn(relatedUser.username)}
  59. >
  60. <i className="icon-fw icon-user-unfollow"></i> {t('admin:user_group_management.remove_from_group')}
  61. </button>
  62. </div>
  63. </div>
  64. </td>
  65. </tr>
  66. );
  67. })}
  68. <tr>
  69. <td></td>
  70. <td className="text-center">
  71. <button className="btn btn-outline-secondary" type="button" onClick={onClickPlusBtn}>
  72. <i className="ti ti-plus"></i>
  73. </button>
  74. </td>
  75. <td></td>
  76. <td></td>
  77. <td></td>
  78. <td></td>
  79. </tr>
  80. </tbody>
  81. </table>
  82. );
  83. };
  84. export default UserGroupUserTable;