fix(dashboard, core-flows, medusa): prevent creation of empty fulfillments (#11664)
This commit is contained in:
7
.changeset/violet-carrots-unite.md
Normal file
7
.changeset/violet-carrots-unite.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@medusajs/dashboard": patch
|
||||
"@medusajs/core-flows": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(core-flows, dashboard, medusa): prevent creatiion of a fulfilment without items
|
||||
@@ -122,19 +122,26 @@ export function OrderCreateFulfillmentForm({
|
||||
{} as Record<string, string | null>
|
||||
)
|
||||
|
||||
const items = Object.entries(data.quantity)
|
||||
.filter(
|
||||
([id, value]) =>
|
||||
!!value && itemShippingProfileMap[id] === selectedShippingProfileId
|
||||
)
|
||||
.map(([id, quantity]) => ({
|
||||
id,
|
||||
quantity,
|
||||
}))
|
||||
|
||||
if (!items.length) {
|
||||
toast.error(t("orders.fulfillment.error.noItems"))
|
||||
return
|
||||
}
|
||||
|
||||
const payload: HttpTypes.AdminCreateOrderFulfillment = {
|
||||
location_id: selectedLocationId,
|
||||
shipping_option_id: shippingOptionId,
|
||||
no_notification: !data.send_notification,
|
||||
items: Object.entries(data.quantity)
|
||||
.filter(
|
||||
([id, value]) =>
|
||||
!!value && itemShippingProfileMap[id] === selectedShippingProfileId
|
||||
)
|
||||
.map(([id, quantity]) => ({
|
||||
id,
|
||||
quantity,
|
||||
})),
|
||||
items,
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -83,6 +83,13 @@ export type CreateFulfillmentValidateOrderStepInput = {
|
||||
export const createFulfillmentValidateOrder = createStep(
|
||||
"create-fulfillment-validate-order",
|
||||
({ order, inputItems }: CreateFulfillmentValidateOrderStepInput) => {
|
||||
if (!inputItems.length) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"No items to fulfill"
|
||||
)
|
||||
}
|
||||
|
||||
throwIfOrderIsCancelled({ order })
|
||||
throwIfItemsDoesNotExistsInOrder({ order, inputItems })
|
||||
throwIfItemsAreNotGroupedByShippingRequirement({ order, inputItems })
|
||||
|
||||
@@ -71,7 +71,7 @@ export type AdminOrderCreateFulfillmentType = z.infer<
|
||||
typeof OrderCreateFulfillment
|
||||
>
|
||||
export const OrderCreateFulfillment = z.object({
|
||||
items: z.array(Item),
|
||||
items: z.array(Item).min(1),
|
||||
location_id: z.string().nullish(),
|
||||
shipping_option_id: z.string().optional(),
|
||||
no_notification: z.boolean().optional(),
|
||||
|
||||
Reference in New Issue
Block a user