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

fix/O3-3983: Allow Same-Day Program Enrollment and Completion #2039

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jwnasambu
Copy link
Contributor

@jwnasambu jwnasambu commented Sep 26, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

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

@jwnasambu
Copy link
Contributor Author

@brandones, @denniskigen, @ibacher I kindly request your guidance to ensure that the form is submitted successfully.

@jwnasambu jwnasambu marked this pull request as draft September 27, 2024 14:12
@jwnasambu jwnasambu marked this pull request as ready for review October 11, 2024 09:05
@brandones
Copy link
Contributor

What's the status of this?

@denniskigen denniskigen self-assigned this Dec 9, 2024
@jwnasambu
Copy link
Contributor Author

@denniskigen, kindly help review my PR at your convenience time, please?

@Muppasanipraneeth
Copy link
Contributor

Muppasanipraneeth commented Feb 3, 2025

  • I guess we can improve Form Validation and Error Handling
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(),
  
  });

@jwnasambu jwnasambu marked this pull request as draft February 3, 2025 20:52
@denniskigen denniskigen removed their assignment Feb 5, 2025
if (selectedDate.toDateString() === today.toDateString()) {
onChange(new Date());
} else {
selectedDate.setUTCHours(23, 59, 59, 999);
Copy link
Contributor

@Muppasanipraneeth Muppasanipraneeth Feb 7, 2025

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);

Copy link
Contributor

@Muppasanipraneeth Muppasanipraneeth Feb 7, 2025

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 @denniskigen correct me if I am wrong when we use selectedDate.setUTCHours(23, 59, 59, 999); we can observe its new day for us

const updatedDateTime = new Date(date);
updatedDateTime.setHours(hours);
updatedDateTime.setMinutes(minutes);
control.setValue('enrollmentDate', updatedDateTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

setValue('enrollmentDate', updatedDateTime);

Comment on lines +243 to +254
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);
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants