@@ -16,7 +16,7 @@ import { FormLabel } from './FormLabel';
16
16
import { FormInvalidMessage } from './FormInvalidMessage' ;
17
17
import { DATE_FORMAT } from '../../utilities/constants' ;
18
18
19
- const calculateAge = dob => `${ Math . floor ( moment ( ) . diff ( dob , 'years' , true ) ) } ` ;
19
+ const calculateAge = dob => ( ! dob ? '' : `${ Math . floor ( moment ( ) . diff ( dob , 'years' , true ) ) } ` ) ;
20
20
21
21
const Action = {
22
22
toggleDatePicker : 'toggleDatePicker' ,
@@ -31,9 +31,9 @@ const Action = {
31
31
const initialState = ( seedDate , isValid ) => ( {
32
32
isValid, // If the date is a valid date
33
33
datePickerOpen : false ,
34
- pickerValue : seedDate . toDate ( ) ,
34
+ pickerValue : seedDate ? .toDate ( ) || new Date ( ) ,
35
35
ageValue : calculateAge ( seedDate ) ,
36
- textInputValue : seedDate . format ( DATE_FORMAT . DD_MM_YYYY ) ,
36
+ textInputValue : seedDate ? seedDate . format ( DATE_FORMAT . DD_MM_YYYY ) : '' ,
37
37
} ) ;
38
38
39
39
const reducer = ( state , action ) => {
@@ -161,7 +161,7 @@ export const FormDOBInput = React.forwardRef(
161
161
const [
162
162
{ datePickerOpen, isValid, pickerValue, ageValue, textInputValue } ,
163
163
{ toggleDatePicker, onPickDate, onTypeDate, onTypeAge } ,
164
- ] = useDobInput ( moment ( value ?? new Date ( ) ) , onChangeDate , onValidate ) ;
164
+ ] = useDobInput ( value ? moment ( value ) : undefined , onChangeDate , onValidate ) ;
165
165
166
166
return (
167
167
< >
0 commit comments