1 import { AdminReservationResponse } from "@medusajs/types"
2 import { Container, Heading } from "@medusajs/ui"
3
4 import { ActionMenu } from "../../../../../components/common/action-menu"
5 import { PencilSquare } from "@medusajs/icons"
6 import { SectionRow } from "../../../../../components/common/section"
7 import { useInventoryItem } from "../../../../../hooks/api/inventory"
8 import { useStockLocation } from "../../../../../hooks/api/stock-locations"
9 import { useTranslation } from "react-i18next"
10 import { formatQuantity } from "../../../../../lib/format-quantity"
11
12 type ReservationGeneralSectionProps = {
13 reservation: AdminReservationResponse["reservation"]
14 }
15
16 export const ReservationGeneralSection = ({
17 reservation,
18 }: ReservationGeneralSectionProps) => {
19 const { t } = useTranslation()
20
21 const { inventory_item: inventoryItem, isPending: isLoadingInventoryItem } =
22 useInventoryItem(reservation.inventory_item_id)
23
24 const { stock_location: location, isPending: isLoadingLocation } =
25 useStockLocation(reservation.location_id)
26
27 if (
28 isLoadingInventoryItem ||
29 !inventoryItem ||
30 isLoadingLocation ||
31 !location
32 ) {
33 return <div>Loading...</div>
34 }
35
36 const locationLevel = inventoryItem.location_levels!.find(
37 (l) => l.location_id === reservation.location_id
38 )
39
40 return (
41 <Container className="divide-y p-0">
42 <div className="flex items-center justify-between px-6 py-4">
43 <Heading>
44 {t("inventory.reservation.header", {
45 itemName: inventoryItem.title ?? inventoryItem.sku,
46 })}
47 </Heading>
48 <ActionMenu
49 groups={[
50 {
51 actions: [
52 {
53 icon: <PencilSquare />,
54 label: t("actions.edit"),
55 to: `edit`,
56 },
57 ],
58 },
59 ]}
60 />
61 </div>
62 <SectionRow
63 title={t("inventory.reservation.lineItemId")}
64 value={reservation.line_item_id} // TODO fetch order instead + add link
65 />
66 <SectionRow
67 title={t("inventory.reservation.description")}
68 value={reservation.description}
69 />
70 <SectionRow
71 title={t("inventory.reservation.location")}
72 value={location?.name}
73 />
74 <SectionRow
75 title={t("inventory.reservation.inStockAtLocation")}
76 value={formatQuantity(
77 locationLevel?.stocked_quantity,
78 inventoryItem.unit_of_measure
79 )}
80 />
81 <SectionRow
82 title={t("inventory.reservation.availableAtLocation")}
83 value={formatQuantity(
84 locationLevel?.available_quantity,
85 inventoryItem.unit_of_measure
86 )}
87 />
88 <SectionRow
89 title={t("inventory.reservation.reservedAtLocation")}
90 value={formatQuantity(
91 locationLevel?.reserved_quantity,
92 inventoryItem.unit_of_measure
93 )}
94 />
95 </Container>
96 )
97 }