diff --git a/src/components/DemoPage/DemoPage.tsx b/src/components/DemoPage/DemoPage.tsx index 0d74c688..7b97610f 100644 --- a/src/components/DemoPage/DemoPage.tsx +++ b/src/components/DemoPage/DemoPage.tsx @@ -19,8 +19,11 @@ import { MutableRefObject, useCallback, useEffect, useRef, useState } from 'reac import { Build, GroupBuild } from 'pnc-api-types-ts'; +import { productMilestoneEntityAttributes } from 'common/productMilestoneEntityAttributes'; + import { useDataBuffer } from 'hooks/useDataBuffer'; import { IFieldConfigs, IFieldValues, useForm } from 'hooks/useForm'; +import { useServiceContainer } from 'hooks/useServiceContainer'; import { useTitle } from 'hooks/useTitle'; import { ActionButton } from 'components/ActionButton/ActionButton'; @@ -41,8 +44,10 @@ import { ProductMilestoneReleaseLabel } from 'components/ProductMilestoneRelease import { ScmRepositoryLink } from 'components/ScmRepositoryLink/ScmRepositoryLink'; import { ScmRepositoryUrl } from 'components/ScmRepositoryUrl/ScmRepositoryUrl'; import { SearchSelect } from 'components/SearchSelect/SearchSelect'; +import { TextInputAsyncValidated } from 'components/TextInputAsyncValidated/TextInputAsyncValidated'; import { TooltipWrapper } from 'components/TooltipWrapper/TooltipWrapper'; +import * as productMilestoneApi from 'services/productMilestoneApi'; import * as projectApi from 'services/projectApi'; import { maxLength, minLength } from 'utils/formValidationHelpers'; @@ -53,10 +58,15 @@ import mockBuildData from './data/mock-build-data.json'; const buildRes: Build[] = mockBuildData; +const validateMultipleFields = (fieldValues: IFieldValues): boolean => { + return !!fieldValues.inputFieldA && !!fieldValues.version; +}; + const fieldConfigs = { inputFieldA: { isRequired: true, validators: [ + { validator: validateMultipleFields, errorMessage: 'inputFieldA and version must be defined.', relatedFields: ['version'] }, { validator: minLength(2), errorMessage: 'Text must be at least two characters long.' }, { validator: maxLength(10), @@ -67,6 +77,16 @@ const fieldConfigs = { selectA: { isRequired: true, }, + version: { + isRequired: true, + validators: [ + { + validator: validateMultipleFields, + errorMessage: 'version and inputFieldA must be defined.', + relatedFields: ['inputFieldA'], + }, + ], + }, } satisfies IFieldConfigs; const initLogData = [ @@ -230,6 +250,9 @@ export const DemoPage = () => { }); }; + const serviceContainerValidateProductMilestone = useServiceContainer(productMilestoneApi.validateProductMilestoneVersion, 0); + const serviceContainerValidateProductMilestone2 = useServiceContainer(productMilestoneApi.validateProductMilestoneVersion, 0); + const selectOptions = [{ value: 'Build' }, { value: 'Option' }, { value: 'Project' }, { value: 'Version' }]; const [isSelectOpen, setIsSelectOpen] = useState(false); @@ -345,6 +368,47 @@ export const DemoPage = () => { )} /> + + {getFieldErrors(productMilestoneEntityAttributes.version.id)} + + } + > + (productMilestoneEntityAttributes.version.id, { + ...fieldConfigs.version, + validators: [ + ...fieldConfigs.version.validators, + { + asyncValidator: (value) => + serviceContainerValidateProductMilestone.run({ + serviceData: { + data: { productVersionId: '101', version: '2.0.' + value }, + }, + }), + }, + { + asyncValidator: (value) => + serviceContainerValidateProductMilestone2.run({ + serviceData: { + data: { productVersionId: '101', version: '2.0.' + value }, + }, + }), + }, + ], + })} + prefixComponent={<>2.0} + /> +