From 9f3c644e2a7797ba7888863e2d478d773ca1970f Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Tue, 28 Nov 2023 09:59:53 +0200 Subject: [PATCH] Added validation to Offers X input fields (#19153) refs https://github.com/TryGhost/Product/issues/4206 - added validation to input fields when creating a new offer --- .../settings/growth/offers/AddOfferModal.tsx | 124 ++++++++++++++---- 1 file changed, 101 insertions(+), 23 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 12bf91a1b0..5007065f65 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 @@ -1,12 +1,12 @@ import PortalFrame from '../../membership/portal/PortalFrame'; import useFeatureFlag from '../../../../hooks/useFeatureFlag'; +import {ErrorMessages, useForm} from '@tryghost/admin-x-framework/hooks'; import {Form, Icon, PreviewModalContent, Select, SelectOption, TextArea, TextField, showToast} from '@tryghost/admin-x-design-system'; import {getOfferPortalPreviewUrl, offerPortalPreviewUrlTypes} from '../../../../utils/getOffersPortalPreviewUrl'; import {getPaidActiveTiers, useBrowseTiers} from '@tryghost/admin-x-framework/api/tiers'; import {getTiersCadences} from '../../../../utils/getTiersCadences'; import {useAddOffer} from '@tryghost/admin-x-framework/api/offers'; import {useEffect, useMemo, useState} from 'react'; -import {useForm} from '@tryghost/admin-x-framework/hooks'; import {useGlobalData} from '../../../providers/GlobalDataProvider'; import {useModal} from '@ebay/nice-modal-react'; import {useRouting} from '@tryghost/admin-x-framework/routing'; @@ -103,6 +103,10 @@ type SidebarProps = { handleAmountInput: (e: React.ChangeEvent) => void; handleDurationInMonthsInput: (e: React.ChangeEvent) => void; handleCodeInput: (e: React.ChangeEvent) => void; + validate: () => void; + clearError: (field: string) => void; + errors: ErrorMessages; + handleTrialAmountInput: (e: React.ChangeEvent) => void; }; const Sidebar: React.FC = ({tierOptions, @@ -121,7 +125,11 @@ const Sidebar: React.FC = ({tierOptions, handleDurationInMonthsInput, handleAmountInput, handleCodeInput, + validate, + errors, + handleTrialAmountInput, amountOptions}) => { + // const handleError = useHandleError(); const getFilteredDurationOptions = () => { // Check if the selected tier's cadence is 'yearly' if (selectedTier?.label?.includes('Yearly')) { @@ -139,10 +147,12 @@ const Sidebar: React.FC = ({tierOptions,
Visible to members on Stripe Checkout page{nameLength} / 40
} + error={Boolean(errors.name)} + hint={errors.name ||
Visible to members on Stripe Checkout page{nameLength} / 40
} maxLength={40} placeholder='Black Friday' title='Name' + onBlur={validate} onChange={(e) => { handleNameInput(e); setNameLength(e.target.value.length); @@ -171,9 +181,21 @@ const Sidebar: React.FC = ({tierOptions, /> { overrides.type !== 'trial' && <>
- { - handleAmountInput(e); - }} /> + { + handleAmountInput(e); + }} + />