|
1
|
import { Heading } from "@medusajs/ui" |
|
2
|
import { useTranslation } from "react-i18next" |
|
3
|
import { useParams } from "react-router-dom" |
|
4
|
import { RouteDrawer } from "../../../../../components/modals" |
|
5
|
import { useInventoryItem } from "../../../../../hooks/api/inventory" |
|
6
|
import { useReservationItem } from "../../../../../hooks/api/reservations" |
|
7
|
import { useStockLocations } from "../../../../../hooks/api/stock-locations" |
|
8
|
import { EditReservationForm } from "./components/edit-reservation-form" |
|
9
|
|
|
10
|
export const ReservationEdit = () => { |
|
11
|
const { id } = useParams() |
|
12
|
const { t } = useTranslation() |
|
13
|
|
|
14
|
const { reservation, isPending, isError, error } = useReservationItem(id!) |
|
15
|
const { inventory_item: inventoryItem } = useInventoryItem( |
|
16
|
reservation?.inventory_item_id!, |
|
17
|
undefined, |
|
18
|
{ |
|
19
|
enabled: !!reservation, |
|
20
|
} |
|
21
|
) |
|
22
|
|
|
23
|
const { stock_locations } = useStockLocations( |
|
24
|
{ |
|
25
|
id: inventoryItem?.location_levels?.map((l) => l.location_id), |
|
26
|
}, |
|
27
|
{ |
|
28
|
enabled: !!inventoryItem?.location_levels, |
|
29
|
} |
|
30
|
) |
|
31
|
|
|
32
|
const ready = !isPending && reservation && inventoryItem && stock_locations |
|
33
|
if (isError) { |
|
34
|
throw error |
|
35
|
} |
|
36
|
|
|
37
|
return ( |
|
38
|
<RouteDrawer> |
|
39
|
<RouteDrawer.Header> |
|
40
|
<Heading>{t("inventory.reservation.editItemDetails")}</Heading> |
|
41
|
</RouteDrawer.Header> |
|
42
|
{ready && ( |
|
43
|
<EditReservationForm |
|
44
|
locations={stock_locations} |
|
45
|
reservation={reservation} |
|
46
|
item={inventoryItem} |
|
47
|
/> |
|
48
|
)} |
|
49
|
</RouteDrawer> |
|
50
|
) |
|
51
|
} |