feat(dashboard,core-flows,js-sdk,types,medusa): Add exchange UI + fixes (#8606)
what: - adds exchange UI - fixes bugs on core-flows and endpoints - random set of tiny fixes https://github.com/user-attachments/assets/b163b9c1-4475-4936-ae98-20795760cc55
This commit is contained in:
@@ -6,7 +6,12 @@ import {
|
||||
OrderExchangeDTO,
|
||||
OrderPreviewDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, Modules, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
ChangeActionType,
|
||||
Modules,
|
||||
OrderChangeStatus,
|
||||
ReturnStatus,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
@@ -19,7 +24,7 @@ import { createRemoteLinkStep, useRemoteQueryStep } from "../../../common"
|
||||
import { reserveInventoryStep } from "../../../definition/cart/steps/reserve-inventory"
|
||||
import { prepareConfirmInventoryInput } from "../../../definition/cart/utils/prepare-confirm-inventory-input"
|
||||
import { createReturnFulfillmentWorkflow } from "../../../fulfillment/workflows/create-return-fulfillment"
|
||||
import { previewOrderChangeStep } from "../../steps"
|
||||
import { previewOrderChangeStep, updateReturnsStep } from "../../steps"
|
||||
import { confirmOrderChanges } from "../../steps/confirm-order-changes"
|
||||
import { createOrderExchangeItemsFromActionsStep } from "../../steps/exchange/create-exchange-items-from-actions"
|
||||
import { createReturnItemsFromActionsStep } from "../../steps/return/create-return-items-from-actions"
|
||||
@@ -57,7 +62,6 @@ function prepareFulfillmentData({
|
||||
items,
|
||||
shippingOption,
|
||||
deliveryAddress,
|
||||
isReturn,
|
||||
}: {
|
||||
order: OrderDTO
|
||||
items: any[]
|
||||
@@ -74,17 +78,15 @@ function prepareFulfillmentData({
|
||||
}
|
||||
}
|
||||
deliveryAddress?: Record<string, any>
|
||||
isReturn?: boolean
|
||||
}) {
|
||||
const orderItemsMap = new Map<string, Required<OrderDTO>["items"][0]>(
|
||||
order.items!.map((i) => [i.id, i])
|
||||
)
|
||||
const fulfillmentItems = items.map((i) => {
|
||||
const orderItem = orderItemsMap.get(i.item_id) ?? i.item
|
||||
const orderItem = orderItemsMap.get(i.id) ?? i.item
|
||||
return {
|
||||
line_item_id: i.item_id,
|
||||
quantity: !isReturn ? i.quantity : undefined,
|
||||
return_quantity: isReturn ? i.quantity : undefined,
|
||||
quantity: i.quantity,
|
||||
title: orderItem.variant_title ?? orderItem.title,
|
||||
sku: orderItem.variant_sku || "",
|
||||
barcode: orderItem.variant_barcode || "",
|
||||
@@ -191,11 +193,8 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
"id",
|
||||
"version",
|
||||
"canceled_at",
|
||||
"items.id",
|
||||
"items.title",
|
||||
"items.variant_title",
|
||||
"items.variant_sku",
|
||||
"items.variant_barcode",
|
||||
"items.*",
|
||||
"items.item.id",
|
||||
"shipping_address.*",
|
||||
],
|
||||
variables: { id: orderExchange.order_id },
|
||||
@@ -248,6 +247,18 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
}
|
||||
)
|
||||
|
||||
when({ returnId }, ({ returnId }) => {
|
||||
return !!returnId
|
||||
}).then(() => {
|
||||
updateReturnsStep([
|
||||
{
|
||||
id: returnId,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
const exchangeId = transform(
|
||||
{ createExchangeItems },
|
||||
({ createExchangeItems }) => {
|
||||
@@ -320,9 +331,12 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
reserveInventoryStep(formatedInventoryItems)
|
||||
})
|
||||
|
||||
when({ returnShippingMethod }, ({ returnShippingMethod }) => {
|
||||
return !!returnShippingMethod
|
||||
}).then(() => {
|
||||
when(
|
||||
{ returnShippingMethod, returnId },
|
||||
({ returnShippingMethod, returnId }) => {
|
||||
return !!returnShippingMethod && !!returnId
|
||||
}
|
||||
).then(() => {
|
||||
const returnShippingOption = useRemoteQueryStep({
|
||||
entry_point: "shipping_options",
|
||||
fields: [
|
||||
@@ -343,7 +357,6 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
order,
|
||||
items: order.items!,
|
||||
shippingOption: returnShippingOption,
|
||||
isReturn: true,
|
||||
},
|
||||
prepareFulfillmentData
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useRemoteQueryStep } from "../../../common"
|
||||
import { updateOrderExchangesStep } from "../../steps/exchange/update-order-exchanges"
|
||||
import { previewOrderChangeStep } from "../../steps/preview-order-change"
|
||||
import { createReturnsStep } from "../../steps/return/create-returns"
|
||||
import { updateOrderChangesStep } from "../../steps/update-order-changes"
|
||||
import {
|
||||
throwIfIsCancelled,
|
||||
throwIfItemsDoesNotExistsInOrder,
|
||||
@@ -124,6 +125,17 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
|
||||
status: [OrderChangeStatus.PENDING, OrderChangeStatus.REQUESTED],
|
||||
})
|
||||
|
||||
when({ createdReturn }, ({ createdReturn }) => {
|
||||
return !!createdReturn?.length
|
||||
}).then(() => {
|
||||
updateOrderChangesStep([
|
||||
{
|
||||
id: orderChange.id,
|
||||
return_id: createdReturn?.[0]?.id,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
exchangeRequestItemReturnValidationStep({
|
||||
order,
|
||||
items: input.items,
|
||||
|
||||
Reference in New Issue
Block a user