mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
fix issue
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user