From ed00cdc832ed09da6bbe7bbff86356f26399353c Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Tue, 7 Jan 2025 19:06:06 +0530 Subject: [PATCH] Fixed empty time case --- src/components/TimeModalPicker.tsx | 2 +- src/components/TimePicker/TimePicker.tsx | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/TimeModalPicker.tsx b/src/components/TimeModalPicker.tsx index 0dfdc90ab0a9..177ea8a5a3e3 100644 --- a/src/components/TimeModalPicker.tsx +++ b/src/components/TimeModalPicker.tsx @@ -70,7 +70,7 @@ function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: Ti diff --git a/src/components/TimePicker/TimePicker.tsx b/src/components/TimePicker/TimePicker.tsx index 7f2e34b16b1a..77a3238b7486 100644 --- a/src/components/TimePicker/TimePicker.tsx +++ b/src/components/TimePicker/TimePicker.tsx @@ -37,6 +37,9 @@ type TimePickerProps = { /** Whether the time value should be validated */ shouldValidate?: boolean; + /** Whether the time value should be validated for future time only */ + shouldValidateFutureTime?: boolean; + /** Whether the picker shows hours, minutes, seconds and milliseconds */ showFullFormat?: boolean; }; @@ -118,7 +121,10 @@ function clearSelectedValue( setSelection({start: newCursorPosition, end: newCursorPosition}); } -function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}, shouldValidate = true, showFullFormat = false}: TimePickerProps, ref: ForwardedRef) { +function TimePicker( + {defaultValue = '', onSubmit, onInputChange = () => {}, shouldValidate = true, shouldValidateFutureTime = true, showFullFormat = false}: TimePickerProps, + ref: ForwardedRef, +) { const {numberFormat, translate} = useLocalize(); const {isExtraSmallScreenHeight} = useResponsiveLayout(); const styles = useThemeStyles(); @@ -166,12 +172,15 @@ function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}, shou setErrorMessage(translate('common.error.invalidTimeRange')); return false; } + if (!shouldValidateFutureTime) { + return true; + } const isValid = DateUtils.isTimeAtLeastOneMinuteInFuture({timeString, dateTimeString: defaultValue}); setError(!isValid); setErrorMessage(translate('common.error.invalidTimeShouldBeFuture')); return isValid; }, - [shouldValidate, hours, minutes, amPmValue, defaultValue, translate], + [shouldValidate, hours, minutes, amPmValue, shouldValidateFutureTime, defaultValue, translate], ); const resetHours = () => {