notification bug fixed
This commit is contained in:
@@ -89,7 +89,7 @@ const AuthRoute = ({ redirectPath = "/login", children }) => {
|
||||
return;
|
||||
}
|
||||
setLoadProfileDetails(res.data);
|
||||
dispatch(updateUserDetails({ ...res.data, loggedIn: true }));
|
||||
dispatch(updateUserDetails({ ...res.data }));
|
||||
setIsLogin({ loading: false, status: true });
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -100,89 +100,64 @@ const AuthRoute = ({ redirectPath = "/login", children }) => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// const filterNotifications = (notifications, filterType) => {
|
||||
// const currentDate = new Date();
|
||||
// if (filterType === "today") {
|
||||
// return notifications?.filter((notification) => {
|
||||
// const notificationDate = new Date(notification?.date);
|
||||
// console.log(notificationDate)
|
||||
// // return (
|
||||
// // notificationDate.getDate() === currentDate.getDate() &&
|
||||
// // notificationDate.getMonth() === currentDate.getMonth() &&
|
||||
// // notificationDate.getFullYear() === currentDate.getFullYear()
|
||||
// // );
|
||||
// });
|
||||
// } else if (filterType === "days") {
|
||||
// const sevenDaysAgo = new Date(currentDate);
|
||||
// sevenDaysAgo.setDate(currentDate.getDate() - 7);
|
||||
// return notifications?.filter((notification) => {
|
||||
// const notificationDate = new Date(notification?.date);
|
||||
// return notificationDate >= sevenDaysAgo;
|
||||
// });
|
||||
// } else {
|
||||
// return notifications;
|
||||
// }
|
||||
// };
|
||||
|
||||
useEffect(() => {
|
||||
if (!loggedIn) {
|
||||
const getNotifications = () => {
|
||||
// function to load user notification
|
||||
dispatch(updateNotifications({ loading: true }));
|
||||
apiCall
|
||||
.getMyNotifications()
|
||||
.then((res) => {
|
||||
if (res.data.internal_return < 0) {
|
||||
dispatch(updateNotifications({ loading: false }));
|
||||
return;
|
||||
}
|
||||
setLoadProfileDetails(res.data);
|
||||
const getNotifications = () => {
|
||||
// function to load user notification
|
||||
dispatch(updateNotifications({ loading: true }));
|
||||
apiCall
|
||||
.getMyNotifications()
|
||||
.then((res) => {
|
||||
if (res.data.internal_return < 0) {
|
||||
dispatch(updateNotifications({ loading: false, data: null }));
|
||||
return;
|
||||
}
|
||||
setLoadProfileDetails(res.data);
|
||||
|
||||
const _raw = res.data?.result_list;
|
||||
const _raw = res.data?.result_list;
|
||||
|
||||
//Sort the notifications in ascending order based on the API time
|
||||
const _sorted = _raw?.sort((a, b) => {
|
||||
const timeA = new Date(a?.date)?.getTime();
|
||||
const timeB = new Date(b?.date)?.getTime();
|
||||
return timeA - timeB;
|
||||
});
|
||||
|
||||
// header component
|
||||
const _header = _sorted?.slice(0, 5);
|
||||
// Notification Layout
|
||||
const _today = _sorted?.slice(0, 7);
|
||||
|
||||
const _days = () => {
|
||||
const sevenDaysAgo = new Date();
|
||||
sevenDaysAgo.setDate(new Date() - 7);
|
||||
return _sorted?.filter((notification) => {
|
||||
const notificationDate = new Date(
|
||||
formattedDate(notification?.date)
|
||||
);
|
||||
return notificationDate >= sevenDaysAgo;
|
||||
});
|
||||
};
|
||||
|
||||
// Dispatch all notifications, sorted, and recent based on their filter type
|
||||
dispatch(
|
||||
updateNotifications({
|
||||
loading: false,
|
||||
data: {
|
||||
raw: _raw,
|
||||
today: _today,
|
||||
// days: _days(),
|
||||
sort: _sorted,
|
||||
header: _header,
|
||||
},
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch(updateNotifications({ loading: false }));
|
||||
//Sort the notifications in ascending order based on the API time
|
||||
const _sorted = _raw?.sort((a, b) => {
|
||||
const timeA = new Date(a?.date)?.getTime();
|
||||
const timeB = new Date(b?.date)?.getTime();
|
||||
return timeA - timeB;
|
||||
});
|
||||
};
|
||||
getNotifications();
|
||||
}
|
||||
|
||||
// header component
|
||||
const _header = _sorted?.slice(0, 5);
|
||||
// Notification Layout
|
||||
const _today = _sorted?.slice(0, 7);
|
||||
|
||||
const _days = () => {
|
||||
const sevenDaysAgo = new Date();
|
||||
sevenDaysAgo.setDate(new Date() - 7);
|
||||
return _sorted?.filter((notification) => {
|
||||
const notificationDate = new Date(
|
||||
formattedDate(notification?.date)
|
||||
);
|
||||
return notificationDate >= sevenDaysAgo;
|
||||
});
|
||||
};
|
||||
|
||||
// Dispatch all notifications, sorted, and recent based on their filter type
|
||||
dispatch(
|
||||
updateNotifications({
|
||||
loading: false,
|
||||
// data: {
|
||||
// raw: _raw,
|
||||
// today: _today,
|
||||
// // days: _days(),
|
||||
// sort: _sorted,
|
||||
// header: _header,
|
||||
// },
|
||||
data: _sorted
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch(updateNotifications({ loading: false, data: null }));
|
||||
});
|
||||
};
|
||||
getNotifications();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user