|
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 { useApiKey } from "../../../hooks/api/api-keys" |
|
10
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider" |
|
11
|
import { ApiKeyType } from "../common/constants" |
|
12
|
import { ApiKeyGeneralSection } from "./components/api-key-general-section" |
|
13
|
import { ApiKeySalesChannelSection } from "./components/api-key-sales-channel-section" |
|
14
|
import { ConfigurableApiKeySalesChannelSection } from "./components/api-key-sales-channel-section/configurable-api-key-sales-channel-section" |
|
15
|
import { apiKeyLoader } from "./loader" |
|
16
|
|
|
17
|
export const ApiKeyManagementDetail = () => { |
|
18
|
const initialData = useLoaderData() as Awaited< |
|
19
|
ReturnType<typeof apiKeyLoader> |
|
20
|
> |
|
21
|
|
|
22
|
const { id } = useParams() |
|
23
|
const isViewConfigEnabled = useFeatureFlag("view_configurations") |
|
24
|
|
|
25
|
const { api_key, isLoading, isError, error } = useApiKey(id!, { |
|
26
|
initialData: initialData, |
|
27
|
}) |
|
28
|
|
|
29
|
if (isLoading || !api_key) { |
|
30
|
return <SingleColumnPageSkeleton showJSON sections={1} /> |
|
31
|
} |
|
32
|
|
|
33
|
const isPublishable = api_key?.type === ApiKeyType.PUBLISHABLE |
|
34
|
|
|
35
|
if (isError) { |
|
36
|
throw error |
|
37
|
} |
|
38
|
|
|
39
|
return ( |
|
40
|
<LayoutComposer |
|
41
|
widgetsZonePrefix="api_key.details" |
|
42
|
preferredLayoutId={CORE_LAYOUT_IDS.SINGLE_COLUMN} |
|
43
|
data={api_key} |
|
44
|
sections={{ |
|
45
|
main: ( |
|
46
|
<> |
|
47
|
<LayoutComposer.Entry id="ApiKeyGeneralSection"> |
|
48
|
<ApiKeyGeneralSection apiKey={api_key} /> |
|
49
|
</LayoutComposer.Entry> |
|
50
|
{isPublishable && ( |
|
51
|
<LayoutComposer.Entry id="ApiKeySalesChannelSection"> |
|
52
|
{isViewConfigEnabled ? ( |
|
53
|
<ConfigurableApiKeySalesChannelSection apiKey={api_key} /> |
|
54
|
) : ( |
|
55
|
<ApiKeySalesChannelSection apiKey={api_key} /> |
|
56
|
)} |
|
57
|
</LayoutComposer.Entry> |
|
58
|
)} |
|
59
|
{detailPageDefaultEntries(api_key, { |
|
60
|
metadata: false, |
|
61
|
permissions: false, |
|
62
|
})} |
|
63
|
</> |
|
64
|
), |
|
65
|
}} |
|
66
|
/> |
|
67
|
) |
|
68
|
} |