Skip to content

Commit e0adb65

Browse files
authored
Merge pull request #368 from DEFRA/bug/FI0-11257-departure-weights-error-display
fix: NMD departure weights — error text, weight persistence and display after clearing (FI0-11257)
2 parents d37df75 + 2c4ee15 commit e0adb65

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

app/.server/storageDocument.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,16 @@ export const updateStorageDocumentCatchDepartureWeights = async (
303303
const netWeightProductDeparture = formData[`weight-net-weight-product-departure-${index}`];
304304
const netWeightFisheryProductDeparture = formData[`weight-net-weight-fishery-product-departure-${index}`];
305305
if (netWeightProductDeparture !== undefined && netWeightFisheryProductDeparture !== undefined) {
306+
// Use null (not undefined) for empty values so the field is explicitly
307+
// included in the JSON body. JSON.stringify silently drops undefined,
308+
// which means the orchestration never receives the clearing intent and
309+
// the old departure-weight value stays in MongoDB.
306310
catches[index]["netWeightProductDeparture"] = !isEmpty(netWeightProductDeparture)
307311
? netWeightProductDeparture
308-
: undefined;
312+
: null;
309313
catches[index]["netWeightFisheryProductDeparture"] = !isEmpty(netWeightFisheryProductDeparture)
310314
? netWeightFisheryProductDeparture
311-
: undefined;
315+
: null;
312316
}
313317
});
314318
} else {

app/routes/create-non-manipulation-document.$documentNumber.departure-product-summary.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ export const ConsignmentWeightTableForm = ({ catches, transportType }: Consignme
5757
if (isArrival) {
5858
weight = catchItem?.netWeightProductArrival;
5959
} else if (
60-
!catchItem?.netWeightProductDeparture &&
61-
!catchItem?.netWeightFisheryProductDeparture &&
60+
// Only fall back to arrival weight when departure was NEVER submitted
61+
// (undefined). A null value means the user explicitly cleared the field;
62+
// in that case show nothing rather than re-showing the arrival weight.
63+
catchItem?.netWeightProductDeparture === undefined &&
64+
catchItem?.netWeightFisheryProductDeparture === undefined &&
6265
catchItem?.netWeightProductArrival
6366
) {
6467
weight = catchItem.netWeightProductArrival;
6568
} else {
66-
weight = catchItem?.netWeightProductDeparture;
69+
weight = catchItem?.netWeightProductDeparture ?? undefined;
6770
}
6871
return weight === undefined ? undefined : Number(weight).toFixed(2);
6972
};
@@ -72,13 +75,13 @@ export const ConsignmentWeightTableForm = ({ catches, transportType }: Consignme
7275
if (isArrival) {
7376
weight = catchItem?.netWeightFisheryProductArrival;
7477
} else if (
75-
!catchItem?.netWeightProductDeparture &&
76-
!catchItem?.netWeightFisheryProductDeparture &&
78+
catchItem?.netWeightProductDeparture === undefined &&
79+
catchItem?.netWeightFisheryProductDeparture === undefined &&
7780
catchItem?.netWeightFisheryProductArrival
7881
) {
7982
weight = catchItem.netWeightFisheryProductArrival;
8083
} else {
81-
weight = catchItem?.netWeightFisheryProductDeparture;
84+
weight = catchItem?.netWeightFisheryProductDeparture ?? undefined;
8285
}
8386
return weight === undefined ? undefined : Number(weight).toFixed(2);
8487
};
@@ -277,7 +280,11 @@ export const action: ActionFunction = async ({ request, params }): Promise<Respo
277280
const isNonJs = form.get("isNonJs") === "true";
278281
const { _action, ...values } = Object.fromEntries(form);
279282
const isDraft = form.get("_action") === "saveAsDraft";
280-
const saveToRedisIfErrors = isDraft;
283+
// Always persist submitted weights (even when validation fails) so that the
284+
// progress page correctly reflects the current state. Without this, a failed
285+
// Confirm submission reverts to the previously-saved valid weights in the DB,
286+
// causing the section to appear Complete even after the user has cleared them.
287+
const saveToRedisIfErrors = true;
281288

282289
const isEdit = (_action as string)?.startsWith("edit-");
283290
const isRemove = (_action as string)?.startsWith("remove-");

app/types/storageDocument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export interface StorageDocumentCatch {
1717
productDescription?: string;
1818
netWeightProductArrival?: string;
1919
netWeightFisheryProductArrival?: string;
20-
netWeightProductDeparture?: string;
21-
netWeightFisheryProductDeparture?: string;
20+
netWeightProductDeparture?: string | null;
21+
netWeightFisheryProductDeparture?: string | null;
2222
_id?: string;
2323
}
2424

public/locales-v2/en/errorsText.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
"sdNetWeightProductDeparturePositiveMax2Decimal": "Enter the net weight on departure as a number with a maximum of 2 decimal places",
264264
"sdNetWeightFisheryProductDepartureErrorMax2DecimalLargerThan0": "Enter the fishery product weight with a maximum of 2 decimal places, larger than 0",
265265
"sdNetWeightFisheryProductDeparturePositiveMax2Decimal": "Enter the fishery product weight as a number with a maximum of 2 decimal places",
266+
"sdNetWeightOrFisheryWeightProductDeparture": "Enter the net weight on departure and the fishery product weight on departure",
266267
"sdNetWeightProductDepartureExceedsArrival": "Departure weight cannot be greater than arrival weight",
267268
"sdNetWeightFisheryProductDepartureExceedsProductDeparture": "Fishery products net weight on arrival cannot exceed the product net weight",
268269
"sdNetWeightProductDepartureExceed12Digit": "The net weight on departure must be less than 100000000000",

0 commit comments

Comments
 (0)