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
This commit is contained in:
Frane Polić
2025-02-28 14:55:35 +00:00
committed by GitHub
parent bf67f69f45
commit bdf9723239
5 changed files with 49 additions and 33 deletions
@@ -50,10 +50,10 @@ import {
useUpdateClaimInboundShipping, useUpdateClaimInboundShipping,
useUpdateClaimOutboundShipping, useUpdateClaimOutboundShipping,
} from "../../../../../hooks/api/claims" } from "../../../../../hooks/api/claims"
import { useUpdateReturn } from "../../../../../hooks/api/returns.tsx" import { useUpdateReturn } from "../../../../../hooks/api/returns"
import { sdk } from "../../../../../lib/client" import { sdk } from "../../../../../lib/client"
import { currencies } from "../../../../../lib/data/currencies" import { currencies } from "../../../../../lib/data/currencies"
import { ReturnShippingPlaceholder } from "../../../common/placeholders.tsx" import { ReturnShippingPlaceholder } from "../../../common/placeholders"
import { ClaimOutboundSection } from "./claim-outbound-section" import { ClaimOutboundSection } from "./claim-outbound-section"
import { ItemPlaceholder } from "./item-placeholder" import { ItemPlaceholder } from "./item-placeholder"
@@ -508,10 +508,10 @@ export const ClaimCreateForm = ({
.filter(Boolean) .filter(Boolean)
const variants = ( const variants = (
await sdk.admin.productVariant.list( await sdk.admin.productVariant.list({
{ id: variantIds }, id: variantIds,
{ fields: "*inventory,*inventory.location_levels" } fields: "*inventory.location_levels",
) })
).variants ).variants
variants.forEach((variant) => { variants.forEach((variant) => {
@@ -732,7 +732,6 @@ export const ClaimCreateForm = ({
</Form.Hint> </Form.Hint>
</div> </div>
{/* TODO: WHAT IF THE RETURN OPTION HAS COMPUTED PRICE*/}
<Form.Field <Form.Field
control={form.control} control={form.control}
name="inbound_option_id" name="inbound_option_id"
@@ -63,6 +63,13 @@ export const ClaimOutboundSection = ({
fields: "*prices,+service_zone.fulfillment_set.location.id", 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 } = useAddClaimOutboundShipping( const { mutateAsync: addOutboundShipping } = useAddClaimOutboundShipping(
claim.id, claim.id,
order.id order.id
@@ -260,11 +267,12 @@ export const ClaimOutboundSection = ({
const variantIds = outboundItems const variantIds = outboundItems
.map((item) => item?.variant_id) .map((item) => item?.variant_id)
.filter(Boolean) .filter(Boolean)
const variants = ( const variants = (
await sdk.admin.productVariant.list( await sdk.admin.productVariant.list({
{ id: variantIds }, id: variantIds,
{ fields: "*inventory,*inventory.location_levels" } fields: "*inventory.location_levels",
) })
).variants ).variants
variants.forEach((variant) => { variants.forEach((variant) => {
@@ -401,11 +409,11 @@ export const ClaimOutboundSection = ({
val && onShippingOptionChange(val) val && onShippingOptionChange(val)
}} }}
{...field} {...field}
options={shipping_options.map((so) => ({ options={outboundShippingOptions.map((so) => ({
label: so.name, label: so.name,
value: so.id, value: so.id,
}))} }))}
disabled={!shipping_options.length} disabled={!outboundShippingOptions.length}
noResultsPlaceholder={<OutboundShippingPlaceholder />} noResultsPlaceholder={<OutboundShippingPlaceholder />}
/> />
</Form.Control> </Form.Control>
@@ -313,10 +313,10 @@ export const ExchangeInboundSection = ({
.filter(Boolean) .filter(Boolean)
const variants = ( const variants = (
await sdk.admin.productVariant.list( await sdk.admin.productVariant.list({
{ id: variantIds }, id: variantIds,
{ fields: "*inventory,*inventory.location_levels" } fields: "*inventory.location_levels",
) })
).variants ).variants
variants.forEach((variant) => { variants.forEach((variant) => {
@@ -30,6 +30,7 @@ import { ItemPlaceholder } from "../../../order-create-claim/components/claim-cr
import { AddExchangeOutboundItemsTable } from "../add-exchange-outbound-items-table" import { AddExchangeOutboundItemsTable } from "../add-exchange-outbound-items-table"
import { ExchangeOutboundItem } from "./exchange-outbound-item" import { ExchangeOutboundItem } from "./exchange-outbound-item"
import { CreateExchangeSchemaType } from "./schema" import { CreateExchangeSchemaType } from "./schema"
import { log } from "console"
type ExchangeOutboundSectionProps = { type ExchangeOutboundSectionProps = {
order: AdminOrder order: AdminOrder
@@ -62,6 +63,13 @@ export const ExchangeOutboundSection = ({
fields: "*prices,+service_zone.fulfillment_set.location.id", 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( const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping(
exchange.id, exchange.id,
order.id order.id
@@ -268,11 +276,12 @@ export const ExchangeOutboundSection = ({
const variantIds = outboundItems const variantIds = outboundItems
.map((item) => item?.variant_id) .map((item) => item?.variant_id)
.filter(Boolean) .filter(Boolean)
const variants = ( const variants = (
await sdk.admin.productVariant.list( await sdk.admin.productVariant.list({
{ id: variantIds }, id: variantIds,
{ fields: "*inventory,*inventory.location_levels" } fields: "*inventory.location_levels",
) })
).variants ).variants
variants.forEach((variant) => { variants.forEach((variant) => {
@@ -410,11 +419,11 @@ export const ExchangeOutboundSection = ({
val && onShippingOptionChange(val) val && onShippingOptionChange(val)
}} }}
{...field} {...field}
options={shipping_options.map((so) => ({ options={outboundShippingOptions.map((so) => ({
label: so.name, label: so.name,
value: so.id, value: so.id,
}))} }))}
disabled={!shipping_options.length} disabled={!outboundShippingOptions.length}
/> />
</Form.Control> </Form.Control>
</Form.Item> </Form.Item>
@@ -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) * [List Product Variants](https://docs.medusajs.com/api/admin#product-variants_getproductvariants)
* API route. * API route.
* *
* @param query - Filters and pagination configurations. * @param query - Filters and pagination configurations.
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* @returns The paginated list of product variants. * @returns The paginated list of product variants.
* *
* @example * @example
* To retrieve the list of product variants: * To retrieve the list of product variants:
* *
* ```ts * ```ts
* sdk.admin.productVariant.list() * sdk.admin.productVariant.list()
* .then(({ variants, count, limit, offset }) => { * .then(({ variants, count, limit, offset }) => {
* console.log(variants) * console.log(variants)
* }) * })
* ``` * ```
* *
* To configure the pagination, pass the `limit` and `offset` query parameters. * To configure the pagination, pass the `limit` and `offset` query parameters.
* *
* For example, to retrieve only 10 items and skip 10 items: * For example, to retrieve only 10 items and skip 10 items:
* *
* ```ts * ```ts
* sdk.admin.productVariant.list({ * sdk.admin.productVariant.list({
* limit: 10, * limit: 10,
@@ -46,10 +46,10 @@ export class ProductVariant {
* console.log(variants) * console.log(variants)
* }) * })
* ``` * ```
* *
* Using the `fields` query parameter, you can specify the fields and relations to retrieve * Using the `fields` query parameter, you can specify the fields and relations to retrieve
* in each campaign: * in each campaign:
* *
* ```ts * ```ts
* sdk.admin.productVariant.list({ * sdk.admin.productVariant.list({
* fields: "id,products" * fields: "id,products"
@@ -58,7 +58,7 @@ export class ProductVariant {
* console.log(variants) * console.log(variants)
* }) * })
* ``` * ```
* *
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations). * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
*/ */
async list( async list(