ActivityTable.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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"></th>
  21. <th scope="col">{t('admin:audit_log_management.username')}</th>
  22. <th scope="col">{t('admin:audit_log_management.date')}</th>
  23. <th scope="col">{t('admin:audit_log_management.action')}</th>
  24. <th scope="col">{t('admin:audit_log_management.ip')}</th>
  25. <th scope="col">{t('admin:audit_log_management.url')}</th>
  26. </tr>
  27. </thead>
  28. <tbody>
  29. {props.activityList.map((activity) => {
  30. return (
  31. <tr data-testid="activity-table" key={activity._id}>
  32. <td>
  33. {activity.user != null && (
  34. <UserPicture user={activity.user} className="picture rounded-circle" />
  35. )}
  36. </td>
  37. <td>
  38. {
  39. activity.user != null
  40. ? (<a href={pagePathUtils.userPageRoot(activity.user)}>{activity.snapshot?.username}</a>)
  41. : (<>{activity.snapshot?.username}</>)
  42. }
  43. </td>
  44. <td>{formatDate(activity.createdAt)}</td>
  45. <td>{t(`admin:audit_log_action.${activity.action}`)}</td>
  46. <td>{activity.ip}</td>
  47. <td>{activity.endpoint}</td>
  48. </tr>
  49. );
  50. })}
  51. </tbody>
  52. </table>
  53. </div>
  54. );
  55. };