feature/IO-3096-GlobalNotifications - add Dayjs, minor packages on backend
This commit is contained in:
@@ -3,6 +3,7 @@ import { Alert, Badge, Button, Checkbox, List, Typography } from "antd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import "./notification-center.styles.scss";
|
||||
import day from "../../utils/day.js";
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
@@ -49,7 +50,7 @@ const NotificationCenterComponent = ({
|
||||
>
|
||||
RO #{notification.roNumber}
|
||||
</Link>
|
||||
<Text type="secondary">{new Date(notification.created_at).toLocaleString()}</Text>
|
||||
<Text type="secondary">{day(notification.created_at).fromNow()}</Text>
|
||||
</Title>
|
||||
<Text strong={!notification.read}>
|
||||
<ul>
|
||||
|
||||
@@ -6,6 +6,10 @@ import { GET_NOTIFICATIONS } from "../../graphql/notifications.queries";
|
||||
import { INITIAL_NOTIFICATIONS, useSocket } from "../../contexts/SocketIO/socketContext.jsx";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors.js";
|
||||
import day from "../../utils/day.js";
|
||||
|
||||
// This will be used to poll for notifications when the socket is disconnected
|
||||
const NOTIFICATION_POLL_INTERVAL_SECONDS = 60;
|
||||
|
||||
export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
||||
const [showUnreadOnly, setShowUnreadOnly] = useState(false);
|
||||
@@ -37,12 +41,12 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
||||
},
|
||||
fetchPolicy: "cache-and-network",
|
||||
notifyOnNetworkStatusChange: true,
|
||||
pollInterval: isConnected ? 0 : 30000,
|
||||
pollInterval: isConnected ? 0 : day.duration(NOTIFICATION_POLL_INTERVAL_SECONDS, "seconds").asMilliseconds(),
|
||||
skip: !userAssociationId,
|
||||
onError: (err) => {
|
||||
setError(err.message);
|
||||
console.error("GET_NOTIFICATIONS error:", err);
|
||||
setTimeout(() => refetch(), 2000);
|
||||
console.error(`Error polling Notifications in notification-center: ${err?.message || ""}`);
|
||||
setTimeout(() => refetch(), day.duration(2, "seconds").asMilliseconds());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,7 +79,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
||||
__typename: notif.__typename
|
||||
};
|
||||
})
|
||||
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
|
||||
.sort((a, b) => day(b.created_at).diff(day(a.created_at)));
|
||||
setNotifications(processedNotifications);
|
||||
setError(null);
|
||||
}
|
||||
@@ -111,7 +115,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
||||
const handleMarkAllRead = useCallback(() => {
|
||||
markAllNotificationsRead()
|
||||
.then(() => {
|
||||
const timestamp = new Date().toISOString();
|
||||
const timestamp = day().toISOString();
|
||||
setNotifications((prev) => {
|
||||
const updatedNotifications = prev.map((notif) =>
|
||||
notif.read === null && notif.associationid === userAssociationId
|
||||
@@ -133,7 +137,7 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
||||
variables: { id: notificationId }
|
||||
})
|
||||
.then(() => {
|
||||
const timestamp = new Date().toISOString();
|
||||
const timestamp = day().toISOString();
|
||||
setNotifications((prev) => {
|
||||
return prev.map((notif) =>
|
||||
notif.id === notificationId && !notif.read ? { ...notif, read: timestamp } : notif
|
||||
|
||||
Reference in New Issue
Block a user