From 9226dc9656273ce28ac3a1532fc5a534ec092754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chy=C5=82a?= Date: Fri, 23 Feb 2024 14:08:04 +0100 Subject: [PATCH] Fix zero value in money cell, improve show discount type in order payment summary (#4685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Display zero value in money cell * Add promotion type to order payment details * Fix types * Add changeset * Extract messages * Update src/components/Datagrid/customCells/Money/utils.test.ts Co-authored-by: Michał Droń * Improve shipping methods update test --------- Co-authored-by: Michał Droń --- .changeset/itchy-queens-sit.md | 6 ++++++ locale/defaultMessages.json | 4 ++++ playwright/pages/shippingMethodsPage.ts | 10 ++++++---- .../Datagrid/customCells/Money/MoneyCell.tsx | 3 ++- .../Datagrid/customCells/Money/utils.test.ts | 12 ++++++++++++ .../Datagrid/customCells/Money/utils.ts | 6 ++++++ .../components/OrderPayment/OrderPayment.tsx | 8 ++------ src/orders/components/OrderPayment/messages.ts | 5 +++++ src/orders/components/OrderPayment/utils.ts | 18 ++++++++++++++++++ 9 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 .changeset/itchy-queens-sit.md create mode 100644 src/components/Datagrid/customCells/Money/utils.test.ts diff --git a/.changeset/itchy-queens-sit.md b/.changeset/itchy-queens-sit.md new file mode 100644 index 00000000000..be18c7e3666 --- /dev/null +++ b/.changeset/itchy-queens-sit.md @@ -0,0 +1,6 @@ +--- +"saleor-dashboard": patch +--- + +Fix showing empty price when value is zero +Improve showing discount type in order payment details diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 5a768b07d35..19ee5b30adf 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -4535,6 +4535,10 @@ "context": "order subtotal price", "string": "Subtotal" }, + "TBdxTP": { + "context": "promotion type order discount", + "string": "Promotion" + }, "TBftMD": { "context": "button. form submit, grant refund edit", "string": "Edit granted refund" diff --git a/playwright/pages/shippingMethodsPage.ts b/playwright/pages/shippingMethodsPage.ts index 0587982e990..25010ffc8f5 100644 --- a/playwright/pages/shippingMethodsPage.ts +++ b/playwright/pages/shippingMethodsPage.ts @@ -77,10 +77,12 @@ export class ShippingMethodsPage extends BasePage { `Navigates to existing shipping method page: ${existingShippingMethodUrl}`, ); await this.page.goto(existingShippingMethodUrl); - await this.shippingZoneNameInput.waitFor({ - state: "visible", - timeout: 10000, - }); + await this.rightSideDetailsPage.channelSection + .locator(this.page.getByTestId("selected-options")) + .waitFor({ + state: "visible", + timeout: 10000, + }); } async gotoExistingShippingRate(shippingMethodId: string, shippingRateId: string) { diff --git a/src/components/Datagrid/customCells/Money/MoneyCell.tsx b/src/components/Datagrid/customCells/Money/MoneyCell.tsx index f304123b2e3..433d745c662 100644 --- a/src/components/Datagrid/customCells/Money/MoneyCell.tsx +++ b/src/components/Datagrid/customCells/Money/MoneyCell.tsx @@ -9,6 +9,7 @@ import { import React from "react"; import { usePriceField } from "../../../PriceField/usePriceField"; +import { hasDiscountValue } from "./utils"; interface MoneyCellProps { readonly kind: "money-cell"; @@ -61,7 +62,7 @@ export const moneyCellRenderer = ( const isRange = Array.isArray(value); const displayValue = isRange ? value[0] : value; - if (!displayValue || !currency) { + if (!hasDiscountValue(displayValue) || !currency) { return true; } diff --git a/src/components/Datagrid/customCells/Money/utils.test.ts b/src/components/Datagrid/customCells/Money/utils.test.ts new file mode 100644 index 00000000000..13a865f24fe --- /dev/null +++ b/src/components/Datagrid/customCells/Money/utils.test.ts @@ -0,0 +1,12 @@ +import { hasDiscountValue } from "./utils"; + +describe("MoneyCell utils", () => { + describe("hasDiscountValue", () => { + it("should return true if value is not undefined, null", () => { + expect(hasDiscountValue(0)).toBe(true); + expect(hasDiscountValue(144)).toBe(true); + expect(hasDiscountValue(undefined)).toBe(false); + expect(hasDiscountValue(null)).toBe(false); + }); + }); +}); diff --git a/src/components/Datagrid/customCells/Money/utils.ts b/src/components/Datagrid/customCells/Money/utils.ts index cbefab2bd1c..fea34a68e48 100644 --- a/src/components/Datagrid/customCells/Money/utils.ts +++ b/src/components/Datagrid/customCells/Money/utils.ts @@ -71,3 +71,9 @@ export function getFormattedMoney( return placeholder; } + +export function hasDiscountValue( + value: number | null | undefined, +): value is number { + return value !== undefined && value !== null; +} diff --git a/src/orders/components/OrderPayment/OrderPayment.tsx b/src/orders/components/OrderPayment/OrderPayment.tsx index d9584a23955..c8b65d0c8eb 100644 --- a/src/orders/components/OrderPayment/OrderPayment.tsx +++ b/src/orders/components/OrderPayment/OrderPayment.tsx @@ -9,7 +9,6 @@ import { giftCardPath } from "@dashboard/giftCards/urls"; import { OrderAction, OrderDetailsFragment, - OrderDiscountType, OrderStatus, } from "@dashboard/graphql"; import { Card, CardContent } from "@material-ui/core"; @@ -24,6 +23,7 @@ import { useStyles } from "./styles"; import { extractOrderGiftCardUsedAmount, extractRefundedAmount, + getDiscountTypeLabel, obtainUsedGifrcard, } from "./utils"; @@ -136,11 +136,7 @@ const OrderPayment: React.FC = props => { - {discount.type === OrderDiscountType.MANUAL ? ( - - ) : ( - - )} + { if (!order) return null; @@ -72,3 +76,17 @@ export const extractRefundedAmount = (order: OrderDetailsFragment): IMoney => { } ); }; + +export const getDiscountTypeLabel = ( + discountType: OrderDiscountType, +): MessageDescriptor => { + switch (discountType) { + case OrderDiscountType.MANUAL: + return orderPaymentMessages.staffAdded; + case OrderDiscountType.PROMOTION: + case OrderDiscountType.ORDER_PROMOTION: + return orderPaymentMessages.promotion; + default: + return orderPaymentMessages.voucher; + } +};