fix: routing-form org redirects when profile slug equals legacy slug (#25003)

* fix: routing-form org redirects when profile slug equals legacy slug

* update

* Update packages/app-store/routing-forms/getEventTypeRedirectUrl.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix type error

* addressed review

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Anik Dhabal Babu
2025-11-18 09:12:58 +00:00
committed by GitHub
co-authored by cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
parent 3490272815
commit 908e5e05f2
2 changed files with 31 additions and 5 deletions
@@ -11,6 +11,9 @@ describe("getAbsoluteEventTypeRedirectUrl", () => {
nonOrgTeamslug: null,
userOrigin: "https://user.cal.com",
teamOrigin: "https://team.cal.com",
user: {
username: null,
},
};
const defaultParams = {
@@ -23,14 +26,26 @@ describe("getAbsoluteEventTypeRedirectUrl", () => {
it("should return WEBAPP_URL for non-migrated user", () => {
const result = getAbsoluteEventTypeRedirectUrl({
...defaultParams,
eventTypeRedirectUrl: "user/event",
form: { ...defaultForm, nonOrgUsername: "user" },
eventTypeRedirectUrl: "old-user/event",
form: {
...defaultForm,
nonOrgUsername: "old-user",
user: { username: "new-user" },
},
});
expect(result).toBe(`${WEBAPP_URL}/user/event?`);
expect(result).toBe(`${WEBAPP_URL}/old-user/event?`);
});
it("should return user origin for migrated user", () => {
const result = getAbsoluteEventTypeRedirectUrl(defaultParams);
const result = getAbsoluteEventTypeRedirectUrl({
...defaultParams,
eventTypeRedirectUrl: "user/event",
form: {
...defaultForm,
nonOrgUsername: "user",
user: { username: "user" },
},
});
expect(result).toBe("https://user.cal.com/user/event?");
});
@@ -58,6 +58,15 @@ export function getAbsoluteEventTypeRedirectUrl({
* The origin for the team the form belongs to
*/
teamOrigin: string;
/**
* The profile user who owns the form
*/
user: {
/**
* Current username on the profile
*/
username: string | null;
};
};
allURLSearchParams: URLSearchParams;
isEmbed?: boolean;
@@ -82,7 +91,9 @@ export function getAbsoluteEventTypeRedirectUrl({
}
if (usernameInRedirectUrl && form.nonOrgUsername) {
const isEventTypeRedirectToOldUser = usernameInRedirectUrl === form.nonOrgUsername;
const hasSameProfileUsername = form.user?.username === form.nonOrgUsername;
const isEventTypeRedirectToOldUser =
!hasSameProfileUsername && usernameInRedirectUrl === form.nonOrgUsername;
if (isEventTypeRedirectToOldUser) {
return `${WEBAPP_URL}/${eventTypeRedirectUrl}?${allURLSearchParams}`;
}