fix: Hotfix-bookings list breaks on unsupported timezone (#10225)

* Adds a check for supportedTimezone values

* adds timezone support check for attendees
pull/10229/head
Syed Ali Shahbaz 2023-07-18 19:19:23 +05:30 committed by GitHub
parent da5d90eb07
commit 89f645c450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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
);