mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 22:18:12 +00:00
changes
This commit is contained in:
@@ -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
|
||||
* ("1–5 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 };
|
||||
|
||||
Reference in New Issue
Block a user