Fixes recurring hard crash in two places to ensure rrule gets valid parameters (#5350)

Co-authored-by: alannnc <alannnc@gmail.com>
pull/5359/head
Alex van Andel 2022-11-03 19:14:19 +00:00 committed by GitHub
parent d7e9bb10b8
commit b0f2ce4818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -176,11 +176,12 @@ function BookingListItem(booking: BookingItemProps) {
setLocationMutation.mutate({ bookingId: booking.id, newLocation });
};
// Extract recurring dates is intensive to run, so use useMemo.
// Calculate the booking date(s) and setup recurring event data to show
// @FIXME: This is importing the RRULE library which is already heavy. Find out a more optimal way do this.
const [recurringStrings, recurringDates] = useMemo(() => {
if (booking.recurringBookings !== undefined && booking.eventType.recurringEvent?.freq !== undefined) {
const [, recurringDates] = useMemo(() => {
if (
booking.recurringBookings !== undefined &&
booking.eventType.recurringEvent?.freq !== undefined &&
booking.recurringEventId
) {
return extractRecurringDates(booking, user?.timeZone, i18n);
}
return [[], []];
@ -275,13 +276,11 @@ function BookingListItem(booking: BookingItemProps) {
attendees={booking.attendees}
/>
</div>
{isPending && (
<Badge className="ltr:mr-2 rtl:ml-2" variant="orange">
{t("unconfirmed")}
</Badge>
)}
{booking.eventType?.team && (
<Badge className="ltr:mr-2 rtl:ml-2" variant="gray">
{booking.eventType.team.name}
@ -292,7 +291,6 @@ function BookingListItem(booking: BookingItemProps) {
{t("pending_payment")}
</Badge>
)}
<div className="mt-2 text-sm text-gray-400">
<RecurringBookingsTooltip booking={booking} recurringDates={recurringDates} />
</div>

View File

@ -75,11 +75,16 @@ export const extractRecurringDates = (
const recurringInfo = booking.recurringBookings.find(
(val) => val.recurringEventId === booking.recurringEventId
);
if (!recurringInfo) {
// something went wrong, fail here before RRule.
return [[], []];
}
const allDates = new RRule({
...rest,
count: recurringInfo?._count.recurringEventId,
dtstart: recurringInfo?._min.startTime,
}).all();
const utcOffset = dayjs(recurringInfo?._min.startTime).tz(timeZone).utcOffset();
const dateStrings = allDates.map((r) => {
return processDate(dayjs.utc(r).utcOffset(utcOffset), i18n);