fix(dashboard): campaign budget labels improvements (#13740)

* fix(dashboard): budget labels and remove promo code

* fix: sidebar label

* fix: update translation
This commit is contained in:
Frane Polić
2025-10-13 18:49:12 +02:00
committed by GitHub
parent 379d763e50
commit 723dc082f0
6 changed files with 97 additions and 20 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---
fix(dashboard): budget labels and remove promo code
@@ -8345,6 +8345,19 @@
"budget": { "budget": {
"type": "object", "type": "object",
"properties": { "properties": {
"attribute": {
"type": "object",
"properties": {
"customer_id": {
"type": "string"
},
"customer_email": {
"type": "string"
}
},
"required": ["customer_id", "customer_email"],
"additionalProperties": false
},
"create": { "create": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -8384,6 +8397,12 @@
}, },
"totalUsedByAttribute": { "totalUsedByAttribute": {
"type": "string" "type": "string"
},
"totalUsedByAttributeCustomerId": {
"type": "string"
},
"totalUsedByAttributeEmail": {
"type": "string"
} }
}, },
"required": [ "required": [
@@ -8393,7 +8412,9 @@
"used", "used",
"budgetAttribute", "budgetAttribute",
"budgetAttributeTooltip", "budgetAttributeTooltip",
"totalUsedByAttribute" "totalUsedByAttribute",
"totalUsedByAttributeCustomerId",
"totalUsedByAttributeEmail"
], ],
"additionalProperties": false "additionalProperties": false
}, },
@@ -8432,11 +8453,22 @@
"title": { "title": {
"type": "string" "type": "string"
}, },
"titleCustomerId": {
"type": "string"
},
"titleEmail": {
"type": "string"
},
"description": { "description": {
"type": "string" "type": "string"
} }
}, },
"required": ["title", "description"], "required": [
"title",
"titleCustomerId",
"titleEmail",
"description"
],
"additionalProperties": false "additionalProperties": false
} }
}, },
@@ -8454,7 +8486,14 @@
"additionalProperties": false "additionalProperties": false
} }
}, },
"required": ["create", "details", "fields", "type", "edit"], "required": [
"attribute",
"create",
"details",
"fields",
"type",
"edit"
],
"additionalProperties": false "additionalProperties": false
}, },
"promotions": { "promotions": {
@@ -2240,6 +2240,10 @@
} }
}, },
"budget": { "budget": {
"attribute": {
"customer_id": "customer",
"customer_email": "email"
},
"create": { "create": {
"hint": "Create a budget for the campaign.", "hint": "Create a budget for the campaign.",
"header": "Campaign Budget" "header": "Campaign Budget"
@@ -2251,8 +2255,10 @@
"limit": "Limit", "limit": "Limit",
"used": "Used", "used": "Used",
"budgetAttribute": "Limit usage per", "budgetAttribute": "Limit usage per",
"budgetAttributeTooltip": "Define how many times the promotion can be used by a specific customer or email.", "budgetAttributeTooltip": "Define how many times the promotion can be used by each customer or email.",
"totalUsedByAttribute": "Budget limit per: {{attribute}}" "totalUsedByAttribute": "Budget limit per: {{attribute}}",
"totalUsedByAttributeCustomerId": "Budget limit per customer",
"totalUsedByAttributeEmail": "Budget limit per email"
}, },
"type": { "type": {
"spend": { "spend": {
@@ -2265,6 +2271,8 @@
}, },
"useByAttribute": { "useByAttribute": {
"title": "Usage by attribute (customer id, email, etc.)", "title": "Usage by attribute (customer id, email, etc.)",
"titleCustomerId": "Usage per customer",
"titleEmail": "Usage per email",
"description": "Set a limit on how many times the promotion can be used by a specific attribute value." "description": "Set a limit on how many times the promotion can be used by a specific attribute value."
} }
}, },
@@ -11,6 +11,22 @@ type CampaignBudgetProps = {
export const CampaignBudget = ({ campaign }: CampaignBudgetProps) => { export const CampaignBudget = ({ campaign }: CampaignBudgetProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const getTranslation = () => {
const budget = campaign.budget
if (budget?.type === "use_by_attribute") {
if (budget?.attribute === "customer_id") {
return t(`campaigns.budget.fields.totalUsedByAttributeCustomerId`)
} else if (budget?.attribute === "customer_email") {
return t(`campaigns.budget.fields.totalUsedByAttributeEmail`)
}
return t(`campaigns.budget.fields.totalUsedByAttribute`, {
attribute: budget?.attribute,
})
}
return t(`campaigns.fields.budget_limit`)
}
return ( return (
<Container className="flex flex-col gap-y-4 px-6 py-4"> <Container className="flex flex-col gap-y-4 px-6 py-4">
<div className="flex justify-between"> <div className="flex justify-between">
@@ -25,11 +41,7 @@ export const CampaignBudget = ({ campaign }: CampaignBudgetProps) => {
className="text-ui-fg-subtle ms-10 mt-[1.5px] font-normal" className="text-ui-fg-subtle ms-10 mt-[1.5px] font-normal"
level="h3" level="h3"
> >
{campaign.budget?.type === "use_by_attribute" {getTranslation()}
? t("campaigns.budget.fields.totalUsedByAttribute", {
attribute: campaign.budget?.attribute,
})
: t("campaigns.fields.budget_limit")}
</Heading> </Heading>
</div> </div>
@@ -382,10 +382,11 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
label: t("fields.email"), label: t("fields.email"),
value: "customer_email", value: "customer_email",
}, },
{ // TEMP disable promotion code for now
label: t("fields.promotionCode"), // {
value: "promotion_code", // label: t("fields.promotionCode"),
}, // value: "promotion_code",
// },
]} ]}
></Combobox> ></Combobox>
</Form.Control> </Form.Control>
@@ -9,6 +9,21 @@ const translationKeyMap = {
use_by_attribute: "useByAttribute", use_by_attribute: "useByAttribute",
} }
const getTranslationKey = (budget: AdminCampaign["budget"]) => {
const translationKey = translationKeyMap[budget?.type] || "-"
if (budget?.type === "use_by_attribute") {
if (budget?.attribute === "customer_id") {
return `campaigns.budget.type.useByAttribute.titleCustomerId`
} else if (budget?.attribute === "customer_email") {
return `campaigns.budget.type.useByAttribute.titleEmail`
}
return `campaigns.budget.type.useByAttribute.title`
}
return `campaigns.budget.type.${translationKey}.title`
}
type CampaignDetailsProps = { type CampaignDetailsProps = {
campaign?: AdminCampaign campaign?: AdminCampaign
} }
@@ -84,12 +99,9 @@ export const CampaignDetails = ({ campaign }: CampaignDetailsProps) => {
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<Text className="txt-small truncate"> <Text className="txt-small truncate">
{t( {t(getTranslationKey(campaign.budget), {
`campaigns.budget.type.${translationKeyMap[campaign.budget?.type]}.title`, defaultValue: "-",
{ })}
defaultValue: "-",
}
)}
</Text> </Text>
</div> </div>
</div> </div>