|
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 { useCustomerGroup } from "../../../hooks/api/customer-groups" |
|
10
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider" |
|
11
|
import { CustomerGroupCustomerSection } from "./components/customer-group-customer-section" |
|
12
|
import { ConfigurableCustomerGroupCustomerSection } from "./components/customer-group-customer-section/configurable-customer-group-customer-section" |
|
13
|
import { CustomerGroupGeneralSection } from "./components/customer-group-general-section" |
|
14
|
import { CUSTOMER_GROUP_DETAIL_FIELDS } from "./constants" |
|
15
|
import { customerGroupLoader } from "./loader" |
|
16
|
|
|
17
|
export const CustomerGroupDetail = () => { |
|
18
|
const initialData = useLoaderData() as Awaited< |
|
19
|
ReturnType<typeof customerGroupLoader> |
|
20
|
> |
|
21
|
|
|
22
|
const { id } = useParams() |
|
23
|
const isViewConfigEnabled = useFeatureFlag("view_configurations") |
|
24
|
const { customer_group, isLoading, isError, error } = useCustomerGroup( |
|
25
|
id!, |
|
26
|
{ |
|
27
|
fields: CUSTOMER_GROUP_DETAIL_FIELDS, |
|
28
|
}, |
|
29
|
{ initialData } |
|
30
|
) |
|
31
|
|
|
32
|
if (isLoading || !customer_group) { |
|
33
|
return <SingleColumnPageSkeleton sections={2} showJSON showMetadata /> |
|
34
|
} |
|
35
|
|
|
36
|
if (isError) { |
|
37
|
throw error |
|
38
|
} |
|
39
|
|
|
40
|
return ( |
|
41
|
<LayoutComposer |
|
42
|
widgetsZonePrefix="customer_group.details" |
|
43
|
preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN} |
|
44
|
data={customer_group} |
|
45
|
sections={{ |
|
46
|
main: ( |
|
47
|
<> |
|
48
|
<LayoutComposer.Entry id="CustomerGroupGeneralSection"> |
|
49
|
<CustomerGroupGeneralSection group={customer_group} /> |
|
50
|
</LayoutComposer.Entry> |
|
51
|
<LayoutComposer.Entry id="CustomerGroupCustomerSection"> |
|
52
|
{isViewConfigEnabled ? ( |
|
53
|
<ConfigurableCustomerGroupCustomerSection |
|
54
|
group={customer_group} |
|
55
|
/> |
|
56
|
) : ( |
|
57
|
<CustomerGroupCustomerSection group={customer_group} /> |
|
58
|
)} |
|
59
|
</LayoutComposer.Entry> |
|
60
|
{detailPageDefaultEntries(customer_group, { permissions: false })} |
|
61
|
</> |
|
62
|
), |
|
63
|
}} |
|
64
|
/> |
|
65
|
) |
|
66
|
} |