mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 08:58:21 +00:00
feat: implement consolidation approval process for shared-wagon bookings
- Add migration for consolidation approvals table and status enum - Create ConsolidationApprovalService to handle approval logic - Implement repository for managing consolidation approvals - Add entity for consolidation approval with necessary fields - Develop frontend components for displaying and managing consolidation approvals - Create tests for consolidation approval service to ensure correct behavior
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { MutationCache, QueryClient } from "@tanstack/react-query";
|
||||
|
||||
import type { InvalidatesMeta } from "@/utils/endpoint";
|
||||
import type { InvalidatesMeta, UpdatesMeta } from "@/utils/endpoint";
|
||||
|
||||
/**
|
||||
* Single app-wide React Query client (do not nest additional providers).
|
||||
@@ -14,13 +14,37 @@ import type { InvalidatesMeta } from "@/utils/endpoint";
|
||||
export const queryClient = new QueryClient({
|
||||
mutationCache: new MutationCache({
|
||||
onSuccess: (data, variables, _context, mutation) => {
|
||||
// Seed first: endpoints that return the entity they just changed write it
|
||||
// straight into its cache key, so the screen updates from the response
|
||||
// instead of round-tripping for data it already holds.
|
||||
const updates = mutation.meta?.updates as UpdatesMeta | undefined;
|
||||
const seeded: readonly unknown[][] = [];
|
||||
if (typeof updates === "function") {
|
||||
for (const [queryKey, value] of updates(variables, data)) {
|
||||
queryClient.setQueryData(queryKey, value);
|
||||
seeded.push(queryKey as unknown[]);
|
||||
}
|
||||
}
|
||||
|
||||
const invalidates = mutation.meta?.invalidates as
|
||||
| InvalidatesMeta
|
||||
| undefined;
|
||||
if (typeof invalidates !== "function") return;
|
||||
|
||||
for (const queryKey of invalidates(variables, data)) {
|
||||
void queryClient.invalidateQueries({ queryKey });
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey,
|
||||
// A seeded key already holds the authoritative value from this very
|
||||
// response — invalidating it would refetch it right back.
|
||||
predicate: seeded.length
|
||||
? (query) =>
|
||||
!seeded.some(
|
||||
(key) =>
|
||||
key.length === query.queryKey.length &&
|
||||
key.every((part, i) => Object.is(part, query.queryKey[i])),
|
||||
)
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
},
|
||||
// Mutation failures are surfaced globally by the axios interceptor in
|
||||
|
||||
Reference in New Issue
Block a user