-
Notifications
You must be signed in to change notification settings - Fork 248
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
(fix) O3-3982: Validate against starting a visit at a future time #2013
Conversation
Hi @denniskigen here is the PR. we can follow from |
d1566bc
to
7361790
Compare
@@ -464,70 +445,66 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |||
.pipe(first()) | |||
.subscribe({ | |||
next: (response) => { | |||
if (response.status === 201) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openmrsFetch handles checking the response headers for us, so explicitly checking the status as we're doing here isn't necessary.
a4ea943
to
aa0d778
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
thanks for comments and addons @denniskigen
6ff6226
to
000bd97
Compare
@@ -121,59 +121,120 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |||
}); | |||
|
|||
const displayVisitStopDateTimeFields = useMemo( | |||
() => visitToEdit?.stopDatetime || showVisitEndDateTimeFields, | |||
() => Boolean(visitToEdit?.stopDatetime) || showVisitEndDateTimeFields, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures displayVisitStopDateTimeFields
always returns a boolean.
onChange={([date]) => onChange(date)} | ||
value={value ? dayjs(value).format('DD/MM/YYYY') : null} | ||
> | ||
<DatePickerInput | ||
id={`${dateFieldName}Input`} | ||
invalid={Boolean(errors[dateFieldName])} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invalid prop expects a boolean.
@@ -78,26 +78,24 @@ const VisitDateTimeField: React.FC<VisitDateTimeFieldProps> = ({ | |||
render={({ field: { onBlur, onChange, value } }) => ( | |||
<TimePicker | |||
id={timeFieldName} | |||
invalid={Boolean(errors[timeFieldName])} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here.
@@ -121,58 +121,73 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |||
}); | |||
|
|||
const displayVisitStopDateTimeFields = useMemo( | |||
() => visitToEdit?.stopDatetime || showVisitEndDateTimeFields, | |||
() => Boolean(visitToEdit?.stopDatetime || showVisitEndDateTimeFields), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to ensure that this variable is always a boolean.
.refine((data) => validateStartTime(data), { | ||
message: t('futureStartTime', 'Visit start time cannot be in the future'), | ||
path: ['visitStartTime'], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change. It runs whatever value gets filled into the Visit start time
input against validateStartTime
. If the start time is in the future, the validation error message above is rendered.
// TODO: Figure out why this test is failing | ||
xit('displays an error message when the visit start time is in the future', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why this test is failing. It mimics the user interaction of filling in the field with a value that ought to trigger the validation (similar to the test just above).
This PR adds validation logic that ensures a visit cannot be started at a time in the future. It does so by adding a refinement to the visitFormSchema zod schema that compares the value of the visitStartTime field with the current timestamp. If the visitStartTime is in the future, a validation error message will be shown under the field, and the form will not be submitted. The error message shown reads "Visit start time cannot be in the future". Additionally, this PR refactors the zod schema, centralizing some of the validation logic into reusable helper functions that are hopefully more easier to maintain. It also adds some test coverage for the new validation logic.
packages/esm-patient-chart-app/src/visit/visit-form/visit-date-time.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-date-time.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Outdated
Show resolved
Hide resolved
Thanks for the review, @vasharma05! |
…enmrs#2013) * (fix) O3-3982: Validate against starting a visit at a future time This PR adds validation logic that ensures a visit cannot be started at a time in the future. It does so by adding a refinement to the visitFormSchema zod schema that compares the value of the visitStartTime field with the current timestamp. If the visitStartTime is in the future, a validation error message will be shown under the field, and the form will not be submitted. The error message shown reads "Visit start time cannot be in the future". Additionally, this PR refactors the zod schema, centralizing some of the validation logic into reusable helper functions that are hopefully more easier to maintain. It also adds some test coverage for the new validation logic. * Review feedback --------- Co-authored-by: Dennis Kigen <[email protected]>
Requirements
Summary
This PR adds validation logic that ensures a visit cannot be started at a time in the future. It does so by adding a refinement to the
visitFormSchema
zod schema that compares the value of thevisitStartTime
field with the current timestamp. If thevisitStartTime
is in the future, a validation error message will be shown under the field, and the form will not be submitted. The error message shown reads "Visit start time cannot be in the future".Screenshots
visit-start-time.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-3982
Other