From 810a8e4fb69ba645c0e2b8966e0897ecb2af760c Mon Sep 17 00:00:00 2001 From: Phillip Kelly Date: Thu, 28 Dec 2023 22:59:29 -0500 Subject: [PATCH] DIG-3805: Bug Fix - In-correct Birthdate Validation --- .../src/__snapshots__/Storyshots.test.ts.snap | 18 ++++++++--------- .../inputs/MemorableDateInput.tsx | 20 +++++++++++++++---- .../__snapshots__/Storyshots.test.ts.snap | 14 ++++++------- .../birth/questions/PersonalInformation.tsx | 7 ++++--- .../registry-certs/lib/helpers.test.ts | 5 +++++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/modules-js/react-fleet/src/__snapshots__/Storyshots.test.ts.snap b/modules-js/react-fleet/src/__snapshots__/Storyshots.test.ts.snap index 1818f5171..6cc298a2c 100644 --- a/modules-js/react-fleet/src/__snapshots__/Storyshots.test.ts.snap +++ b/modules-js/react-fleet/src/__snapshots__/Storyshots.test.ts.snap @@ -2580,7 +2580,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput default 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -2624,7 +2624,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput error 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -2694,7 +2694,7 @@ exports[`Storyshots Form Elements|Inputs/TextInput variations 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -2875,7 +2875,7 @@ exports[`Storyshots Form Elements|SelectDropdown default 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -2928,7 +2928,7 @@ exports[`Storyshots Form Elements|SelectDropdown variants 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -4450,7 +4450,7 @@ exports[`Storyshots ProgressBar default 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -4511,7 +4511,7 @@ exports[`Storyshots ProgressBar first step (interactive demo) 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -4572,7 +4572,7 @@ exports[`Storyshots ProgressBar last step (interactive demo) 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -4633,7 +4633,7 @@ exports[`Storyshots ProgressBar with task name 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > diff --git a/modules-js/react-fleet/src/form-elements/inputs/MemorableDateInput.tsx b/modules-js/react-fleet/src/form-elements/inputs/MemorableDateInput.tsx index 0524353e2..f018a97c9 100644 --- a/modules-js/react-fleet/src/form-elements/inputs/MemorableDateInput.tsx +++ b/modules-js/react-fleet/src/form-elements/inputs/MemorableDateInput.tsx @@ -24,6 +24,7 @@ interface Props { handleDate: (newDate: Date | null) => void; resetDate?: boolean; disabled?: boolean; + modDateTime?: boolean; } interface State { @@ -145,7 +146,7 @@ export default class MemorableDateInput extends React.Component { // date. This lets us show the date constraints while they’re editing. lastValidityError = this.state.lastValidityError; } else { - date = fieldsToDate(fields); + date = fieldsToDate(fields, this.props.modDateTime); lastValidityError = this.isDateValid(date); if (lastValidityError) { @@ -181,7 +182,7 @@ export default class MemorableDateInput extends React.Component { // don’t disturb inputs if people temporarily make invalid dates while // editing. if (!inputCompleteError(fields)) { - const date = fieldsToDate(fields); + const date = fieldsToDate(fields, this.props.modDateTime); fields = dateToFields(date); } @@ -577,8 +578,19 @@ export function dateValidError( return errorString; } -function fieldsToDate({ year, month, day }: Fields): Date { - return new Date(Date.UTC(+year, +month - 1, +day)); +function fieldsToDate( + { year, month, day }: Fields, + modDateTime?: boolean | null +): Date { + let retDate = new Date(Date.UTC(+year, +month - 1, +day)); + + if (modDateTime && modDateTime === true) { + retDate = new Date( + new Date(Date.UTC(+year, +month - 1, 1 + +day)).setHours(0, 0, 0, 0) + ); + } + + return retDate; } function dateToFields(date: Date): Fields { diff --git a/services-js/registry-certs/client/__snapshots__/Storyshots.test.ts.snap b/services-js/registry-certs/client/__snapshots__/Storyshots.test.ts.snap index aa8274cdb..ffee63e4f 100644 --- a/services-js/registry-certs/client/__snapshots__/Storyshots.test.ts.snap +++ b/services-js/registry-certs/client/__snapshots__/Storyshots.test.ts.snap @@ -39192,7 +39192,7 @@ exports[`Storyshots Common Components/DateRangePicker default 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -39405,7 +39405,7 @@ exports[`Storyshots Common Components/DateRangePicker range too vast 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -39618,7 +39618,7 @@ exports[`Storyshots Common Components/DateRangePicker with values 1`] = ` style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -39784,7 +39784,7 @@ exports[`Storyshots Common Components/DateRangePicker/DateComponent default 1`] style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -39887,7 +39887,7 @@ exports[`Storyshots Common Components/DateRangePicker/DateComponent with values style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -41699,7 +41699,7 @@ exports[`Storyshots Common Components/Question Components/AltSpellings default 1 style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > @@ -41848,7 +41848,7 @@ exports[`Storyshots Common Components/Question Components/AltSpellings with exis style={ Object { "margin": "2rem auto", - "maxWidth": "600px", + "maxWidth": "768px", } } > diff --git a/services-js/registry-certs/client/birth/questions/PersonalInformation.tsx b/services-js/registry-certs/client/birth/questions/PersonalInformation.tsx index e9eb14901..4c843a9e0 100644 --- a/services-js/registry-certs/client/birth/questions/PersonalInformation.tsx +++ b/services-js/registry-certs/client/birth/questions/PersonalInformation.tsx @@ -131,6 +131,7 @@ export default class PersonalInformation extends Component { onlyAllowPast={true} earliestDate={EARLIEST_DATE} handleDate={this.handleDateChange} + modDateTime={true} /> @@ -145,15 +146,15 @@ export default class PersonalInformation extends Component { private renderRecentBirthWarningText(): ReactChild { const { birthCertificateRequest } = this.props; const { birthDate } = birthCertificateRequest.requestInformation; + const pickUpDate = getPickUpDate(birthDate); return (

Birth Certificate is Being Processed

Birth information takes up to two weeks to arrive from a hospital to the City of Boston. Please submit an order after{' '} - {getPickUpDate(birthDate)}. We - apologize for the inconvenience. If you have any questions or - concerns, please{' '} + {pickUpDate}. We apologize for + the inconvenience. If you have any questions or concerns, please{' '} { const expect12152023: Date = new Date('Mon Dec 01 2023'); expect(getPickUpDate(expect12152023)).toBe('12/15/2023'); }); + + it('Registry Cert Pickup Date - 12/18/2023 + 14 days = 01/01/2024', () => { + const expect01012024: Date = new Date('Mon Dec 18 2023'); + expect(getPickUpDate(expect01012024)).toBe('1/1/2024'); + }); });