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 authored and GitHub committed 2024-07-03 13:34:39 +02:00
1 parent 617a5972bf
commit 40dbaf890f
1 file changed
+15 -18
@@ -37,16 +37,13 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
name: `application_method.currency_code`, name: `application_method.currency_code`,
}) })
const watchPromotionCurrencyCode = useWatch({ const currency = currencyValue || promotionCurrencyValue
control: form.control,
name: "application_method.currency_code",
})
useEffect(() => { useEffect(() => {
form.setValue(`${fieldScope}budget.limit`, null) form.setValue(`${fieldScope}budget.limit`, null)
if (watchValueType === "spend") { if (isTypeSpend) {
form.setValue(`campaign.budget.currency_code`, watchPromotionCurrencyCode) form.setValue(`campaign.budget.currency_code`, promotionCurrencyValue)
} }
if (watchValueType === "usage") { if (watchValueType === "usage") {
@@ -54,15 +51,15 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
} }
}, [watchValueType]) }, [watchValueType])
if (watchPromotionCurrencyCode) { if (promotionCurrencyValue) {
const formCampaignBudget = form.getValues().campaign?.budget const formCampaignBudget = form.getValues().campaign?.budget
const formCampaignCurrency = formCampaignBudget?.currency_code const formCampaignCurrency = formCampaignBudget?.currency_code
if ( if (
formCampaignBudget?.type === "spend" && 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.Item>
<Form.Label <Form.Label
tooltip={ tooltip={
currencyValue fieldScope?.length && !currency
? undefined ? t("promotions.tooltips.campaignType")
: t("promotions.tooltips.campaignType") : undefined
} }
> >
{t("campaigns.budget.fields.type")} {t("campaigns.budget.fields.type")}
@@ -219,7 +216,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
value={"spend"} value={"spend"}
label={t("campaigns.budget.type.spend.title")} label={t("campaigns.budget.type.spend.title")}
description={t("campaigns.budget.type.spend.description")} description={t("campaigns.budget.type.spend.description")}
disabled={!!!(currencyValue || promotionCurrencyValue)} disabled={fieldScope?.length ? !currency : false}
/> />
</RadioGroup> </RadioGroup>
</Form.Control> </Form.Control>
@@ -239,7 +236,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
<Form.Item> <Form.Item>
<Form.Label <Form.Label
tooltip={ tooltip={
fieldScope.length fieldScope?.length && !currency
? t("promotions.campaign_currency.tooltip") ? t("promotions.campaign_currency.tooltip")
: undefined : undefined
} }
@@ -292,9 +289,9 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
<Form.Item className="basis-1/2"> <Form.Item className="basis-1/2">
<Form.Label <Form.Label
tooltip={ tooltip={
currencyValue !currency && isTypeSpend
? undefined ? t("promotions.fields.amount.tooltip")
: t("promotions.fields.amount.tooltip") : undefined
} }
> >
{t("campaigns.budget.fields.limit")} {t("campaigns.budget.fields.limit")}
@@ -313,7 +310,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => {
} }
{...field} {...field}
value={value} value={value}
disabled={!currencyValue} disabled={!currency && isTypeSpend}
/> />
) : ( ) : (
<Input <Input