From 89f645c4507b15b5d255a61179f8b271acde5091 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:19:23 +0530 Subject: [PATCH] fix: Hotfix-bookings list breaks on unsupported timezone (#10225) * Adds a check for supportedTimezone values * adds timezone support check for attendees --- packages/lib/date-fns/index.ts | 17 +++++++++++++++++ .../popover/MeetingTimeInTimezones.tsx | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/lib/date-fns/index.ts b/packages/lib/date-fns/index.ts index 9f92f7b7dc..446ca7ec35 100644 --- a/packages/lib/date-fns/index.ts +++ b/packages/lib/date-fns/index.ts @@ -30,6 +30,23 @@ export const formatTime = ( : dayjs(date).format(timeFormat === 12 ? "h:mma" : "HH:mm"); }; +/** + * Checks if a provided timeZone string is recognized as a valid timezone by dayjs. + * + * @param {string} timeZone - The timezone string to be verified. + * @returns {boolean} - Returns 'true' if the provided timezone string is recognized as a valid timezone by dayjs. Otherwise, returns 'false'. + * + */ +export const isSupportedTimeZone = (timeZone: string) => { + try { + dayjs().tz(timeZone); + return true; + } catch (error) { + return false; + } +}; + + /** * Returns a localized and translated date or time, based on the native * Intl.DateTimeFormat available to JS. Undefined values mean the browser's diff --git a/packages/ui/components/popover/MeetingTimeInTimezones.tsx b/packages/ui/components/popover/MeetingTimeInTimezones.tsx index 9069966786..cac9cfc385 100644 --- a/packages/ui/components/popover/MeetingTimeInTimezones.tsx +++ b/packages/ui/components/popover/MeetingTimeInTimezones.tsx @@ -5,6 +5,7 @@ import { isNextDayInTimezone, isPreviousDayInTimezone, sortByTimezone, + isSupportedTimeZone, } from "@calcom/lib/date-fns"; import { Globe } from "../icon"; @@ -34,8 +35,12 @@ const MeetingTimeInTimezones = ({ endTime, }: MeetingTimeInTimezonesProps) => { if (!userTimezone || !attendees.length) return null; - - const attendeeTimezones = attendees.map((attendee) => attendee.timeZone); + + // If attendeeTimezone is unsupported, we fallback to host timezone. Unsupported Attendee timezone can be used due to bad API booking request in the past | backward-compatibility + + const attendeeTimezones = attendees.map((attendee) => { + return isSupportedTimeZone(attendee.timeZone) ? attendee.timeZone : userTimezone; + }); const uniqueTimezones = [userTimezone, ...attendeeTimezones].filter( (value, index, self) => self.indexOf(value) === index );