|
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 { useCollection } from "../../../hooks/api/collections" |
|
10
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider" |
|
11
|
import { CollectionGeneralSection } from "./components/collection-general-section" |
|
12
|
import { CollectionProductSection } from "./components/collection-product-section" |
|
13
|
import { ConfigurableCollectionProductSection } from "./components/collection-product-section/configurable-collection-product-section" |
|
14
|
import { collectionLoader } from "./loader" |
|
15
|
|
|
16
|
export const CollectionDetail = () => { |
|
17
|
const initialData = useLoaderData() as Awaited< |
|
18
|
ReturnType<typeof collectionLoader> |
|
19
|
> |
|
20
|
const isViewConfigEnabled = useFeatureFlag("view_configurations") |
|
21
|
|
|
22
|
const { id } = useParams() |
|
23
|
const { collection, isLoading, isError, error } = useCollection(id!, { |
|
24
|
initialData, |
|
25
|
}) |
|
26
|
|
|
27
|
if (isLoading || !collection) { |
|
28
|
return <SingleColumnPageSkeleton sections={2} showJSON showMetadata /> |
|
29
|
} |
|
30
|
|
|
31
|
if (isError) { |
|
32
|
throw error |
|
33
|
} |
|
34
|
|
|
35
|
return ( |
|
36
|
<LayoutComposer |
|
37
|
widgetsZonePrefix="product_collection.details" |
|
38
|
preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN} |
|
39
|
data={collection} |
|
40
|
sections={{ |
|
41
|
main: ( |
|
42
|
<> |
|
43
|
<LayoutComposer.Entry id="CollectionGeneralSection"> |
|
44
|
<CollectionGeneralSection collection={collection} /> |
|
45
|
</LayoutComposer.Entry> |
|
46
|
<LayoutComposer.Entry id="CollectionProductSection"> |
|
47
|
{isViewConfigEnabled ? ( |
|
48
|
<ConfigurableCollectionProductSection collection={collection} /> |
|
49
|
) : ( |
|
50
|
<CollectionProductSection collection={collection} /> |
|
51
|
)} |
|
52
|
</LayoutComposer.Entry> |
|
53
|
{detailPageDefaultEntries(collection, { permissions: false })} |
|
54
|
</> |
|
55
|
), |
|
56
|
}} |
|
57
|
/> |
|
58
|
) |
|
59
|
} |