Skip to content

Commit d495dd6

Browse files
committed
updated shipping cost conditional render & complete action fields update
1 parent 5776d9e commit d495dd6

4 files changed

Lines changed: 32 additions & 34 deletions

File tree

apps/backend/src/foodManufacturers/manufacturers.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ describe('FoodManufacturersService', () => {
578578
expect(result['Donations']).toBe('2');
579579
expect(result['Value Donated']).toBe('$925');
580580
expect(result['Items Donated']).toBe('225');
581-
expect(result['lbs Donated']).toBe('225.03125');
581+
expect(result['lbs Donated']).toBe('225.03');
582582
});
583583

584584
it('throws NotFoundException for non-existent manufacturer', async () => {

apps/backend/src/foodManufacturers/manufacturers.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export class FoodManufacturersService {
475475
Donations: String(result.donations),
476476
'Value Donated': `$${Number(result.total_value)}`,
477477
'Items Donated': String(result.total_items),
478-
'lbs Donated': `${Number(result.total_lbs)}`,
478+
'lbs Donated': `${Number(result.total_lbs).toFixed(2)}`,
479479
};
480480
}
481481
}

apps/backend/src/orders/dtos/bulk-update-tracking-cost.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ export class OrderTrackingCostEntryDto {
2323
},
2424
{ message: 'Tracking link must be a valid HTTP/HTTPS URL' },
2525
)
26-
trackingLink?: string;
26+
trackingLink?: string | null;
2727

2828
@IsOptional()
2929
@IsNumber(
3030
{ maxDecimalPlaces: 2 },
3131
{ message: 'Shipping cost must have at most 2 decimal places' },
3232
)
3333
@Min(0, { message: 'Shipping cost cannot be negative' })
34-
shippingCost?: number;
34+
shippingCost?: number | null;
3535

3636
@IsOptional()
3737
@IsBoolean()

apps/frontend/src/components/forms/fmCompleteRequiredActionsModal.tsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -261,38 +261,24 @@ const FmCompleteRequiredActionsModal: React.FC<
261261
orderFormData[order.orderId];
262262
const originalTracking = order.trackingLink ?? '';
263263
const originalCost = order.shippingCost?.toString() ?? '';
264-
// The paid-by-SSF flag is only meaningful alongside a shipping cost,
265-
// so only treat a flag change as a change when a cost is present.
266-
const flagChanged =
267-
shippingCost !== '' &&
268-
shippingCostPaidBySsf !== order.shippingCostPaidBySsf;
269264
return (
270265
trackingLink !== originalTracking ||
271266
shippingCost !== originalCost ||
272-
flagChanged
267+
shippingCostPaidBySsf !== order.shippingCostPaidBySsf
273268
);
274269
})
275-
.map(
276-
(
277-
order,
278-
): {
279-
orderId: number;
280-
trackingLink?: string;
281-
shippingCost?: number;
282-
shippingCostPaidBySsf?: boolean;
283-
} => {
284-
const { trackingLink, shippingCost, shippingCostPaidBySsf } =
285-
orderFormData[order.orderId];
286-
return {
287-
orderId: order.orderId,
288-
...(trackingLink.trim() !== '' && { trackingLink }),
289-
...(shippingCost !== '' && {
290-
shippingCost: parseFloat(shippingCost),
291-
shippingCostPaidBySsf,
292-
}),
293-
};
294-
},
295-
);
270+
// Send every field, using null for cleared values so removing a
271+
// previously saved cost or link actually persists
272+
.map((order) => {
273+
const { trackingLink, shippingCost, shippingCostPaidBySsf } =
274+
orderFormData[order.orderId];
275+
return {
276+
orderId: order.orderId,
277+
trackingLink: trackingLink.trim() !== '' ? trackingLink : null,
278+
shippingCost: shippingCost !== '' ? parseFloat(shippingCost) : null,
279+
shippingCostPaidBySsf,
280+
};
281+
});
296282

297283
if (ordersToUpdate.length > 0) {
298284
await ApiClient.bulkUpdateTrackingCostInfo({
@@ -378,19 +364,31 @@ const FmCompleteRequiredActionsModal: React.FC<
378364
min={0}
379365
step={0.01}
380366
value={orderFormData[currentOrder.orderId].shippingCost}
381-
onChange={(e) =>
367+
onChange={(e) => {
382368
updateOrderField(
383369
currentOrder.orderId,
384370
'shippingCost',
385371
e.target.value,
386-
)
387-
}
372+
);
373+
// The paid-by-SSF flag is only meaningful alongside a
374+
// shipping cost, so clear it when the cost is cleared
375+
if (e.target.value === '') {
376+
updateOrderField(
377+
currentOrder.orderId,
378+
'shippingCostPaidBySsf',
379+
false,
380+
);
381+
}
382+
}}
388383
/>
389384
<Checkbox.Root
390385
mt={3}
391386
checked={
392387
orderFormData[currentOrder.orderId].shippingCostPaidBySsf
393388
}
389+
disabled={
390+
orderFormData[currentOrder.orderId].shippingCost === ''
391+
}
394392
size="sm"
395393
borderRadius="2px"
396394
onCheckedChange={(e: { checked: boolean }) =>

0 commit comments

Comments
 (0)