diff --git a/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.test.ts b/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.test.ts index 1d13289c20..fd34ba0a22 100644 --- a/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.test.ts +++ b/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.test.ts @@ -81,9 +81,10 @@ describe("isVisitorWithinPercentage", () => { }); // Test for fallback to random behavior when no UUID is provided - it("should not enable feature when UUID is notavailable", () => { + it("should not enable feature when UUID is not available unless the feature is 100% enabled", () => { mockGetCookie({ expectedUid: undefined }); expect(isVisitorWithinPercentage({ percentage: 50 })).toBe(false); + expect(isVisitorWithinPercentage({ percentage: 100 })).toBe(true); }); it("should disable the feature when percentage is 0", () => { diff --git a/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.ts b/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.ts index 88a04582f4..d7b576668d 100644 --- a/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.ts +++ b/packages/features/bookings/Booker/utils/isFeatureEnabledForVisitor.ts @@ -8,6 +8,12 @@ export const isVisitorWithinPercentage = ({ percentage }: { percentage: number } if (process.env.NEXT_PUBLIC_IS_E2E) { return true; } + + // Because uid cookie is known to be not accessible in third party context inside embed(in some cases), we could just return true if the feature is 100% enabled + // It ensures that when the feature is 100% enabled, it is enabled in embeds too + if (percentage >= 100) { + return true; + } // TODO: The cookie is currently set when a timeslot is selected but we plan to create it on visitor's visit itself // Current purpose is to identify the visitor who reserved a timeslot but could be used for feature rollout and other UX improvements(like if duplicate booking is attempted by the same person) const visitorId = getCookie("uid"); diff --git a/packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts b/packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts index 697f7fc59e..130f5c4989 100644 --- a/packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts +++ b/packages/trpc/server/routers/viewer/slots/isAvailable.handler.ts @@ -55,7 +55,14 @@ export const isAvailableHandler = async ({ if (isReserved) { return { ...slot, - status: "reserved" as const, + // Consider reserved slots as available till we fix issues with reserved slots + // 1. Reservation must be attempted only if the cookie is set. reservation endpoint shouldn't create the cookie itself. It should skip reservation if there is no cookie in request + // 2. We could consider reducing the reservation time. + // 3. There could still be a problem that if multiple people on the same booking page try to book the same slot only one would be successful and other would be not and when they try to select some other slot, similarly only one would be successful and rest won't. + // This could cause frustration for users because they would see the slot as available but when they try to book it, it is not available(Note we fetch the status of the selected slot only). This would be most common for first available slot + // Maybe we want to reserve the slot when confirm button is clicked because in cases where it takes long time to book, it could disable the confirm button earlier. + status: "available" as const, + realStatus: "reserved" as const, }; } diff --git a/packages/trpc/server/routers/viewer/slots/isAvailable.schema.ts b/packages/trpc/server/routers/viewer/slots/isAvailable.schema.ts index 379b69d24a..6307fe456e 100644 --- a/packages/trpc/server/routers/viewer/slots/isAvailable.schema.ts +++ b/packages/trpc/server/routers/viewer/slots/isAvailable.schema.ts @@ -18,6 +18,7 @@ export const ZIsAvailableOutputSchema = z.object({ utcStartIso: z.string(), utcEndIso: z.string(), status: z.enum(["available", "reserved", "minBookNoticeViolation", "slotInPast"]), + realStatus: z.enum(["available", "reserved", "minBookNoticeViolation", "slotInPast"]).optional(), }) ), });