From 155b9021d00c353073d920b5ddc6ede9c8509b74 Mon Sep 17 00:00:00 2001 From: Sampo Tawast Date: Wed, 20 Sep 2023 14:56:51 +0300 Subject: [PATCH] fix: validate de minimis dates with shared function --- .../application/deMinimisAid/utils/validation.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/frontend/benefit/applicant/src/components/applications/forms/application/deMinimisAid/utils/validation.ts b/frontend/benefit/applicant/src/components/applications/forms/application/deMinimisAid/utils/validation.ts index d1bf2da925..fb689f6449 100644 --- a/frontend/benefit/applicant/src/components/applications/forms/application/deMinimisAid/utils/validation.ts +++ b/frontend/benefit/applicant/src/components/applications/forms/application/deMinimisAid/utils/validation.ts @@ -1,3 +1,4 @@ +import { validateIsFutureDate } from '@frontend/benefit-shared/src/utils/dates'; import { DE_MINIMIS_AID_GRANTED_AT_MAX_DATE, DE_MINIMIS_AID_GRANTED_AT_MIN_DATE, @@ -7,7 +8,7 @@ import { VALIDATION_MESSAGE_KEYS, } from 'benefit-shared/constants'; import { DeMinimisAid } from 'benefit-shared/types/application'; -import { isBefore, isFuture } from 'date-fns'; +import { isBefore } from 'date-fns'; import { TFunction } from 'next-i18next'; import { convertToUIDateFormat, parseDate } from 'shared/utils/date.utils'; import { getNumberValue } from 'shared/utils/string.utils'; @@ -35,16 +36,7 @@ export const getValidationSchema = (t: TFunction): Yup.SchemaOf => message: t(VALIDATION_MESSAGE_KEYS.DATE_MAX, { max: convertToUIDateFormat(DE_MINIMIS_AID_GRANTED_AT_MAX_DATE), }), - test: (value) => { - if (!value) return false; - - const date = parseDate(value); - - if (date && isFuture(date)) { - return false; - } - return true; - }, + test: (value) => validateIsFutureDate(value), }) .test({ message: t(VALIDATION_MESSAGE_KEYS.DATE_MIN, {