|
1
|
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared" |
|
2
|
import { useLoaderData, useParams } from "react-router-dom" |
|
3
|
|
|
4
|
import { useRegion } from "../../../hooks/api/regions" |
|
5
|
import { RegionCountrySection } from "./components/region-country-section" |
|
6
|
import { RegionGeneralSection } from "./components/region-general-section" |
|
7
|
import { regionLoader } from "./loader" |
|
8
|
|
|
9
|
import { SingleColumnPageSkeleton } from "../../../components/common/skeleton" |
|
10
|
import { LayoutComposer, detailPageDefaultEntries } from "../../../components/layout-composer" |
|
11
|
import { usePricePreferences } from "../../../hooks/api/price-preferences" |
|
12
|
import { REGION_DETAIL_FIELDS } from "./constants" |
|
13
|
|
|
14
|
export const RegionDetail = () => { |
|
15
|
const initialData = useLoaderData() as Awaited< |
|
16
|
ReturnType<typeof regionLoader> |
|
17
|
> |
|
18
|
|
|
19
|
const { id } = useParams() |
|
20
|
const { |
|
21
|
region, |
|
22
|
isPending: isLoading, |
|
23
|
isError: isRegionError, |
|
24
|
error: regionError, |
|
25
|
} = useRegion( |
|
26
|
id!, |
|
27
|
{ fields: REGION_DETAIL_FIELDS }, |
|
28
|
{ |
|
29
|
initialData, |
|
30
|
} |
|
31
|
) |
|
32
|
|
|
33
|
const { |
|
34
|
price_preferences: pricePreferences, |
|
35
|
isPending: isLoadingPreferences, |
|
36
|
isError: isPreferencesError, |
|
37
|
error: preferencesError, |
|
38
|
} = usePricePreferences( |
|
39
|
{ |
|
40
|
attribute: "region_id", |
|
41
|
value: id, |
|
42
|
}, |
|
43
|
{ enabled: !!region } |
|
44
|
) |
|
45
|
|
|
46
|
if (isLoading || isLoadingPreferences || !region) { |
|
47
|
return <SingleColumnPageSkeleton sections={2} showJSON showMetadata /> |
|
48
|
} |
|
49
|
|
|
50
|
if (isRegionError) { |
|
51
|
throw regionError |
|
52
|
} |
|
53
|
|
|
54
|
if (isPreferencesError) { |
|
55
|
throw preferencesError |
|
56
|
} |
|
57
|
|
|
58
|
return ( |
|
59
|
<LayoutComposer |
|
60
|
widgetsZonePrefix="region.details" |
|
61
|
preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN} |
|
62
|
data={region} |
|
63
|
sections={{ |
|
64
|
main: ( |
|
65
|
<> |
|
66
|
<LayoutComposer.Entry id="RegionGeneralSection"> |
|
67
|
<RegionGeneralSection |
|
68
|
region={region} |
|
69
|
pricePreferences={pricePreferences ?? []} |
|
70
|
/> |
|
71
|
</LayoutComposer.Entry> |
|
72
|
<LayoutComposer.Entry id="RegionCountrySection"> |
|
73
|
<RegionCountrySection region={region} /> |
|
74
|
</LayoutComposer.Entry> |
|
75
|
{detailPageDefaultEntries(region, { permissions: false })} |
|
76
|
</> |
|
77
|
), |
|
78
|
}} |
|
79
|
/> |
|
80
|
) |
|
81
|
} |