From bbb34405a24615843a204827e30e0efc49d739e5 Mon Sep 17 00:00:00 2001 From: Kim Date: Wed, 27 Nov 2024 13:57:02 -0500 Subject: [PATCH] Only compare datetimes when time is valid --- .../Dashboard/PaMessageForm/MainForm.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx b/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx index 64b96ef5..7387a8e0 100644 --- a/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx +++ b/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx @@ -189,11 +189,12 @@ const MainForm = ({ onChange={(event) => setStartDate(event.target.value)} isInvalid={ validated && - (startDateTime.isSameOrAfter(endDateTime) || - !startDateTime.isValid()) + ((moment(startTime, "HH:mm").isValid() && + startDateTime.isSameOrAfter(endDateTime)) || + !moment(startDate, "YYYY-MM-DD").isValid()) } /> - {startDateTime.isValid() ? ( + {moment(startDate, "YYYY-MM-DD").isValid() ? ( Start date/time needs to be before the end date/time @@ -266,11 +267,12 @@ const MainForm = ({ onChange={(event) => setEndDate(event.target.value)} isInvalid={ validated && - (endDateTime.isSameOrBefore(moment()) || - !endDateTime.isValid()) + ((moment(endTime, "HH:mm").isValid() && + endDateTime.isSameOrBefore(moment())) || + !moment(endDate, "YYYY-MM-DD").isValid()) } /> - {endDateTime.isValid() ? ( + {moment(endDate, "YYYY-MM-DD").isValid() ? ( Date is in the past