feature/IO-3096-GlobalNotifications - Checkpoint
This commit is contained in:
@@ -128,7 +128,6 @@ function Header({
|
|||||||
|
|
||||||
const { isConnected } = useSocket(bodyshop);
|
const { isConnected } = useSocket(bodyshop);
|
||||||
const [notificationVisible, setNotificationVisible] = useState(false);
|
const [notificationVisible, setNotificationVisible] = useState(false);
|
||||||
const [displayCount, setDisplayCount] = useState(0); // Explicit state for badge
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: unreadData,
|
data: unreadData,
|
||||||
@@ -141,37 +140,17 @@ function Header({
|
|||||||
|
|
||||||
const unreadCount = unreadData?.notifications_aggregate?.aggregate?.count ?? 0;
|
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
|
// Initial fetch and socket status handling
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Running initial refetchUnread");
|
|
||||||
refetchUnread();
|
refetchUnread();
|
||||||
}, [refetchUnread]);
|
}, [refetchUnread]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isConnected && !unreadLoading) {
|
if (!isConnected && !unreadLoading) {
|
||||||
console.log("Socket disconnected, refetching unread count");
|
|
||||||
refetchUnread();
|
refetchUnread();
|
||||||
}
|
}
|
||||||
}, [isConnected, unreadLoading, 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) => {
|
const handleNotificationClick = (e) => {
|
||||||
setNotificationVisible(!notificationVisible);
|
setNotificationVisible(!notificationVisible);
|
||||||
if (handleMenuClick) handleMenuClick(e);
|
if (handleMenuClick) handleMenuClick(e);
|
||||||
@@ -710,7 +689,7 @@ function Header({
|
|||||||
icon: unreadLoading ? (
|
icon: unreadLoading ? (
|
||||||
<Spin size="small" />
|
<Spin size="small" />
|
||||||
) : (
|
) : (
|
||||||
<Badge count={displayCount}>
|
<Badge count={unreadCount}>
|
||||||
<BellFilled />
|
<BellFilled />
|
||||||
</Badge>
|
</Badge>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
|||||||
const handleNotification = (data) => {
|
const handleNotification = (data) => {
|
||||||
const { jobId, jobRoNumber, notificationId, associationId, notifications } = data;
|
const { jobId, jobRoNumber, notificationId, associationId, notifications } = data;
|
||||||
|
|
||||||
|
console.log(`Got RO ${jobRoNumber}`);
|
||||||
|
|
||||||
const newNotification = {
|
const newNotification = {
|
||||||
__typename: "notifications",
|
__typename: "notifications",
|
||||||
id: notificationId,
|
id: notificationId,
|
||||||
@@ -96,8 +98,7 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
|||||||
fcm_text: notifications.map((notif) => notif.body).join(". ") + ".",
|
fcm_text: notifications.map((notif) => notif.body).join(". ") + ".",
|
||||||
scenario_meta: JSON.stringify(notifications.map((notif) => notif.variables || {})),
|
scenario_meta: JSON.stringify(notifications.map((notif) => notif.variables || {})),
|
||||||
created_at: new Date(notifications[0].timestamp).toISOString(),
|
created_at: new Date(notifications[0].timestamp).toISOString(),
|
||||||
read: null,
|
read: null
|
||||||
job: { ro_number: jobRoNumber }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -115,9 +116,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
|||||||
scenario_meta
|
scenario_meta
|
||||||
created_at
|
created_at
|
||||||
read
|
read
|
||||||
job {
|
|
||||||
ro_number
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@@ -140,9 +138,6 @@ export const SocketProvider = ({ children, bodyshop }) => {
|
|||||||
scenario_meta
|
scenario_meta
|
||||||
created_at
|
created_at
|
||||||
read
|
read
|
||||||
job {
|
|
||||||
ro_number
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
|||||||
Reference in New Issue
Block a user