Skip to content

Commit 3fa1db9

Browse files
authored
fix(dashboard): allocation UI for orders with more than 20 reservation items (medusajs#12989)
1 parent 35bd9f0 commit 3fa1db9

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
---
4+
5+
fix(dashboard): allocation UI for orders with more than 20 reservation items
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
import { HttpTypes } from "@medusajs/types"
1+
import { AdminOrder, AdminOrderLineItem, HttpTypes } from "@medusajs/types"
22

33
export const getPaymentsFromOrder = (order: HttpTypes.AdminOrder) => {
44
return order.payment_collections
55
.map((collection: HttpTypes.AdminPaymentCollection) => collection.payments)
66
.flat(1)
77
.filter(Boolean) as HttpTypes.AdminPayment[]
88
}
9+
10+
/**
11+
* Returns a limit for number of reservations that order can have.
12+
*/
13+
export function getReservationsLimitCount(order: AdminOrder) {
14+
if (!order?.items?.length) {
15+
return 0
16+
}
17+
18+
return order.items.reduce(
19+
(acc: number, item: AdminOrderLineItem) =>
20+
acc + (item.variant?.inventory_items?.length || 1),
21+
0
22+
)
23+
}

packages/admin/dashboard/src/routes/orders/order-create-fulfillment/components/order-create-fulfillment-form/order-create-fulfillment-form.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
useReservationItems,
2424
useShippingOptions,
2525
} from "../../../../../hooks/api"
26+
import { getReservationsLimitCount } from "../../../../../lib/orders"
2627

2728
type OrderCreateFulfillmentFormProps = {
2829
order: AdminOrder
@@ -41,6 +42,7 @@ export function OrderCreateFulfillmentForm({
4142

4243
const { reservations } = useReservationItems({
4344
line_item_id: order.items.map((i) => i.id),
45+
limit: getReservationsLimitCount(order),
4446
})
4547

4648
const itemReservedQuantitiesMap = useMemo(

packages/admin/dashboard/src/routes/orders/order-detail/components/order-summary-section/order-summary-section.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { useReturns } from "../../../../../hooks/api/returns"
5151
import { useDate } from "../../../../../hooks/use-date"
5252
import { getTotalCreditLines } from "../../../../../lib/credit-line"
5353
import { formatCurrency } from "../../../../../lib/format-currency"
54+
import { getReservationsLimitCount } from "../../../../../lib/orders"
5455
import {
5556
getLocaleAmount,
5657
getStylizedAmount,
@@ -78,6 +79,7 @@ export const OrderSummarySection = ({
7879
const { reservations } = useReservationItems(
7980
{
8081
line_item_id: order?.items?.map((i) => i.id),
82+
limit: getReservationsLimitCount(order),
8183
},
8284
{ enabled: Array.isArray(order?.items) }
8385
)

0 commit comments

Comments
 (0)