Skip to content

Commit

Permalink
Fix showing promotion discount type in order summary (#4689)
Browse files Browse the repository at this point in the history
* Show promotion discount type

* Add changeset
  • Loading branch information
poulch authored Feb 26, 2024
1 parent 232cd2a commit e234ddc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-brooms-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix showing promotion discount type in order summary
9 changes: 3 additions & 6 deletions src/orders/components/OrderSummaryCard/OrderSummaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import CardTitle from "@dashboard/components/CardTitle";
import Link from "@dashboard/components/Link";
import { giftCardPath } from "@dashboard/giftCards/urls";
import { OrderDetailsFragment, OrderDiscountType } from "@dashboard/graphql";
import { OrderDetailsFragment } from "@dashboard/graphql";
import { Card, CardContent } from "@material-ui/core";
import { makeStyles } from "@saleor/macaw-ui";
import React from "react";
Expand All @@ -15,6 +15,7 @@ import { SummaryList } from "./SummaryList";
import {
extractOrderGiftCardUsedAmount,
getDeliveryMethodName,
getDiscountTypeLabel,
getTaxTypeText,
} from "./utils";

Expand Down Expand Up @@ -71,11 +72,7 @@ const OrderSummaryCard: React.FC<OrderPaymentProps> = ({ order }) => {
<SummaryLine
key={discount.id}
text={<FormattedMessage {...orderSummaryMessages.discount} />}
subText={
discount.type === OrderDiscountType.MANUAL
? intl.formatMessage(orderSummaryMessages.staffAdded)
: intl.formatMessage(orderSummaryMessages.voucher)
}
subText={intl.formatMessage(getDiscountTypeLabel(discount.type))}
money={discount.amount}
/>
))}
Expand Down
5 changes: 5 additions & 0 deletions src/orders/components/OrderSummaryCard/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const orderSummaryMessages = defineMessages({
defaultMessage: "Voucher",
description: "voucher type order discount",
},
promotion: {
id: "TBdxTP",
defaultMessage: "Promotion",
description: "promotion type order discount",
},
total: {
id: "zb4eBO",
defaultMessage: "Total",
Expand Down
22 changes: 20 additions & 2 deletions src/orders/components/OrderSummaryCard/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// @ts-strict-ignore
import { subtractMoney } from "@dashboard/components/Money";
import { GiftCardEventsEnum, OrderDetailsFragment } from "@dashboard/graphql";
import {
GiftCardEventsEnum,
OrderDetailsFragment,
OrderDiscountType,
} from "@dashboard/graphql";
import { getOrderCharged } from "@dashboard/orders/utils/data";
import { IMoney } from "@dashboard/utils/intl";
import compact from "lodash/compact";
import { IntlShape } from "react-intl";
import { IntlShape, MessageDescriptor } from "react-intl";

import { orderSummaryMessages } from "./messages";

Expand Down Expand Up @@ -80,3 +84,17 @@ export const getTaxTypeText = (
}
return intl.formatMessage(orderSummaryMessages.vatNotIncluded);
};

export const getDiscountTypeLabel = (
discountType: OrderDiscountType,
): MessageDescriptor => {
switch (discountType) {
case OrderDiscountType.MANUAL:
return orderSummaryMessages.staffAdded;
case OrderDiscountType.PROMOTION:
case OrderDiscountType.ORDER_PROMOTION:
return orderSummaryMessages.promotion;
default:
return orderSummaryMessages.voucher;
}
};

0 comments on commit e234ddc

Please sign in to comment.