fix(dashboard, core-flows, medusa): prevent creation of empty fulfillments (#11664)

This commit is contained in:
Frane Polić
2025-03-03 17:54:20 +01:00
committed by GitHub
parent 40a9cffb34
commit e23f204b7c
4 changed files with 31 additions and 10 deletions

View 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

View File

@@ -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 {

View File

@@ -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 })

View File

@@ -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(),