1 import { ArrowUpRightOnBox, PencilSquare } from "@medusajs/icons"
2 import { HttpTypes } from "@medusajs/types"
3 import { Container, Heading, Text } from "@medusajs/ui"
4 import { useTranslation } from "react-i18next"
5 import { useParams } from "react-router-dom"
6
7 import { ActionMenu } from "../../../../../components/common/action-menu"
8 import { DateRangeDisplay } from "../../../../../components/common/date-range-display"
9 import { NoRecords } from "../../../../../components/common/empty-table-content"
10
11 const CampaignDetailSection = ({
12 campaign,
13 }: {
14 campaign: HttpTypes.AdminCampaign
15 }) => {
16 return (
17 <div className="flex flex-col gap-y-3">
18 <div className="text-ui-fg-muted flex items-center gap-x-1.5">
19 <Text size="small" weight="plus" className="text-ui-fg-base">
20 {campaign.name}
21 </Text>
22 <Text size="small" weight="plus">
23 ·
24 </Text>
25 <Text size="small" weight="plus">
26 {campaign.campaign_identifier}
27 </Text>
28 </div>
29 <DateRangeDisplay
30 startsAt={campaign.starts_at}
31 endsAt={campaign.ends_at}
32 showTime
33 />
34 </div>
35 )
36 }
37
38 export const CampaignSection = ({
39 campaign,
40 }: {
41 campaign: HttpTypes.AdminCampaign | null
42 }) => {
43 const { t } = useTranslation()
44 const { id } = useParams()
45
46 const actions = [
47 {
48 label: t("actions.edit"),
49 to: "add-to-campaign",
50 icon: <PencilSquare />,
51 },
52 ]
53
54 if (campaign) {
55 actions.unshift({
56 label: t("promotions.campaign.actions.goToCampaign"),
57 to: `/campaigns/${campaign.id}`,
58 icon: <ArrowUpRightOnBox />,
59 })
60 }
61
62 return (
63 <Container>
64 <div className="flex items-center justify-between">
65 <Heading level="h2">{t("promotions.fields.campaign")}</Heading>
66
67 <ActionMenu
68 groups={[
69 {
70 actions,
71 },
72 ]}
73 />
74 </div>
75
76 {campaign ? (
77 <CampaignDetailSection campaign={campaign} />
78 ) : (
79 <NoRecords
80 className="h-[180px] pt-4 text-center"
81 title="Not part of a campaign"
82 message="Add this promotion to an existing campaign"
83 action={{
84 to: `/promotions/${id}/add-to-campaign`,
85 label: "Add to Campaign",
86 }}
87 buttonVariant="transparentIconLeft"
88 />
89 )}
90 </Container>
91 )
92 }