From f29d7975a81a9c786701c5d16f56205893169c4d Mon Sep 17 00:00:00 2001 From: Princi Vershwal Date: Wed, 13 Dec 2023 16:37:15 +0530 Subject: [PATCH] Removed validation onBlur (#19358) Fixes [PROD-209](https://linear.app/tryghost/issue/PROD-209/when-an-input-is-focused-and-a-modal-is-closed-error-messages-are) --- .../settings/growth/offers/AddOfferModal.tsx | 33 ------------------- .../settings/growth/offers/EditOfferModal.tsx | 4 +-- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx index 8376aa0b19..98241cb5e0 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/AddOfferModal.tsx @@ -170,11 +170,6 @@ const Sidebar: React.FC = ({tierOptions, maxLength={40} placeholder='Black Friday' title='Offer name' - onBlur={(e) => { - if (!e.target.value && e.target.value.length === 0) { - errors.name = 'Name is required'; - } - }} onChange={(e) => { handleNameInput(e); setNameLength(e.target.value.length); @@ -187,11 +182,6 @@ const Sidebar: React.FC = ({tierOptions, placeholder='Black Friday Special' title='Display title' value={overrides.displayTitle.value} - onBlur={(e) => { - if (!e.target.value && e.target.value.length === 0) { - errors.displayTitle = 'Display title is required'; - } - }} onChange={(e) => { handleDisplayTitleInput(e); }} @@ -240,19 +230,6 @@ const Sidebar: React.FC = ({tierOptions, ? (overrides.fixedAmount === 0 ? '' : overrides.fixedAmount?.toString()) : (overrides.percentAmount === 0 ? '' : overrides.percentAmount?.toString()) } - onBlur={() => { - if (overrides.type === 'percent' && overrides.percentAmount === 0) { - errors.amount = 'Enter an amount greater than 0.'; - } - - if (overrides.type === 'percent' && overrides.percentAmount && (overrides.percentAmount < 0 || overrides.percentAmount >= 100)) { - errors.amount = 'Amount must be between 0 and 100%.'; - } - - if (overrides.type === 'fixed' && overrides.fixedAmount && overrides.fixedAmount <= 0) { - errors.amount = 'Enter an amount greater than 0.'; - } - }} onChange={(e) => { handleAmountInput(e); }} @@ -292,11 +269,6 @@ const Sidebar: React.FC = ({tierOptions, title='Trial duration' type='number' value={overrides.trialAmount?.toString()} - onBlur={(e) => { - if (Number(e.target.value) < 1) { - errors.amount = 'Free trial must be at least 1 day.'; - } - }} onChange={(e) => { handleTrialAmountInput(e); }} @@ -310,11 +282,6 @@ const Sidebar: React.FC = ({tierOptions, placeholder='black-friday' title='Offer code' value={overrides.code.value} - onBlur={(e) => { - if (!e.target.value && e.target.value.length === 0) { - errors.code = 'Code is required'; - } - }} onChange={(e) => { handleCodeInput(e); }} diff --git a/apps/admin-x-settings/src/components/settings/growth/offers/EditOfferModal.tsx b/apps/admin-x-settings/src/components/settings/growth/offers/EditOfferModal.tsx index b029e687e5..2b3d04c909 100644 --- a/apps/admin-x-settings/src/components/settings/growth/offers/EditOfferModal.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/offers/EditOfferModal.tsx @@ -25,7 +25,7 @@ const Sidebar: React.FC<{ errors: ErrorMessages, offer: Offer, updateOffer: (fields: Partial) => void, - validate: () => void}> = ({clearError, errors, offer, updateOffer, validate}) => { + validate: () => void}> = ({clearError, errors, offer, updateOffer}) => { const {siteData} = useGlobalData(); const [isCopied, setIsCopied] = useState(false); const handleError = useHandleError(); @@ -131,7 +131,6 @@ const Sidebar: React.FC<{ placeholder='Black Friday' title='Offer name' value={offer?.name} - onBlur={validate} onChange={(e) => { setNameLength(e.target.value.length); updateOffer({name: e.target.value}); @@ -156,7 +155,6 @@ const Sidebar: React.FC<{ placeholder='black-friday' title='Offer code' value={offer?.code} - onBlur={validate} onChange={e => updateOffer({code: e.target.value})} onKeyDown={() => clearError('name')} />