feature/IO-3096-GlobalNotifications - Checkpoint
This commit is contained in:
@@ -22,7 +22,6 @@ const NotificationCenterComponent = ({
|
||||
const { t } = useTranslation();
|
||||
|
||||
const renderNotification = (index, notification) => {
|
||||
console.log("Rendering notification at index:", index, notification);
|
||||
return (
|
||||
<List.Item
|
||||
key={`${notification.id}-${index}`}
|
||||
@@ -58,12 +57,10 @@ const NotificationCenterComponent = ({
|
||||
);
|
||||
};
|
||||
|
||||
console.log("NotificationCenterComponent render:", { notifications, loading, error, showUnreadOnly });
|
||||
|
||||
return (
|
||||
<div className={`notification-center ${visible ? "visible" : ""}`}>
|
||||
<div className="notification-header">
|
||||
<h3>{t("notifications.labels.new-notification-title")}</h3>
|
||||
<h3>{t("notifications.labels.notification-center")}</h3>
|
||||
<div className="notification-controls">
|
||||
<Checkbox checked={showUnreadOnly} onChange={(e) => toggleUnreadOnly(e.target.checked)}>
|
||||
{t("notifications.labels.show-unread-only")}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
position: absolute;
|
||||
top: 64px;
|
||||
right: 0;
|
||||
width: 600px;
|
||||
//width: 600px;
|
||||
background: #fff; /* White background, Ant’s default */
|
||||
color: rgba(0, 0, 0, 0.85); /* Primary text color in Ant 5 */
|
||||
border: 1px solid #d9d9d9; /* Neutral gray border */
|
||||
|
||||
@@ -42,7 +42,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
break;
|
||||
}
|
||||
if (!import.meta.env.DEV) return;
|
||||
console.log(`Received message for bodyshop ${bodyshop.id}:`, message);
|
||||
};
|
||||
|
||||
const handleConnect = () => {
|
||||
@@ -50,7 +49,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
setClientId(socketInstance.id);
|
||||
setIsConnected(true);
|
||||
store.dispatch(setWssStatus("connected"));
|
||||
console.log("Socket connected, ID:", socketInstance.id);
|
||||
};
|
||||
|
||||
const handleReconnect = () => {
|
||||
@@ -87,24 +85,19 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
};
|
||||
|
||||
const handleNotification = (data) => {
|
||||
const { jobId, bodyShopId, notificationId, associationId, notifications } = data;
|
||||
console.log("Socket Notification Received (ID:", notificationId, "):", {
|
||||
jobId,
|
||||
bodyShopId,
|
||||
associationId,
|
||||
notifications
|
||||
});
|
||||
const { jobId, jobRoNumber, notificationId, associationId, notifications } = data;
|
||||
|
||||
const newNotification = {
|
||||
__typename: "notifications",
|
||||
id: notificationId,
|
||||
jobid: jobId,
|
||||
associationid: associationId || null,
|
||||
associationid: associationId,
|
||||
scenario_text: JSON.stringify(notifications.map((notif) => notif.body)),
|
||||
fcm_text: notifications.map((notif) => notif.body).join(". ") + ".",
|
||||
scenario_meta: JSON.stringify(notifications.map((notif) => notif.variables || {})),
|
||||
created_at: new Date(notifications[0].timestamp).toISOString(),
|
||||
read: null
|
||||
read: null,
|
||||
job: { ro_number: jobRoNumber }
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -122,13 +115,15 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
scenario_meta
|
||||
created_at
|
||||
read
|
||||
job {
|
||||
ro_number
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
})?.notifications || [];
|
||||
|
||||
if (existingNotifications.some((n) => n.id === newNotification.id)) {
|
||||
console.log("Duplicate notification detected, skipping:", notificationId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,6 +140,9 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
scenario_meta
|
||||
created_at
|
||||
read
|
||||
job {
|
||||
ro_number
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
@@ -156,15 +154,12 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
broadcast: true
|
||||
});
|
||||
|
||||
console.log("Cache updated with new notification:", newNotification);
|
||||
|
||||
client.cache.modify({
|
||||
id: "ROOT_QUERY",
|
||||
fields: {
|
||||
notifications_aggregate(existing = { aggregate: { count: 0 } }) {
|
||||
const isUnread = newNotification.read === null;
|
||||
const countChange = isUnread ? 1 : 0;
|
||||
console.log("Updating unread count from socket:", existing.aggregate.count + countChange);
|
||||
return {
|
||||
...existing,
|
||||
aggregate: {
|
||||
@@ -199,7 +194,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
||||
socketInstance.on("disconnect", handleDisconnect);
|
||||
socketInstance.on("bodyshop-message", handleBodyshopMessage);
|
||||
socketInstance.on("message", (message) => {
|
||||
console.log("Raw socket message:", message);
|
||||
try {
|
||||
if (typeof message === "string" && message.startsWith("42")) {
|
||||
const parsedMessage = JSON.parse(message.slice(2));
|
||||
|
||||
Reference in New Issue
Block a user