Skip to content

Commit

Permalink
Only compare datetimes when time is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJKim committed Nov 27, 2024
1 parent 43aac0c commit bbb3440
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions assets/js/components/Dashboard/PaMessageForm/MainForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() ? (
<Form.Control.Feedback type="invalid">
Start date/time needs to be before the end date/time
</Form.Control.Feedback>
Expand Down Expand Up @@ -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() ? (
<Form.Control.Feedback type="invalid">
Date is in the past
</Form.Control.Feedback>
Expand Down

0 comments on commit bbb3440

Please sign in to comment.