InAppNotificationList.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { FC } from 'react';
  2. import { PaginateResult } from 'mongoose';
  3. import { useTranslation } from 'react-i18next';
  4. import { IInAppNotification } from '../../interfaces/in-app-notification';
  5. import InAppNotificationElm from './InAppNotificationElm';
  6. type Props = {
  7. inAppNotificationData: PaginateResult<IInAppNotification> | undefined;
  8. };
  9. const InAppNotificationList: FC<Props> = (props: Props) => {
  10. const { t } = useTranslation();
  11. const { inAppNotificationData } = props;
  12. if (inAppNotificationData == null) {
  13. return (
  14. <div className="wiki">
  15. <div className="text-muted text-center">
  16. <i className="fa fa-2x fa-spinner fa-pulse mr-1"></i>
  17. </div>
  18. </div>
  19. );
  20. }
  21. const notifications = inAppNotificationData.docs;
  22. const renderInAppNotificationList = () => {
  23. const inAppNotificationList = notifications.map((notification: IInAppNotification) => {
  24. return (
  25. <div className="d-flex flex-row" key={notification._id}>
  26. <InAppNotificationElm notification={notification} />
  27. </div>
  28. );
  29. });
  30. return inAppNotificationList;
  31. };
  32. return (
  33. <>
  34. {notifications.length === 0 ? <>{t('in_app_notification.no_notification')}</> : renderInAppNotificationList()}
  35. </>
  36. );
  37. };
  38. export default InAppNotificationList;