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(parental-leave): User will not be able to choose endDate on child's 2nd birthday #18103

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

helgifr
Copy link
Member

@helgifr helgifr commented Feb 25, 2025

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features
    • Introduced dynamic date calculations in the parental leave form, offering a more intuitive period end date selection based on expected arrival or adoption dates.
  • Bug Fixes
    • Refined date validation to correctly accept an end date that matches the calculated maximum threshold, ensuring smoother form submissions.

@helgifr helgifr requested a review from a team as a code owner February 25, 2025 10:14
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Walkthrough

The changes enhance date-related logic in a parental leave application. In the PeriodEndDate component, new utility functions and constants are imported to compute an expected date and calculate a dynamic maximum end date for the leave period. The DateFormField component now receives the computed maximum date as a property. Additionally, the date validation logic in the validatePeriod function has been modified to use an inclusive comparison (greater than or equal) for the maximum date check.

Changes

File(s) Change Summary
libs/.../PeriodEndDate.tsx, ../../lib/parentalLeaveUtils, ../../config Imported new utility functions and constants; defined expectedDateOfBirthOrAdoptionDateOrBirthDate and computed dob; calculated maximumEndDate by adding months and subtracting a day; updated the maxDate prop in DateFormField.
libs/.../answerValidationSections/utils.ts Modified the condition in validatePeriod to check if the end date is greater than or equal to maximumEndDate and consolidated import statements.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant PeriodEndDate
  participant DateFormField
  participant Validator

  User->>PeriodEndDate: Render component
  PeriodEndDate->>Utility: Retrieve expected date (getExpectedDateOfBirthOrAdoptionDateOrBirthDate)
  Utility-->>PeriodEndDate: Return expected date -> parse to dob
  PeriodEndDate->>Utility: Calculate maximumEndDate (addMonths & addDays)
  Utility-->>PeriodEndDate: Return maximumEndDate
  PeriodEndDate->>DateFormField: Set maxDate attribute
  User->>DateFormField: Input end date
  DateFormField->>Validator: Validate end date (check >= maximumEndDate)
  Validator-->>DateFormField: Return validation result
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • ylfahfa
  • birkirkristmunds

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64689a9 and e060c84.

📒 Files selected for processing (2)
  • libs/application/templates/parental-leave/src/fields/PeriodEndDate/PeriodEndDate.tsx (3 hunks)
  • libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`libs/**/*`: "Confirm that the code adheres to the following...

libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
  • libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts
  • libs/application/templates/parental-leave/src/fields/PeriodEndDate/PeriodEndDate.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare / install
🔇 Additional comments (5)
libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts (2)

19-19: Improved import organization

Good job consolidating related imports from the same file into a single import statement. This makes the code more concise and easier to maintain.


231-231:

❓ Verification inconclusive

Changed condition to prevent selecting the child's 2nd birthday

The validation now rejects end dates that are equal to or greater than the maximum end date, rather than just those greater than the maximum. This aligns with the PR objective to prevent users from selecting the child's 2nd birthday as the end date.

However, there's a subtle inconsistency between this file and PeriodEndDate.tsx. In this file, maximumEndDate is defined as exactly the child's 2nd birthday (line 143: const maximumEndDate = addMonths(dob, usageMaxMonths)), while in PeriodEndDate.tsx it's calculated as the day before the 2nd birthday. Consider aligning these calculations.


🏁 Script executed:

#!/bin/bash
# Look for other occurrences of maximumEndDate calculation
rg "maximumEndDate.*=.*addMonths" -A 2 -B 2

Length of output: 671


Action Required: Align End Date Calculation Between Modules
The search confirms that in libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts the maximumEndDate is defined directly as the child's 2nd birthday via const maximumEndDate = addMonths(dob, usageMaxMonths). However, as noted, the PeriodEndDate.tsx module calculates the end date as the day before the 2nd birthday. Please consider aligning the logic between these two modules to maintain consistency.

  • Location:
    • utils.ts (line 143): const maximumEndDate = addMonths(dob, usageMaxMonths)
    • Action: Update one of the calculations to match the other (either subtracting a day in utils.ts or revising the calculation in PeriodEndDate.tsx).
libs/application/templates/parental-leave/src/fields/PeriodEndDate/PeriodEndDate.tsx (3)

28-32: Good use of date-fns utility functions

The added imports provide the necessary functionality for date calculations and parsing. Using date-fns utility functions follows good practices for handling dates in JavaScript.


58-67: Robust calculation of the maximum end date

The implementation properly handles the case when the date of birth is not available by setting maximumEndDate to undefined. The comment "Day before child becomes 2 years old" clearly explains the intent of this calculation.

The maximumEndDate is calculated as one day before the child's second birthday, which aligns with the PR objective of preventing users from selecting the child's 2nd birthday as the end date.


100-100: Correctly applied the maxDate restriction

The DateFormField now receives the computed maximumEndDate, which will prevent users from selecting dates beyond the allowed range in the UI.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Feb 25, 2025

View your CI Pipeline Execution ↗ for commit e060c84.

Command Status Duration Result
nx run-many --projects application-system-api -... ✅ Succeeded 16m 21s View ↗
nx run-many --projects application-system-form,... ✅ Succeeded 5m 16s View ↗
nx run-many --target=build --projects=applicati... ✅ Succeeded 2m 22s View ↗
nx run-many --target=build --projects=api --par... ✅ Succeeded 3m 34s View ↗
nx run-many --target=build --projects=applicati... ✅ Succeeded 1m 36s View ↗
nx run-many --target=build --projects=system-e2... ✅ Succeeded 5s View ↗
nx run-many --target=lint --projects=applicatio... ✅ Succeeded 11s View ↗
nx run-many --projects api,api-domains-applicat... ✅ Succeeded 13s View ↗
Additional runs (2) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-25 10:39:53 UTC

@helgifr helgifr enabled auto-merge February 25, 2025 10:35
Copy link
Member

@ylfahfa ylfahfa left a comment

Choose a reason for hiding this comment

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

lgtm 🌟

@helgifr helgifr added this pull request to the merge queue Feb 25, 2025
Merged via the queue into main with commit b2358ac Feb 25, 2025
39 checks passed
@helgifr helgifr deleted the fix/child-2nd-birthday-endDate branch February 25, 2025 11:24
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.

2 participants