1 import { ChartPie, PencilSquare } from "@medusajs/icons"
2 import { AdminCampaign } from "@medusajs/types"
3 import { Container, Heading, Text } from "@medusajs/ui"
4 import { Trans, useTranslation } from "react-i18next"
5 import { ActionMenu } from "../../../../../components/common/action-menu"
6
7 type CampaignBudgetProps = {
8 campaign: AdminCampaign
9 }
10
11 export const CampaignBudget = ({ campaign }: CampaignBudgetProps) => {
12 const { t } = useTranslation()
13
14 const getTranslation = () => {
15 const budget = campaign.budget
16
17 if (budget?.type === "use_by_attribute") {
18 if (budget?.attribute === "customer_id") {
19 return t(`campaigns.budget.fields.totalUsedByAttributeCustomerId`)
20 } else if (budget?.attribute === "customer_email") {
21 return t(`campaigns.budget.fields.totalUsedByAttributeEmail`)
22 }
23 return t(`campaigns.budget.fields.totalUsedByAttribute`, {
24 attribute: budget?.attribute,
25 })
26 }
27 return t(`campaigns.fields.budget_limit`)
28 }
29
30 return (
31 <Container className="flex flex-col gap-y-4 px-6 py-4">
32 <div className="flex justify-between">
33 <div className="mb-2 grid flex-grow grid-cols-[28px_1fr] items-center gap-x-3">
34 <div className="bg-ui-bg-base shadow-borders-base flex size-7 items-center justify-center rounded-md">
35 <div className="bg-ui-bg-component flex size-6 items-center justify-center rounded-[4px]">
36 <ChartPie className="text-ui-fg-subtle" />
37 </div>
38 </div>
39
40 <Heading level="h2">{getTranslation()}</Heading>
41 </div>
42
43 <ActionMenu
44 groups={[
45 {
46 actions: [
47 {
48 icon: <PencilSquare />,
49 label: t("actions.edit"),
50 to: `edit-budget`,
51 },
52 ],
53 },
54 ]}
55 />
56 </div>
57
58 <div>
59 <Text
60 className="text-ui-fg-subtle border-ui-border-strong border-l-4 ps-3"
61 size="small"
62 leading="compact"
63 >
64 <Trans
65 i18nKey="campaigns.totalSpend"
66 values={{
67 amount: campaign?.budget?.limit || "no limit",
68 currency:
69 campaign?.budget?.type === "spend" && campaign?.budget.limit
70 ? campaign.budget?.currency_code
71 : "",
72 }}
73 components={[
74 <span
75 key="amount"
76 className="text-ui-fg-base txt-compact-medium-plus text-lg"
77 />,
78 <span
79 key="currency"
80 className="text-ui-fg-base txt-compact-medium-plus text-lg"
81 />,
82 ]}
83 />
84 </Text>
85 </div>
86 </Container>
87 )
88 }