Skip to content

Commit

Permalink
fix: validate de minimis dates with shared function
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast committed Sep 20, 2023
1 parent eceb562 commit 155b902
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -35,16 +36,7 @@ export const getValidationSchema = (t: TFunction): Yup.SchemaOf<DeMinimisAid> =>
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, {
Expand Down

0 comments on commit 155b902

Please sign in to comment.