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(parental-leave): Allow period that is less than 2 weeks if continuous from previos period #18260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

helgifr
Copy link
Member

@helgifr helgifr commented Mar 6, 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
    • Enhanced the parental leave form to more accurately determine the earliest allowable end date.
    • Improved leave period validation by ensuring that consecutive periods follow continuously, which helps reduce potential errors during submission.

@helgifr helgifr requested a review from a team as a code owner March 6, 2025 15:52
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request refactors the parental leave application by updating how the minimum end date is calculated and enhancing period validation. The form no longer imports a configuration value for minimum period days, instead invoking a new utility function, getMinimumEndDate. In addition, the period validation logic now imports and uses a new function, isPeriodsContinuous, to verify if consecutive periods are contiguous. Both functions are defined in the shared utility module, streamlining date calculations and improving code maintainability.

Changes

File(s) Change Summary
libs/application/templates/parental-leave/src/forms/ParentalLeaveForm.ts Removed the minPeriodDays import; replaced inline minimum date logic with a call to getMinimumEndDate.
libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts Added import and integration of isPeriodsContinuous in the validatePeriod function to check period continuity.
libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts Introduced two new functions: getMinimumEndDate for calculating the minimum end date based on periods and isPeriodsContinuous for checking if two periods are contiguous; added import for isSameDay from date-fns.

Sequence Diagram(s)

sequenceDiagram
    participant PF as ParentalLeaveForm
    participant PLU as parentalLeaveUtils
    participant IP as isPeriodsContinuous

    PF->>PLU: getMinimumEndDate(application)
    PLU->>PLU: Retrieve last two periods from application
    PLU->>IP: Check continuity between periods
    IP-->>PLU: Return boolean status
    PLU-->>PF: Return calculated minimum end date (or null)
Loading
sequenceDiagram
    participant VP as validatePeriod (Utils)
    participant PLU as parentalLeaveUtils

    VP->>PLU: isPeriodsContinuous(prevPeriod, currentPeriod)
    PLU-->>VP: Return true/false
    VP->>VP: Continue validation based on continuity result and date checks
Loading

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • ylfahfa

📜 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 1ae0cec and 7ee3a64.

📒 Files selected for processing (3)
  • libs/application/templates/parental-leave/src/forms/ParentalLeaveForm.ts (3 hunks)
  • libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts (2 hunks)
  • libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts (3 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/forms/ParentalLeaveForm.ts
  • libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts
🔇 Additional comments (6)
libs/application/templates/parental-leave/src/forms/ParentalLeaveForm.ts (1)

1535-1535: Well-structured code change using utility function.

Replacing custom implementation with getMinimumEndDate utility function enhances code modularity and maintainability.

libs/application/templates/parental-leave/src/lib/answerValidationSections/utils.ts (2)

21-23: Updated imports for new functionality.

Good addition of isPeriodsContinuous import to support the new validation logic.


260-261: Enhanced validation to support continuous periods.

Added a condition to bypass minimum period length validation when periods are continuous, which directly implements the feature from the PR title: "Allow period that is less than 2 weeks if continuous from previous period".

libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts (3)

83-83: Added necessary date utility import.

Good addition of the isSameDay import to support the new period continuity check functionality.


2216-2229: Well-implemented utility function for minimum end date calculation.

The getMinimumEndDate function properly implements logic to determine the minimum end date based on whether periods are continuous. This supports the feature allowing shorter periods when continuous from previous ones.

This function:

  1. Retrieves the last two periods from the application data
  2. Returns null if no next period exists
  3. If periods are continuous, adds just one day to the start date
  4. Otherwise, uses the standard minimum period days calculation

2231-2245: Clear and concise period continuity check implementation.

The isPeriodsContinuous function has a simple, focused implementation that checks if two periods are continuous by verifying if the previous period's end date is the day before the next period's start date.

The function:

  1. Handles null/undefined periods safely
  2. Uses isSameDay with addDays for accurate date comparison
  3. Has a clear return value indicating continuity status
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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 Mar 6, 2025

View your CI Pipeline Execution ↗ for commit 7ee3a64.

Command Status Duration Result
nx run-many --projects application-system-api -... ✅ Succeeded 6m 28s View ↗
nx run-many --target=build --projects=api --par... ✅ Succeeded 4m 30s View ↗
nx run-many --projects application-system-form,... ✅ Succeeded 4m 2s View ↗
nx run-many --target=build --projects=applicati... ✅ Succeeded 2m 33s View ↗
nx run-many --target=build --projects=applicati... ✅ Succeeded 2m 14s View ↗
nx run-many --projects api,api-domains-applicat... ✅ Succeeded 7s View ↗
nx run-many --target=lint --projects=applicatio... ✅ Succeeded 5s View ↗
nx run-many --target=build --projects=system-e2... ✅ Succeeded 4s View ↗
Additional runs (2) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-03-06 16:04:20 UTC

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.

1 participant