fix: refresh slots on timezone change for booker timezone restrictions#27491
fix: refresh slots on timezone change for booker timezone restrictions#27491
Conversation
Add timezone change detection and slot refresh to BookerPlatformWrapper and EventTypeCalendarViewComponent to handle restriction schedules with useBookerTimezone enabled.
…ponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
…ponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
…opagation Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
hariombalhara
left a comment
There was a problem hiding this comment.
Dead code: useTimezoneBasedSlotRefresh and useTimezoneChangeDetection are not imported by any component — they're only referenced by each other and their own test files. These are leftovers from the earlier callback-based approach that was replaced by the inline useRef timezone-pinning pattern. These four files should be removed:
- useTimezoneBasedSlotRefresh.ts
- useTimezoneBasedSlotRefresh.test.ts
- useTimezoneChangeDetection.ts
- useTimezoneChangeDetection.test.ts
Duplicated logic — extract a shared hook. The same timezone-pinning pattern is copy-pasted in three places:
- useEvent.ts:105-111
- BookerPlatformWrapper.tsx:247-251
- EventTypeCalendarViewComponent.tsx:72-76
Consider extracting a small shared hook, e.g.:
export function useStableTimezone( timezone: string, restrictionSchedule?: { id: number | null; useBookerTimezone: boolean }): string { const initialRef = useRef(timezone); const shouldPin = restrictionSchedule?.id != null && restrictionSchedule.id > 0 && restrictionSchedule.useBookerTimezone === false; return shouldPin ? initialRef.current : timezone;}Each call site then becomes a one-liner. This also gives a single place to add tests (which could replace the now-dead
useTimezoneChangeDetectiontests).
…ection code Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
|
Addressed both items from the latest review:
|
calcom#27491) * fix: refresh slots on timezone change for booker timezone restrictions * refactor: use useMemo for timezone change detection * revert: remove unnecessary formatting changes * feat: add timezone refresh for platform components Add timezone change detection and slot refresh to BookerPlatformWrapper and EventTypeCalendarViewComponent to handle restriction schedules with useBookerTimezone enabled. * refactor: extract timezone slot refresh logic into reusable hook * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * fix * fix: prevent unnecessary getSchedule calls when useBookerTimezone is disabled * fix: add timezone fields to BookerEvent type * fix: add missing properties to BookerEvent and BookerEventProfile types * trying to fix type errors * Add restrictionScheduleId and useBookerTimezone fields * fix: correct import path for useBookerTime hook Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: explicitly include restrictionScheduleId and useBookerTimezone in getPublicEvent return Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * chore: trigger fresh CI build Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: cast event.data to BookerEvent for timezone fields access Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: address review feedback for timezone slot refresh Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: add explicit return type to event handler to ensure type propagation Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: extract useStableTimezone hook and remove dead timezone detection code Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> --------- Co-authored-by: hackice20 <yashkam431@gmail.com> Co-authored-by: Yash <116657771+hackice20@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
calcom#27491) * fix: refresh slots on timezone change for booker timezone restrictions * refactor: use useMemo for timezone change detection * revert: remove unnecessary formatting changes * feat: add timezone refresh for platform components Add timezone change detection and slot refresh to BookerPlatformWrapper and EventTypeCalendarViewComponent to handle restriction schedules with useBookerTimezone enabled. * refactor: extract timezone slot refresh logic into reusable hook * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * fix * fix: prevent unnecessary getSchedule calls when useBookerTimezone is disabled * fix: add timezone fields to BookerEvent type * fix: add missing properties to BookerEvent and BookerEventProfile types * trying to fix type errors * Add restrictionScheduleId and useBookerTimezone fields * fix: correct import path for useBookerTime hook * fix: explicitly include restrictionScheduleId and useBookerTimezone in getPublicEvent return * chore: trigger fresh CI build * fix: cast event.data to BookerEvent for timezone fields access * refactor: address review feedback for timezone slot refresh * refactor: add explicit return type to event handler to ensure type propagation * refactor: extract useStableTimezone hook and remove dead timezone detection code --------- Co-authored-by: hackice20 <yashkam431@gmail.com> Co-authored-by: Yash <116657771+hackice20@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
#27491) * fix: refresh slots on timezone change for booker timezone restrictions * refactor: use useMemo for timezone change detection * revert: remove unnecessary formatting changes * feat: add timezone refresh for platform components Add timezone change detection and slot refresh to BookerPlatformWrapper and EventTypeCalendarViewComponent to handle restriction schedules with useBookerTimezone enabled. * refactor: extract timezone slot refresh logic into reusable hook * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> * fix * fix: prevent unnecessary getSchedule calls when useBookerTimezone is disabled * fix: add timezone fields to BookerEvent type * fix: add missing properties to BookerEvent and BookerEventProfile types * trying to fix type errors * Add restrictionScheduleId and useBookerTimezone fields * fix: correct import path for useBookerTime hook Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: explicitly include restrictionScheduleId and useBookerTimezone in getPublicEvent return Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * chore: trigger fresh CI build Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * fix: cast event.data to BookerEvent for timezone fields access Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: address review feedback for timezone slot refresh Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: add explicit return type to event handler to ensure type propagation Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> * refactor: extract useStableTimezone hook and remove dead timezone detection code Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com> --------- Co-authored-by: hackice20 <yashkam431@gmail.com> Co-authored-by: Yash <116657771+hackice20@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
What does this PR do?
Fixes timezone-based slot refresh behavior when event types have restriction schedules that use the booker's timezone. When a user changes their timezone in the booking widget, the available slots now correctly refresh to reflect the new timezone constraints.
Continues work from #26026
Changes
useStableTimezoneshared hook (packages/features/bookings/Booker/hooks/useStableTimezone.ts):useBookerTimezone: false, the timezone is pinned to the initial value (preventing unnecessary refetches). Otherwise, it follows the booker's current timezone.useScheduleForEvent,BookerPlatformWrapper, andEventTypeCalendarViewComponent.Type fixes:
useBookerTimezoneandrestrictionScheduleIdtoBookerEventPick list (picked directly fromPublicEvent)getPublicEventreturn value (both for regular and dynamic event types)Promise<PublicEventType>return type toevent.handler.tsto ensure tRPC properly propagates the type chainBookerEventProfileto includebrandColor,darkBrandColor,theme,weekStart,usernameStable timezone in schedule hooks:
useScheduleForEventaccepts arestrictionSchedule: { id, useBookerTimezone }prop and delegates touseStableTimezone.BookerPlatformWrapperandEventTypeCalendarViewComponentconstruct therestrictionScheduleobject fromevent.dataand calluseStableTimezonedirectly.Dead code removal:
useTimezoneBasedSlotRefresh.ts,useTimezoneBasedSlotRefresh.test.ts,useTimezoneChangeDetection.ts,useTimezoneChangeDetection.test.ts— these were leftovers from the earlier callback-based approach, no longer imported by any component.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
useBookerTimezoneenabledExpected behavior: Slots should refresh when timezone changes and the event has a restriction schedule using booker timezone. When
useBookerTimezoneis false, changing timezone should not trigger a refetch (timezone is pinned to the initial value).Human Review Checklist
useStableTimezonecorrectly captures the initial timezone on mount (usesuseRef) — if the component remounts, the ref resets. Confirm this is acceptable for the booker flow.restrictionScheduleprop construction at each of the three call sites correctly mapsevent.data.restrictionScheduleIdandevent.data.useBookerTimezone.=inbookerForm=andavailableTimeSlots=— these should be auto-fixed by linter but weren't flagged as errors.Checklist
Link to Devin run: https://app.devin.ai/sessions/d9b2bc5dbc7a482ab580d5bc843576ce
Requested by: @alishaz-polymath