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

User Availabilities Exception related fixes #9977

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

rithviknishad
Copy link
Member

@rithviknishad rithviknishad commented Jan 15, 2025

Proposed Changes

image

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Release Notes

  • Localization

    • Added new translation keys for exceptions and session slots.
    • Enhanced internationalization support across scheduling components.
  • New Features

    • Improved query parameter management for scheduling sheets.
    • Added advanced slot computation for scheduling availability.
    • Enhanced date validation for schedule exceptions and templates.
  • Improvements

    • Refined user availability tab functionality.
    • Updated scheduling component state management.
    • Improved handling of scheduling exceptions and time slots.

…te; wire add exception button; fix same day exception validation;
Copy link

netlify bot commented Jan 15, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 6cffa9c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/678789b70c88d90008f96e7d
😎 Deploy Preview https://deploy-preview-9977--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@rithviknishad rithviknishad changed the title Exception related fixes User Availabilities Exception related fixes Jan 15, 2025
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces enhancements to the scheduling and exception handling functionality across multiple components. The changes focus on improving internationalization, query parameter management, and slot computation. Key modifications include updating localization files, refactoring components to use query parameters for state management, and implementing a new function to compute appointment slots while considering exceptions.

Changes

File Change Summary
public/locale/en.json Added new translation keys for exceptions and session slot information; modified existing entry for session slots.
src/components/Users/UserAvailabilityTab.tsx Updated query parameters, added internationalization support, enhanced availability and exception rendering.
src/pages/Scheduling/components/CreateScheduleExceptionSheet.tsx Improved date validation logic, query parameter management, and sheet state control.
src/pages/Scheduling/components/CreateScheduleTemplateSheet.tsx Modified query parameter handling, date validation, and sheet visibility management.
src/pages/Scheduling/utils.ts Added computeAppointmentSlots function, new type VirtualSlot, and updated imports.

Assessment against linked issues

Objective Addressed Explanation
Add exception button not working
Strike off schedule details for dates with exceptions

Possibly related PRs

Suggested labels

tested, P1

Suggested reviewers

  • Jacobjeevan
  • bodhish

Poem

🐰 Slots and exceptions dance with grace,
Code hops through time and space,
Calendars bloom with newfound might,
Scheduling magic takes its flight!
A rabbit's code, precise and neat 🗓️

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

cypress bot commented Jan 15, 2025

CARE    Run #4326

Run Properties:  status check passed Passed #4326  •  git commit 6cffa9cd4c: User Availabilities Exception related fixes
Project CARE
Branch Review rithviknishad/fix/9959-issues-in-exceptions
Run status status check passed Passed #4326
Run duration 01m 45s
Commit git commit 6cffa9cd4c: User Availabilities Exception related fixes
Committer Rithvik Nishad
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

Copy link

cloudflare-workers-and-pages bot commented Jan 15, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6cffa9c
Status: ✅  Deploy successful!
Preview URL: https://e25b7435.care-fe.pages.dev
Branch Preview URL: https://rithviknishad-fix-9959-issue.care-fe.pages.dev

View logs

@rithviknishad rithviknishad marked this pull request as ready for review January 15, 2025 07:54
@rithviknishad rithviknishad requested a review from a team as a code owner January 15, 2025 07:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/pages/Scheduling/components/CreateScheduleExceptionSheet.tsx (1)

109-119: Consider combining the useEffect hooks.

The two useEffect hooks for form value updates can be combined to reduce the number of re-renders.

Apply this diff to combine the hooks:

-  useEffect(() => {
-    if (qParams.valid_from) {
-      form.setValue("valid_from", new Date(qParams.valid_from));
-    }
-  }, [qParams.valid_from, form]);
-
-  useEffect(() => {
-    if (qParams.valid_to) {
-      form.setValue("valid_to", new Date(qParams.valid_to));
-    }
-  }, [qParams.valid_to, form]);
+  useEffect(() => {
+    if (qParams.valid_from) {
+      form.setValue("valid_from", new Date(qParams.valid_from));
+    }
+    if (qParams.valid_to) {
+      form.setValue("valid_to", new Date(qParams.valid_to));
+    }
+  }, [qParams.valid_from, qParams.valid_to, form]);
src/components/Users/UserAvailabilityTab.tsx (1)

51-53: Consider using qParams.tab directly.

Instead of creating a new variable view, consider using qParams.tab directly to reduce potential synchronization issues.

Apply this diff to remove the redundant variable:

-  const view = qParams.tab || "schedule";
+  const currentTab = qParams.tab ?? "schedule";

Then update all occurrences of view to currentTab.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe50f07 and 964d5f6.

📒 Files selected for processing (5)
  • public/locale/en.json (2 hunks)
  • src/components/Users/UserAvailabilityTab.tsx (6 hunks)
  • src/pages/Scheduling/components/CreateScheduleExceptionSheet.tsx (6 hunks)
  • src/pages/Scheduling/components/CreateScheduleTemplateSheet.tsx (6 hunks)
  • src/pages/Scheduling/utils.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (15)
src/pages/Scheduling/utils.ts (1)

45-48: LGTM!

The type definition is clear and correctly structured with the required fields.

src/pages/Scheduling/components/CreateScheduleExceptionSheet.tsx (4)

45-49: LGTM!

The QueryParams type is well-defined with appropriate optional parameters.


59-61: LGTM!

Good use of replace: false to merge with existing query params, and the comment clearly explains the reasoning.


92-95: LGTM!

The date validation is more intuitive using isAfter, and the error is correctly mapped to the valid_from field.


159-167: LGTM!

The sheet state is correctly managed through URL parameters, with proper cleanup on close.

src/components/Users/UserAvailabilityTab.tsx (3)

44-47: LGTM!

The AvailabilityTabQueryParams type is well-defined with appropriate optional parameters.


162-174: LGTM!

The "Add Exception" button correctly sets query parameters and uses dateQueryString for consistent date formatting.


261-284: LGTM!

The exception display is well-implemented with clear visual indication using diagonal stripes and proper time formatting.

src/pages/Scheduling/components/CreateScheduleTemplateSheet.tsx (4)

62-64: LGTM!

The QueryParams type is well-defined with appropriate optional parameters.


74-76: LGTM!

Good use of replace: false to merge with existing query params, and the comment clearly explains the reasoning.


147-150: LGTM!

The date validation is more intuitive using isAfter, and the error is correctly mapped to the valid_from field.


246-251: LGTM!

The sheet state is correctly managed through URL parameters, with proper cleanup on close.

public/locale/en.json (3)

982-982: LGTM! Clear and consistent translation key.

The translation follows the established naming and capitalization patterns in the file.


1882-1882: LGTM! Clear slot information format.

The translation uses proper interpolation syntax and follows consistent terminology.


1883-1883: Consider HTML sanitization for the strike-through tag.

While the translation is well-formatted and consistent, ensure that the HTML <s> tag is properly sanitized when rendered to prevent XSS vulnerabilities.

src/pages/Scheduling/utils.ts Outdated Show resolved Hide resolved
src/components/Users/UserAvailabilityTab.tsx Outdated Show resolved Hide resolved
@rithviknishad rithviknishad self-assigned this Jan 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Users/UserAvailabilityTab.tsx (2)

357-357: Address the TODO comment for handling multiple days of the week.

The comment indicates that multiple days of the week handling is pending implementation.

Would you like me to help implement the multiple days of week handling or create a GitHub issue to track this task?


336-436: Consider extracting appointment-specific logic into a separate component.

The component handles both regular and appointment slot types. Consider extracting the appointment-specific logic (lines 365-432) into a separate AppointmentAvailabilityDetails component for better maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 964d5f6 and 6cffa9c.

📒 Files selected for processing (2)
  • src/components/Users/UserAvailabilityTab.tsx (6 hunks)
  • src/pages/Scheduling/utils.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Users/UserAvailabilityTab.tsx (1)
Learnt from: rithviknishad
PR: ohcnetwork/care_fe#9977
File: src/components/Users/UserAvailabilityTab.tsx:193-251
Timestamp: 2025-01-15T08:13:18.414Z
Learning: The `computeAppointmentSlots` function in scheduling utils is efficient enough for real-world scenarios without memoization, as it has linear complexity based on the number of slots in a day, not the number of exceptions.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (7)
src/pages/Scheduling/utils.ts (4)

1-14: LGTM!

The imports are well-organized and all imported functions are utilized effectively in the implementation.


45-50: LGTM!

The VirtualSlot type is well-designed, providing a clear structure for appointment slots with proper tracking of availability and associated exceptions.


126-126: LGTM!

Good addition of Math.floor to ensure slot counts are always whole numbers.


52-117: 🛠️ Refactor suggestion

Add input validation to prevent runtime errors.

The function should validate its inputs before processing:

  1. Check if availability.availability[0] exists
  2. Validate slot_size_in_minutes is positive

Apply this diff to add the necessary validations:

 export function computeAppointmentSlots(
   availability: ScheduleAvailability & { slot_type: "appointment" },
   exceptions: ScheduleException[],
   referenceDate: Date = new Date(),
 ) {
+  if (!availability.availability[0]) {
+    throw new Error("Availability must have at least one time slot");
+  }
+
+  if (!availability.slot_size_in_minutes || availability.slot_size_in_minutes <= 0) {
+    throw new Error("Invalid slot size");
+  }
+
   const startTime = parse(
     availability.availability[0].start_time,
     "HH:mm:ss",
     referenceDate,
   );
⛔ Skipped due to learnings
Learnt from: rithviknishad
PR: ohcnetwork/care_fe#9977
File: src/components/Users/UserAvailabilityTab.tsx:193-251
Timestamp: 2025-01-15T08:13:18.414Z
Learning: The `computeAppointmentSlots` function in scheduling utils is efficient enough for real-world scenarios without memoization, as it has linear complexity based on the number of slots in a day, not the number of exceptions.
src/components/Users/UserAvailabilityTab.tsx (3)

Line range hint 1-60: LGTM!

The imports are well-organized and the query parameter types are properly defined with clear type constraints.


64-66: LGTM!

Good implementation of internationalization and consistent naming with the tab parameter.


246-334: LGTM!

The DayDetailsPopover component is well-implemented with proper separation of concerns and good handling of overflow content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review required
Development

Successfully merging this pull request may close these issues.

Add exception button is not working in calendar view of schedule template page
2 participants