fix: Team and User Links (#15342)

* fix: Team and User Links

* Add tests
This commit is contained in:
Hariom Balhara
2024-06-06 11:40:29 +00:00
committed by GitHub
parent 4153e5b2d5
commit def87ea84a
7 changed files with 55 additions and 17 deletions
@@ -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})` : ""}`,
@@ -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;
@@ -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>
+30
View File
@@ -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");
});
});
});
+2 -10
View File
@@ -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,
@@ -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);
};