fix issue

This commit is contained in:
Marshal
2026-07-16 00:33:31 +00:00
parent 234a74e812
commit 41fe04652f
51 changed files with 1895 additions and 206 deletions

View File

@@ -298,7 +298,17 @@ const FleetResourcePage = () => {
const handleFormSubmit = async (values: Record<string, unknown>) => {
try {
if (editing && "id" in editing) {
await update.mutateAsync({ slug, id: String(editing.id), data: values });
// PATCH only the fields the user actually changed. Re-sending the whole
// form used to re-submit status/currentYardId on every save — which,
// for a locomotive/wagon coupled to a built train, silently diverged
// the consist (editing a name could move the loco to another yard).
const editingRecord = editing as unknown as Record<string, unknown>;
const changed = Object.fromEntries(
Object.entries(values).filter(
([key, value]) => value !== editingRecord[key],
),
);
await update.mutateAsync({ slug, id: String(editing.id), data: changed });
toast({ title: `${config.entityLabel} updated` });
} else {
await create.mutateAsync({ slug, data: values });