From 697ac3e74d38e59437b6fc6497d2771ec7592811 Mon Sep 17 00:00:00 2001 From: Nuwan Chathuranga Date: Fri, 8 Oct 2021 19:31:54 +0530 Subject: [PATCH] add notifications page --- .../navbar/JKNotificationDropdown.js | 6 +- .../components/notification/JKNotification.js | 3 +- jam-ui/src/components/page/JKNotifications.js | 70 +++++++++++++++++++ jam-ui/src/layouts/JKDashboardRoutes.js | 2 + 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 jam-ui/src/components/page/JKNotifications.js diff --git a/jam-ui/src/components/navbar/JKNotificationDropdown.js b/jam-ui/src/components/navbar/JKNotificationDropdown.js index 7c894e073..a255eafe8 100644 --- a/jam-ui/src/components/navbar/JKNotificationDropdown.js +++ b/jam-ui/src/components/navbar/JKNotificationDropdown.js @@ -115,13 +115,13 @@ const JKNotificationDropdown = () => { {isIterableArray(notifications) && notifications.map(notification => ( - - + + ))}
- + View all
diff --git a/jam-ui/src/components/notification/JKNotification.js b/jam-ui/src/components/notification/JKNotification.js index e913898bf..d0b7920f0 100644 --- a/jam-ui/src/components/notification/JKNotification.js +++ b/jam-ui/src/components/notification/JKNotification.js @@ -9,6 +9,7 @@ import { removeNotification } from '../../store/features/notificationSlice'; import JKGenericNotification from './JKGenericNotification'; import JKFriendRequestNotification from './JKFriendRequestNotification'; import TextMessageNotification from './JKTextMessageNotification'; +import classNames from 'classnames'; function JKNotification(props) { @@ -56,7 +57,7 @@ function JKNotification(props) { } }; - return ({render()}); + return ({render()}); // // {avatar && ( diff --git a/jam-ui/src/components/page/JKNotifications.js b/jam-ui/src/components/page/JKNotifications.js new file mode 100644 index 000000000..e6ea0f2b6 --- /dev/null +++ b/jam-ui/src/components/page/JKNotifications.js @@ -0,0 +1,70 @@ +import React, { useState, useEffect } from 'react'; +import { Alert, Card, CardBody, Col, Row } from 'reactstrap'; +import classNames from 'classnames'; +import JKNotification from '../notification/JKNotification'; +import FalconCardHeader from '../common/FalconCardHeader'; +import Loader from '../common/Loader'; +import { isIterableArray } from '../../helpers/utils'; + +import { fetchNotifications } from '../../store/features/notificationSlice'; +import { useDispatch, useSelector } from 'react-redux'; +import { useAuth } from '../../context/AuthContext'; + +const JKNotifications = () => { + const { currentUser } = useAuth(); + const dispatch = useDispatch(); + const notifications = useSelector(state => state.notification.notifications); + const loadingState = useSelector(state => state.notification.state); + + const LIMIT = 20; + const [page, setPage] = useState(0); + + const loadNotifications = async () => { + try { + const options = { + userId: currentUser.id, + offset: page * LIMIT, + limit: LIMIT + }; + await dispatch(fetchNotifications(options)).unwrap(); + //setPage(prev => prev + 1); + } catch (error) { + console.log(error); + } + }; + + useEffect(() => { + loadNotifications(); + }, []); + + return ( + + + {/*
+ + Mark all as read + +
*/} +
+ + {loadingState === 'loading' ? ( + + ) : isIterableArray(notifications) ? ( + notifications.map(notification => ( + + )) + ) : ( + + + + No notifications found! + + + + )} + +
+ ); +}; + +export default JKNotifications; diff --git a/jam-ui/src/layouts/JKDashboardRoutes.js b/jam-ui/src/layouts/JKDashboardRoutes.js index 96f1b1bca..190268a2e 100644 --- a/jam-ui/src/layouts/JKDashboardRoutes.js +++ b/jam-ui/src/layouts/JKDashboardRoutes.js @@ -1,11 +1,13 @@ import React from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import JKPeople from '../components/page/JKPeople'; +import JKNotifications from '../components/page/JKNotifications'; const JKDashboardRoutes = () => ( + {/*Redirect*/}