Skip to content

Commit 4359e8e

Browse files
authored
Merge pull request #4354 from openmsupply/#4350-unable-to-create-patient
DOB Defaults
2 parents 4d3a1dd + cc99e09 commit 4359e8e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/utilities/formInputConfigs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const FORM_INPUT_CONFIGS = seedObject => ({
121121
},
122122
[FORM_INPUT_KEYS.DATE_OF_BIRTH]: {
123123
type: FORM_INPUT_TYPES.DATE_OF_BIRTH,
124-
initialValue: new Date(),
124+
initialValue: '',
125125
key: 'dateOfBirth',
126126
invalidMessage: formInputStrings.must_be_a_date,
127127
isRequired: true,

src/widgets/FormInputs/FormDOBInput.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { FormLabel } from './FormLabel';
1616
import { FormInvalidMessage } from './FormInvalidMessage';
1717
import { DATE_FORMAT } from '../../utilities/constants';
1818

19-
const calculateAge = dob => `${Math.floor(moment().diff(dob, 'years', true))}`;
19+
const calculateAge = dob => (!dob ? '' : `${Math.floor(moment().diff(dob, 'years', true))}`);
2020

2121
const Action = {
2222
toggleDatePicker: 'toggleDatePicker',
@@ -31,9 +31,9 @@ const Action = {
3131
const initialState = (seedDate, isValid) => ({
3232
isValid, // If the date is a valid date
3333
datePickerOpen: false,
34-
pickerValue: seedDate.toDate(),
34+
pickerValue: seedDate?.toDate() || new Date(),
3535
ageValue: calculateAge(seedDate),
36-
textInputValue: seedDate.format(DATE_FORMAT.DD_MM_YYYY),
36+
textInputValue: seedDate ? seedDate.format(DATE_FORMAT.DD_MM_YYYY) : '',
3737
});
3838

3939
const reducer = (state, action) => {
@@ -161,7 +161,7 @@ export const FormDOBInput = React.forwardRef(
161161
const [
162162
{ datePickerOpen, isValid, pickerValue, ageValue, textInputValue },
163163
{ toggleDatePicker, onPickDate, onTypeDate, onTypeAge },
164-
] = useDobInput(moment(value ?? new Date()), onChangeDate, onValidate);
164+
] = useDobInput(value ? moment(value) : undefined, onChangeDate, onValidate);
165165

166166
return (
167167
<>

0 commit comments

Comments
 (0)