From 97d1df0bfd7eee1b05a1303678405a765e83c84a Mon Sep 17 00:00:00 2001 From: bryantran04 Date: Wed, 25 Jan 2023 01:01:22 -0800 Subject: [PATCH] fix: incorrect date range if end date picked first --- .../common/ReactDayPicker/ReactDayPicker.jsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/components/common/ReactDayPicker/ReactDayPicker.jsx b/client/components/common/ReactDayPicker/ReactDayPicker.jsx index 38a978266..ca113162c 100644 --- a/client/components/common/ReactDayPicker/ReactDayPicker.jsx +++ b/client/components/common/ReactDayPicker/ReactDayPicker.jsx @@ -39,7 +39,17 @@ function ReactDayPicker({ // first day in their date range if from and to are set, or if they're both // unset. Otherwise, they are selecting the last day. if (!(startDate && endDate)) { - setToDay(day); + // If the user picks the first date then picks the second date that is before the first date + // Reassign the From and To Day + if (moment(day).format(INTERNAL_DATE_SPEC) < startDate) { + const tempDate = startDate; + setToDay(moment(tempDate).toDate()); + setFromDay(day); + updateEndDate(tempDate); + setEnteredTo(moment(tempDate).toDate()); + } else { + setToDay(day); + } return; } setFromDay(day);