|
1
|
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared" |
|
2
|
import { useLoaderData, useParams } from "react-router-dom" |
|
3
|
|
|
4
|
import { TwoColumnPageSkeleton } from "../../../components/common/skeleton" |
|
5
|
import { LayoutComposer, detailPageDefaultEntries } from "../../../components/layout-composer" |
|
6
|
import { useInventoryItem } from "../../../hooks/api" |
|
7
|
import { useReservationItem } from "../../../hooks/api/reservations" |
|
8
|
import { InventoryItemGeneralSection } from "../../inventory/inventory-detail/components/inventory-item-general-section" |
|
9
|
import { ReservationGeneralSection } from "./components/reservation-general-section" |
|
10
|
import { reservationItemLoader } from "./loader" |
|
11
|
|
|
12
|
export const ReservationDetail = () => { |
|
13
|
const { id } = useParams() |
|
14
|
|
|
15
|
const initialData = useLoaderData() as Awaited< |
|
16
|
ReturnType<typeof reservationItemLoader> |
|
17
|
> |
|
18
|
|
|
19
|
const { reservation, isLoading, isError, error } = useReservationItem( |
|
20
|
id!, |
|
21
|
undefined, |
|
22
|
{ |
|
23
|
initialData, |
|
24
|
} |
|
25
|
) |
|
26
|
|
|
27
|
// TEMP: fetch directly since the fields are not populated with reservation call |
|
28
|
const { inventory_item } = useInventoryItem( |
|
29
|
reservation?.inventory_item?.id!, |
|
30
|
undefined, |
|
31
|
{ enabled: !!reservation?.inventory_item?.id! } |
|
32
|
) |
|
33
|
|
|
34
|
if (isLoading || !reservation) { |
|
35
|
return ( |
|
36
|
<TwoColumnPageSkeleton |
|
37
|
mainSections={1} |
|
38
|
sidebarSections={1} |
|
39
|
showJSON |
|
40
|
showMetadata |
|
41
|
/> |
|
42
|
) |
|
43
|
} |
|
44
|
|
|
45
|
if (isError) { |
|
46
|
throw error |
|
47
|
} |
|
48
|
|
|
49
|
return ( |
|
50
|
<LayoutComposer |
|
51
|
widgetsZonePrefix="reservation.details" |
|
52
|
preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN} |
|
53
|
data={reservation} |
|
54
|
sections={{ |
|
55
|
main: ( |
|
56
|
<> |
|
57
|
<LayoutComposer.Entry id="ReservationGeneralSection"> |
|
58
|
<ReservationGeneralSection reservation={reservation} /> |
|
59
|
</LayoutComposer.Entry> |
|
60
|
{detailPageDefaultEntries(reservation)} |
|
61
|
</> |
|
62
|
), |
|
63
|
side: ( |
|
64
|
<> |
|
65
|
{inventory_item && ( |
|
66
|
<LayoutComposer.Entry id="InventoryItemGeneralSection"> |
|
67
|
<InventoryItemGeneralSection inventoryItem={inventory_item} /> |
|
68
|
</LayoutComposer.Entry> |
|
69
|
)} |
|
70
|
</> |
|
71
|
), |
|
72
|
}} |
|
73
|
/> |
|
74
|
) |
|
75
|
} |