From 61fe80bb7af1c96eda5ee22b9fa9f09fa3ab37f7 Mon Sep 17 00:00:00 2001 From: Dawid Date: Thu, 22 Sep 2022 11:03:21 +0200 Subject: [PATCH] Fix no product error on unconfirmed order lines (#2324) * Fix no product error onunconfirmed order lines * Update changelog with fix no product error --- CHANGELOG.md | 1 + locale/defaultMessages.json | 4 ++++ .../OrderDraftDetailsProducts/messages.ts | 5 +++++ .../OrderDraftDetailsProducts/useLineAlerts.ts | 17 ++++++++++------- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665679c81..226857763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable, unreleased changes to this project will be documented in this file. - Pass query params in `ORDER_DETAILS_MORE_ACTIONS` and `PRODUCT_DETAILS_MORE_ACTIONS` mounting points - #2100 by @witoszekdev - Add product variant reference attribute - #2268 by @droniu - Fix exit form dialog false positive - #2311 by @orzechdev +- Fix no product error on unconfirmed order lines - #2324 by @orzechdev ## 3.4 diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index d7d80f070..4f3dd3ecb 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -6567,6 +6567,10 @@ "context": "gift card history message", "string": "Gift card was activated" }, + "pEMxyy": { + "context": "alert message", + "string": "This product does no longer exist." + }, "pFVX6g": { "string": "Variant with these attributes already exists" }, diff --git a/src/orders/components/OrderDraftDetailsProducts/messages.ts b/src/orders/components/OrderDraftDetailsProducts/messages.ts index 7d84b55b6..bc5b3328a 100644 --- a/src/orders/components/OrderDraftDetailsProducts/messages.ts +++ b/src/orders/components/OrderDraftDetailsProducts/messages.ts @@ -11,4 +11,9 @@ export const lineAlertMessages = defineMessages({ defaultMessage: "This product is not available for sale in this channel.", description: "alert message", }, + notExists: { + id: "pEMxyy", + defaultMessage: "This product does no longer exist.", + description: "alert message", + }, }); diff --git a/src/orders/components/OrderDraftDetailsProducts/useLineAlerts.ts b/src/orders/components/OrderDraftDetailsProducts/useLineAlerts.ts index 22476f8d9..db78948c2 100644 --- a/src/orders/components/OrderDraftDetailsProducts/useLineAlerts.ts +++ b/src/orders/components/OrderDraftDetailsProducts/useLineAlerts.ts @@ -14,18 +14,21 @@ const useLineAlerts = ({ line, error }: UseLineAlertsOpts) => { const intl = useIntl(); const alerts = useMemo(() => { - const { - variant: { - product: { isAvailableForPurchase }, - }, - } = line; - const alerts: string[] = []; if (error) { alerts.push(getOrderErrorMessage(error, intl)); } - if (!isAvailableForPurchase) { + + const product = line.variant?.product; + + if (!product) { + alerts.push(intl.formatMessage(lineAlertMessages.notExists)); + } + + const isAvailableForPurchase = product?.isAvailableForPurchase; + + if (product && !isAvailableForPurchase) { alerts.push(intl.formatMessage(lineAlertMessages.notAvailable)); }