1 import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared"
2 import { useLoaderData, useParams } from "react-router-dom"
3 import { useState } from "react"
4
5 import { useTaxRegion } from "../../../hooks/api/tax-regions"
6 import { TaxRegionDetailSection } from "./components/tax-region-detail-section"
7 import { TaxRegionProvinceSection } from "./components/tax-region-province-section"
8
9 import { SingleColumnPageSkeleton } from "../../../components/common/skeleton"
10 import { LayoutComposer, detailPageDefaultEntries } from "../../../components/layout-composer"
11 import { TaxRegionOverrideSection } from "./components/tax-region-override-section"
12 import { TaxRegionSublevelAlert } from "./components/tax-region-sublevel-alert"
13 import { TaxRegionProviderSection } from "./tax-region-provider-section"
14 import { taxRegionLoader } from "./loader"
15
16 export const TaxRegionDetail = () => {
17 const { id } = useParams()
18 const [showSublevelRegions, setShowSublevelRegions] = useState(false)
19
20 const initialData = useLoaderData() as Awaited<
21 ReturnType<typeof taxRegionLoader>
22 >
23
24 const {
25 tax_region: taxRegion,
26 isLoading,
27 isError,
28 error,
29 } = useTaxRegion(id!, undefined, { initialData })
30
31 if (isLoading || !taxRegion) {
32 return <SingleColumnPageSkeleton sections={4} showJSON />
33 }
34
35 if (isError) {
36 throw error
37 }
38
39 return (
40 <LayoutComposer
41 widgetsZonePrefix="tax.details"
42 preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN}
43 data={taxRegion}
44 sections={{
45 main: (
46 <>
47 <LayoutComposer.Entry id="TaxRegionSublevelAlert">
48 <TaxRegionSublevelAlert
49 taxRegion={taxRegion}
50 showSublevelRegions={showSublevelRegions}
51 setShowSublevelRegions={setShowSublevelRegions}
52 />
53 </LayoutComposer.Entry>
54 <LayoutComposer.Entry id="TaxRegionDetailSection">
55 <TaxRegionDetailSection taxRegion={taxRegion} />
56 </LayoutComposer.Entry>
57 <LayoutComposer.Entry id="TaxRegionProvinceSection">
58 <TaxRegionProvinceSection
59 taxRegion={taxRegion}
60 showSublevelRegions={showSublevelRegions}
61 />
62 </LayoutComposer.Entry>
63 <LayoutComposer.Entry id="TaxRegionOverrideSection">
64 <TaxRegionOverrideSection taxRegion={taxRegion} />
65 </LayoutComposer.Entry>
66 <LayoutComposer.Entry id="TaxRegionProviderSection">
67 <TaxRegionProviderSection taxRegion={taxRegion} />
68 </LayoutComposer.Entry>
69 {detailPageDefaultEntries(taxRegion, { metadata: false, permissions: false })}
70 </>
71 ),
72 }}
73 />
74 )
75 }