fix: Across Org Scenarios - Wrong links for event and team (#12358)
Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
1 parent
f1caaad536
commit
e5e0fa97eb
35 files changed
+570
-154
No files matched your search
@@ -19,8 +19,22 @@ export const getUserAvatarUrl = (
|
||||
}`;
|
||||
};
|
||||
|
||||
export function getTeamAvatarUrl(
|
||||
team: Pick<Team, "slug"> & {
|
||||
organizationId?: number | null;
|
||||
logoUrl?: string | null;
|
||||
requestedSlug: string | null;
|
||||
}
|
||||
) {
|
||||
if (team.logoUrl) {
|
||||
return team.logoUrl;
|
||||
}
|
||||
const slug = team.slug ?? team.requestedSlug;
|
||||
return `${WEBAPP_URL}/team/${slug}/avatar.png${team.organizationId ? `?orgId=${team.organizationId}` : ""}`;
|
||||
}
|
||||
|
||||
export const getOrgAvatarUrl = (
|
||||
org: Pick<Team, "id" | "slug"> & {
|
||||
org: Pick<Team, "slug"> & {
|
||||
logoUrl?: string | null;
|
||||
requestedSlug: string | null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
|
||||
export const getBookerBaseUrlSync = (
|
||||
orgSlug: string | null,
|
||||
options?: {
|
||||
protocol: boolean;
|
||||
}
|
||||
) => {
|
||||
return getOrgFullOrigin(orgSlug ?? "", options);
|
||||
};
|
||||
|
||||
export const getTeamUrlSync = (
|
||||
{
|
||||
orgSlug,
|
||||
teamSlug,
|
||||
}: {
|
||||
orgSlug: string | null;
|
||||
teamSlug: string | null;
|
||||
},
|
||||
options?: {
|
||||
protocol: boolean;
|
||||
}
|
||||
) => {
|
||||
const bookerUrl = getBookerBaseUrlSync(orgSlug, options);
|
||||
teamSlug = teamSlug || "";
|
||||
if (orgSlug) {
|
||||
return `${bookerUrl}/${teamSlug}`;
|
||||
}
|
||||
return `${bookerUrl}/team/${teamSlug}`;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import { WEBAPP_URL } from "../constants";
|
||||
import { getBrand } from "../server/getBrand";
|
||||
|
||||
export const getBookerBaseUrl = async (user: { organizationId: number | null }) => {
|
||||
const orgBrand = await getBrand(user.organizationId);
|
||||
return orgBrand?.fullDomain ?? WEBAPP_URL;
|
||||
};
|
||||
|
||||
export const getTeamBookerUrl = async (team: { organizationId: number | null }) => {
|
||||
const orgBrand = await getBrand(team.organizationId);
|
||||
return orgBrand?.fullDomain ?? WEBAPP_URL;
|
||||
};
|
||||
@@ -15,6 +15,9 @@ import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-u
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import { WEBAPP_URL } from "./constants";
|
||||
import { getBookerBaseUrl } from "./getBookerUrl/server";
|
||||
|
||||
interface getEventTypeByIdProps {
|
||||
eventTypeId: number;
|
||||
userId: number;
|
||||
@@ -106,6 +109,11 @@ export default async function getEventTypeById({
|
||||
successRedirectUrl: true,
|
||||
currency: true,
|
||||
bookingFields: true,
|
||||
owner: {
|
||||
select: {
|
||||
organizationId: true,
|
||||
},
|
||||
},
|
||||
parent: {
|
||||
select: {
|
||||
teamId: true,
|
||||
@@ -167,6 +175,7 @@ export default async function getEventTypeById({
|
||||
username: true,
|
||||
email: true,
|
||||
id: true,
|
||||
organizationId: true,
|
||||
},
|
||||
},
|
||||
hidden: true,
|
||||
@@ -257,12 +266,18 @@ export default async function getEventTypeById({
|
||||
metadata: parsedMetaData,
|
||||
customInputs: parsedCustomInputs,
|
||||
users: rawEventType.users,
|
||||
bookerUrl: restEventType.team
|
||||
? await getBookerBaseUrl({ organizationId: restEventType.team.parentId })
|
||||
: restEventType.owner
|
||||
? await getBookerBaseUrl(restEventType.owner)
|
||||
: WEBAPP_URL,
|
||||
children: restEventType.children.flatMap((ch) =>
|
||||
ch.owner !== null
|
||||
? {
|
||||
...ch,
|
||||
owner: {
|
||||
...ch.owner,
|
||||
avatar: getUserAvatarUrl(ch.owner),
|
||||
email: ch.owner.email,
|
||||
name: ch.owner.name ?? "",
|
||||
username: ch.owner.username ?? "",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { WEBAPP_URL } from "../constants";
|
||||
import { getBrand } from "./getBrand";
|
||||
|
||||
export const getBookerUrl = async (user: { organizationId: number | null }) => {
|
||||
const orgBrand = await getBrand(user.organizationId);
|
||||
return orgBrand?.fullDomain ?? WEBAPP_URL;
|
||||
};
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { WEBAPP_URL } from "../../../constants";
|
||||
import { getBookerBaseUrlSync } from "../../../getBookerUrl/client";
|
||||
import { getTeam, getOrg } from "../../repository/team";
|
||||
|
||||
export type TeamWithMembers = Awaited<ReturnType<typeof getTeamWithMembers>>;
|
||||
@@ -158,7 +158,7 @@ export async function getTeamWithMembers(args: {
|
||||
.map((membership) => membership.team.slug)
|
||||
: null,
|
||||
avatar: `${WEBAPP_URL}/${m.user.username}/avatar.png`,
|
||||
orgOrigin: getOrgFullOrigin(m.user.organization?.slug || ""),
|
||||
bookerUrl: getBookerBaseUrlSync(m.user.organization?.slug || ""),
|
||||
connectedApps: !isTeamView
|
||||
? credentials?.map((cred) => {
|
||||
const appSlug = cred.app?.slug;
|
||||
|
||||
Reference in new issue
Block a user