-
Notifications
You must be signed in to change notification settings - Fork 250
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-3983: Allow Same-Day Program Enrollment and Completion #2039
base: main
Are you sure you want to change the base?
Conversation
@brandones, @denniskigen, @ibacher I kindly request your guidance to ensure that the form is submitted successfully. |
What's the status of this? |
9ac0687
to
2d78f5a
Compare
@denniskigen, kindly help review my PR at your convenience time, please? |
const createProgramsFormSchema = (t: TFunction) =>
z.object({
selectedProgram: z.string().trim().min(1, t('programRequired', 'Program is required')),
enrollmentDate: z.date()
.max(new Date(), t('enrollmentDateFuture', 'Enrollment date cannot be in the future')),
completionDate: z.date().nullable(),
enrollmentLocation: z.string().
trim().min(1, t('locationRequired', 'Location is required')),
selectedProgramStatus: z.string(),
}); |
packages/esm-patient-programs-app/src/programs/programs-form.workspace.tsx
Outdated
Show resolved
Hide resolved
if (selectedDate.toDateString() === today.toDateString()) { | ||
onChange(new Date()); | ||
} else { | ||
selectedDate.setUTCHours(23, 59, 59, 999); |
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.
selectedDate.setHours(23, 59, 59, 999);
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.
![Screenshot 2025-02-07 at 8 35 58 AM](https://private-user-images.githubusercontent.com/141117659/410740806-f92fc4da-c2d3-43a0-b4d1-60aeead7526a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMzU1NzAsIm5iZiI6MTczOTAzNTI3MCwicGF0aCI6Ii8xNDExMTc2NTkvNDEwNzQwODA2LWY5MmZjNGRhLWMyZDMtNDNhMC1iNGQxLTYwYWVlYWQ3NTI2YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOFQxNzIxMTBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jYWEwZmMzNDNiMDA0NWI1YmQ1NTdlMzA0MjVlZGZmYjQ1ZjMwNmYxMDFmZTJjODQ1MmI3ZTA1OTZjYTQxN2YxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.VTPvLUwu10kjqpw_fgYJmtk3T6F-ljFyC1OUcx96AY8)
const updatedDateTime = new Date(date); | ||
updatedDateTime.setHours(hours); | ||
updatedDateTime.setMinutes(minutes); | ||
control.setValue('enrollmentDate', updatedDateTime); |
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.
setValue('enrollmentDate', updatedDateTime);
render={({ field: { onChange, value } }) => { | ||
const handleChange = ([date]) => { | ||
if (!date) return; | ||
|
||
const selectedDate = new Date(date); | ||
const today = new Date(); | ||
today.setHours(0, 0, 0, 0); | ||
|
||
if (selectedDate.toDateString() === today.toDateString()) { | ||
onChange(new Date()); | ||
} else { | ||
selectedDate.setUTCHours(23, 59, 59, 999); |
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.
handleChange should be moved outside of render to prevent it from being recreated on every render.
Requirements
Summary
I fixed the minimum selectable date for the completion date in the date picker to equal to the enrollment date set to midnight preventing the selection of an invalid date range where a completion date could occur before the enrollment date. I also modified the schema to allow completionDate to be equal to enrollmentDate.
Screenshots
screencast.2025-02-03.3.AM-47-12.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-3983
Other