fix: #10973 back button not working as expected in embed (#11073)

Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
VijayandHariom Balhara authored and GitHub committed 2023-09-05 15:40:09 +05:30
1 parent 2e12f09f05
commit c12abd75a8
6 files changed
+51 -11

No files matched your search

@@ -34,6 +34,7 @@ import { Alert, Button, EmptyScreen, Form, showToast } from "@calcom/ui";
import { Calendar } from "@calcom/ui/components/icon";
import { useBookerStore } from "../../store";
import { useSlotReservationId } from "../../useSlotReservationId";
import { useEvent } from "../../utils/event";
import { BookingFields } from "./BookingFields";
import { FormSkeleton } from "./Skeleton";
@@ -45,8 +46,16 @@ type BookEventFormProps = {
type DefaultValues = Record<string, unknown>;
export const BookEventForm = ({ onCancel }: BookEventFormProps) => {
const [slotReservationId, setSlotReservationId] = useSlotReservationId();
const reserveSlotMutation = trpc.viewer.public.slots.reserveSlot.useMutation({
trpc: { context: { skipBatch: true } },
trpc: {
context: {
skipBatch: true,
},
},
onSuccess: (data) => {
setSlotReservationId(data.uid);
},
});
const removeSelectedSlot = trpc.viewer.public.slots.removeSelectedSlotMark.useMutation({
trpc: { context: { skipBatch: true } },
@@ -82,7 +91,7 @@ export const BookEventForm = ({ onCancel }: BookEventFormProps) => {
return () => {
if (eventType) {
removeSelectedSlot.mutate();
removeSelectedSlot.mutate({ uid: slotReservationId });
}
clearInterval(interval);
};
@@ -0,0 +1,15 @@
// TODO: It would be lost on refresh, so we need to persist it.
// Though, we are persisting it in a cookie(`uid` cookie is set through reserveSlot call)
// but that becomes a third party cookie in context of embed and thus isn't accessible inside embed
// So, we need to persist it in top window as first party cookie in that case.
let slotReservationId: null | string = null;
export const useSlotReservationId = () => {
function set(uid: string) {
slotReservationId = uid;
}
function get() {
return slotReservationId;
}
return [get(), set] as const;
};