Skip to content

feat: A new feature auto-referesh slots on timezone change #22455

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Vansh5632
Copy link
Contributor

@Vansh5632 Vansh5632 commented Jul 13, 2025

What does this PR do?

Fixes an issue where available time slots were not refreshing when users changed their timezone in events with restriction schedules enabled.

##Video

Screencast.from.2025-07-15.15-07-39.mp4

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox. N/A
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Create an event type with:
    • Restriction schedule enabled (restrictionScheduleId set)
    • "Use booker's timezone" option enabled (useBookerTimezone: true)
  2. Open the booking page
  3. Change the timezone using the timezone selector
  4. Verify that available time slots refresh automatically
  5. Test edge cases:
    • Events without restriction schedules (should NOT refresh)
    • Events with useBookerTimezone: false (should NOT refresh

Summary by cubic

Time slots now refresh automatically when users change their timezone on booking pages with restriction schedules and "use booker's timezone" enabled, matching CAL-6060 requirements.

  • New Features
    • Detects timezone changes and refreshes available slots only when both restriction schedules and booker's timezone are active.

Copy link

vercel bot commented Jul 13, 2025

@Vansh5632 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jul 13, 2025
@graphite-app graphite-app bot requested a review from a team July 13, 2025 14:26
@github-actions github-actions bot added consumer ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work ✅ good first issue Good for newcomers 🐛 bug Something isn't working labels Jul 13, 2025
@dosubot dosubot bot added bookings area: bookings, availability, timezones, double booking ✨ feature New feature or request labels Jul 13, 2025
Copy link

graphite-app bot commented Jul 13, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/13/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (07/13/25)

1 label was added to this PR based on Keith Williams's automation.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic found 1 issue across 4 files. Review it in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

…ChangeDetection.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@kart1ka
Copy link
Contributor

kart1ka commented Jul 13, 2025

Hey @Vansh5632, Thanks for the PR. Could you please add a loom video showing that your changes work?
Some tests and type checks sees to be failing. Pls address them as well.

@kart1ka kart1ka marked this pull request as draft July 13, 2025 14:53
@Vansh5632 Vansh5632 marked this pull request as ready for review July 15, 2025 09:39
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Walkthrough

This change introduces timezone change detection to the booking flow. A new React hook, useTimezoneChangeDetection, is created to monitor the user's timezone and determine if booking slots should be refreshed. The hook is integrated into the Booker component, which now invalidates and refreshes available slots when the timezone changes, but only if the event uses a restriction schedule and is configured to use the booker's timezone. The BookerEvent type and the event data selection logic are updated to include the necessary fields. Comprehensive unit and integration tests, as well as documentation, are added to validate and describe the new behavior.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-playwright".

(The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-playwright@latest --save-dev

The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60fdc6c and 24fd75c.

📒 Files selected for processing (1)
  • packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Security Check
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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.

@Vansh5632
Copy link
Contributor Author

I have added the video showing the changes

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)
packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.ts (2)

17-28: Remove dead code from useEffect.

The ref is initialized with the current timezone value on line 15, so the null check on line 19 will never be true. This code is unreachable and should be removed.

  useEffect(() => {
-    // Initialize the previous timezone on first render
-    if (previousTimezoneRef.current === null) {
-      previousTimezoneRef.current = timezone;
-      return;
-    }
-
-    // Update the previous timezone when timezone changes
-    if (previousTimezoneRef.current !== timezone) {
-      previousTimezoneRef.current = timezone;
-    }
+    // Update the previous timezone when timezone changes
+    previousTimezoneRef.current = timezone;
   }, [timezone]);

30-40: Consider caching the shouldRefreshSlots result.

The shouldRefreshSlots function is called on every render, but its result only changes when timezone or event data changes. Consider memoizing this calculation for better performance.

+import { useEffect, useRef, useMemo } from "react";

-  const shouldRefreshSlots = () => {
+  const shouldRefreshSlots = useMemo(() => {
     const hasTimezoneChanged = previousTimezoneRef.current !== timezone;
     const hasRestrictionSchedule = !!eventData?.restrictionScheduleId;
     const isUsingBookerTimezone = !!eventData?.useBookerTimezone;

     // Only refresh slots when:
     // 1. Timezone has changed
     // 2. Event has a restriction schedule
     // 3. Event is configured to use booker's timezone
     return hasTimezoneChanged && hasRestrictionSchedule && isUsingBookerTimezone;
-  };
+  }, [timezone, eventData?.restrictionScheduleId, eventData?.useBookerTimezone]);

   return {
-    shouldRefreshSlots: shouldRefreshSlots(),
+    shouldRefreshSlots,
     currentTimezone: timezone,
     previousTimezone: previousTimezoneRef.current,
   };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 163c7ff and 74ed0fd.

📒 Files selected for processing (4)
  • packages/features/bookings/Booker/Booker.tsx (2 hunks)
  • packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.ts (1 hunks)
  • packages/features/bookings/types.ts (1 hunks)
  • packages/features/eventtypes/lib/getPublicEvent.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/features/bookings/Booker/Booker.tsx (1)
packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.ts (1)
  • useTimezoneChangeDetection (13-47)
🔇 Additional comments (4)
packages/features/bookings/types.ts (1)

65-66: LGTM! Type extension correctly supports the new timezone detection feature.

The addition of restrictionScheduleId and useBookerTimezone properties to the BookerEvent type properly supports the timezone change detection functionality. The optional and nullable typing is appropriate for these database fields.

packages/features/eventtypes/lib/getPublicEvent.ts (1)

155-156: LGTM! Database selection correctly includes the new timezone-related fields.

The addition of restrictionScheduleId and useBookerTimezone to the Prisma selection ensures these fields are fetched from the database and available for the timezone change detection logic.

packages/features/bookings/Booker/Booker.tsx (2)

39-39: LGTM! Clean import of the new timezone detection hook.


133-151: LGTM! Proper integration of timezone change detection.

The implementation correctly:

  1. Extracts the required event data properties for timezone detection
  2. Uses the hook to determine when slots should be refreshed
  3. Invalidates the schedule when timezone changes meet the specified conditions

The conditional logic aligns with the PR requirements to only refresh slots when both a restriction schedule is active and the "use booker's timezone" option is enabled.

@devkumar4
Copy link

Hey @Vansh5632 , if you need support fixing the failing tests or addressing any remaining feedback, happy to collaborate!

@anikdhabal anikdhabal added the Medium priority Created by Linear-GitHub Sync label Jul 16, 2025
@alishaz-polymath
Copy link
Member

@Vansh5632 Thank you for the PR. Could you please add tests to confirm and ensure that your changes work 🙏

- Add unit tests for useTimezoneChangeDetection hook (10 test cases)
- Add type definition tests for BookerEvent interface (3 test cases)
- Add integration tests for Booker component timezone handling (6 test cases)
- Add detailed documentation in TIMEZONE_TESTS.md
- Fix hook logic to prevent refresh on initial render
- Total coverage: 19 passing tests across unit, type, and integration levels
@github-actions github-actions bot added the enterprise area: enterprise, audit log, organisation, SAML, SSO label Jul 17, 2025
@Vansh5632
Copy link
Contributor Author

@alishaz-polymath i have added the required test cases for the changes

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: 1

🧹 Nitpick comments (2)
packages/features/bookings/types.test.ts (1)

8-41: Consider expanding test coverage for type safety.

While the current tests verify basic property assignment, consider adding tests for:

  • Type constraints and validation
  • Integration with other BookerEvent properties
  • Edge cases with different data types

Example additional test case:

it("should maintain type safety with all required properties", () => {
  const completeEvent: BookerEvent = {
    // ... all required properties
    restrictionScheduleId: 123,
    useBookerTimezone: true,
    // This would help catch type mismatches
  };
  
  expect(completeEvent).toBeDefined();
});
packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx (1)

81-315: Comprehensive component-level integration tests!

This test suite provides excellent coverage of the Booker component's timezone integration functionality. The tests validate:

  • Initial render behavior without triggering slot refresh
  • Proper slot refresh triggering when conditions are met
  • Event data structure handling and extraction
  • Graceful handling of null/missing event data
  • Various restriction schedule configurations

The MockBooker component effectively simulates the actual component behavior for testing purposes.

Consider consolidating with similar integration tests.

There appears to be some overlap between this test file and TimezoneIntegration.test.tsx. Consider whether both files are necessary or if they can be consolidated to reduce maintenance overhead.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4106aa0 and 0e3ee80.

📒 Files selected for processing (6)
  • packages/features/bookings/Booker/TimezoneIntegration.test.tsx (1 hunks)
  • packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx (1 hunks)
  • packages/features/bookings/Booker/components/hooks/TIMEZONE_TESTS.md (1 hunks)
  • packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.test.ts (1 hunks)
  • packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.ts (1 hunks)
  • packages/features/bookings/types.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/features/bookings/Booker/components/hooks/TIMEZONE_TESTS.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.341Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
packages/features/bookings/Booker/components/TimezoneIntegration.test.tsx (1)
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.341Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
🧬 Code Graph Analysis (1)
packages/features/bookings/types.test.ts (1)
packages/features/bookings/types.ts (1)
  • BookerEvent (34-70)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Security Check
🔇 Additional comments (2)
packages/features/bookings/Booker/components/hooks/useTimezoneChangeDetection.test.ts (1)

19-310: Excellent comprehensive test coverage!

This test suite thoroughly covers the useTimezoneChangeDetection hook with proper scenarios including:

  • Initial state and first render behavior
  • Timezone change detection with proper conditions
  • Graceful handling of null/undefined event data
  • Edge cases with missing restriction schedules
  • Rapid timezone changes and various formats
  • Proper ref updates for previous timezone tracking

The mocking strategy and test structure are well-implemented and provide confidence in the hook's reliability.

packages/features/bookings/Booker/TimezoneIntegration.test.tsx (1)

97-252: Well-structured integration tests!

This test suite effectively validates the integration between event data and timezone detection functionality. The tests cover:

  • Proper event data extraction and passing to the hook
  • Handling of various event data states (null, missing, with restrictions)
  • Correct slot refresh triggering based on timezone changes
  • Graceful handling of edge cases

The simplified TimezoneIntegrationTest component approach effectively isolates the integration logic for testing.

- Remove duplicate TimezoneIntegration.test.tsx from incorrect location
- Fix import paths in components/TimezoneIntegration.test.tsx to use correct relative paths
- All 7 integration tests now pass successfully
@Vansh5632
Copy link
Contributor Author

@alishaz-polymath can you please review it and tell me further changes

Copy link
Contributor

github-actions bot commented Aug 4, 2025

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Aug 4, 2025
@Vansh5632
Copy link
Contributor Author

can anyone check this PR and tell me the changes required to make in this

@kart1ka
Copy link
Contributor

kart1ka commented Aug 4, 2025

@Vansh5632 Yes, We will review.

@github-actions github-actions bot removed the Stale label Aug 5, 2025
Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

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

left a suggestion

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this file is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay removing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bookings area: bookings, availability, timezones, double booking 🐛 bug Something isn't working community Created by Linear-GitHub Sync consumer enterprise area: enterprise, audit log, organisation, SAML, SSO ✨ feature New feature or request ✅ good first issue Good for newcomers Medium priority Created by Linear-GitHub Sync ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upon changing timezone, we need to update slots when restrictionSchedule is being used with useBookerTimezone enabled
5 participants