From 3ac4ac4c1b0441145eda53190040db9d48309357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dro=C5=84?= Date: Thu, 7 Jul 2022 17:28:12 +0200 Subject: [PATCH] Fix fulfilling deleted variants (#2090) * Add optional chaining * Fix type * Fix a similar bug in the stock exceeded dialog * Add keys to fulfillment lines * Add undefined to return type --- src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx | 1 + .../OrderFulfillStockExceededDialogLine.tsx | 2 +- src/orders/utils/data.ts | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx index 26d90aba6..5ddf1dde4 100644 --- a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx +++ b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx @@ -230,6 +230,7 @@ const OrderFulfillPage: React.FC = props => { getToFulfillOrderLines(order?.lines), (line: OrderFulfillLineFragment, lineIndex) => ( {line?.productName} - {"attributes" in line.variant && ( + {line.variant && "attributes" in line.variant && ( {getAttributesCaption(line.variant?.attributes)} diff --git a/src/orders/utils/data.ts b/src/orders/utils/data.ts index c24f3ec58..3c816d29f 100644 --- a/src/orders/utils/data.ts +++ b/src/orders/utils/data.ts @@ -372,10 +372,10 @@ export const transformFuflillmentLinesToStockInputFormsetData = ( })); export const getAttributesCaption = ( - attributes: OrderFulfillLineFragment["variant"]["attributes"], -): string => + attributes: OrderFulfillLineFragment["variant"]["attributes"] | undefined, +): string | undefined => attributes - .map(attribute => + ?.map(attribute => attribute.values.map(attributeValue => attributeValue.name).join(", "), ) .join(" / ");