From c6896ffa6a1bc5c0ee8c4eea55feebea3497e47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:15:26 +0200 Subject: [PATCH] fix(dashboard): campaign UI improvements (#13723) * fix(dashboard): campaign UI improvements * fix: camel case translation key --- .changeset/swift-pillows-invent.md | 5 +++ .../src/i18n/translations/$schema.json | 31 ++++++++++++++----- .../dashboard/src/i18n/translations/en.json | 9 ++++-- .../create-campaign-form.tsx | 1 + .../campaign-budget/campaign-budget.tsx | 6 ++-- .../campaign-spend/campaign-spend.tsx | 8 +++-- .../create-campaign-form-fields.tsx | 4 +++ .../campaign-details.tsx | 19 ++++++++++-- 8 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 .changeset/swift-pillows-invent.md diff --git a/.changeset/swift-pillows-invent.md b/.changeset/swift-pillows-invent.md new file mode 100644 index 0000000000..c4ad4ebbab --- /dev/null +++ b/.changeset/swift-pillows-invent.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard): campaign UI improvements diff --git a/packages/admin/dashboard/src/i18n/translations/$schema.json b/packages/admin/dashboard/src/i18n/translations/$schema.json index 472b2d7606..f514bfa30d 100644 --- a/packages/admin/dashboard/src/i18n/translations/$schema.json +++ b/packages/admin/dashboard/src/i18n/translations/$schema.json @@ -8312,6 +8312,9 @@ "total_used": { "type": "string" }, + "totalUsedByAttribute": { + "type": "string" + }, "budget_limit": { "type": "string" }, @@ -8333,6 +8336,7 @@ "end_date", "total_spend", "total_used", + "totalUsedByAttribute", "budget_limit", "campaign_id" ], @@ -8378,10 +8382,7 @@ "budgetAttributeTooltip": { "type": "string" }, - "limitBudgetAttributeCustomer": { - "type": "string" - }, - "limitBudgetAttributeEmail": { + "totalUsedByAttribute": { "type": "string" } }, @@ -8392,8 +8393,7 @@ "used", "budgetAttribute", "budgetAttributeTooltip", - "limitBudgetAttributeCustomer", - "limitBudgetAttributeEmail" + "totalUsedByAttribute" ], "additionalProperties": false }, @@ -8425,9 +8425,22 @@ }, "required": ["title", "description"], "additionalProperties": false + }, + "useByAttribute": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": ["title", "description"], + "additionalProperties": false } }, - "required": ["spend", "usage"], + "required": ["spend", "usage", "useByAttribute"], "additionalProperties": false }, "edit": { @@ -11162,6 +11175,9 @@ "discountable": { "type": "string" }, + "promotionCode": { + "type": "string" + }, "handle": { "type": "string" }, @@ -11588,6 +11604,7 @@ "category", "collection", "discountable", + "promotionCode", "handle", "subtitle", "by", diff --git a/packages/admin/dashboard/src/i18n/translations/en.json b/packages/admin/dashboard/src/i18n/translations/en.json index 1b4c96427f..a37b5d4ced 100644 --- a/packages/admin/dashboard/src/i18n/translations/en.json +++ b/packages/admin/dashboard/src/i18n/translations/en.json @@ -2233,6 +2233,7 @@ "end_date": "End date", "total_spend": "Budget spent", "total_used": "Budget used", + "totalUsedByAttribute": "Total used", "budget_limit": "Budget limit", "campaign_id": { "hint": "Disabled campaigns have budget in a different currency than the promotion." @@ -2251,8 +2252,7 @@ "used": "Used", "budgetAttribute": "Limit usage per", "budgetAttributeTooltip": "Define how many times the promotion can be used by a specific customer or email.", - "limitBudgetAttributeCustomer": "Budget limit per customer", - "limitBudgetAttributeEmail": "Budget limit per email" + "totalUsedByAttribute": "Budget limit per: {{attribute}}" }, "type": { "spend": { @@ -2262,6 +2262,10 @@ "usage": { "title": "Usage", "description": "Set a limit on how many times the promotion can be used." + }, + "useByAttribute": { + "title": "Usage by attribute (customer id, email, etc.)", + "description": "Set a limit on how many times the promotion can be used by a specific attribute value." } }, "edit": { @@ -3008,6 +3012,7 @@ "category": "Category", "collection": "Collection", "discountable": "Discountable", + "promotionCode": "Promotion code", "handle": "Handle", "subtitle": "Subtitle", "by": "By", diff --git a/packages/admin/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx b/packages/admin/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx index 8503c9a2f6..0fc4ea4f5d 100644 --- a/packages/admin/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx +++ b/packages/admin/dashboard/src/routes/campaigns/campaign-create/components/create-campaign-form/create-campaign-form.tsx @@ -40,6 +40,7 @@ export const CreateCampaignForm = () => { const handleSubmit = form.handleSubmit(async (data) => { const attribute = data.budget.attribute || null + const type = attribute ? "use_by_attribute" : data.budget.type await mutateAsync( diff --git a/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-budget/campaign-budget.tsx b/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-budget/campaign-budget.tsx index 77d88b6eba..60671b93f7 100644 --- a/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-budget/campaign-budget.tsx +++ b/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-budget/campaign-budget.tsx @@ -26,9 +26,9 @@ export const CampaignBudget = ({ campaign }: CampaignBudgetProps) => { level="h3" > {campaign.budget?.type === "use_by_attribute" - ? campaign.budget?.attribute === "customer_id" - ? t("campaigns.budget.fields.limitBudgetAttributeCustomer") - : t("campaigns.budget.fields.limitBudgetAttributeEmail") + ? t("campaigns.budget.fields.totalUsedByAttribute", { + attribute: campaign.budget?.attribute, + }) : t("campaigns.fields.budget_limit")} diff --git a/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-spend/campaign-spend.tsx b/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-spend/campaign-spend.tsx index b4f61e317b..191633a125 100644 --- a/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-spend/campaign-spend.tsx +++ b/packages/admin/dashboard/src/routes/campaigns/campaign-detail/components/campaign-spend/campaign-spend.tsx @@ -20,9 +20,11 @@ export const CampaignSpend = ({ campaign }: CampaignSpendProps) => { - {campaign.budget?.type === "spend" - ? t("campaigns.fields.total_spend") - : t("campaigns.fields.total_used")} + {campaign.budget?.type === "use_by_attribute" + ? t("campaigns.fields.totalUsedByAttribute") + : campaign.budget?.type === "spend" + ? t("campaigns.fields.total_spend") + : t("campaigns.fields.total_used")} diff --git a/packages/admin/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx b/packages/admin/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx index 678ec1597a..5de9c8ec4f 100644 --- a/packages/admin/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx +++ b/packages/admin/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx @@ -382,6 +382,10 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => { label: t("fields.email"), value: "customer_email", }, + { + label: t("fields.promotionCode"), + value: "promotion_code", + }, ]} > diff --git a/packages/admin/dashboard/src/routes/promotions/promotion-add-campaign/components/add-campaign-promotion-form/campaign-details.tsx b/packages/admin/dashboard/src/routes/promotions/promotion-add-campaign/components/add-campaign-promotion-form/campaign-details.tsx index 2a3fd306d9..8a21b390f9 100644 --- a/packages/admin/dashboard/src/routes/promotions/promotion-add-campaign/components/add-campaign-promotion-form/campaign-details.tsx +++ b/packages/admin/dashboard/src/routes/promotions/promotion-add-campaign/components/add-campaign-promotion-form/campaign-details.tsx @@ -3,6 +3,12 @@ import { Heading, Text } from "@medusajs/ui" import { Fragment } from "react" import { useTranslation } from "react-i18next" +const translationKeyMap = { + spend: "spend", + usage: "usage", + use_by_attribute: "useByAttribute", +} + type CampaignDetailsProps = { campaign?: AdminCampaign } @@ -77,7 +83,14 @@ export const CampaignDetails = ({ campaign }: CampaignDetailsProps) => {
- {campaign.budget?.type || "-"} + + {t( + `campaigns.budget.type.${translationKeyMap[campaign.budget?.type]}.title`, + { + defaultValue: "-", + } + )} +
@@ -105,7 +118,9 @@ export const CampaignDetails = ({ campaign }: CampaignDetailsProps) => {
- {t("campaigns.budget.fields.used")} + {campaign.budget?.type === "use_by_attribute" + ? t("campaigns.fields.totalUsedByAttribute") + : t("campaigns.budget.fields.used")}