From 7cd5647f81f57b9c458c3a647154a0a5bb2ef781 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 18 Dec 2023 12:57:49 -0500 Subject: [PATCH] :bug: Invalidate isSameOrBefore for enddate wave (#1632) https://issues.redhat.com/browse/MTA-1815 Signed-off-by: ibolton336 --- .../components/migration-wave-form.tsx | 67 +++++++++++-------- client/src/index.tsx | 2 + 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/client/src/app/pages/migration-waves/components/migration-wave-form.tsx b/client/src/app/pages/migration-waves/components/migration-wave-form.tsx index b67ad4d42b..a7983cada7 100644 --- a/client/src/app/pages/migration-waves/components/migration-wave-form.tsx +++ b/client/src/app/pages/migration-waves/components/migration-wave-form.tsx @@ -20,6 +20,7 @@ import { useUpdateMigrationWaveMutation, } from "@app/queries/migration-waves"; import dayjs from "dayjs"; + import { Stakeholder, StakeholderGroup, @@ -268,10 +269,16 @@ export const WaveForm: React.FC = ({ }; const endDateRangeValidator = (date: Date) => { - const sDate = startDate || new Date(); - if (sDate >= date) { - return "Date is before allowable range."; + const selectedEndDate = dayjs(date); + const selectedStartDate = startDate ? dayjs(startDate) : null; + + if ( + !selectedStartDate || + selectedEndDate.isSameOrBefore(selectedStartDate, "day") + ) { + return "End date must be at least one day after the start date."; } + return ""; }; @@ -281,7 +288,8 @@ export const WaveForm: React.FC = ({ const stakeholderGroupsToRefs = (names: string[] | undefined | null) => matchItemsToRefs(stakeholderGroups, (i) => i.name, names); - const dateRef = useRef(null); + const startDateRef = useRef(null); + const endDateRef = useRef(null); return (
@@ -295,7 +303,7 @@ export const WaveForm: React.FC = ({ /> -
+
= ({ aria-label={name} onChange={(e, val) => { onChange(val); - trigger("endDateStr"); // Validation of endDateStr depends on startDateStr + trigger("endDateStr"); }} placeholder="MM/DD/YYYY" value={value} dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")} dateParse={(val) => dayjs(val).toDate()} validators={[startDateRangeValidator]} - appendTo={() => dateRef.current || document.body} + appendTo={() => startDateRef.current || document.body} /> )} /> @@ -330,30 +338,31 @@ export const WaveForm: React.FC = ({ > to - - ( - { - onChange(val); - }} - placeholder="MM/DD/YYYY" - value={value} - dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")} - dateParse={(val) => dayjs(val).toDate()} - validators={[endDateRangeValidator]} - appendTo={() => document.body} - /> - )} - /> +
+ ( + onChange(val)} + placeholder="MM/DD/YYYY" + value={value && startDate ? value : ""} + dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")} + dateParse={(val) => dayjs(val).toDate()} + validators={[endDateRangeValidator]} + appendTo={() => endDateRef.current || document.body} + /> + )} + /> +
+