fix: only showcase tooltip when currency is not set (#7920)

* fix: only showcase tooltip when currency is not set

* chore: scope tooltip only if of type spend
This commit is contained in:
Riqwan Thamir
2024-07-03 13:34:39 +02:00
committed by GitHub
parent 617a5972bf
commit 40dbaf890f

View File

@@ -37,16 +37,13 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
name: `application_method.currency_code`,
})
const watchPromotionCurrencyCode = useWatch({
control: form.control,
name: "application_method.currency_code",
})
const currency = currencyValue || promotionCurrencyValue
useEffect(() => {
form.setValue(`${fieldScope}budget.limit`, null)
if (watchValueType === "spend") {
form.setValue(`campaign.budget.currency_code`, watchPromotionCurrencyCode)
if (isTypeSpend) {
form.setValue(`campaign.budget.currency_code`, promotionCurrencyValue)
}
if (watchValueType === "usage") {
@@ -54,15 +51,15 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
}
}, [watchValueType])
if (watchPromotionCurrencyCode) {
if (promotionCurrencyValue) {
const formCampaignBudget = form.getValues().campaign?.budget
const formCampaignCurrency = formCampaignBudget?.currency_code
if (
formCampaignBudget?.type === "spend" &&
formCampaignCurrency !== watchPromotionCurrencyCode
formCampaignCurrency !== promotionCurrencyValue
) {
form.setValue("campaign.budget.currency_code", watchPromotionCurrencyCode)
form.setValue("campaign.budget.currency_code", promotionCurrencyValue)
}
}
@@ -195,9 +192,9 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
<Form.Item>
<Form.Label
tooltip={
currencyValue
? undefined
: t("promotions.tooltips.campaignType")
fieldScope?.length && !currency
? t("promotions.tooltips.campaignType")
: undefined
}
>
{t("campaigns.budget.fields.type")}
@@ -219,7 +216,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
value={"spend"}
label={t("campaigns.budget.type.spend.title")}
description={t("campaigns.budget.type.spend.description")}
disabled={!!!(currencyValue || promotionCurrencyValue)}
disabled={fieldScope?.length ? !currency : false}
/>
</RadioGroup>
</Form.Control>
@@ -239,7 +236,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
<Form.Item>
<Form.Label
tooltip={
fieldScope.length
fieldScope?.length && !currency
? t("promotions.campaign_currency.tooltip")
: undefined
}
@@ -292,9 +289,9 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
<Form.Item className="basis-1/2">
<Form.Label
tooltip={
currencyValue
? undefined
: t("promotions.fields.amount.tooltip")
!currency && isTypeSpend
? t("promotions.fields.amount.tooltip")
: undefined
}
>
{t("campaigns.budget.fields.limit")}
@@ -313,7 +310,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
}
{...field}
value={value}
disabled={!currencyValue}
disabled={!currency && isTypeSpend}
/>
) : (
<Input