|
1
|
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared" |
|
2
|
import { useLoaderData, useParams } from "react-router-dom" |
|
3
|
|
|
4
|
import { SingleColumnPageSkeleton } from "../../../components/common/skeleton" |
|
5
|
import { |
|
6
|
LayoutComposer, |
|
7
|
detailPageDefaultEntries, |
|
8
|
} from "../../../components/layout-composer" |
|
9
|
import { useProductOption } from "../../../hooks/api" |
|
10
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider" |
|
11
|
import { productOptionLoader } from "./loader.ts" |
|
12
|
import { ProductOptionGeneralSection } from "./components/product-option-general-section" |
|
13
|
import { ProductOptionProductSection } from "./components/product-option-product-section" |
|
14
|
import { ConfigurableProductOptionProductSection } from "./components/product-option-product-section/configurable-product-option-product-section" |
|
15
|
import { ProductOptionValuesSection } from "./components/product-option-values-section" |
|
16
|
import { ConfigurableProductOptionValuesSection } from "./components/product-option-values-section/configurable-product-option-values-section" |
|
17
|
|
|
18
|
export const ProductOptionDetail = () => { |
|
19
|
const { id } = useParams() |
|
20
|
const isViewConfigEnabled = useFeatureFlag("view_configurations") |
|
21
|
|
|
22
|
const initialData = useLoaderData() as Awaited< |
|
23
|
ReturnType<typeof productOptionLoader> |
|
24
|
> |
|
25
|
|
|
26
|
const { product_option, isLoading, isError, error } = useProductOption( |
|
27
|
id!, |
|
28
|
{ fields: "-products" }, |
|
29
|
{ |
|
30
|
initialData, |
|
31
|
} |
|
32
|
) |
|
33
|
|
|
34
|
if (isLoading || !product_option) { |
|
35
|
return <SingleColumnPageSkeleton sections={2} showJSON showMetadata /> |
|
36
|
} |
|
37
|
|
|
38
|
if (isError) { |
|
39
|
throw error |
|
40
|
} |
|
41
|
|
|
42
|
return ( |
|
43
|
<LayoutComposer |
|
44
|
widgetsZonePrefix="product_option.details" |
|
45
|
preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN} |
|
46
|
data={product_option} |
|
47
|
sections={{ |
|
48
|
main: ( |
|
49
|
<> |
|
50
|
<LayoutComposer.Entry id="ProductOptionGeneralSection"> |
|
51
|
<ProductOptionGeneralSection productOption={product_option} /> |
|
52
|
</LayoutComposer.Entry> |
|
53
|
<LayoutComposer.Entry id="ProductOptionValuesSection"> |
|
54
|
{isViewConfigEnabled ? ( |
|
55
|
<ConfigurableProductOptionValuesSection |
|
56
|
productOption={product_option} |
|
57
|
/> |
|
58
|
) : ( |
|
59
|
<ProductOptionValuesSection productOption={product_option} /> |
|
60
|
)} |
|
61
|
</LayoutComposer.Entry> |
|
62
|
<LayoutComposer.Entry id="ProductOptionProductSection"> |
|
63
|
{isViewConfigEnabled ? ( |
|
64
|
<ConfigurableProductOptionProductSection |
|
65
|
productOptionId={product_option.id} |
|
66
|
/> |
|
67
|
) : ( |
|
68
|
<ProductOptionProductSection |
|
69
|
productOptionId={product_option.id} |
|
70
|
/> |
|
71
|
)} |
|
72
|
</LayoutComposer.Entry> |
|
73
|
{detailPageDefaultEntries(product_option, { permissions: false })} |
|
74
|
</> |
|
75
|
), |
|
76
|
}} |
|
77
|
/> |
|
78
|
) |
|
79
|
} |