From 242c7736ab517027e5de18ffcc6502c18d1327ea Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 5 Nov 2024 12:30:57 +0000 Subject: [PATCH] Improve optional chaining checks - Fixes bug where part_detail is potentially undefined --- src/frontend/src/forms/PurchaseOrderForms.tsx | 11 ++++++----- src/frontend/src/forms/StockForms.tsx | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/forms/PurchaseOrderForms.tsx b/src/frontend/src/forms/PurchaseOrderForms.tsx index add7d9241427..4e485acc627a 100644 --- a/src/frontend/src/forms/PurchaseOrderForms.tsx +++ b/src/frontend/src/forms/PurchaseOrderForms.tsx @@ -348,7 +348,8 @@ function LineItemFormRow({ if ( !record.destination && !record.destination_detail && - location === record.part_detail.category_default_location + record.part_detail && + location === record.part_detail?.category_default_location ) { return t`Part category default location selected`; } @@ -511,8 +512,8 @@ function LineItemFormRow({ } /> - {(record.part_detail.default_location || - record.part_detail.category_default_location) && ( + {(record.part_detail?.default_location || + record.part_detail?.category_default_location) && ( } tooltip={t`Store at default location`} @@ -520,8 +521,8 @@ function LineItemFormRow({ props.changeFn( props.idx, 'location', - record.part_detail.default_location ?? - record.part_detail.category_default_location + record.part_detail?.default_location ?? + record.part_detail?.category_default_location ) } tooltipAlignment="top" diff --git a/src/frontend/src/forms/StockForms.tsx b/src/frontend/src/forms/StockForms.tsx index 3bb9cf91cb88..7857427f4c17 100644 --- a/src/frontend/src/forms/StockForms.tsx +++ b/src/frontend/src/forms/StockForms.tsx @@ -325,14 +325,14 @@ function StockItemDefaultMove({ const { data } = useSuspenseQuery({ queryKey: [ 'location', - stockItem.part_detail.default_location ?? - stockItem.part_detail.category_default_location + stockItem.part_detail?.default_location ?? + stockItem.part_detail?.category_default_location ], queryFn: async () => { const url = apiUrl( ApiEndpoints.stock_location_list, - stockItem.part_detail.default_location ?? - stockItem.part_detail.category_default_location + stockItem.part_detail?.default_location ?? + stockItem.part_detail?.category_default_location ); return api @@ -384,8 +384,8 @@ function moveToDefault( children: , onConfirm: () => { if ( - stockItem.location === stockItem.part_detail.default_location || - stockItem.location === stockItem.part_detail.category_default_location + stockItem.location === stockItem.part_detail?.default_location || + stockItem.location === stockItem.part_detail?.category_default_location ) { return; } @@ -400,8 +400,8 @@ function moveToDefault( } ], location: - stockItem.part_detail.default_location ?? - stockItem.part_detail.category_default_location + stockItem.part_detail?.default_location ?? + stockItem.part_detail?.category_default_location }) .then((response) => { refresh();