fix(core-flows): Unsetting reason on return items (#8470)
This commit is contained in:
@@ -985,6 +985,73 @@ medusaIntegrationTestRunner({
|
||||
expect(inventoryLevel[0].stocked_quantity).toEqual(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/returns/:id/request-items/:action_id", () => {
|
||||
let returnId
|
||||
let itemChange
|
||||
|
||||
beforeEach(async () => {
|
||||
let result = await api.post(
|
||||
"/admin/returns",
|
||||
{
|
||||
order_id: order.id,
|
||||
description: "Test",
|
||||
location_id: location.id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
returnId = result.data.return.id
|
||||
})
|
||||
|
||||
it("should unset reason and note", async () => {
|
||||
const item = order.items[0]
|
||||
let result = (
|
||||
await api.post(
|
||||
`/admin/returns/${returnId}/request-items`,
|
||||
{
|
||||
items: [
|
||||
{
|
||||
id: item.id,
|
||||
quantity: 2,
|
||||
reason_id: returnReason.id,
|
||||
internal_note: "Test note",
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.order_preview
|
||||
|
||||
itemChange = result.items[0].actions[0]
|
||||
|
||||
expect(result.items[0].actions[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
details: expect.objectContaining({
|
||||
reason_id: returnReason.id,
|
||||
}),
|
||||
internal_note: "Test note",
|
||||
})
|
||||
)
|
||||
|
||||
result = (
|
||||
await api.post(
|
||||
`/admin/returns/${returnId}/request-items/${itemChange.id}`,
|
||||
{ quantity: 1, reason_id: null, internal_note: null },
|
||||
adminHeaders
|
||||
)
|
||||
).data.order_preview
|
||||
|
||||
expect(result.items[0].actions[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
details: expect.objectContaining({
|
||||
reason_id: null,
|
||||
}),
|
||||
internal_note: null,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -436,34 +436,36 @@ export const ReturnCreateForm = ({
|
||||
className="bg-ui-bg-field mt-4 block h-[56px] w-full rounded-lg border border-dashed"
|
||||
/>
|
||||
)}
|
||||
{items.map((item, index) => (
|
||||
<ReturnItem
|
||||
key={item.id}
|
||||
item={itemsMap.get(item.item_id)!}
|
||||
previewItem={previewItemsMap.get(item.item_id)!}
|
||||
currencyCode={order.currency_code}
|
||||
form={form}
|
||||
onRemove={() => {
|
||||
const actionId = previewItems
|
||||
.find((i) => i.id === item.item_id)
|
||||
?.actions?.find((a) => a.action === "RETURN_ITEM")?.id
|
||||
{items
|
||||
.filter((item) => !!previewItemsMap.get(item.item_id))
|
||||
.map((item, index) => (
|
||||
<ReturnItem
|
||||
key={item.id}
|
||||
item={itemsMap.get(item.item_id)!}
|
||||
previewItem={previewItemsMap.get(item.item_id)}
|
||||
currencyCode={order.currency_code}
|
||||
form={form}
|
||||
onRemove={() => {
|
||||
const actionId = previewItems
|
||||
.find((i) => i.id === item.item_id)
|
||||
?.actions?.find((a) => a.action === "RETURN_ITEM")?.id
|
||||
|
||||
if (actionId) {
|
||||
removeReturnItem(actionId)
|
||||
}
|
||||
}}
|
||||
onUpdate={(payload) => {
|
||||
const actionId = previewItems
|
||||
.find((i) => i.id === item.item_id)
|
||||
?.actions?.find((a) => a.action === "RETURN_ITEM")?.id
|
||||
if (actionId) {
|
||||
removeReturnItem(actionId)
|
||||
}
|
||||
}}
|
||||
onUpdate={(payload) => {
|
||||
const actionId = previewItems
|
||||
.find((i) => i.id === item.item_id)
|
||||
?.actions?.find((a) => a.action === "RETURN_ITEM")?.id
|
||||
|
||||
if (actionId) {
|
||||
updateReturnItem({ ...payload, actionId })
|
||||
}
|
||||
}}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
if (actionId) {
|
||||
updateReturnItem({ ...payload, actionId })
|
||||
}
|
||||
}}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
{!showPlaceholder && (
|
||||
<div className="mt-8 flex flex-col gap-y-4">
|
||||
{/*LOCATION*/}
|
||||
|
||||
@@ -177,8 +177,8 @@ function ReturnItem({
|
||||
className="flex-shrink"
|
||||
variant="transparent"
|
||||
onClick={() => {
|
||||
onUpdate({ reason_id: null }) // TODO BE: we should be able to set to unset reason here
|
||||
form.setValue(`items.${index}.reason_id`, "")
|
||||
onUpdate({ reason_id: null })
|
||||
form.setValue(`items.${index}.reason_id`, null)
|
||||
}}
|
||||
>
|
||||
<XMark className="text-ui-fg-muted" />
|
||||
|
||||
@@ -5,13 +5,13 @@ import {
|
||||
OrderWorkflow,
|
||||
ReturnDTO,
|
||||
} from "@medusajs/types"
|
||||
import { ChangeActionType, OrderChangeStatus } from "@medusajs/utils"
|
||||
import { ChangeActionType, isDefined, OrderChangeStatus } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../../common"
|
||||
import {
|
||||
@@ -119,7 +119,9 @@ export const updateRequestItemReturnWorkflow = createWorkflow(
|
||||
id: input.action_id,
|
||||
details: {
|
||||
quantity: data.quantity ?? originalAction.details?.quantity,
|
||||
reason_id: data.reason_id ?? originalAction.details?.reason_id,
|
||||
reason_id: isDefined(data.reason_id)
|
||||
? data.reason_id
|
||||
: originalAction.details?.reason_id,
|
||||
},
|
||||
internal_note: data.internal_note,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user