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:
@@ -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 = ({
|
||||
</Form.Hint>
|
||||
</div>
|
||||
|
||||
{/* TODO: WHAT IF THE RETURN OPTION HAS COMPUTED PRICE*/}
|
||||
<Form.Field
|
||||
control={form.control}
|
||||
name="inbound_option_id"
|
||||
|
||||
@@ -63,6 +63,13 @@ export const ClaimOutboundSection = ({
|
||||
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(
|
||||
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={<OutboundShippingPlaceholder />}
|
||||
/>
|
||||
</Form.Control>
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
</Form.Control>
|
||||
</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)
|
||||
* 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(
|
||||
|
||||
Reference in New Issue
Block a user