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
This commit is contained in:
Michał Droń 2022-07-07 17:28:12 +02:00 committed by GitHub
parent a54fc0396b
commit 3ac4ac4c1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View file

@ -230,6 +230,7 @@ const OrderFulfillPage: React.FC<OrderFulfillPageProps> = props => {
getToFulfillOrderLines(order?.lines),
(line: OrderFulfillLineFragment, lineIndex) => (
<OrderFulfillLine
key={line.id}
line={line}
lineIndex={lineIndex}
warehouseId={warehouse?.id}

View file

@ -38,7 +38,7 @@ const OrderFulfillStockExceededDialogLine: React.FC<OrderFulfillStockExceededDia
thumbnail={line?.thumbnail?.url}
>
{line?.productName}
{"attributes" in line.variant && (
{line.variant && "attributes" in line.variant && (
<Typography color="textSecondary" variant="caption">
{getAttributesCaption(line.variant?.attributes)}
</Typography>

View file

@ -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(" / ");