Skip to content

Commit 3c0fc2e

Browse files
ShashwatPSkart1kaDevanshusharma2005anikdhabal
authored
fix: reschedule issue when limited booking is enabled in the event settings. (calcom#23717)
* fix * fix fix * cleanup * Update useBookings.ts * Update store.ts --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com> Co-authored-by: Devanshu Sharma <devanshusharma658@gmail.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
1 parent c702da0 commit 3c0fc2e

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

packages/features/bookings/Booker/__tests__/test-utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const createMockStore = (initialState?: Partial<BookerStore>): StoreApi<BookerSt
5151
bookingUid: null,
5252
bookingData: null,
5353
setBookingData: vi.fn(),
54+
setRescheduleUid: vi.fn(),
5455
initialize: vi.fn(),
5556
formValues: {},
5657
setFormValues: vi.fn(),

packages/features/bookings/Booker/components/hooks/useBookings.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import { useMutation } from "@tanstack/react-query";
44
import { useRouter } from "next/navigation";
55
import { useRef, useState, useEffect } from "react";
6+
import { shallow } from "zustand/shallow";
67

78
import { createPaymentLink } from "@calcom/app-store/stripepayment/lib/client";
89
import { useHandleBookEvent } from "@calcom/atoms/hooks/bookings/useHandleBookEvent";
910
import dayjs from "@calcom/dayjs";
1011
import { sdkActionManager } from "@calcom/embed-core/embed-iframe";
1112
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
12-
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
1313
import { updateQueryParam, getQueryParam } from "@calcom/features/bookings/Booker/utils/query-param";
1414
import { createBooking, createRecurringBooking, createInstantBooking } from "@calcom/features/bookings/lib";
1515
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
@@ -177,9 +177,15 @@ export const useBookings = ({
177177
const eventTypeId = useBookerStoreContext((state) => state.eventId);
178178
const isInstantMeeting = useBookerStoreContext((state) => state.isInstantMeeting);
179179

180-
const rescheduleUid = useBookerStoreContext((state) => state.rescheduleUid);
180+
const [rescheduleUid, setRescheduleUid] = useBookerStoreContext(
181+
(state) => [state.rescheduleUid, state.setRescheduleUid],
182+
shallow
183+
);
181184
const rescheduledBy = useBookerStoreContext((state) => state.rescheduledBy);
182-
const bookingData = useBookerStoreContext((state) => state.bookingData);
185+
const [bookingData, setBookingData] = useBookerStoreContext(
186+
(state) => [state.bookingData, state.setBookingData],
187+
shallow
188+
);
183189
const timeslot = useBookerStoreContext((state) => state.selectedTimeslot);
184190
const { t } = useLocale();
185191
const bookingSuccessRedirect = useBookingSuccessRedirect();
@@ -383,16 +389,12 @@ export const useBookings = ({
383389
};
384390

385391
if (error.message === ErrorCode.BookerLimitExceededReschedule && error.data?.rescheduleUid) {
386-
useBookerStore.setState({
387-
rescheduleUid: error.data?.rescheduleUid,
388-
});
389-
useBookerStore.setState({
390-
bookingData: {
391-
uid: error.data?.rescheduleUid,
392-
startTime: error.data?.startTime,
393-
attendees: error.data?.attendees,
394-
} as unknown as GetBookingType,
395-
});
392+
setRescheduleUid(error.data?.rescheduleUid);
393+
setBookingData({
394+
uid: error.data?.rescheduleUid,
395+
startTime: error.data?.startTime,
396+
attendees: error.data?.attendees,
397+
} as unknown as GetBookingType);
396398
}
397399
},
398400
});

packages/features/bookings/Booker/store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export type BookerStore = {
138138
* object is something that's fetched server side.
139139
*/
140140
rescheduleUid: string | null;
141+
setRescheduleUid: (rescheduleUid: string | null) => void;
141142
rescheduledBy: string | null;
142143
bookingUid: string | null;
143144
bookingData: GetBookingType | null;
@@ -415,6 +416,9 @@ export const createBookerStore = () =>
415416
setBookingData: (bookingData: GetBookingType | null | undefined) => {
416417
set({ bookingData: bookingData ?? null });
417418
},
419+
setRescheduleUid: (rescheduleUid: string | null) => {
420+
set({ rescheduleUid });
421+
},
418422
recurringEventCount: null,
419423
setRecurringEventCount: (recurringEventCount: number | null) => set({ recurringEventCount }),
420424
occurenceCount: null,

0 commit comments

Comments
 (0)