Scheduling infrastructure for absolutely everyone.
fix: Team and User Links (#15342)
Hariom Balharadef87ea84acf
diff --git a/apps/web/components/eventtype/EventTeamTab.tsx b/apps/web/components/eventtype/EventTeamTab.tsxindex f76603cf3a5..a5dc455b19d 100644--- a/apps/web/components/eventtype/EventTeamTab.tsx+++ b/apps/web/components/eventtype/EventTeamTab.tsx@@ -33,6 +33,7 @@ export const mapMemberToChildrenOption = (membership: member.membership,eventTypeSlugs: member.eventTypes ?? [],avatar: member.avatar,+ profile: member.profile,},value: `${member.id ?? ""}`,label: `${member.name || member.email || ""}${!member.username ? ` (${pendingString})` : ""}`,diff --git a/packages/features/test/orgDomains.test.ts b/packages/features/ee/organizations/lib/orgDomains.test.tssimilarity index 100%rename from packages/features/test/orgDomains.test.tsrename to packages/features/ee/organizations/lib/orgDomains.test.tsdiff --git a/packages/features/ee/teams/pages/team-profile-view.tsx b/packages/features/ee/teams/pages/team-profile-view.tsxindex 64a9e684cf1..43f51a7c38e 100644--- a/packages/features/ee/teams/pages/team-profile-view.tsx+++ b/packages/features/ee/teams/pages/team-profile-view.tsx@@ -115,7 +115,12 @@ const ProfileView = () => {const isAdmin =team && (team.membership.role === MembershipRole.OWNER || team.membership.role === MembershipRole.ADMIN);- const permalink = `${WEBAPP_URL}/team/${team?.slug}`;+ const permalink = team+ ? `${getTeamUrlSync({+ orgSlug: team.parent ? team.parent.slug : null,+ teamSlug: team.slug,+ })}`+ : "";const isBioEmpty = !team || !team.bio || !team.bio.replace("<p><br></p>", "").length;diff --git a/packages/features/eventtypes/components/ChildrenEventTypeSelect.tsx b/packages/features/eventtypes/components/ChildrenEventTypeSelect.tsxindex 24488c5b7cd..be6fd104b35 100644--- a/packages/features/eventtypes/components/ChildrenEventTypeSelect.tsx+++ b/packages/features/eventtypes/components/ChildrenEventTypeSelect.tsx@@ -1,11 +1,11 @@import { useAutoAnimate } from "@formkit/auto-animate/react";import type { Props } from "react-select";-import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";import { classNames } from "@calcom/lib";-import { WEBSITE_URL } from "@calcom/lib/constants";+import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";import { useLocale } from "@calcom/lib/hooks/useLocale";import { MembershipRole } from "@calcom/prisma/enums";+import type { UserProfile } from "@calcom/types/UserProfile";import { Avatar, Badge, Button, ButtonGroup, Select, Switch, Tooltip } from "@calcom/ui";export type ChildrenEventType = {@@ -20,6 +20,7 @@ export type ChildrenEventType = {username: string;membership: MembershipRole;eventTypeSlugs: string[];+ profile: UserProfile;};slug: string;hidden: boolean;@@ -35,10 +36,7 @@ export const ChildrenEventTypeSelect = ({onChange: (value: readonly ChildrenEventType[]) => void;}) => {const { t } = useLocale();- const orgBranding = useOrgBranding();-const [animationRef] = useAutoAnimate<HTMLUListElement>();- const domain = orgBranding?.fullDomain ?? WEBSITE_URL;return (<>@@ -109,7 +107,9 @@ export const ChildrenEventTypeSelect = ({color="secondary"target="_blank"variant="icon"- href={`${domain}/${children.owner?.username}/${children.slug}`}+ href={`${getBookerBaseUrlSync(+ children.owner.profile?.organization?.slug ?? null+ )}/${children.owner?.username}/${children.slug}`}StartIcon="external-link"/></Tooltip>diff --git a/packages/lib/getBookerUrl/client.test.ts b/packages/lib/getBookerUrl/client.test.tsnew file mode 100644index 00000000000..4a57c545ce3--- /dev/null+++ b/packages/lib/getBookerUrl/client.test.ts@@ -0,0 +1,30 @@+import { describe, it, vi, expect } from "vitest";++import { getTeamUrlSync } from "./client";+import * as getBookerBaseUrlSyncExport from "./getBookerBaseUrlSync";++vi.mock("./getBookerBaseUrlSync", async () => {+ return {+ getBookerBaseUrlSync: vi.fn(),+ };+});++describe("getBookerUrl:client", () => {+ describe("getTeamUrlSync", () => {+ it("if orgSlug is null, it should return a URL with /team in it", () => {+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-ignore+ getBookerBaseUrlSyncExport.getBookerBaseUrlSync.mockReturnValueOnce("https://abc.com");+ const url = getTeamUrlSync({ orgSlug: null, teamSlug: "myTeam" });+ expect(url).toBe("https://abc.com/team/myTeam");+ });++ it("if orgSlug is set, it should return a URL without /team in it", () => {+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-ignore+ getBookerBaseUrlSyncExport.getBookerBaseUrlSync.mockReturnValueOnce("https://acme.com");+ const url = getTeamUrlSync({ orgSlug: "acme", teamSlug: "myTeam" });+ expect(url).toBe("https://acme.com/myTeam");+ });+ });+});diff --git a/packages/lib/getBookerUrl/client.ts b/packages/lib/getBookerUrl/client.tsindex 6eaa6927644..c018d51f13b 100644--- a/packages/lib/getBookerUrl/client.ts+++ b/packages/lib/getBookerUrl/client.ts@@ -1,14 +1,6 @@-import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";--export const getBookerBaseUrlSync = (- orgSlug: string | null,- options?: {- protocol: boolean;- }-) => {- return getOrgFullOrigin(orgSlug ?? "", options);-};+import { getBookerBaseUrlSync } from "./getBookerBaseUrlSync";+export { getBookerBaseUrlSync } from "./getBookerBaseUrlSync";export const getTeamUrlSync = ({orgSlug,diff --git a/packages/lib/getBookerUrl/getBookerBaseUrlSync.ts b/packages/lib/getBookerUrl/getBookerBaseUrlSync.tsnew file mode 100644index 00000000000..2109bec8164--- /dev/null+++ b/packages/lib/getBookerUrl/getBookerBaseUrlSync.ts@@ -0,0 +1,10 @@+import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";++export const getBookerBaseUrlSync = (+ orgSlug: string | null,+ options?: {+ protocol: boolean;+ }+) => {+ return getOrgFullOrigin(orgSlug ?? "", options);+};