1 import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared"
2 import { useLoaderData, useParams } from "react-router-dom"
3
4 import { useStockLocation } from "../../../hooks/api/stock-locations"
5 import { LocationGeneralSection } from "./components/location-general-section"
6 import LocationsSalesChannelsSection from "./components/location-sales-channels-section/locations-sales-channels-section"
7 import { locationLoader } from "./loader"
8
9 import { TwoColumnPageSkeleton } from "../../../components/common/skeleton"
10 import { LayoutComposer, detailPageDefaultEntries } from "../../../components/layout-composer"
11 import LocationsFulfillmentProvidersSection from "./components/location-fulfillment-providers-section/location-fulfillment-providers-section"
12 import { LOCATION_DETAILS_FIELD } from "./constants"
13
14 export const LocationDetail = () => {
15 const initialData = useLoaderData() as Awaited<
16 ReturnType<typeof locationLoader>
17 >
18
19 const { location_id } = useParams()
20 const {
21 stock_location: location,
22 isPending: isLoading,
23 isError,
24 error,
25 } = useStockLocation(
26 location_id!,
27 { fields: LOCATION_DETAILS_FIELD },
28 { initialData }
29 )
30
31 if (isLoading || !location) {
32 return (
33 <TwoColumnPageSkeleton mainSections={3} sidebarSections={2} showJSON />
34 )
35 }
36
37 if (isError) {
38 throw error
39 }
40
41 return (
42 <LayoutComposer
43 widgetsZonePrefix="location.details"
44 preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN}
45 data={location}
46 sections={{
47 main: (
48 <>
49 <LayoutComposer.Entry id="LocationGeneralSection">
50 <LocationGeneralSection location={location} />
51 </LayoutComposer.Entry>
52 {detailPageDefaultEntries(location)}
53 </>
54 ),
55 side: (
56 <>
57 <LayoutComposer.Entry id="LocationsSalesChannelsSection">
58 <LocationsSalesChannelsSection location={location} />
59 </LayoutComposer.Entry>
60 <LayoutComposer.Entry id="LocationsFulfillmentProvidersSection">
61 <LocationsFulfillmentProvidersSection location={location} />
62 </LayoutComposer.Entry>
63 </>
64 ),
65 }}
66 />
67 )
68 }