Skip to content

Commit c24a4b2

Browse files
committed
🐛 Invalidate isSameOrBefore for enddate wave
Signed-off-by: ibolton336 <[email protected]>
1 parent 67ab924 commit c24a4b2

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

client/src/app/pages/migration-waves/components/migration-wave-form.tsx

+38-29
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
useUpdateMigrationWaveMutation,
2121
} from "@app/queries/migration-waves";
2222
import dayjs from "dayjs";
23+
2324
import {
2425
Stakeholder,
2526
StakeholderGroup,
@@ -268,10 +269,16 @@ export const WaveForm: React.FC<WaveFormProps> = ({
268269
};
269270

270271
const endDateRangeValidator = (date: Date) => {
271-
const sDate = startDate || new Date();
272-
if (sDate >= date) {
273-
return "Date is before allowable range.";
272+
const selectedEndDate = dayjs(date);
273+
const selectedStartDate = startDate ? dayjs(startDate) : null;
274+
275+
if (
276+
!selectedStartDate ||
277+
selectedEndDate.isSameOrBefore(selectedStartDate, "day")
278+
) {
279+
return "End date must be at least one day after the start date.";
274280
}
281+
275282
return "";
276283
};
277284

@@ -281,7 +288,8 @@ export const WaveForm: React.FC<WaveFormProps> = ({
281288
const stakeholderGroupsToRefs = (names: string[] | undefined | null) =>
282289
matchItemsToRefs(stakeholderGroups, (i) => i.name, names);
283290

284-
const dateRef = useRef<HTMLDivElement | null>(null);
291+
const startDateRef = useRef<HTMLDivElement | null>(null);
292+
const endDateRef = useRef<HTMLDivElement | null>(null);
285293

286294
return (
287295
<Form onSubmit={handleSubmit(onSubmit)}>
@@ -295,7 +303,7 @@ export const WaveForm: React.FC<WaveFormProps> = ({
295303
/>
296304
</GridItem>
297305
<GridItem span={3}>
298-
<div ref={dateRef}>
306+
<div ref={startDateRef}>
299307
<HookFormPFGroupController
300308
control={control}
301309
name="startDateStr"
@@ -307,14 +315,14 @@ export const WaveForm: React.FC<WaveFormProps> = ({
307315
aria-label={name}
308316
onChange={(e, val) => {
309317
onChange(val);
310-
trigger("endDateStr"); // Validation of endDateStr depends on startDateStr
318+
trigger("endDateStr");
311319
}}
312320
placeholder="MM/DD/YYYY"
313321
value={value}
314322
dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")}
315323
dateParse={(val) => dayjs(val).toDate()}
316324
validators={[startDateRangeValidator]}
317-
appendTo={() => dateRef.current || document.body}
325+
appendTo={() => startDateRef.current || document.body}
318326
/>
319327
)}
320328
/>
@@ -330,30 +338,31 @@ export const WaveForm: React.FC<WaveFormProps> = ({
330338
>
331339
to
332340
</GridItem>
333-
334341
<GridItem span={8}>
335-
<HookFormPFGroupController
336-
control={control}
337-
name="endDateStr"
338-
label="Potential End Date"
339-
fieldId="endDateStr"
340-
isRequired
341-
renderInput={({ field: { value, name, onChange } }) => (
342-
<DatePicker
343-
aria-label={name}
344-
onChange={(e, val) => {
345-
onChange(val);
346-
}}
347-
placeholder="MM/DD/YYYY"
348-
value={value}
349-
dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")}
350-
dateParse={(val) => dayjs(val).toDate()}
351-
validators={[endDateRangeValidator]}
352-
appendTo={() => document.body}
353-
/>
354-
)}
355-
/>
342+
<div ref={endDateRef}>
343+
<HookFormPFGroupController
344+
control={control}
345+
name="endDateStr"
346+
label="Potential End Date"
347+
fieldId="endDateStr"
348+
isRequired
349+
renderInput={({ field: { value, name, onChange } }) => (
350+
<DatePicker
351+
isDisabled={!startDate}
352+
aria-label={name}
353+
onChange={(e, val) => onChange(val)}
354+
placeholder="MM/DD/YYYY"
355+
value={value && startDate ? value : ""}
356+
dateFormat={(val) => dayjs(val).format("MM/DD/YYYY")}
357+
dateParse={(val) => dayjs(val).toDate()}
358+
validators={[endDateRangeValidator]}
359+
appendTo={() => endDateRef.current || document.body}
360+
/>
361+
)}
362+
/>
363+
</div>
356364
</GridItem>
365+
357366
<GridItem span={12}>
358367
<HookFormPFGroupController
359368
control={control}

client/src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import App from "@app/App";
88
import reportWebVitals from "@app/reportWebVitals";
99
import { KeycloakProvider } from "@app/components/KeycloakProvider";
1010
import dayjs from "dayjs";
11+
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
1112
import utc from "dayjs/plugin/utc";
1213
import timezone from "dayjs/plugin/timezone";
1314
import customParseFormat from "dayjs/plugin/customParseFormat";
1415

1516
dayjs.extend(utc);
1617
dayjs.extend(timezone);
1718
dayjs.extend(customParseFormat);
19+
dayjs.extend(isSameOrBefore);
1820

1921
const queryClient = new QueryClient();
2022

0 commit comments

Comments
 (0)