@eintrek/erp-shell 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-org-side-effects.d.ts +9 -3
- package/dist/index.esm.js +17 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -351,9 +351,15 @@ function useOrganizationIdState(initialOrganizationId, actions) {
|
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
/**
|
|
354
|
-
* Invalidate ALL React Query queries when `organizationId` changes
|
|
355
|
-
* (
|
|
356
|
-
*
|
|
354
|
+
* Invalidate ALL React Query queries when `organizationId` changes between
|
|
355
|
+
* two real orgs (e.g. the user switches org in the picker). Skips the
|
|
356
|
+
* initial mount and the first-resolve transition (undefined/null/"" → x)
|
|
357
|
+
* — that's the URL `[code]` segment finally syncing into the ERP context,
|
|
358
|
+
* not a real switch, and invalidating there triggers a cascade of refetches
|
|
359
|
+
* on top of the queries that already just fired.
|
|
360
|
+
*
|
|
361
|
+
* Use inside the ERP provider so org-scoped data is wiped cleanly when the
|
|
362
|
+
* user really does switch between two orgs.
|
|
357
363
|
*/
|
|
358
364
|
function useInvalidateQueriesOnOrgChange(organizationId) {
|
|
359
365
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -367,7 +373,15 @@ function useInvalidateQueriesOnOrgChange(organizationId) {
|
|
|
367
373
|
}
|
|
368
374
|
if (previousRef.current === organizationId)
|
|
369
375
|
return;
|
|
376
|
+
const wasEmpty = previousRef.current === undefined ||
|
|
377
|
+
previousRef.current === null ||
|
|
378
|
+
previousRef.current === "";
|
|
370
379
|
previousRef.current = organizationId;
|
|
380
|
+
// First-resolve: nothing to invalidate yet (queries either haven't run
|
|
381
|
+
// or are running with the right key already). Real org switches (a → b)
|
|
382
|
+
// still hit the invalidate path below.
|
|
383
|
+
if (wasEmpty)
|
|
384
|
+
return;
|
|
371
385
|
queryClient.invalidateQueries();
|
|
372
386
|
}, [organizationId, queryClient]);
|
|
373
387
|
}
|