From 40dbaf890f02509f2a5f31426d26288b4bcfc75c Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 3 Jul 2024 13:34:39 +0200 Subject: [PATCH] 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 --- .../create-campaign-form-fields.tsx | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/admin-next/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx b/packages/admin-next/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx index 1403aa55ad..6f0ce38cbc 100644 --- a/packages/admin-next/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx +++ b/packages/admin-next/dashboard/src/routes/campaigns/common/components/create-campaign-form-fields/create-campaign-form-fields.tsx @@ -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 = "" }) => { {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} /> @@ -239,7 +236,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => { { {t("campaigns.budget.fields.limit")} @@ -313,7 +310,7 @@ export const CreateCampaignFormFields = ({ form, fieldScope = "" }) => { } {...field} value={value} - disabled={!currencyValue} + disabled={!currency && isTypeSpend} /> ) : (