From bdf972323967c46da045575fb9f2e8c6c0c97af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Fri, 28 Feb 2025 15:55:35 +0100 Subject: [PATCH] fix(dashboard): filter outbound shipping options in RMA (#11629) **What** - filter out return shipping options for Claims/Exchanges - fix the incorrect display of "missing inventory" warning --- CLOSES CMRC-946 CLOSES CMRC-947 --- .../claim-create-form/claim-create-form.tsx | 13 ++++++------ .../claim-outbound-section.tsx | 20 ++++++++++++------ .../exchange-inbound-section.tsx | 8 +++---- .../exchange-outbound-section.tsx | 21 +++++++++++++------ .../core/js-sdk/src/admin/product-variant.ts | 20 +++++++++--------- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx index ca8b4c3b4e..2d5c21d88e 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx @@ -50,10 +50,10 @@ import { useUpdateClaimInboundShipping, useUpdateClaimOutboundShipping, } from "../../../../../hooks/api/claims" -import { useUpdateReturn } from "../../../../../hooks/api/returns.tsx" +import { useUpdateReturn } from "../../../../../hooks/api/returns" import { sdk } from "../../../../../lib/client" import { currencies } from "../../../../../lib/data/currencies" -import { ReturnShippingPlaceholder } from "../../../common/placeholders.tsx" +import { ReturnShippingPlaceholder } from "../../../common/placeholders" import { ClaimOutboundSection } from "./claim-outbound-section" import { ItemPlaceholder } from "./item-placeholder" @@ -508,10 +508,10 @@ export const ClaimCreateForm = ({ .filter(Boolean) const variants = ( - await sdk.admin.productVariant.list( - { id: variantIds }, - { fields: "*inventory,*inventory.location_levels" } - ) + await sdk.admin.productVariant.list({ + id: variantIds, + fields: "*inventory.location_levels", + }) ).variants variants.forEach((variant) => { @@ -732,7 +732,6 @@ export const ClaimCreateForm = ({ - {/* TODO: WHAT IF THE RETURN OPTION HAS COMPUTED PRICE*/} + !!shippingOption.rules.find( + (r) => r.attribute === "is_return" && r.value === "false" + ) + ) + const { mutateAsync: addOutboundShipping } = useAddClaimOutboundShipping( claim.id, order.id @@ -260,11 +267,12 @@ export const ClaimOutboundSection = ({ const variantIds = outboundItems .map((item) => item?.variant_id) .filter(Boolean) + const variants = ( - await sdk.admin.productVariant.list( - { id: variantIds }, - { fields: "*inventory,*inventory.location_levels" } - ) + await sdk.admin.productVariant.list({ + id: variantIds, + fields: "*inventory.location_levels", + }) ).variants variants.forEach((variant) => { @@ -401,11 +409,11 @@ export const ClaimOutboundSection = ({ val && onShippingOptionChange(val) }} {...field} - options={shipping_options.map((so) => ({ + options={outboundShippingOptions.map((so) => ({ label: so.name, value: so.id, }))} - disabled={!shipping_options.length} + disabled={!outboundShippingOptions.length} noResultsPlaceholder={} /> diff --git a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx index eb4e8be325..64bbf97e2e 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx @@ -313,10 +313,10 @@ export const ExchangeInboundSection = ({ .filter(Boolean) const variants = ( - await sdk.admin.productVariant.list( - { id: variantIds }, - { fields: "*inventory,*inventory.location_levels" } - ) + await sdk.admin.productVariant.list({ + id: variantIds, + fields: "*inventory.location_levels", + }) ).variants variants.forEach((variant) => { diff --git a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx index f3234e859b..a812ac4da2 100644 --- a/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx +++ b/packages/admin/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx @@ -30,6 +30,7 @@ import { ItemPlaceholder } from "../../../order-create-claim/components/claim-cr import { AddExchangeOutboundItemsTable } from "../add-exchange-outbound-items-table" import { ExchangeOutboundItem } from "./exchange-outbound-item" import { CreateExchangeSchemaType } from "./schema" +import { log } from "console" type ExchangeOutboundSectionProps = { order: AdminOrder @@ -62,6 +63,13 @@ export const ExchangeOutboundSection = ({ fields: "*prices,+service_zone.fulfillment_set.location.id", }) + const outboundShippingOptions = shipping_options.filter( + (shippingOption) => + !!shippingOption.rules.find( + (r) => r.attribute === "is_return" && r.value === "false" + ) + ) + const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping( exchange.id, order.id @@ -268,11 +276,12 @@ export const ExchangeOutboundSection = ({ const variantIds = outboundItems .map((item) => item?.variant_id) .filter(Boolean) + const variants = ( - await sdk.admin.productVariant.list( - { id: variantIds }, - { fields: "*inventory,*inventory.location_levels" } - ) + await sdk.admin.productVariant.list({ + id: variantIds, + fields: "*inventory.location_levels", + }) ).variants variants.forEach((variant) => { @@ -410,11 +419,11 @@ export const ExchangeOutboundSection = ({ val && onShippingOptionChange(val) }} {...field} - options={shipping_options.map((so) => ({ + options={outboundShippingOptions.map((so) => ({ label: so.name, value: so.id, }))} - disabled={!shipping_options.length} + disabled={!outboundShippingOptions.length} /> diff --git a/packages/core/js-sdk/src/admin/product-variant.ts b/packages/core/js-sdk/src/admin/product-variant.ts index 910d3eed43..65f98b7f4d 100644 --- a/packages/core/js-sdk/src/admin/product-variant.ts +++ b/packages/core/js-sdk/src/admin/product-variant.ts @@ -15,28 +15,28 @@ export class ProductVariant { } /** - * This method retrieves a paginated list of product variants. It sends a request to the + * This method retrieves a paginated list of product variants. It sends a request to the * [List Product Variants](https://docs.medusajs.com/api/admin#product-variants_getproductvariants) * API route. - * + * * @param query - Filters and pagination configurations. * @param headers - Headers to pass in the request. * @returns The paginated list of product variants. - * + * * @example * To retrieve the list of product variants: - * + * * ```ts * sdk.admin.productVariant.list() * .then(({ variants, count, limit, offset }) => { * console.log(variants) * }) * ``` - * + * * To configure the pagination, pass the `limit` and `offset` query parameters. - * + * * For example, to retrieve only 10 items and skip 10 items: - * + * * ```ts * sdk.admin.productVariant.list({ * limit: 10, @@ -46,10 +46,10 @@ export class ProductVariant { * console.log(variants) * }) * ``` - * + * * Using the `fields` query parameter, you can specify the fields and relations to retrieve * in each campaign: - * + * * ```ts * sdk.admin.productVariant.list({ * fields: "id,products" @@ -58,7 +58,7 @@ export class ProductVariant { * console.log(variants) * }) * ``` - * + * * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations). */ async list(