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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion packages/esm-patient-registration-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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;
showHeading: boolean;
validation?: {
required: boolean;
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