UserGroupUserTable.tsx 3.3 KB

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