From 6e09ec9bb29171d73e6c8693850817dc851b04f2 Mon Sep 17 00:00:00 2001 From: Wojciech Mista Date: Thu, 23 Dec 2021 16:00:37 +0100 Subject: [PATCH] Use variant prices in add product modal (#1698) * Replace channel price with variant price; add new price label * Update fixtures * Remove unused code * Remove unused style * Lint fix * Remove type conversion * lint fix * update queries and types * CR Fixes * Money align right --- .../DiscountedPrice/DiscountedPrice.tsx | 28 ++++ src/components/DiscountedPrice/styles.ts | 12 ++ src/fragments/orders.ts | 3 + src/fragments/types/OrderDetailsFragment.ts | 6 + src/misc.ts | 11 ++ .../OrderPriceLabel/OrderPriceLabel.tsx | 30 ++++ .../components/OrderPriceLabel/styles.ts | 13 ++ .../OrderProductAddDialog.tsx | 6 +- src/orders/fixtures.ts | 144 +++++++++++++++++- src/orders/queries.ts | 15 ++ src/orders/types/FulfillOrder.ts | 6 + src/orders/types/OrderCancel.ts | 6 + src/orders/types/OrderCapture.ts | 6 + src/orders/types/OrderConfirm.ts | 6 + src/orders/types/OrderDetails.ts | 6 + src/orders/types/OrderDiscountAdd.ts | 6 + src/orders/types/OrderDiscountDelete.ts | 6 + src/orders/types/OrderDiscountUpdate.ts | 6 + src/orders/types/OrderDraftCancel.ts | 6 + src/orders/types/OrderDraftFinalize.ts | 6 + src/orders/types/OrderDraftUpdate.ts | 6 + src/orders/types/OrderFulfillmentApprove.ts | 6 + src/orders/types/OrderFulfillmentCancel.ts | 6 + .../types/OrderFulfillmentRefundProducts.ts | 6 + .../types/OrderFulfillmentUpdateTracking.ts | 6 + src/orders/types/OrderLineDelete.ts | 6 + src/orders/types/OrderLineDiscountRemove.ts | 6 + src/orders/types/OrderLineDiscountUpdate.ts | 6 + src/orders/types/OrderLineUpdate.ts | 6 + src/orders/types/OrderLinesAdd.ts | 6 + src/orders/types/OrderMarkAsPaid.ts | 6 + src/orders/types/OrderRefund.ts | 6 + src/orders/types/OrderShippingMethodUpdate.ts | 6 + src/orders/types/OrderUpdate.ts | 6 + src/orders/types/OrderVoid.ts | 6 + src/orders/types/SearchOrderVariant.ts | 33 ++++ src/orders/utils/data.ts | 22 ++- .../OrderDetails/OrderDraftDetails/index.tsx | 7 +- 38 files changed, 466 insertions(+), 14 deletions(-) create mode 100644 src/components/DiscountedPrice/DiscountedPrice.tsx create mode 100644 src/components/DiscountedPrice/styles.ts create mode 100644 src/orders/components/OrderPriceLabel/OrderPriceLabel.tsx create mode 100644 src/orders/components/OrderPriceLabel/styles.ts diff --git a/src/components/DiscountedPrice/DiscountedPrice.tsx b/src/components/DiscountedPrice/DiscountedPrice.tsx new file mode 100644 index 000000000..15409bd0e --- /dev/null +++ b/src/components/DiscountedPrice/DiscountedPrice.tsx @@ -0,0 +1,28 @@ +import { Typography } from "@material-ui/core"; +import React from "react"; + +import Money, { IMoney } from "../Money"; +import { useStyles } from "./styles"; + +interface DiscountedPriceProps { + regularPrice: IMoney; + discountedPrice: IMoney; +} + +const DiscountedPrice: React.FC = ({ + regularPrice, + discountedPrice +}) => { + const classes = useStyles(); + + return ( + <> + + + + + + ); +}; + +export default DiscountedPrice; diff --git a/src/components/DiscountedPrice/styles.ts b/src/components/DiscountedPrice/styles.ts new file mode 100644 index 000000000..35b07bed4 --- /dev/null +++ b/src/components/DiscountedPrice/styles.ts @@ -0,0 +1,12 @@ +import { makeStyles } from "@saleor/macaw-ui"; + +export const useStyles = makeStyles( + theme => ({ + strike: { + textDecoration: "line-through", + color: theme.palette.grey[400], + fontSize: "smaller" + } + }), + { name: "DiscountedPrice" } +); diff --git a/src/fragments/orders.ts b/src/fragments/orders.ts index ced4e9048..e908ddb93 100644 --- a/src/fragments/orders.ts +++ b/src/fragments/orders.ts @@ -313,6 +313,9 @@ export const fragmentOrderDetails = gql` name currencyCode slug + defaultCountry { + code + } } isPaid } diff --git a/src/fragments/types/OrderDetailsFragment.ts b/src/fragments/types/OrderDetailsFragment.ts index 373f1a924..41f223b97 100644 --- a/src/fragments/types/OrderDetailsFragment.ts +++ b/src/fragments/types/OrderDetailsFragment.ts @@ -539,6 +539,11 @@ export interface OrderDetailsFragment_invoices { status: JobStatusEnum; } +export interface OrderDetailsFragment_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDetailsFragment_channel { __typename: "Channel"; isActive: boolean; @@ -546,6 +551,7 @@ export interface OrderDetailsFragment_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDetailsFragment_channel_defaultCountry; } export interface OrderDetailsFragment { diff --git a/src/misc.ts b/src/misc.ts index 775431f0b..2ee6df692 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -14,6 +14,7 @@ import { orderStatusMessages, paymentStatusMessages } from "./intl"; +import { OrderDetails_order_shippingAddress } from "./orders/types/OrderDetails"; import { MutationResultAdditionalProps, PartialMutationProviderOutput, @@ -354,6 +355,16 @@ export function findInEnum(needle: string, haystack: TEnum) { throw new Error(`Key ${needle} not found in enum`); } +export function addressToAddressInput( + address: T & OrderDetails_order_shippingAddress +): AddressInput { + const { id, __typename, ...rest } = address; + return { + ...rest, + country: findInEnum(address.country.code, CountryCode) + }; +} + export function findValueInEnum( needle: string, haystack: TEnum diff --git a/src/orders/components/OrderPriceLabel/OrderPriceLabel.tsx b/src/orders/components/OrderPriceLabel/OrderPriceLabel.tsx new file mode 100644 index 000000000..345285482 --- /dev/null +++ b/src/orders/components/OrderPriceLabel/OrderPriceLabel.tsx @@ -0,0 +1,30 @@ +import DiscountedPrice from "@saleor/components/DiscountedPrice/DiscountedPrice"; +import Money from "@saleor/components/Money"; +import { SearchOrderVariant_search_edges_node_variants_pricing } from "@saleor/orders/types/SearchOrderVariant"; +import * as React from "react"; + +import { useStyles } from "./styles"; + +interface OrderPriceLabelProps { + pricing: SearchOrderVariant_search_edges_node_variants_pricing; +} + +const OrderPriceLabel: React.FC = ({ pricing }) => { + const classes = useStyles(); + + if (pricing.onSale) { + const { price, priceUndiscounted } = pricing; + return ( +
+ +
+ ); + } + + return ; +}; + +export default OrderPriceLabel; diff --git a/src/orders/components/OrderPriceLabel/styles.ts b/src/orders/components/OrderPriceLabel/styles.ts new file mode 100644 index 000000000..c33734c8a --- /dev/null +++ b/src/orders/components/OrderPriceLabel/styles.ts @@ -0,0 +1,13 @@ +import { makeStyles } from "@saleor/macaw-ui"; + +export const useStyles = makeStyles( + () => ({ + percentDiscountLabelContainer: { + display: "flex", + flexDirection: "column", + alignItems: "flex-end", + justifyContent: "flex-end" + } + }), + { name: "OrderPriceLabel" } +); diff --git a/src/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx b/src/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx index 059468656..a0565becd 100644 --- a/src/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx +++ b/src/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx @@ -16,7 +16,6 @@ import ConfirmButton, { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; import FormSpacer from "@saleor/components/FormSpacer"; -import Money from "@saleor/components/Money"; import ResponsiveTable from "@saleor/components/ResponsiveTable"; import TableCellAvatar from "@saleor/components/TableCellAvatar"; import { OrderErrorFragment } from "@saleor/fragments/types/OrderErrorFragment"; @@ -36,6 +35,7 @@ import { SearchOrderVariant_search_edges_node, SearchOrderVariant_search_edges_node_variants } from "../../types/SearchOrderVariant"; +import OrderPriceLabel from "../OrderPriceLabel/OrderPriceLabel"; const useStyles = makeStyles( theme => ({ @@ -365,9 +365,7 @@ const OrderProductAddDialog: React.FC = props => { )} - {variant?.channelListings[0]?.price && ( - - )} + ))} diff --git a/src/orders/fixtures.ts b/src/orders/fixtures.ts index 55271d18d..3852a6dba 100644 --- a/src/orders/fixtures.ts +++ b/src/orders/fixtures.ts @@ -837,7 +837,11 @@ export const order = (placeholder: string): OrderDetails_order => ({ currencyCode: "USD", id: "123454", isActive: true, - name: "Default Channel" + name: "Default Channel", + defaultCountry: { + code: "CA", + __typename: "CountryDisplay" + } }, created: "2018-09-11T09:37:28.185874+00:00", customerNote: "Lorem ipsum dolor sit amet", @@ -1424,7 +1428,11 @@ export const draftOrder = (placeholder: string): OrderDetails_order => ({ currencyCode: "USD", id: "123454", isActive: true, - name: "Default Channel" + name: "Default Channel", + defaultCountry: { + code: "CA", + __typename: "CountryDisplay" + } }, created: "2018-09-20T23:23:39.811428+00:00", customerNote: "Lorem ipsum dolor sit", @@ -1695,7 +1703,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjAy", name: "500ml", - sku: "93855755" + sku: "93855755", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } }, { __typename: "ProductVariant" as "ProductVariant", @@ -1733,7 +1761,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjAz", name: "1l", - sku: "43226647" + sku: "43226647", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } }, { __typename: "ProductVariant" as "ProductVariant", @@ -1771,7 +1819,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjA0", name: "2l", - sku: "80884671" + sku: "80884671", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } } ] }, @@ -1820,7 +1888,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjEx", name: "500ml", - sku: "43200242" + sku: "43200242", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } }, { __typename: "ProductVariant" as "ProductVariant", @@ -1858,7 +1946,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjEy", name: "1l", - sku: "79129513" + sku: "79129513", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } }, { __typename: "ProductVariant" as "ProductVariant", @@ -1896,7 +2004,27 @@ export const orderLineSearch = ( ], id: "UHJvZHVjdFZhcmlhbnQ6MjEz", name: "2l", - sku: "75799450" + sku: "75799450", + pricing: { + __typename: "VariantPricingInfo", + onSale: false, + price: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + }, + priceUndiscounted: { + __typename: "TaxedMoney", + gross: { + amount: 1, + currency: "USD", + __typename: "Money" + } + } + } } ] } diff --git a/src/orders/queries.ts b/src/orders/queries.ts index f7c5607da..718a05034 100644 --- a/src/orders/queries.ts +++ b/src/orders/queries.ts @@ -169,11 +169,13 @@ export const useOrderQuery = makeQuery( ); export const searchOrderVariant = gql` + ${fragmentMoney} query SearchOrderVariant( $channel: String! $first: Int! $query: String! $after: String + $address: AddressInput ) { search: products( first: $first @@ -192,6 +194,19 @@ export const searchOrderVariant = gql` id name sku + pricing(address: $address) { + priceUndiscounted { + gross { + ...Money + } + } + price { + gross { + ...Money + } + } + onSale + } channelListings { channel { id diff --git a/src/orders/types/FulfillOrder.ts b/src/orders/types/FulfillOrder.ts index ebfbd7e04..5b97fcb86 100644 --- a/src/orders/types/FulfillOrder.ts +++ b/src/orders/types/FulfillOrder.ts @@ -548,6 +548,11 @@ export interface FulfillOrder_orderFulfill_order_invoices { status: JobStatusEnum; } +export interface FulfillOrder_orderFulfill_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface FulfillOrder_orderFulfill_order_channel { __typename: "Channel"; isActive: boolean; @@ -555,6 +560,7 @@ export interface FulfillOrder_orderFulfill_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: FulfillOrder_orderFulfill_order_channel_defaultCountry; } export interface FulfillOrder_orderFulfill_order { diff --git a/src/orders/types/OrderCancel.ts b/src/orders/types/OrderCancel.ts index 7990635bf..3027e7664 100644 --- a/src/orders/types/OrderCancel.ts +++ b/src/orders/types/OrderCancel.ts @@ -546,6 +546,11 @@ export interface OrderCancel_orderCancel_order_invoices { status: JobStatusEnum; } +export interface OrderCancel_orderCancel_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderCancel_orderCancel_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderCancel_orderCancel_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderCancel_orderCancel_order_channel_defaultCountry; } export interface OrderCancel_orderCancel_order { diff --git a/src/orders/types/OrderCapture.ts b/src/orders/types/OrderCapture.ts index 53d1e0ee8..d4ee36967 100644 --- a/src/orders/types/OrderCapture.ts +++ b/src/orders/types/OrderCapture.ts @@ -546,6 +546,11 @@ export interface OrderCapture_orderCapture_order_invoices { status: JobStatusEnum; } +export interface OrderCapture_orderCapture_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderCapture_orderCapture_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderCapture_orderCapture_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderCapture_orderCapture_order_channel_defaultCountry; } export interface OrderCapture_orderCapture_order { diff --git a/src/orders/types/OrderConfirm.ts b/src/orders/types/OrderConfirm.ts index fc5795723..1a7a6af93 100644 --- a/src/orders/types/OrderConfirm.ts +++ b/src/orders/types/OrderConfirm.ts @@ -546,6 +546,11 @@ export interface OrderConfirm_orderConfirm_order_invoices { status: JobStatusEnum; } +export interface OrderConfirm_orderConfirm_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderConfirm_orderConfirm_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderConfirm_orderConfirm_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderConfirm_orderConfirm_order_channel_defaultCountry; } export interface OrderConfirm_orderConfirm_order { diff --git a/src/orders/types/OrderDetails.ts b/src/orders/types/OrderDetails.ts index 3e43fa044..0112e8e01 100644 --- a/src/orders/types/OrderDetails.ts +++ b/src/orders/types/OrderDetails.ts @@ -539,6 +539,11 @@ export interface OrderDetails_order_invoices { status: JobStatusEnum; } +export interface OrderDetails_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDetails_order_channel { __typename: "Channel"; isActive: boolean; @@ -546,6 +551,7 @@ export interface OrderDetails_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDetails_order_channel_defaultCountry; } export interface OrderDetails_order { diff --git a/src/orders/types/OrderDiscountAdd.ts b/src/orders/types/OrderDiscountAdd.ts index 55a90670d..f7ff25e10 100644 --- a/src/orders/types/OrderDiscountAdd.ts +++ b/src/orders/types/OrderDiscountAdd.ts @@ -546,6 +546,11 @@ export interface OrderDiscountAdd_orderDiscountAdd_order_invoices { status: JobStatusEnum; } +export interface OrderDiscountAdd_orderDiscountAdd_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDiscountAdd_orderDiscountAdd_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDiscountAdd_orderDiscountAdd_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDiscountAdd_orderDiscountAdd_order_channel_defaultCountry; } export interface OrderDiscountAdd_orderDiscountAdd_order { diff --git a/src/orders/types/OrderDiscountDelete.ts b/src/orders/types/OrderDiscountDelete.ts index 86dbf2f0f..de98826f4 100644 --- a/src/orders/types/OrderDiscountDelete.ts +++ b/src/orders/types/OrderDiscountDelete.ts @@ -546,6 +546,11 @@ export interface OrderDiscountDelete_orderDiscountDelete_order_invoices { status: JobStatusEnum; } +export interface OrderDiscountDelete_orderDiscountDelete_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDiscountDelete_orderDiscountDelete_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDiscountDelete_orderDiscountDelete_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDiscountDelete_orderDiscountDelete_order_channel_defaultCountry; } export interface OrderDiscountDelete_orderDiscountDelete_order { diff --git a/src/orders/types/OrderDiscountUpdate.ts b/src/orders/types/OrderDiscountUpdate.ts index 091f2f604..3ab245c36 100644 --- a/src/orders/types/OrderDiscountUpdate.ts +++ b/src/orders/types/OrderDiscountUpdate.ts @@ -546,6 +546,11 @@ export interface OrderDiscountUpdate_orderDiscountUpdate_order_invoices { status: JobStatusEnum; } +export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDiscountUpdate_orderDiscountUpdate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDiscountUpdate_orderDiscountUpdate_order_channel_defaultCountry; } export interface OrderDiscountUpdate_orderDiscountUpdate_order { diff --git a/src/orders/types/OrderDraftCancel.ts b/src/orders/types/OrderDraftCancel.ts index 4806d0287..a730bbb10 100644 --- a/src/orders/types/OrderDraftCancel.ts +++ b/src/orders/types/OrderDraftCancel.ts @@ -546,6 +546,11 @@ export interface OrderDraftCancel_draftOrderDelete_order_invoices { status: JobStatusEnum; } +export interface OrderDraftCancel_draftOrderDelete_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDraftCancel_draftOrderDelete_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDraftCancel_draftOrderDelete_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDraftCancel_draftOrderDelete_order_channel_defaultCountry; } export interface OrderDraftCancel_draftOrderDelete_order { diff --git a/src/orders/types/OrderDraftFinalize.ts b/src/orders/types/OrderDraftFinalize.ts index 82ac5c4ff..45c3c8514 100644 --- a/src/orders/types/OrderDraftFinalize.ts +++ b/src/orders/types/OrderDraftFinalize.ts @@ -546,6 +546,11 @@ export interface OrderDraftFinalize_draftOrderComplete_order_invoices { status: JobStatusEnum; } +export interface OrderDraftFinalize_draftOrderComplete_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDraftFinalize_draftOrderComplete_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDraftFinalize_draftOrderComplete_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDraftFinalize_draftOrderComplete_order_channel_defaultCountry; } export interface OrderDraftFinalize_draftOrderComplete_order { diff --git a/src/orders/types/OrderDraftUpdate.ts b/src/orders/types/OrderDraftUpdate.ts index 373c61aa1..db7f3d20a 100644 --- a/src/orders/types/OrderDraftUpdate.ts +++ b/src/orders/types/OrderDraftUpdate.ts @@ -546,6 +546,11 @@ export interface OrderDraftUpdate_draftOrderUpdate_order_invoices { status: JobStatusEnum; } +export interface OrderDraftUpdate_draftOrderUpdate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderDraftUpdate_draftOrderUpdate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderDraftUpdate_draftOrderUpdate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderDraftUpdate_draftOrderUpdate_order_channel_defaultCountry; } export interface OrderDraftUpdate_draftOrderUpdate_order { diff --git a/src/orders/types/OrderFulfillmentApprove.ts b/src/orders/types/OrderFulfillmentApprove.ts index 8a234f4c8..8b31d9464 100644 --- a/src/orders/types/OrderFulfillmentApprove.ts +++ b/src/orders/types/OrderFulfillmentApprove.ts @@ -546,6 +546,11 @@ export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_invoices status: JobStatusEnum; } +export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderFulfillmentApprove_orderFulfillmentApprove_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderFulfillmentApprove_orderFulfillmentApprove_order_channel_defaultCountry; } export interface OrderFulfillmentApprove_orderFulfillmentApprove_order { diff --git a/src/orders/types/OrderFulfillmentCancel.ts b/src/orders/types/OrderFulfillmentCancel.ts index a1b585e79..101d21c3d 100644 --- a/src/orders/types/OrderFulfillmentCancel.ts +++ b/src/orders/types/OrderFulfillmentCancel.ts @@ -546,6 +546,11 @@ export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_invoices { status: JobStatusEnum; } +export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderFulfillmentCancel_orderFulfillmentCancel_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderFulfillmentCancel_orderFulfillmentCancel_order_channel_defaultCountry; } export interface OrderFulfillmentCancel_orderFulfillmentCancel_order { diff --git a/src/orders/types/OrderFulfillmentRefundProducts.ts b/src/orders/types/OrderFulfillmentRefundProducts.ts index 779af3f8b..3297c2f34 100644 --- a/src/orders/types/OrderFulfillmentRefundProducts.ts +++ b/src/orders/types/OrderFulfillmentRefundProducts.ts @@ -648,6 +648,11 @@ export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_o status: JobStatusEnum; } +export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel { __typename: "Channel"; isActive: boolean; @@ -655,6 +660,7 @@ export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_o name: string; currencyCode: string; slug: string; + defaultCountry: OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order_channel_defaultCountry; } export interface OrderFulfillmentRefundProducts_orderFulfillmentRefundProducts_order { diff --git a/src/orders/types/OrderFulfillmentUpdateTracking.ts b/src/orders/types/OrderFulfillmentUpdateTracking.ts index 840e5dcb1..9242aa96c 100644 --- a/src/orders/types/OrderFulfillmentUpdateTracking.ts +++ b/src/orders/types/OrderFulfillmentUpdateTracking.ts @@ -546,6 +546,11 @@ export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_o status: JobStatusEnum; } +export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_o name: string; currencyCode: string; slug: string; + defaultCountry: OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order_channel_defaultCountry; } export interface OrderFulfillmentUpdateTracking_orderFulfillmentUpdateTracking_order { diff --git a/src/orders/types/OrderLineDelete.ts b/src/orders/types/OrderLineDelete.ts index bb2007ce5..c38f03246 100644 --- a/src/orders/types/OrderLineDelete.ts +++ b/src/orders/types/OrderLineDelete.ts @@ -546,6 +546,11 @@ export interface OrderLineDelete_orderLineDelete_order_invoices { status: JobStatusEnum; } +export interface OrderLineDelete_orderLineDelete_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderLineDelete_orderLineDelete_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderLineDelete_orderLineDelete_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderLineDelete_orderLineDelete_order_channel_defaultCountry; } export interface OrderLineDelete_orderLineDelete_order { diff --git a/src/orders/types/OrderLineDiscountRemove.ts b/src/orders/types/OrderLineDiscountRemove.ts index 2dae38359..6a506c3b3 100644 --- a/src/orders/types/OrderLineDiscountRemove.ts +++ b/src/orders/types/OrderLineDiscountRemove.ts @@ -546,6 +546,11 @@ export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_invoices status: JobStatusEnum; } +export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderLineDiscountRemove_orderLineDiscountRemove_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderLineDiscountRemove_orderLineDiscountRemove_order_channel_defaultCountry; } export interface OrderLineDiscountRemove_orderLineDiscountRemove_order { diff --git a/src/orders/types/OrderLineDiscountUpdate.ts b/src/orders/types/OrderLineDiscountUpdate.ts index e076e2425..f01d08491 100644 --- a/src/orders/types/OrderLineDiscountUpdate.ts +++ b/src/orders/types/OrderLineDiscountUpdate.ts @@ -546,6 +546,11 @@ export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_invoices status: JobStatusEnum; } +export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderLineDiscountUpdate_orderLineDiscountUpdate_order_channel_defaultCountry; } export interface OrderLineDiscountUpdate_orderLineDiscountUpdate_order { diff --git a/src/orders/types/OrderLineUpdate.ts b/src/orders/types/OrderLineUpdate.ts index b404685e9..eeaa3ca9b 100644 --- a/src/orders/types/OrderLineUpdate.ts +++ b/src/orders/types/OrderLineUpdate.ts @@ -546,6 +546,11 @@ export interface OrderLineUpdate_orderLineUpdate_order_invoices { status: JobStatusEnum; } +export interface OrderLineUpdate_orderLineUpdate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderLineUpdate_orderLineUpdate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderLineUpdate_orderLineUpdate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderLineUpdate_orderLineUpdate_order_channel_defaultCountry; } export interface OrderLineUpdate_orderLineUpdate_order { diff --git a/src/orders/types/OrderLinesAdd.ts b/src/orders/types/OrderLinesAdd.ts index 848f4838b..1624446bd 100644 --- a/src/orders/types/OrderLinesAdd.ts +++ b/src/orders/types/OrderLinesAdd.ts @@ -546,6 +546,11 @@ export interface OrderLinesAdd_orderLinesCreate_order_invoices { status: JobStatusEnum; } +export interface OrderLinesAdd_orderLinesCreate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderLinesAdd_orderLinesCreate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderLinesAdd_orderLinesCreate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderLinesAdd_orderLinesCreate_order_channel_defaultCountry; } export interface OrderLinesAdd_orderLinesCreate_order { diff --git a/src/orders/types/OrderMarkAsPaid.ts b/src/orders/types/OrderMarkAsPaid.ts index 59d75134a..b06950a1e 100644 --- a/src/orders/types/OrderMarkAsPaid.ts +++ b/src/orders/types/OrderMarkAsPaid.ts @@ -546,6 +546,11 @@ export interface OrderMarkAsPaid_orderMarkAsPaid_order_invoices { status: JobStatusEnum; } +export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderMarkAsPaid_orderMarkAsPaid_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderMarkAsPaid_orderMarkAsPaid_order_channel_defaultCountry; } export interface OrderMarkAsPaid_orderMarkAsPaid_order { diff --git a/src/orders/types/OrderRefund.ts b/src/orders/types/OrderRefund.ts index 6ce53d5da..8ecf664cd 100644 --- a/src/orders/types/OrderRefund.ts +++ b/src/orders/types/OrderRefund.ts @@ -546,6 +546,11 @@ export interface OrderRefund_orderRefund_order_invoices { status: JobStatusEnum; } +export interface OrderRefund_orderRefund_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderRefund_orderRefund_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderRefund_orderRefund_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderRefund_orderRefund_order_channel_defaultCountry; } export interface OrderRefund_orderRefund_order { diff --git a/src/orders/types/OrderShippingMethodUpdate.ts b/src/orders/types/OrderShippingMethodUpdate.ts index 5307c7f84..1d5eb4934 100644 --- a/src/orders/types/OrderShippingMethodUpdate.ts +++ b/src/orders/types/OrderShippingMethodUpdate.ts @@ -554,6 +554,11 @@ export interface OrderShippingMethodUpdate_orderUpdateShipping_order_invoices { status: JobStatusEnum; } +export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel { __typename: "Channel"; isActive: boolean; @@ -561,6 +566,7 @@ export interface OrderShippingMethodUpdate_orderUpdateShipping_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderShippingMethodUpdate_orderUpdateShipping_order_channel_defaultCountry; } export interface OrderShippingMethodUpdate_orderUpdateShipping_order { diff --git a/src/orders/types/OrderUpdate.ts b/src/orders/types/OrderUpdate.ts index ba63331b5..88520bc16 100644 --- a/src/orders/types/OrderUpdate.ts +++ b/src/orders/types/OrderUpdate.ts @@ -546,6 +546,11 @@ export interface OrderUpdate_orderUpdate_order_invoices { status: JobStatusEnum; } +export interface OrderUpdate_orderUpdate_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderUpdate_orderUpdate_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderUpdate_orderUpdate_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderUpdate_orderUpdate_order_channel_defaultCountry; } export interface OrderUpdate_orderUpdate_order { diff --git a/src/orders/types/OrderVoid.ts b/src/orders/types/OrderVoid.ts index e2e31e2c0..00eead8ad 100644 --- a/src/orders/types/OrderVoid.ts +++ b/src/orders/types/OrderVoid.ts @@ -546,6 +546,11 @@ export interface OrderVoid_orderVoid_order_invoices { status: JobStatusEnum; } +export interface OrderVoid_orderVoid_order_channel_defaultCountry { + __typename: "CountryDisplay"; + code: string; +} + export interface OrderVoid_orderVoid_order_channel { __typename: "Channel"; isActive: boolean; @@ -553,6 +558,7 @@ export interface OrderVoid_orderVoid_order_channel { name: string; currencyCode: string; slug: string; + defaultCountry: OrderVoid_orderVoid_order_channel_defaultCountry; } export interface OrderVoid_orderVoid_order { diff --git a/src/orders/types/SearchOrderVariant.ts b/src/orders/types/SearchOrderVariant.ts index 5743f2fac..8a19d8380 100644 --- a/src/orders/types/SearchOrderVariant.ts +++ b/src/orders/types/SearchOrderVariant.ts @@ -3,6 +3,8 @@ // @generated // This file was automatically generated and should not be edited. +import { AddressInput } from "./../../types/globalTypes"; + // ==================================================== // GraphQL query operation: SearchOrderVariant // ==================================================== @@ -12,6 +14,35 @@ export interface SearchOrderVariant_search_edges_node_thumbnail { url: string; } +export interface SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted_gross { + __typename: "Money"; + amount: number; + currency: string; +} + +export interface SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted { + __typename: "TaxedMoney"; + gross: SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted_gross; +} + +export interface SearchOrderVariant_search_edges_node_variants_pricing_price_gross { + __typename: "Money"; + amount: number; + currency: string; +} + +export interface SearchOrderVariant_search_edges_node_variants_pricing_price { + __typename: "TaxedMoney"; + gross: SearchOrderVariant_search_edges_node_variants_pricing_price_gross; +} + +export interface SearchOrderVariant_search_edges_node_variants_pricing { + __typename: "VariantPricingInfo"; + priceUndiscounted: SearchOrderVariant_search_edges_node_variants_pricing_priceUndiscounted | null; + price: SearchOrderVariant_search_edges_node_variants_pricing_price | null; + onSale: boolean | null; +} + export interface SearchOrderVariant_search_edges_node_variants_channelListings_channel { __typename: "Channel"; id: string; @@ -37,6 +68,7 @@ export interface SearchOrderVariant_search_edges_node_variants { id: string; name: string; sku: string | null; + pricing: SearchOrderVariant_search_edges_node_variants_pricing | null; channelListings: SearchOrderVariant_search_edges_node_variants_channelListings[] | null; } @@ -76,4 +108,5 @@ export interface SearchOrderVariantVariables { first: number; query: string; after?: string | null; + address?: AddressInput | null; } diff --git a/src/orders/utils/data.ts b/src/orders/utils/data.ts index 1dd8a57c2..bad5a57cf 100644 --- a/src/orders/utils/data.ts +++ b/src/orders/utils/data.ts @@ -1,7 +1,13 @@ import { IMoney, subtractMoney } from "@saleor/components/Money"; import { WarehouseFragment } from "@saleor/fragments/types/WarehouseFragment"; import { FormsetData } from "@saleor/hooks/useFormset"; -import { FulfillmentStatus, OrderErrorCode } from "@saleor/types/globalTypes"; +import { addressToAddressInput } from "@saleor/misc"; +import { + AddressInput, + CountryCode, + FulfillmentStatus, + OrderErrorCode +} from "@saleor/types/globalTypes"; import { LineItemData, @@ -298,3 +304,17 @@ export const isStockError = ( return isQuantityLargerThanAvailable || isError; }; + +export const getVariantSearchAddress = ( + order: OrderDetails_order +): AddressInput => { + if (order.shippingAddress) { + return addressToAddressInput(order.shippingAddress); + } + + if (order.billingAddress) { + return addressToAddressInput(order.billingAddress); + } + + return { country: order.channel.defaultCountry.code as CountryCode }; +}; diff --git a/src/orders/views/OrderDetails/OrderDraftDetails/index.tsx b/src/orders/views/OrderDetails/OrderDraftDetails/index.tsx index 65e929a5c..a11dca43e 100644 --- a/src/orders/views/OrderDetails/OrderDraftDetails/index.tsx +++ b/src/orders/views/OrderDetails/OrderDraftDetails/index.tsx @@ -13,6 +13,7 @@ import { } from "@saleor/orders/components/OrderCustomerChangeDialog/form"; import OrderCustomerChangeDialog from "@saleor/orders/components/OrderCustomerChangeDialog/OrderCustomerChangeDialog"; import { OrderDetails } from "@saleor/orders/types/OrderDetails"; +import { getVariantSearchAddress } from "@saleor/orders/utils/data"; import { OrderDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderDiscountProvider"; import { OrderLineDiscountProvider } from "@saleor/products/components/OrderDiscountProviders/OrderLineDiscountProvider"; import useCustomerSearch from "@saleor/searches/useCustomerSearch"; @@ -73,7 +74,11 @@ export const OrderDraftDetails: React.FC = ({ search: variantSearch, result: variantSearchOpts } = useOrderVariantSearch({ - variables: { ...DEFAULT_INITIAL_SEARCH_DATA, channel: order.channel.slug } + variables: { + ...DEFAULT_INITIAL_SEARCH_DATA, + channel: order.channel.slug, + address: getVariantSearchAddress(order) + } }); const {