mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 11:21:18 +00:00
add hard capacity ceiling to weight limit rules
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { isAxiosError } from "axios";
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
@@ -47,6 +48,18 @@ interface ScheduleWorkspacePanelProps {
|
||||
|
||||
const GREEN = "var(--mantine-color-edr-green-6)";
|
||||
|
||||
/** Pull the API's violation detail out of an error (e.g. "No CW3 wagon available…"). */
|
||||
function apiErrorMessage(error: unknown, fallback: string): string {
|
||||
if (isAxiosError(error)) {
|
||||
const data = error.response?.data as Record<string, unknown> | undefined;
|
||||
const violations = data?.violations;
|
||||
if (Array.isArray(violations) && violations.length) return violations.join(", ");
|
||||
if (typeof data?.message === "string") return data.message;
|
||||
if (Array.isArray(data?.message)) return (data.message as string[]).join(", ");
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deadline + label for the window phase this schedule is currently in.
|
||||
* Phases run: window open (windowClosesAt) → document review (docReviewEndsAt)
|
||||
@@ -198,8 +211,12 @@ export function ScheduleWorkspacePanel({
|
||||
onChanged();
|
||||
void poolQuery.refetch();
|
||||
})
|
||||
.catch(() =>
|
||||
toast({ title: "Could not add booking", variant: "destructive" }),
|
||||
.catch((error) =>
|
||||
toast({
|
||||
title: "Could not add booking",
|
||||
description: apiErrorMessage(error, "Validation failed — check capacity and status."),
|
||||
variant: "destructive",
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -211,8 +228,12 @@ export function ScheduleWorkspacePanel({
|
||||
onChanged();
|
||||
void poolQuery.refetch();
|
||||
})
|
||||
.catch(() =>
|
||||
toast({ title: "Could not remove booking", variant: "destructive" }),
|
||||
.catch((error) =>
|
||||
toast({
|
||||
title: "Could not remove booking",
|
||||
description: apiErrorMessage(error, "Please try again."),
|
||||
variant: "destructive",
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -226,8 +247,12 @@ export function ScheduleWorkspacePanel({
|
||||
onChanged();
|
||||
void poolQuery.refetch();
|
||||
})
|
||||
.catch(() =>
|
||||
toast({ title: "Could not reassign booking", variant: "destructive" }),
|
||||
.catch((error) =>
|
||||
toast({
|
||||
title: "Could not reassign booking",
|
||||
description: apiErrorMessage(error, "Target train may be closed or full."),
|
||||
variant: "destructive",
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user