feature/IO-3096-GlobalNotifications - Checkpoint

This commit is contained in:
Dave Richer
2025-02-25 20:08:55 -05:00
parent 7f547c90c2
commit 7e2bd128e8
2 changed files with 4 additions and 30 deletions

View File

@@ -128,7 +128,6 @@ function Header({
const { isConnected } = useSocket(bodyshop);
const [notificationVisible, setNotificationVisible] = useState(false);
const [displayCount, setDisplayCount] = useState(0); // Explicit state for badge
const {
data: unreadData,
@@ -141,37 +140,17 @@ function Header({
const unreadCount = unreadData?.notifications_aggregate?.aggregate?.count ?? 0;
// Update displayCount when unreadCount changes
useEffect(() => {
console.log("Updating displayCount with unreadCount:", unreadCount);
setDisplayCount(unreadCount);
}, [unreadCount]);
// Initial fetch and socket status handling
useEffect(() => {
console.log("Running initial refetchUnread");
refetchUnread();
}, [refetchUnread]);
useEffect(() => {
if (!isConnected && !unreadLoading) {
console.log("Socket disconnected, refetching unread count");
refetchUnread();
}
}, [isConnected, unreadLoading, refetchUnread]);
// Debug logging
useEffect(() => {
console.log("Unread Count State:", {
unreadCount,
displayCount,
unreadLoading,
isConnected,
unreadData: unreadData?.notifications_aggregate,
rawUnreadData: unreadData
});
}, [unreadCount, displayCount, unreadLoading, isConnected, unreadData]);
const handleNotificationClick = (e) => {
setNotificationVisible(!notificationVisible);
if (handleMenuClick) handleMenuClick(e);
@@ -710,7 +689,7 @@ function Header({
icon: unreadLoading ? (
<Spin size="small" />
) : (
<Badge count={displayCount}>
<Badge count={unreadCount}>
<BellFilled />
</Badge>
),

View File

@@ -87,6 +87,8 @@ export const SocketProvider = ({ children, bodyshop }) => {
const handleNotification = (data) => {
const { jobId, jobRoNumber, notificationId, associationId, notifications } = data;
console.log(`Got RO ${jobRoNumber}`);
const newNotification = {
__typename: "notifications",
id: notificationId,
@@ -96,8 +98,7 @@ export const SocketProvider = ({ children, bodyshop }) => {
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,
job: { ro_number: jobRoNumber }
read: null
};
try {
@@ -115,9 +116,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
scenario_meta
created_at
read
job {
ro_number
}
}
}
`
@@ -140,9 +138,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
scenario_meta
created_at
read
job {
ro_number
}
}
}
`,