fix rate edit

This commit is contained in:
Marshal
2026-07-17 10:15:26 +00:00
parent 18311f22f7
commit 801872c106
20 changed files with 1227 additions and 112 deletions

View File

@@ -48,6 +48,30 @@ export interface SubmitPriorityRuleChangePayload {
update?: Record<string, unknown>;
}
/** Approval workflow for edits to LIVE rates — a DRAFT rate still edits directly. */
const RATE_CHANGES_BASE = "/rate-change-requests";
export interface RateChangeRequest {
id: string;
rateId: string;
rate?: RuleEngineRecord | null;
/** Changed fields only. */
payload: Record<string, unknown>;
/** What those same fields were when the change was filed. */
previousValues: Record<string, unknown>;
status: "PENDING" | "APPROVED" | "REJECTED";
requestedByUserId: string | null;
decidedByUserId: string | null;
decidedAt: string | null;
decisionNote: string | null;
createdAt: string;
}
export interface SubmitRateChangePayload {
rateId: string;
update: Record<string, unknown>;
}
const RESOURCE_BASE: Record<RuleEngineResourceSlug, string> = {
"cargo-types": URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES,
"container-types": URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPES,
@@ -306,6 +330,44 @@ export const ruleEngineService = {
return unwrap(response.data) as PriorityRuleChangeRequest;
},
/** Propose a change to a LIVE rate — it stays at its current value until approved. */
submitRateChange: async (
payload: SubmitRateChangePayload,
): Promise<RateChangeRequest> => {
const response = await client.post(RATE_CHANGES_BASE, payload);
return unwrap(response.data) as RateChangeRequest;
},
listRateChanges: async (
status?: RateChangeRequest["status"],
): Promise<RateChangeRequest[]> => {
const response = await client.get(RATE_CHANGES_BASE, {
params: status ? { status } : undefined,
});
const body = unwrap(response.data) as unknown;
return Array.isArray(body) ? (body as RateChangeRequest[]) : [];
},
approveRateChange: async (
id: string,
decisionNote?: string,
): Promise<RateChangeRequest> => {
const response = await client.post(`${RATE_CHANGES_BASE}/${id}/approve`, {
decisionNote,
});
return unwrap(response.data) as RateChangeRequest;
},
rejectRateChange: async (
id: string,
decisionNote?: string,
): Promise<RateChangeRequest> => {
const response = await client.post(`${RATE_CHANGES_BASE}/${id}/reject`, {
decisionNote,
});
return unwrap(response.data) as RateChangeRequest;
},
getApprovalChain: async (
requiresDirectorApproval = true,
): Promise<RuleEngineRecord[]> => {