InAppNotificationPage.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { FC, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import InAppNotificationList from './InAppNotificationList';
  4. import { useSWRxInAppNotifications } from '../../stores/in-app-notification';
  5. import PaginationWrapper from '../PaginationWrapper';
  6. import CustomNavAndContents from '../CustomNavigation/CustomNavAndContents';
  7. import PasswordSettings from '../Me/PasswordSettings';
  8. const InAppNotificationPage: FC = () => {
  9. const [activePage, setActivePage] = useState(1);
  10. const [offset, setOffset] = useState(0);
  11. const limit = 10;
  12. const { data: inAppNotificationData } = useSWRxInAppNotifications(limit, offset);
  13. const { t } = useTranslation();
  14. if (inAppNotificationData == null) {
  15. return (
  16. <div className="wiki">
  17. <div className="text-muted text-center">
  18. <i className="fa fa-2x fa-spinner fa-pulse mr-1"></i>
  19. </div>
  20. </div>
  21. );
  22. }
  23. const setPageNumber = (selectedPageNumber): void => {
  24. setActivePage(selectedPageNumber);
  25. const offset = (selectedPageNumber - 1) * limit;
  26. setOffset(offset);
  27. };
  28. const AllInAppNotificationList = () => {
  29. return (
  30. <>
  31. <InAppNotificationList inAppNotificationData={inAppNotificationData} />
  32. <PaginationWrapper
  33. activePage={activePage}
  34. changePage={setPageNumber}
  35. totalItemsCount={inAppNotificationData.totalDocs}
  36. pagingLimit={inAppNotificationData.limit}
  37. align="center"
  38. size="sm"
  39. />
  40. </>
  41. );
  42. };
  43. const navTabMapping = {
  44. user_infomation: {
  45. Icon: () => <i className="icon-fw icon-user"></i>,
  46. Content: AllInAppNotificationList,
  47. i18n: t('in_app_notification.all'),
  48. index: 0,
  49. },
  50. external_accounts: {
  51. Icon: () => <i className="icon-fw icon-share-alt"></i>,
  52. Content: PasswordSettings,
  53. i18n: t('in_app_notification.unopend'),
  54. index: 1,
  55. },
  56. };
  57. return (
  58. <CustomNavAndContents navTabMapping={navTabMapping} />
  59. );
  60. };
  61. export default InAppNotificationPage;