AuditLogManagement.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { FC, useState, useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { AllSupportedActionType } from '~/interfaces/activity';
  4. import { useSWRxActivityList } from '~/stores/activity';
  5. import PaginationWrapper from '../PaginationWrapper';
  6. import { ActivityTable } from './AuditLog/ActivityTable';
  7. import { SelectQueryDropdown } from './AuditLog/SelectQueryDropdown';
  8. const PAGING_LIMIT = 10;
  9. export const AuditLogManagement: FC = () => {
  10. const { t } = useTranslation();
  11. const [activePage, setActivePage] = useState<number>(1);
  12. const offset = (activePage - 1) * PAGING_LIMIT;
  13. const [actionQuery, setActionQuery] = useState('');
  14. const { data: activityListData, error } = useSWRxActivityList(PAGING_LIMIT, offset);
  15. const activityList = activityListData?.docs != null ? activityListData.docs : [];
  16. const totalActivityNum = activityListData?.totalDocs != null ? activityListData.totalDocs : 0;
  17. const isLoading = activityListData === undefined && error == null;
  18. const setActivePageBySelectedPageNum = useCallback((selectedPageNum: number) => {
  19. setActivePage(selectedPageNum);
  20. }, []);
  21. return (
  22. <div data-testid="admin-auditlog">
  23. <h2>{t('AuditLog')}</h2>
  24. { isLoading
  25. ? (
  26. <div className="text-muted text-center mb-5">
  27. <i className="fa fa-2x fa-spinner fa-pulse mr-1"></i>
  28. </div>
  29. )
  30. : (
  31. <>
  32. <SelectQueryDropdown
  33. dropdownLabel="select_action"
  34. dropdownItemList={AllSupportedActionType}
  35. setQueryHandler={setActionQuery}
  36. />
  37. <ActivityTable activityList={activityList} />
  38. <PaginationWrapper
  39. activePage={activePage}
  40. changePage={setActivePageBySelectedPageNum}
  41. totalItemsCount={totalActivityNum}
  42. pagingLimit={PAGING_LIMIT}
  43. align="center"
  44. size="sm"
  45. />
  46. </>
  47. )
  48. }
  49. </div>
  50. );
  51. };