From b7d4d06c434eb03395496dc490a32460e74c497d Mon Sep 17 00:00:00 2001 From: VitalyDevico <96239692+VitalyDevico@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:47:42 +0300 Subject: [PATCH] X2-10221 | fixed datepicker for specific case (#336) * X2-10221 | fixed datepicker for case when user first clicked on the date that will go to 'to'and then to 'from' * fexed lint issue * added comment * added missing argument * added condition for same date --- src/components/DatePicker/DatePicker.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/DatePicker/DatePicker.jsx b/src/components/DatePicker/DatePicker.jsx index 179a44f80..9d4e5d1d7 100644 --- a/src/components/DatePicker/DatePicker.jsx +++ b/src/components/DatePicker/DatePicker.jsx @@ -145,12 +145,27 @@ export const DatePicker = ({ const to = toDate(now(day, timezoneName).endOf("day"), false); onChange({ from, to }, options, event); - } else { + } else if (DateUtils.isDayBefore(value.from, toDate(now(day, timezoneName)))) { + // this works if the user first clicked on the date that will go to "from", and the second click to "to" onChange( DateUtils.addDayToRange(toDate(now(day, timezoneName).endOf("day"), false), value), options, event, ); + } else if ( + DateUtils.isDayAfter(value.from, toDate(now(day, timezoneName))) || + DateUtils.isSameDay(value.from, toDate(now(day, timezoneName))) + ) { + // this works if the user first clicked on the date that will go to "to", and the second click to "from" + // also this works when the user has selected one date + onChange( + { + from: toDate(now(day, timezoneName).startOf("day")), + to: toDate(now(value.from).endOf("day"), false), + }, + options, + event, + ); } } else { onChange(toDate(now(day, timezoneName)), options, event);