Files
edr-platform/apps/edr-freight-web/backoffice/src/utils/queryInvalidation.ts
Marshal 4b7f6d2548 enhance contract and booking services with server-side search and validation improvements
- Added  parameter to  and  for server-side free-text search on contract reference, company name, and booking details.
- Introduced new validation errors in  for container clashes and space issues when creating bookings.
- Implemented paginated dropdown settings retrieval in .
- Updated  to fetch active yards using a new method that handles pagination.
- Enhanced  with a  method to fetch all records by walking through pages.
- Refactored  to support filtering and pagination in schedule listings.
- Improved  to return a paginated list of facilities.
- Updated UI components in  and  to utilize debounced search inputs for better performance.
- Added alerts in  to inform users about booking constraints related to splits and capacity.
- Enhanced  to display notifications for split bookings and capacity usage.
2026-07-12 10:51:31 +00:00

64 lines
2.2 KiB
TypeScript

import type { QueryClient } from "@tanstack/react-query";
import { QUERY_KEYS } from "@/constants/QUERY_KEYS";
import type {
RuleEngineListResult,
RuleEngineRecord,
RuleEngineResourceSlug,
} from "@/types/rule-engine";
export function invalidateBookings(qc: QueryClient): Promise<void> {
return qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.ROOT });
}
export function invalidateBookingDetail(
qc: QueryClient,
id: string,
): Promise<void> {
return Promise.all([
qc.invalidateQueries({ queryKey: QUERY_KEYS.BOOKINGS.byId(id) }),
invalidateBookings(qc),
]).then(() => undefined);
}
/** Update a single row in all cached list queries for a rule-engine resource. */
export function patchRuleEngineListRecord(
qc: QueryClient,
resource: RuleEngineResourceSlug | string,
updated: RuleEngineRecord,
): void {
const updatedId = String(updated.id);
qc.setQueriesData<RuleEngineListResult<RuleEngineRecord>>(
{ queryKey: ["rule-engine", "list", resource] },
(old) => {
if (!old?.items?.length) return old;
const index = old.items.findIndex((row) => String(row.id) === updatedId);
if (index === -1) return old;
const items = old.items.slice();
items[index] = { ...items[index], ...updated };
return { ...old, items };
},
);
}
/**
* Invalidate and refetch active rule-engine list queries for a resource.
* Also covers the page-walked order/full lists (order-list key), which show
* the same rows and must refresh after any create/update/delete.
*/
export async function invalidateRuleEngineList(
qc: QueryClient,
resource: RuleEngineResourceSlug | string,
): Promise<void> {
const listKey = ["rule-engine", "list", resource] as const;
const orderListKey = ["rule-engine", "order-list", resource] as const;
await qc.invalidateQueries({ queryKey: listKey });
await qc.invalidateQueries({ queryKey: orderListKey });
await qc.refetchQueries({ queryKey: listKey, type: "active" });
await qc.refetchQueries({ queryKey: orderListKey, type: "active" });
}
export function invalidateRuleEngineRoot(qc: QueryClient): Promise<void> {
return qc.invalidateQueries({ queryKey: QUERY_KEYS.RULE_ENGINE.ROOT });
}