feat(sync): live cross-module cache invalidation (no manual refresh)
- procurement store refreshes right after a warehouse receipt (arrivals) and after role/project changes (organization/admin), so the ledger reflects warehouse actions immediately - refetchOnWindowFocus enabled on the shared query client - BroadcastChannel (lib/crossTab.ts): mutations broadcast 'quotes' / 'inventory'; all warehouse pages + the store hook resync open tabs automatically (receipt in one tab updates the ledger in another) - warehouse mutations (stock changes) notify other tabs; same-page refresh behavior unchanged
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { apiV26 } from "../../lib/api";
|
||||
import { useAuthStore } from "../../store/auth";
|
||||
import { useDataChanged } from "../../lib/crossTab";
|
||||
import type { InventoryRow, InventoryTransaction, Warehouse } from "../../lib/types";
|
||||
|
||||
export interface LookupData {
|
||||
@@ -63,6 +64,14 @@ export function useInventoryData(): InventoryData {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
// تبهای دیگر (ثبت تراکنش/رسید در تب دوم) → بازخوانی خودکار همین صفحه
|
||||
useDataChanged(
|
||||
useCallback(() => {
|
||||
void load();
|
||||
}, [load]),
|
||||
["quotes", "inventory"],
|
||||
);
|
||||
|
||||
const scopedWarehouses = useMemo(
|
||||
() =>
|
||||
user?.role === "admin" || user?.role === "procurement_manager"
|
||||
|
||||
Reference in New Issue
Block a user