ActivityTable.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React, { FC } from 'react';
  2. import { format } from 'date-fns';
  3. import { IActivityHasId } from '~/interfaces/activity';
  4. type Props = {
  5. activityList: IActivityHasId[]
  6. }
  7. const formatDate = (date) => {
  8. return format(new Date(date), 'yyyy/MM/dd HH:mm:ss');
  9. };
  10. const ActivityTable: FC<Props> = (props: Props) => {
  11. return (
  12. <div className="table-responsive text-nowrap h-100">
  13. <table className="table table-default table-bordered table-user-list">
  14. <thead>
  15. <tr>
  16. <th scope="col">username</th>
  17. <th scope="col">targetModel</th>
  18. <th scope="col">action</th>
  19. <th scope="col">createdAt</th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. {props.activityList.map((activity) => {
  24. return (
  25. <tr data-testid="user-table-tr" key={activity._id}>
  26. <td>{activity.user?.username}</td>
  27. <td>{activity.targetModel}</td>
  28. <td>{activity.action}</td>
  29. <td>{formatDate(activity.createdAt)}</td>
  30. </tr>
  31. );
  32. })}
  33. </tbody>
  34. </table>
  35. </div>
  36. );
  37. };
  38. export default ActivityTable;