This commit is contained in:
Marshal
2026-07-15 14:27:00 +00:00
parent 19c9da28ae
commit d7d9db9c3a
10 changed files with 554 additions and 25 deletions

View File

@@ -246,10 +246,13 @@ export const useRuleEngineMutations = (resource: RuleEngineResourceSlug) => {
/**
* Priority-rule approval workflow. Every create/update/delete of a priority
* config is SUBMITTED as a change request; an approver applies or rejects it.
* Error toasts surface the backend message so range-collision rejections
* ("15 overlaps existing rule …") reach the user verbatim.
* Backend messages (range collision, gap, ceiling) surface verbatim — through
* `onErrorMessage` (the page shows them in a modal) or a toast as fallback.
*/
export const usePriorityRuleWorkflow = (enabled: boolean) => {
export const usePriorityRuleWorkflow = (
enabled: boolean,
onErrorMessage?: (message: string) => void,
) => {
const qc = useQueryClient();
const backendMessage = (err: unknown, fallback: string) => {
@@ -259,6 +262,12 @@ export const usePriorityRuleWorkflow = (enabled: boolean) => {
return msg || fallback;
};
const showError = (err: unknown, fallback: string) => {
const message = backendMessage(err, fallback);
if (onErrorMessage) onErrorMessage(message);
else toast.error(message);
};
const pending = useQuery({
queryKey: QUERY_KEYS.RULE_ENGINE.priorityRuleChanges,
queryFn: () => ruleEngineService.listPriorityRuleChanges("PENDING"),
@@ -270,6 +279,10 @@ export const usePriorityRuleWorkflow = (enabled: boolean) => {
queryKey: QUERY_KEYS.RULE_ENGINE.priorityRuleChanges,
});
await invalidateRuleEngineList(qc, "priority-configs");
// The full order-list backs the auto-filled min field — keep it fresh too.
await qc.invalidateQueries({
queryKey: QUERY_KEYS.RULE_ENGINE.orderList("priority-configs"),
});
};
const submit = useMutation({
@@ -279,7 +292,7 @@ export const usePriorityRuleWorkflow = (enabled: boolean) => {
toast.success("Change submitted for approval — the team has been notified");
await invalidate();
},
onError: (err) => toast.error(backendMessage(err, "Failed to submit change")),
onError: (err) => showError(err, "Failed to submit change"),
});
const approve = useMutation({
@@ -289,7 +302,7 @@ export const usePriorityRuleWorkflow = (enabled: boolean) => {
toast.success("Change approved and applied");
await invalidate();
},
onError: (err) => toast.error(backendMessage(err, "Failed to approve change")),
onError: (err) => showError(err, "Failed to approve change"),
});
const reject = useMutation({
@@ -299,7 +312,7 @@ export const usePriorityRuleWorkflow = (enabled: boolean) => {
toast.success("Change rejected");
await invalidate();
},
onError: (err) => toast.error(backendMessage(err, "Failed to reject change")),
onError: (err) => showError(err, "Failed to reject change"),
});
return { pending, submit, approve, reject };