Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-3632 - Add config for maxDate and minDate to DateObsField #1261

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/esm-patient-registration-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Type, validator, validators } from '@openmrs/esm-framework';
import _default from 'yup/lib/locale';

export interface SectionDefinition {
id: string;
Expand All @@ -12,7 +13,8 @@ export interface FieldDefinition {
label?: string;
uuid: string;
placeholder?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well remove placeholder here too? Also, these should be removed from the actual config schema and not just the types.

dateFormat?: string;
allowFutureDates?: boolean;
allowPastDates?: boolean;
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified the type but you have not modified the actual config schema.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must modify the actual config schema; there should be a console warning about that visible in the browser console logs. Please use the browser console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

showHeading: boolean;
validation?: {
required: boolean;
Expand Down Expand Up @@ -176,6 +178,16 @@ export const esmPatientRegistrationSchema = {
_default: '',
_description: 'Placeholder that will appear in the input.',
},
allowFutureDates: {
_type: Type.Boolean,
_default: true,
_description: 'Indicates whether the date input field should allow the selection of future dates or not.',
},
allowPastDates: {
_type: Type.Boolean,
_default: true,
_description: 'Indicates whether the date input field should allow the selection of past dates or not.',
},
validation: {
required: { _type: Type.Boolean, _default: false },
matches: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function ObsField({ fieldDefinition }: ObsFieldProps) {
concept={concept}
label={fieldDefinition.label}
required={fieldDefinition.validation.required}
dateFormat={fieldDefinition.dateFormat}
placeholder={fieldDefinition.placeholder}
allowPastDates={fieldDefinition.allowPastDates}
allowFutureDates={fieldDefinition.allowFutureDates}
/>
);
case 'Coded':
Expand Down Expand Up @@ -159,14 +159,16 @@ interface DateObsFieldProps {
concept: ConceptResponse;
label: string;
required?: boolean;
dateFormat?: string;
placeholder?: string;
allowPastDates?: boolean;
allowFutureDates?: boolean;
}

function DateObsField({ concept, label, required, placeholder }: DateObsFieldProps) {
function DateObsField({ concept, label, required, allowPastDates, allowFutureDates }: DateObsFieldProps) {
const { t } = useTranslation();
const fieldName = `obs.${concept.uuid}`;
const { setFieldValue } = useContext(PatientRegistrationContext);
const futureDatesAllowed = allowFutureDates ?? true;
const pastDatesAllowed = allowPastDates ?? true;

const onDateChange = (date: Date) => {
setFieldValue(fieldName, date);
Expand All @@ -188,6 +190,8 @@ function DateObsField({ concept, label, required, placeholder }: DateObsFieldPro
isInvalid={errors[fieldName] && touched[fieldName]}
invalidText={t(meta.error)}
value={field.value}
minDate={!pastDatesAllowed ? new Date() : undefined}
maxDate={!futureDatesAllowed ? new Date() : undefined}
/>
</>
);
Expand Down
Loading