From 3714d5faab91e0a22c6b8b9af2fb423395ad41b7 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:22:53 +0530 Subject: [PATCH] fix: routing form redirects to use app.cal.com instead of cal.com (#21924) * fix: routing form redirects to use app.cal.com instead of cal.com * Update packages/lib/hooks/useBookerUrl.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * update --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- .../__tests__/getEventTypeRedirectUrl.test.ts | 10 +++++----- .../routing-forms/enrichFormWithMigrationData.ts | 6 +++--- packages/features/embed/lib/EmbedTabs.tsx | 6 +++--- packages/features/embed/lib/hooks/index.tsx | 4 ++-- packages/lib/hooks/useBookerUrl.ts | 5 +++++ 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/app-store/routing-forms/__tests__/getEventTypeRedirectUrl.test.ts b/packages/app-store/routing-forms/__tests__/getEventTypeRedirectUrl.test.ts index 0e9e6f724b..a24859d53c 100644 --- a/packages/app-store/routing-forms/__tests__/getEventTypeRedirectUrl.test.ts +++ b/packages/app-store/routing-forms/__tests__/getEventTypeRedirectUrl.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; -import { CAL_URL } from "@calcom/lib/constants"; +import { WEBAPP_URL } from "@calcom/lib/constants"; import { getAbsoluteEventTypeRedirectUrl } from "../getEventTypeRedirectUrl"; @@ -20,13 +20,13 @@ describe("getAbsoluteEventTypeRedirectUrl", () => { isEmbed: false, }; - it("should return CAL_URL for non-migrated user", () => { + it("should return WEBAPP_URL for non-migrated user", () => { const result = getAbsoluteEventTypeRedirectUrl({ ...defaultParams, eventTypeRedirectUrl: "user/event", form: { ...defaultForm, nonOrgUsername: "user" }, }); - expect(result).toBe(`${CAL_URL}/user/event?`); + expect(result).toBe(`${WEBAPP_URL}/user/event?`); }); it("should return user origin for migrated user", () => { @@ -34,13 +34,13 @@ describe("getAbsoluteEventTypeRedirectUrl", () => { expect(result).toBe("https://user.cal.com/user/event?"); }); - it("should return CAL_URL for non-migrated team", () => { + it("should return WEBAPP_URL for non-migrated team", () => { const result = getAbsoluteEventTypeRedirectUrl({ ...defaultParams, eventTypeRedirectUrl: "team/team1/event", form: { ...defaultForm, nonOrgTeamslug: "team1" }, }); - expect(result).toBe(`${CAL_URL}/team/team1/event?`); + expect(result).toBe(`${WEBAPP_URL}/team/team1/event?`); }); it("should return team origin for migrated team", () => { diff --git a/packages/app-store/routing-forms/enrichFormWithMigrationData.ts b/packages/app-store/routing-forms/enrichFormWithMigrationData.ts index f5deb5f875..55863b273c 100644 --- a/packages/app-store/routing-forms/enrichFormWithMigrationData.ts +++ b/packages/app-store/routing-forms/enrichFormWithMigrationData.ts @@ -1,5 +1,5 @@ import { getOrgFullOrigin } from "@calcom/features/ee/organizations/lib/orgDomains"; -import { CAL_URL } from "@calcom/lib/constants"; +import { WEBAPP_URL } from "@calcom/lib/constants"; import { teamMetadataSchema, userMetadata } from "@calcom/prisma/zod-utils"; export const enrichFormWithMigrationData = < @@ -45,12 +45,12 @@ export const enrichFormWithMigrationData = < ? getOrgFullOrigin(formOwnerOrgSlug, { protocol: true, }) - : CAL_URL, + : WEBAPP_URL, teamOrigin: form.team?.parent?.slug ? getOrgFullOrigin(form.team.parent.slug, { protocol: true, }) - : CAL_URL, + : WEBAPP_URL, nonOrgUsername, nonOrgTeamslug, }; diff --git a/packages/features/embed/lib/EmbedTabs.tsx b/packages/features/embed/lib/EmbedTabs.tsx index 183f5c55a0..becc9762d2 100644 --- a/packages/features/embed/lib/EmbedTabs.tsx +++ b/packages/features/embed/lib/EmbedTabs.tsx @@ -3,7 +3,7 @@ import { forwardRef } from "react"; import type { BookerLayout } from "@calcom/features/bookings/Booker/types"; import { APP_NAME } from "@calcom/lib/constants"; -import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; +import { useEmbedBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { TextArea } from "@calcom/ui/components/form"; @@ -188,7 +188,7 @@ ${getEmbedTypeSpecificString({ HTMLIFrameElement | HTMLTextAreaElement | null, { calLink: string; embedType: EmbedType; previewState: PreviewState; namespace: string } >(function Preview({ calLink, embedType }, ref) { - const bookerUrl = useBookerUrl(); + const bookerUrl = useEmbedBookerUrl(); const iframeSrc = `${EMBED_PREVIEW_HTML_URL}?embedType=${embedType}&calLink=${calLink}&embedLibUrl=${embedLibUrl}&bookerUrl=${bookerUrl}`; if (ref instanceof Function || !ref) { return null; @@ -329,7 +329,7 @@ const getInstructionString = ({ }; function useGetEmbedSnippetString(namespace: string | null) { - const bookerUrl = useBookerUrl(); + const bookerUrl = useEmbedBookerUrl(); // TODO: Import this string from @calcom/embed-snippet // Right now the problem is that embed-snippet export is not minified and has comments which makes it unsuitable for giving it to users. // If we can minify that during build time and then import the built code here, that could work diff --git a/packages/features/embed/lib/hooks/index.tsx b/packages/features/embed/lib/hooks/index.tsx index ea7f659bbe..1ac426ed72 100644 --- a/packages/features/embed/lib/hooks/index.tsx +++ b/packages/features/embed/lib/hooks/index.tsx @@ -1,4 +1,4 @@ -import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; +import { useEmbedBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; export const useEmbedTypes = () => { @@ -319,6 +319,6 @@ export const useEmbedTypes = () => { }; export const useEmbedCalOrigin = () => { - const bookerUrl = useBookerUrl(); + const bookerUrl = useEmbedBookerUrl(); return bookerUrl; }; diff --git a/packages/lib/hooks/useBookerUrl.ts b/packages/lib/hooks/useBookerUrl.ts index 329afc73f4..d634c4b1d9 100644 --- a/packages/lib/hooks/useBookerUrl.ts +++ b/packages/lib/hooks/useBookerUrl.ts @@ -5,3 +5,8 @@ export const useBookerUrl = () => { const orgBranding = useOrgBranding(); return orgBranding?.fullDomain ?? WEBSITE_URL ?? WEBAPP_URL; }; + +export const useEmbedBookerUrl = () => { + const orgBranding = useOrgBranding(); + return orgBranding?.fullDomain ?? WEBAPP_URL; +};