This commit is contained in:
NotII
2025-07-20 23:34:42 +01:00
parent 0617ea5289
commit b329c8422d
6 changed files with 294 additions and 42 deletions

View File

@@ -17,6 +17,7 @@ import { clientFetch } from "@/lib/api";
import { toast } from "sonner";
import { getCookie } from "@/lib/api";
import axios from "axios";
import { cacheUtils } from '@/lib/api-client';
interface Order {
_id: string;
@@ -24,6 +25,8 @@ interface Order {
status: string;
totalPrice: number;
orderDate: string;
underpaid?: boolean;
underpaymentAmount?: number;
}
interface ChatMessage {
@@ -139,15 +142,22 @@ export default function UnifiedNotifications() {
const orderData = await clientFetch(`/orders?status=paid&limit=10&orderDate[gte]=${timestamp}`);
const orders: Order[] = orderData.orders || [];
// Filter out orders that are still showing as underpaid (cache issue)
const validPaidOrders = orders.filter(order => {
// Only include orders that are actually fully paid (not underpaid)
return order.status === 'paid' &&
(!order.underpaid || order.underpaymentAmount === 0);
});
// If this is the first fetch, just store the orders without notifications
if (isInitialOrdersFetch.current) {
orders.forEach(order => seenOrderIds.current.add(order._id));
validPaidOrders.forEach(order => seenOrderIds.current.add(order._id));
isInitialOrdersFetch.current = false;
return;
}
// Check for new paid orders that haven't been seen before
const latestNewOrders = orders.filter(order => !seenOrderIds.current.has(order._id));
const latestNewOrders = validPaidOrders.filter(order => !seenOrderIds.current.has(order._id));
// Show notifications for new orders
if (latestNewOrders.length > 0) {
@@ -178,6 +188,9 @@ export default function UnifiedNotifications() {
// Update the state with new orders for the dropdown
setNewOrders(prev => [...latestNewOrders, ...prev].slice(0, 10));
// Invalidate order cache to ensure all components refresh
cacheUtils.invalidateOrderData();
}
} catch (error) {
console.error("Error checking for new orders:", error);