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