Skip to content

Commit c3a5158

Browse files
kart1kavolneianikdhabalDevanshusharma2005
authored
feat: add availabilityLoaded embed event (calcom#21350)
* feat: add availabiityLoaded embed event * chore * fix --------- Co-authored-by: Volnei Munhoz <volnei.munhoz@gmail.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: Devanshu Sharma <devanshusharma658@gmail.com>
1 parent a9e14b9 commit c3a5158

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

packages/embeds/embed-core/playground/lib/playground.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,24 @@ Cal("on", {
636636
callback: bookingSuccessfulV2Callback,
637637
});
638638

639+
const availabilityLoadedCallback = (e: EmbedEvent<"availabilityLoaded">) => {
640+
const data = e.detail.data;
641+
console.log("availabilityLoaded", {
642+
eventId: data.eventId,
643+
eventSlug: data.eventSlug,
644+
});
645+
646+
Cal("off", {
647+
action: "availabilityLoaded",
648+
callback: availabilityLoadedCallback,
649+
});
650+
};
651+
652+
Cal("on", {
653+
action: "availabilityLoaded",
654+
callback: availabilityLoadedCallback,
655+
});
656+
639657
if (only === "all" || only === "ns:skeletonDemo") {
640658
Cal("init", "skeletonDemo", {
641659
debug: true,

packages/embeds/embed-core/src/sdk-action-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export type EventDataMap = {
3737
};
3838
};
3939
linkReady: Record<string, never>;
40+
availabilityLoaded: {
41+
eventId: number;
42+
eventSlug: string;
43+
};
4044
__connectInitiated: Record<string, never>;
4145
__connectCompleted: Record<string, never>;
4246
bookingSuccessfulV2: BaseBookingEventPayload & {

packages/embeds/embed-react/inline.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ function App() {
5050
callback,
5151
});
5252

53+
const availabilityLoadedCallback = (e: EmbedEvent<"availabilityLoaded">) => {
54+
const data = e.detail.data;
55+
console.log("availabilityLoaded", {
56+
eventId: data.eventId,
57+
eventSlug: data.eventSlug,
58+
});
59+
60+
api("off", {
61+
action: "availabilityLoaded",
62+
callback: availabilityLoadedCallback,
63+
});
64+
};
65+
66+
api("on", {
67+
action: "availabilityLoaded",
68+
callback: availabilityLoadedCallback,
69+
});
70+
5371
// Also, validates the type of e.detail.data as TS runs on this file
5472
const bookingSuccessfulV2Callback = (e: EmbedEvent<"bookingSuccessfulV2">) => {
5573
const data = e.detail.data;

packages/features/schedules/lib/use-schedule/useSchedule.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useSearchParams } from "next/navigation";
22

33
import { updateEmbedBookerState } from "@calcom/embed-core/src/embed-iframe";
4+
import { sdkActionManager } from "@calcom/embed-core/src/sdk-event";
45
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
56
import { isBookingDryRun } from "@calcom/features/bookings/Booker/utils/isBookingDryRun";
67
import { useTimesForSchedule } from "@calcom/features/schedules/lib/use-schedule/useTimesForSchedule";
@@ -30,6 +31,19 @@ export type UseScheduleWithCacheArgs = {
3031
enabled?: boolean;
3132
};
3233

34+
const getAvailabilityLoadedEventPayload = ({
35+
eventId,
36+
eventSlug,
37+
}: {
38+
eventId: number;
39+
eventSlug: string;
40+
}) => {
41+
return {
42+
eventId,
43+
eventSlug,
44+
};
45+
};
46+
3347
export const useSchedule = ({
3448
month,
3549
timezone,
@@ -148,6 +162,13 @@ export const useSchedule = ({
148162
slotsQuery: teamScheduleV2,
149163
});
150164

165+
if (teamScheduleV2.isSuccess && eventId && eventSlug) {
166+
sdkActionManager?.fire(
167+
"availabilityLoaded",
168+
getAvailabilityLoadedEventPayload({ eventId, eventSlug })
169+
);
170+
}
171+
151172
return {
152173
...teamScheduleV2,
153174
/**
@@ -164,6 +185,13 @@ export const useSchedule = ({
164185
slotsQuery: schedule,
165186
});
166187

188+
if (schedule.isSuccess && eventId && eventSlug) {
189+
sdkActionManager?.fire(
190+
"availabilityLoaded",
191+
getAvailabilityLoadedEventPayload({ eventId, eventSlug })
192+
);
193+
}
194+
167195
return {
168196
...schedule,
169197
/**

0 commit comments

Comments
 (0)