|
1
|
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared" |
|
2
|
import { useLoaderData, useParams } from "react-router-dom" |
|
3
|
|
|
4
|
import { useCampaign } from "../../../hooks/api/campaigns" |
|
5
|
import { CampaignBudget } from "./components/campaign-budget" |
|
6
|
import { CampaignGeneralSection } from "./components/campaign-general-section" |
|
7
|
import { CampaignPromotionSection } from "./components/campaign-promotion-section" |
|
8
|
import { ConfigurableCampaignPromotionSection } from "./components/campaign-promotion-section/configurable-campaign-promotion-section" |
|
9
|
import { CampaignSpend } from "./components/campaign-spend" |
|
10
|
import { campaignLoader } from "./loader" |
|
11
|
|
|
12
|
import { TwoColumnPageSkeleton } from "../../../components/common/skeleton" |
|
13
|
import { |
|
14
|
LayoutComposer, |
|
15
|
detailPageDefaultEntries, |
|
16
|
} from "../../../components/layout-composer" |
|
17
|
import { useFeatureFlag } from "../../../providers/feature-flag-provider" |
|
18
|
import { CampaignConfigurationSection } from "./components/campaign-configuration-section" |
|
19
|
import { CAMPAIGN_DETAIL_FIELDS } from "./constants" |
|
20
|
|
|
21
|
export const CampaignDetail = () => { |
|
22
|
const initialData = useLoaderData() as Awaited< |
|
23
|
ReturnType<typeof campaignLoader> |
|
24
|
> |
|
25
|
|
|
26
|
const { id } = useParams() |
|
27
|
const isViewConfigEnabled = useFeatureFlag("view_configurations") |
|
28
|
const { campaign, isLoading, isError, error } = useCampaign( |
|
29
|
id!, |
|
30
|
{ fields: CAMPAIGN_DETAIL_FIELDS }, |
|
31
|
{ initialData } |
|
32
|
) |
|
33
|
|
|
34
|
if (isLoading || !campaign) { |
|
35
|
return ( |
|
36
|
<TwoColumnPageSkeleton |
|
37
|
mainSections={2} |
|
38
|
sidebarSections={3} |
|
39
|
showJSON |
|
40
|
showMetadata |
|
41
|
/> |
|
42
|
) |
|
43
|
} |
|
44
|
|
|
45
|
if (isError) { |
|
46
|
throw error |
|
47
|
} |
|
48
|
|
|
49
|
return ( |
|
50
|
<LayoutComposer |
|
51
|
widgetsZonePrefix="campaign.details" |
|
52
|
preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN} |
|
53
|
data={campaign} |
|
54
|
sections={{ |
|
55
|
main: ( |
|
56
|
<> |
|
57
|
<LayoutComposer.Entry id="CampaignGeneralSection"> |
|
58
|
<CampaignGeneralSection campaign={campaign} /> |
|
59
|
</LayoutComposer.Entry> |
|
60
|
<LayoutComposer.Entry id="CampaignPromotionSection"> |
|
61
|
{isViewConfigEnabled ? ( |
|
62
|
<ConfigurableCampaignPromotionSection campaign={campaign} /> |
|
63
|
) : ( |
|
64
|
<CampaignPromotionSection campaign={campaign} /> |
|
65
|
)} |
|
66
|
</LayoutComposer.Entry> |
|
67
|
{detailPageDefaultEntries(campaign)} |
|
68
|
</> |
|
69
|
), |
|
70
|
side: ( |
|
71
|
<> |
|
72
|
<LayoutComposer.Entry id="CampaignConfigurationSection"> |
|
73
|
<CampaignConfigurationSection campaign={campaign} /> |
|
74
|
</LayoutComposer.Entry> |
|
75
|
<LayoutComposer.Entry id="CampaignSpend"> |
|
76
|
<CampaignSpend campaign={campaign} /> |
|
77
|
</LayoutComposer.Entry> |
|
78
|
<LayoutComposer.Entry id="CampaignBudget"> |
|
79
|
<CampaignBudget campaign={campaign} /> |
|
80
|
</LayoutComposer.Entry> |
|
81
|
</> |
|
82
|
), |
|
83
|
}} |
|
84
|
/> |
|
85
|
) |
|
86
|
} |