diff --git a/src/components/Notification/index.jsx b/src/components/Notification/index.jsx index 44d1bc1..919ce48 100644 --- a/src/components/Notification/index.jsx +++ b/src/components/Notification/index.jsx @@ -12,32 +12,50 @@ const tabs = [ title: "Today's", }, { - id: 1, + id: 2, date: "days", title: "7 days", }, { - id: 1, + id: 3, date: "all", title: "All", }, ]; export default function Notification() { - const [selectTab, setValue] = useState(tabs ? tabs[0].title : ""); + const [selectTab, setValue] = useState(tabs ? tabs[2].title : ""); const { notifications } = useSelector((state) => state?.notifications); + const [notificationData, setNotificationData] = useState(notifications?.data || []) + + const [currentPage, setCurrentPage] = useState(0); const indexOfFirstItem = Number(currentPage); - const indexOfLastItem = Number(indexOfFirstItem) + 6; - const currentNotifications = notifications?.data?.raw?.slice( - indexOfFirstItem, - indexOfLastItem - ); - - console.log(currentNotifications); + const indexOfLastItem = Number(indexOfFirstItem) + Number(process.env.REACT_APP_ITEM_PER_PAGE); + const currentNotifications = notificationData?.slice(indexOfFirstItem, indexOfLastItem); + + console.log('TESTING', currentNotifications) const filterHandler = (value) => { setValue(value); + switch(value){ + case `Today's`: + // setNotificationData(notifications?.data?.slice(0,5)) + setNotificationData(notifications?.data.filter(item => (new Date().getTime() - new Date(item.date).getTime())/(1000*60*60*24) <= 1)) + setCurrentPage(0) + break; + case `All`: + setNotificationData(notifications?.data) + setCurrentPage(0) + break; + case `7 days`: + // setNotificationData(notifications?.data?.slice(0,2)) + setNotificationData(notifications?.data.filter(item => (new Date().getTime() - new Date(item.date).getTime())/(1000*60*60*24) <= 7)) + setCurrentPage(0) + break; + default: + break; + } }; const handlePagination = (e) => { @@ -57,7 +75,7 @@ export default function Notification() {
- {item?.title} - {/* - successfully done - */} -
-
-
+ {item?.title}
+ {/*
+ successfully done
+ */}
+
+
-
+