fix: preserve booker timezone selection#23806
Conversation
|
@tembo-io[bot] is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
Walkthrough
Possibly related PRs
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/features/bookings/Booker/components/EventMeta.tsx (1)
245-248: Fix mismatch: fallback should include schedule.timeZone when lockedTimeZone is absentWhen the event is locked but
lockedTimeZoneis null/empty whileschedule.timeZoneexists, the effect sets the store toschedule.timeZone, yet the select rendersCURRENT_TIMEZONE, causing a visible discrepancy (and it’s disabled, so the user can’t correct it).Apply:
- value={ - event.lockTimeZoneToggleOnBookingPage - ? event.lockedTimeZone || CURRENT_TIMEZONE - : timezone - } + value={ + event.lockTimeZoneToggleOnBookingPage + ? event.lockedTimeZone || event.schedule?.timeZone || CURRENT_TIMEZONE + : timezone + }
🧹 Nitpick comments (3)
packages/features/bookings/Booker/components/EventMeta.tsx (2)
118-125: Keep BookerStore timezone in sync when enforcing a locked TZYou set only
timePreferenceshere. If other parts rely on the Booker store’stimezone, they may drift.Proposed tweak:
if (event?.lockTimeZoneToggleOnBookingPage) { const timezone = event.lockedTimeZone || event.schedule?.timeZone; if (timezone) { setTimezone(timezone); + setBookerStoreTimezone(timezone); } }
148-153: Guard navigator for SSR safetyAccessing
navigator.languagecan throw during SSR iflocaleis null.Apply:
- const userLocale = locale ?? navigator.language; + const userLocale = + locale ?? (typeof navigator !== "undefined" ? navigator.language : i18n.language);packages/features/bookings/lib/timePreferences.ts (1)
16-31: Validate stored timezone; fall back when invalidIf localStorage contains an invalid/old IANA TZ, downstream formatting can break. Validate before using; otherwise use
CURRENT_TIMEZONE. Also good to keep SSR-safety via the webstorage wrapper (please confirm).Apply:
/** * Get the initial timezone for the booker, ensuring it's auto-detected from the browser * if not previously set by the user. */ -const getInitialTimezone = () => { - const savedTimezone = localStorage.getItem(timezoneLocalStorageKey); - - // If user has previously set a timezone preference, use that - if (savedTimezone) { - return savedTimezone; - } - - // Auto-detect timezone from browser - don't save to localStorage yet - // Only save when user explicitly changes timezone - return CURRENT_TIMEZONE; -}; +const isValidTimezone = (tz: string) => { + try { + // Throws if tz is not a valid IANA zone + new Intl.DateTimeFormat(undefined, { timeZone: tz }); + return true; + } catch { + return false; + } +}; + +const getInitialTimezone = () => { + const savedTimezone = localStorage.getItem(timezoneLocalStorageKey) ?? undefined; + if (savedTimezone && isValidTimezone(savedTimezone)) return savedTimezone; + // Auto-detect from browser; don't persist until user changes explicitly + return CURRENT_TIMEZONE; +};Verification ask: confirm
@calcom/lib/webstorageis SSR-safe (no directwindow.localStorageaccess on server).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/features/bookings/Booker/components/EventMeta.tsx(1 hunks)packages/features/bookings/lib/timePreferences.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Always use
t()for text localization in frontend code; direct text embedding should trigger a warning
Files:
packages/features/bookings/Booker/components/EventMeta.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/features/bookings/Booker/components/EventMeta.tsxpackages/features/bookings/lib/timePreferences.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/bookings/Booker/components/EventMeta.tsxpackages/features/bookings/lib/timePreferences.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/bookings/lib/timePreferences.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Tests / Unit
- GitHub Check: Type check / check-types
- GitHub Check: Linters / lint
🔇 Additional comments (2)
packages/features/bookings/Booker/components/EventMeta.tsx (1)
126-128: Comment clarifies intent—goodClear note prevents future regressions when lock is off.
packages/features/bookings/lib/timePreferences.ts (1)
44-45: Helper extraction LGTMSwitching init to
getInitialTimezone()improves readability and centralizes behavior.
kart1ka
left a comment
There was a problem hiding this comment.
Could you please mention the exact issue this PR is resolving? We are also going to need a loom video that shows this fixes the bug.
|
This PR is being marked as stale due to inactivity. |
|
Appreciate the contribution @Aamod007 but this PR's code results in no change. Closing for now. |
Description
Fix timezone handling for bookings when
lockTimeZoneis not enabledChanges
getInitialTimezone()function to handle timezone selection