Skip to content

Commit

Permalink
fix: prevent runtime error when only one date range is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Dec 11, 2024
1 parent 5e46787 commit dba52da
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,24 @@ const getRelativeRangeErrors = (startValue, endValue, submitAttempted) => {
return errors;
};

const isAbsoluteRangeFilterValid = (fromValue, toValue) => {
if (!fromValue && !toValue) {
const isAbsoluteRangeFilterValid = (from, to) => {
if (!from?.value && !to?.value) {
return false;
}
const fromValue = from?.value;
const toValue = to?.value;
const parseResultFrom = fromValue ? parseDate(fromValue) : { isValid: true, moment: null };
const parseResultTo = toValue ? parseDate(toValue) : { isValid: true, moment: null };

if ((fromValue && !fromValue.isValid) || (toValue && !toValue.isValid)) {
if (!(parseResultFrom.isValid && parseResultTo.isValid)) {
return false;
}
const isValidMomentDate = () =>
parseResultFrom.momentDate &&
parseResultTo.momentDate &&
parseResultFrom.momentDate.isAfter(parseResultTo.momentDate);

return !DateFilter.isFromAfterTo(fromValue?.value, toValue?.value);
return !isValidMomentDate();
};

const isRelativeRangeFilterValid = (startValue, endValue) => {
Expand Down

0 comments on commit dba52da

Please sign in to comment.