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 { useCustomer } from "../../../hooks/api/customers"
10 import { useFeatureFlag } from "../../../providers/feature-flag-provider"
11 import { PermissionsRequirementsProvider } from "../../../providers/permissions-provider"
12 import { CustomerAddressSection } from "./components/customer-address-section/customer-address-section"
13 import { CustomerGeneralSection } from "./components/customer-general-section"
14 import { CustomerGroupSection } from "./components/customer-group-section"
15 import { ConfigurableCustomerGroupSection } from "./components/customer-group-section/configurable-customer-group-section"
16 import { CustomerOrderSection } from "./components/customer-order-section"
17 import { ConfigurableCustomerOrderSection } from "./components/customer-order-section/configurable-customer-order-section"
18 import { customerLoader } from "./loader"
19
20 export const CustomerDetail = () => {
21 const { id } = useParams()
22 const isViewConfigEnabled = useFeatureFlag("view_configurations")
23
24 const initialData = useLoaderData() as Awaited<
25 ReturnType<typeof customerLoader>
26 >
27 const { customer, isLoading, isError, error } = useCustomer(
28 id!,
29 { fields: "+*addresses" },
30 { initialData }
31 )
32
33 if (isLoading || !customer) {
34 return <SingleColumnPageSkeleton sections={2} showJSON showMetadata />
35 }
36
37 if (isError) {
38 throw error
39 }
40
41 return (
42 <PermissionsRequirementsProvider>
43 <LayoutComposer
44 widgetsZonePrefix="customer.details"
45 preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN}
46 data={customer}
47 sections={{
48 main: (
49 <>
50 <LayoutComposer.Entry id="CustomerGeneralSection">
51 <CustomerGeneralSection customer={customer} />
52 </LayoutComposer.Entry>
53 <LayoutComposer.Entry id="CustomerOrderSection">
54 {isViewConfigEnabled ? (
55 <ConfigurableCustomerOrderSection customer={customer} />
56 ) : (
57 <CustomerOrderSection customer={customer} />
58 )}
59 </LayoutComposer.Entry>
60 <LayoutComposer.Entry id="CustomerGroupSection">
61 {isViewConfigEnabled ? (
62 <ConfigurableCustomerGroupSection customer={customer} />
63 ) : (
64 <CustomerGroupSection customer={customer} />
65 )}
66 </LayoutComposer.Entry>
67 {detailPageDefaultEntries(customer)}
68 </>
69 ),
70 side: (
71 <>
72 <LayoutComposer.Entry id="CustomerAddressSection">
73 <CustomerAddressSection customer={customer} />
74 </LayoutComposer.Entry>
75 </>
76 ),
77 }}
78 />
79 </PermissionsRequirementsProvider>
80 )
81 }