fix: filling users logic (#18128)
* fix filling users logic * fix type check * refactor
This commit is contained in:
@@ -6,10 +6,7 @@ import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
|
||||
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
|
||||
import { getSlugOrRequestedSlug, orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
|
||||
import { getUsernameList } from "@calcom/lib/defaultEvents";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { RedirectType } from "@calcom/prisma/client";
|
||||
@@ -58,6 +55,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isPrivate: true,
|
||||
hideBranding: true,
|
||||
parent: {
|
||||
select: {
|
||||
@@ -87,6 +85,16 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
metadata: true,
|
||||
length: true,
|
||||
hidden: true,
|
||||
hosts: {
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
name: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
isOrganization: true,
|
||||
@@ -103,21 +111,51 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
notFound: true,
|
||||
} as const;
|
||||
}
|
||||
const eventData = team.eventTypes[0];
|
||||
const eventTypeId = eventData.id;
|
||||
|
||||
// INFO: This code was pulled from getPublicEvent and used here.
|
||||
// Calling the tRPC fetch to get the public event data is incredibly slow
|
||||
// for large teams and we don't want to add it back. Future refactors will happen
|
||||
// to speed up this call.
|
||||
const usernameList = getUsernameList(teamSlug);
|
||||
let users: { username: string; name: string }[] = [];
|
||||
|
||||
if (!team.isPrivate && eventData.hosts.length > 0) {
|
||||
users = eventData.hosts
|
||||
.filter((host) => host.user.username)
|
||||
.map((host) => ({
|
||||
username: host.user.username ?? "",
|
||||
name: host.user.name ?? "",
|
||||
}));
|
||||
}
|
||||
if (!team.isPrivate && eventData.hosts.length === 0) {
|
||||
// a minimalistic version of `getOwnerFromUsersArray` in `getPublicEvent.ts`
|
||||
// backward compatibility logic for team event types that have users[] but not hosts[]
|
||||
const { users: data } = await prisma.eventType.findUniqueOrThrow({
|
||||
where: { id: eventTypeId },
|
||||
select: {
|
||||
users: {
|
||||
select: {
|
||||
username: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
users =
|
||||
data.length > 0
|
||||
? [
|
||||
{
|
||||
username: data[0].username ?? "",
|
||||
name: data[0].name ?? "",
|
||||
},
|
||||
]
|
||||
: [];
|
||||
}
|
||||
|
||||
const orgSlug = isValidOrgDomain ? currentOrgDomain : null;
|
||||
const name = team.parent?.name ?? team.name ?? null;
|
||||
const usersInOrgContext = await UserRepository.findUsersByUsername({
|
||||
usernameList,
|
||||
orgSlug: team.parent?.slug || null,
|
||||
});
|
||||
|
||||
const eventData = team.eventTypes[0];
|
||||
const eventTypeId = eventData.id;
|
||||
|
||||
let booking: GetBookingType | null = null;
|
||||
if (rescheduleUid) {
|
||||
@@ -169,11 +207,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
username: orgSlug ?? null,
|
||||
},
|
||||
title: eventData.title,
|
||||
users: usersInOrgContext.map((user) => ({
|
||||
...user,
|
||||
metadata: undefined,
|
||||
bookerUrl: getBookerBaseUrlSync(user.profile?.organization?.slug ?? null),
|
||||
})),
|
||||
users,
|
||||
hidden: eventData.hidden,
|
||||
},
|
||||
booking,
|
||||
|
||||
@@ -22,13 +22,17 @@ type Props = {
|
||||
NonNullable<Awaited<ReturnType<typeof getPublicEvent>>>,
|
||||
"id" | "length" | "metadata" | "entity" | "profile" | "title" | "users" | "hidden"
|
||||
>,
|
||||
"profile"
|
||||
"profile" | "users"
|
||||
> & {
|
||||
profile: {
|
||||
image: string | undefined;
|
||||
name: string | null;
|
||||
username: string | null;
|
||||
};
|
||||
users: {
|
||||
username: string;
|
||||
name: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
booking?: GetBookingType;
|
||||
@@ -159,7 +163,7 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
|
||||
username: eventData.profile.username ?? null,
|
||||
},
|
||||
title: eventData.title,
|
||||
users: eventData.users,
|
||||
users: eventData.users.map((user) => ({ username: user.username ?? "", name: user.name ?? "" })),
|
||||
hidden: eventData.hidden,
|
||||
},
|
||||
user: usernames.join("+"),
|
||||
@@ -255,7 +259,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
username: eventData.profile.username ?? null,
|
||||
},
|
||||
title: eventData.title,
|
||||
users: eventData.users,
|
||||
users: eventData.users.map((user) => ({ username: user.username ?? "", name: user.name ?? "" })),
|
||||
hidden: eventData.hidden,
|
||||
},
|
||||
user: username,
|
||||
|
||||
@@ -14,13 +14,17 @@ interface BookerSeoProps {
|
||||
isTeamEvent?: boolean;
|
||||
eventData?: Omit<
|
||||
Pick<NonNullable<Awaited<ReturnType<typeof getPublicEvent>>>, "profile" | "title" | "users" | "hidden">,
|
||||
"profile"
|
||||
"profile" | "users"
|
||||
> & {
|
||||
profile: {
|
||||
image: string | undefined;
|
||||
name: string | null;
|
||||
username: string | null;
|
||||
};
|
||||
users: {
|
||||
username: string;
|
||||
name: string;
|
||||
}[];
|
||||
};
|
||||
entity: {
|
||||
fromRedirectOfNonOrgLink: boolean;
|
||||
|
||||
Reference in New Issue
Block a user