ActivityTable.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { FC } from 'react';
  2. import { pagePathUtils } from '@growi/core';
  3. import { UserPicture } from '@growi/ui';
  4. import { format } from 'date-fns';
  5. import { useTranslation } from 'react-i18next';
  6. import { IActivityHasId } from '~/interfaces/activity';
  7. type Props = {
  8. activityList: IActivityHasId[]
  9. }
  10. const formatDate = (date) => {
  11. return format(new Date(date), 'yyyy/MM/dd HH:mm:ss');
  12. };
  13. export const ActivityTable : FC<Props> = (props: Props) => {
  14. const { t } = useTranslation();
  15. return (
  16. <div className="table-responsive text-nowrap h-100">
  17. <table className="table table-default table-bordered table-user-list">
  18. <thead>
  19. <tr>
  20. <th scope="col">{t('admin:audit_log_management.user')}</th>
  21. <th scope="col">{t('admin:audit_log_management.date')}</th>
  22. <th scope="col">{t('admin:audit_log_management.action')}</th>
  23. <th scope="col">{t('admin:audit_log_management.ip')}</th>
  24. <th scope="col">{t('admin:audit_log_management.url')}</th>
  25. </tr>
  26. </thead>
  27. <tbody>
  28. {props.activityList.map((activity) => {
  29. return (
  30. <tr data-testid="activity-table" key={activity._id}>
  31. <td>
  32. { activity.user != null && (
  33. <>
  34. <UserPicture user={activity.user} className="picture rounded-circle" />
  35. <a className="ml-2" href={pagePathUtils.userPageRoot(activity.user)}>{activity.snapshot?.username}</a>
  36. </>
  37. )}
  38. </td>
  39. <td>{formatDate(activity.createdAt)}</td>
  40. <td>{t(`admin:audit_log_action.${activity.action}`)}</td>
  41. <td>{activity.ip}</td>
  42. <td>{activity.endpoint}</td>
  43. </tr>
  44. );
  45. })}
  46. </tbody>
  47. </table>
  48. </div>
  49. );
  50. };