From d55c74f8e061804dd81287a461bf9fe60a4fc513 Mon Sep 17 00:00:00 2001 From: Aman Chaturvedi Date: Fri, 3 Nov 2023 17:29:33 +0530 Subject: [PATCH] TP-42454 | fix --- src/components/form/components/DateInput.tsx | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/form/components/DateInput.tsx b/src/components/form/components/DateInput.tsx index 371d8afc..a99e037b 100644 --- a/src/components/form/components/DateInput.tsx +++ b/src/components/form/components/DateInput.tsx @@ -1,5 +1,5 @@ import { View } from 'react-native'; -import React, { useEffect, useState } from 'react'; +import React, { useMemo } from 'react'; import Text from '../../../../RN-UI-LIB/src/components/Text'; import { GenericStyles } from '../../../../RN-UI-LIB/src/styles'; import { useAppSelector } from '../../../hooks'; @@ -12,7 +12,6 @@ import { CLICKSTREAM_EVENT_NAMES } from '../../../common/Constants'; import { AnswerType } from '../interface'; import WebBasedDatePicker from '../../../../RN-UI-LIB/src/components/WebBasedDatePicker'; import { - BUSINESS_DATE_FORMAT, CUSTOM_ISO_DATE_FORMAT, DefaultPickerModeVisibleFormatMapping, IDateTimePickerMode, @@ -68,6 +67,16 @@ const DateInput: React.FC = (props) => { }); }; + const maxDate = useMemo(() => { + if (question.metadata.validators?.[Validators.MAX_DATE]?.value === DateValue.END_OF_MONTH) { + return new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).toString(); + } + if (question.metadata.validators?.[Validators.MAX_TODAY]?.value) { + return new Date().toString(); + } + return ''; + }, [question]); + return ( @@ -114,14 +123,7 @@ const DateInput: React.FC = (props) => { type="date" onChange={(text) => handleChange(text, onChange)} outputFormat="DD-MM-YYYY" - max={ - question.metadata.validators?.[Validators.MAX_DATE]?.value === - DateValue.END_OF_MONTH - ? new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).toString() - : question.metadata.validators?.[Validators.MAX_TODAY]?.value - ? new Date().toString() - : '' - } + max={maxDate} /> ); }}