UserGroupUserTable.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react';
  2. import { UserPicture } from '@growi/ui/dist/components';
  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. 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">
  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 && <td>
  43. <div className="btn-group admin-user-menu">
  44. <button
  45. type="button"
  46. id={`admin-group-menu-button-${relatedUser._id}`}
  47. className="btn btn-outline-secondary btn-sm dropdown-toggle"
  48. data-toggle="dropdown"
  49. >
  50. <i className="icon-settings"></i>
  51. </button>
  52. <div className="dropdown-menu" role="menu" aria-labelledby={`admin-group-menu-button-${relatedUser._id}`}>
  53. <button
  54. className="dropdown-item"
  55. type="button"
  56. onClick={() => props.onClickRemoveUserBtn(relatedUser.username)}
  57. >
  58. <i className="icon-fw icon-user-unfollow"></i> {t('admin:user_group_management.remove_from_group')}
  59. </button>
  60. </div>
  61. </div>
  62. </td>}
  63. </tr>
  64. );
  65. })}
  66. {!props.isExternalGroup && <tr>
  67. <td></td>
  68. <td className="text-center">
  69. <button className="btn btn-outline-secondary" type="button" onClick={props.onClickPlusBtn}>
  70. <i className="ti ti-plus"></i>
  71. </button>
  72. </td>
  73. <td></td>
  74. <td></td>
  75. <td></td>
  76. <td></td>
  77. </tr>}
  78. </tbody>
  79. </table>
  80. );
  81. };