feature/IO-3096-GlobalNotifications - Checkpoint - Notification Center
This commit is contained in:
@@ -24,7 +24,7 @@ const NotificationCenterComponent = ({
|
|||||||
scenarioTextLength: notification.scenarioText.length,
|
scenarioTextLength: notification.scenarioText.length,
|
||||||
read: notification.read,
|
read: notification.read,
|
||||||
created_at: notification.created_at,
|
created_at: notification.created_at,
|
||||||
associationid: notification.associationid // Log associationid for debugging
|
associationid: notification.associationid
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<List.Item
|
<List.Item
|
||||||
@@ -41,6 +41,7 @@ const NotificationCenterComponent = ({
|
|||||||
</ul>
|
</ul>
|
||||||
</Text>
|
</Text>
|
||||||
<Text type="secondary">{new Date(notification.created_at).toLocaleString()}</Text>
|
<Text type="secondary">{new Date(notification.created_at).toLocaleString()}</Text>
|
||||||
|
{notification.associationid && <Text type="secondary">Association ID: {notification.associationid}</Text>}
|
||||||
</div>
|
</div>
|
||||||
</Badge>
|
</Badge>
|
||||||
</List.Item>
|
</List.Item>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { useQuery, useMutation } from "@apollo/client";
|
import { useQuery, useMutation } from "@apollo/client";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import NotificationCenterComponent from "./notification-center.component";
|
import NotificationCenterComponent from "./notification-center.component";
|
||||||
@@ -29,6 +29,18 @@ export function NotificationCenterContainer({ visible, onClose }) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(
|
||||||
|
"Notifications data updated:",
|
||||||
|
data?.notifications?.map((n) => ({
|
||||||
|
id: n.id,
|
||||||
|
read: n.read,
|
||||||
|
created_at: n.created_at,
|
||||||
|
associationid: n.associationid
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
const [markAllReadMutation, { error: mutationError }] = useMutation(MARK_ALL_NOTIFICATIONS_READ, {
|
const [markAllReadMutation, { error: mutationError }] = useMutation(MARK_ALL_NOTIFICATIONS_READ, {
|
||||||
update: (cache) => {
|
update: (cache) => {
|
||||||
cache.modify({
|
cache.modify({
|
||||||
@@ -51,57 +63,53 @@ export function NotificationCenterContainer({ visible, onClose }) {
|
|||||||
// Remove refetchNotifications function and useEffect/context logic
|
// Remove refetchNotifications function and useEffect/context logic
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data?.notifications) {
|
if (data?.notifications) {
|
||||||
const processedNotifications = data.notifications.map((notif) => {
|
const processedNotifications = data.notifications
|
||||||
let scenarioText;
|
.map((notif) => {
|
||||||
let scenarioMeta;
|
let scenarioText;
|
||||||
try {
|
let scenarioMeta;
|
||||||
scenarioText =
|
try {
|
||||||
typeof notif.scenario_text === "string" ? JSON.parse(notif.scenario_text) : notif.scenario_text || [];
|
scenarioText =
|
||||||
scenarioMeta =
|
typeof notif.scenario_text === "string" ? JSON.parse(notif.scenario_text) : notif.scenario_text || [];
|
||||||
typeof notif.scenario_meta === "string" ? JSON.parse(notif.scenario_meta) : notif.scenario_meta || [];
|
scenarioMeta =
|
||||||
} catch (e) {
|
typeof notif.scenario_meta === "string" ? JSON.parse(notif.scenario_meta) : notif.scenario_meta || [];
|
||||||
console.error("Error parsing JSON for notification:", notif.id, e);
|
} catch (e) {
|
||||||
scenarioText = [notif.fcm_text || "Invalid notification data"];
|
console.error("Error parsing JSON for notification:", notif.id, e);
|
||||||
scenarioMeta = [];
|
scenarioText = [notif.fcm_text || "Invalid notification data"];
|
||||||
}
|
scenarioMeta = [];
|
||||||
|
}
|
||||||
|
|
||||||
if (!Array.isArray(scenarioText)) scenarioText = [scenarioText];
|
if (!Array.isArray(scenarioText)) scenarioText = [scenarioText];
|
||||||
if (!Array.isArray(scenarioMeta)) scenarioMeta = [scenarioMeta];
|
if (!Array.isArray(scenarioMeta)) scenarioMeta = [scenarioMeta];
|
||||||
|
|
||||||
console.log("Processed notification:", {
|
console.log("Processed notification:", {
|
||||||
id: notif.id,
|
id: notif.id,
|
||||||
scenarioText,
|
scenarioText,
|
||||||
scenarioMeta,
|
scenarioMeta,
|
||||||
read: notif.read,
|
read: notif.read,
|
||||||
created_at: notif.created_at,
|
created_at: notif.created_at,
|
||||||
raw: notif // Log raw data for debugging
|
associationid: notif.associationid,
|
||||||
});
|
raw: notif
|
||||||
return {
|
});
|
||||||
id: notif.id,
|
return {
|
||||||
jobid: notif.jobid,
|
id: notif.id,
|
||||||
associationid: notif.associationid,
|
jobid: notif.jobid,
|
||||||
scenarioText,
|
associationid: notif.associationid,
|
||||||
scenarioMeta, // Add scenarioMeta for completeness (optional for rendering)
|
scenarioText,
|
||||||
created_at: notif.created_at,
|
scenarioMeta,
|
||||||
read: notif.read,
|
created_at: notif.created_at,
|
||||||
__typename: notif.__typename
|
read: notif.read,
|
||||||
};
|
__typename: notif.__typename
|
||||||
});
|
};
|
||||||
|
})
|
||||||
|
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); // Explicitly sort by created_at desc
|
||||||
|
|
||||||
console.log(
|
|
||||||
"Notifications data updated:",
|
|
||||||
data?.notifications?.map((n) => ({
|
|
||||||
id: n.id,
|
|
||||||
read: n.read,
|
|
||||||
created_at: n.created_at
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
console.log(
|
console.log(
|
||||||
"Processed Notifications:",
|
"Processed Notifications:",
|
||||||
processedNotifications.map((n) => ({
|
processedNotifications.map((n) => ({
|
||||||
id: n.id,
|
id: n.id,
|
||||||
read: n.read,
|
read: n.read,
|
||||||
created_at: n.created_at
|
created_at: n.created_at,
|
||||||
|
associationid: n.associationid
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
console.log("Number of notifications to render:", processedNotifications.length);
|
console.log("Number of notifications to render:", processedNotifications.length);
|
||||||
@@ -137,7 +145,9 @@ export function NotificationCenterContainer({ visible, onClose }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleMarkAllRead = () => {
|
const handleMarkAllRead = () => {
|
||||||
markAllReadMutation();
|
markAllReadMutation().catch((e) =>
|
||||||
|
console.error(`Something went wrong marking all notifications read: ${e?.message || ""}`)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user