Skip to content

Commit

Permalink
(chore): Update OpenmrsDatePicker props (#1262)
Browse files Browse the repository at this point in the history
* (chore): Update OpenmrsDatePicker props

* (chore): Remove unused import
  • Loading branch information
NethmiRodrigo authored and brandones committed Aug 1, 2024
1 parent c9001c3 commit 1f90f96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { type ChangeEvent, useCallback, useContext } from 'react';
import { ContentSwitcher, Layer, Switch, TextInput } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { useField } from 'formik';
import { type CalendarDate, getLocalTimeZone } from '@internationalized/date';
import { PatientRegistrationContext } from '../../patient-registration-context';
import { OpenmrsDatePicker, useConfig } from '@openmrs/esm-framework';
import { type RegistrationConfig } from '../../../config-schema';
Expand Down Expand Up @@ -106,6 +105,7 @@ export const DobField: React.FC = () => {
onChange={onDateChange}
maxDate={today}
labelText={t('dateOfBirthLabelText', 'Date of Birth')}
isInvalid={!!(birthdateMeta.touched && birthdateMeta.error)}
invalidText={t(birthdateMeta.error)}
value={birthdate.value}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ function DateObsField({ concept, label, required, placeholder }: DateObsFieldPro
const fieldName = `obs.${concept.uuid}`;
const { setFieldValue } = useContext(PatientRegistrationContext);

const onDateChange = ([date]) => {
const refinedDate = date instanceof Date ? new Date(date.setHours(0, 0, 0, 0)) : new Date(date);
setFieldValue(fieldName, refinedDate);
const onDateChange = (date: Date) => {
setFieldValue(fieldName, date);
};

return (
Expand All @@ -184,14 +183,12 @@ function DateObsField({ concept, label, required, placeholder }: DateObsFieldPro
id={fieldName}
{...field}
isRequired={required}
onChange={(date) => onDateChange([date])}
onChange={onDateChange}
labelText={label ?? concept.display}
isInvalid={errors[fieldName] && touched[fieldName]}
invalidText={t(meta.error)}
value={field.value}
/>
{errors[fieldName] && touched[fieldName] && (
<div className={styles.radioFieldError}>{meta.error && t(meta.error)}</div>
)}
</>
);
}}
Expand Down

0 comments on commit 1f90f96

Please sign in to comment.