chore: reduce team data footprint (#11478)

This commit is contained in:
Leo Giovanetti authored and GitHub committed 2023-09-21 18:08:34 -03:00
1 parent 86b3a33ff6
commit 578495de87
10 files changed
+75 -53

No files matched your search

@@ -10,10 +10,15 @@ import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
*/
export type OrganizationBranding =
| ({
/** 1 */
id: number;
/** Acme */
name?: string;
/** acme */
slug: string;
/** https://acme.cal.com */
fullDomain: string;
/** cal.com */
domainSuffix: string;
} & z.infer<typeof teamMetadataSchema>)
| null
@@ -121,7 +121,7 @@ export default function MemberListItem(props: Props) {
const bookerUrlWithoutProtocol = bookerUrl.replace(/^https?:\/\//, "");
const bookingLink = !!props.member.username && `${bookerUrlWithoutProtocol}/${props.member.username}`;
const isAdmin = props.team && ["ADMIN", "OWNER"].includes(props.team.membership?.role);
const appList = props.member.connectedApps.map(({ logo, name, externalId }) => {
const appList = props.member.connectedApps?.map(({ logo, name, externalId }) => {
return logo ? (
externalId ? (
<div className="ltr:mr-2 rtl:ml-2 ">
@@ -11,7 +11,6 @@ interface Props {
id?: number;
name?: string | null;
slug?: string | null;
logo?: string | null;
bio?: string | null;
hideBranding?: boolean | undefined;
role: MembershipRole;
@@ -1,5 +1,5 @@
import classNames from "@calcom/lib/classNames";
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { MembershipRole } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
@@ -20,7 +20,6 @@ interface Props {
id?: number;
name?: string | null;
slug?: string | null;
logo?: string | null;
bio?: string | null;
hideBranding?: boolean | undefined;
role: MembershipRole;
@@ -66,7 +65,7 @@ export default function TeamInviteListItem(props: Props) {
<div className="flex">
<Avatar
size="mdLg"
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
imageSrc={`${WEBAPP_URL}/team/${team.slug}/avatar.png`}
alt="Team Logo"
className=""
/>
@@ -149,7 +149,6 @@ const MembersView = () => {
{
id: team.id,
accepted: team.membership.accepted || false,
logo: team.logo,
name: team.name,
slug: team.slug,
role: team.membership.role,
@@ -94,7 +94,6 @@ const ProfileView = () => {
if (team) {
form.setValue("name", team.name || "");
form.setValue("slug", team.slug || "");
form.setValue("logo", team.logo || "");
form.setValue("bio", team.bio || "");
if (team.slug === null && (team?.metadata as Prisma.JsonObject)?.requestedSlug) {
form.setValue("slug", ((team?.metadata as Prisma.JsonObject)?.requestedSlug as string) || "");
@@ -165,7 +164,6 @@ const ProfileView = () => {
handleSubmit={(values) => {
if (team) {
const variables = {
logo: values.logo,
name: values.name,
slug: values.slug,
bio: values.bio,
+1
View File
@@ -6,6 +6,7 @@ export const CALCOM_ENV = process.env.CALCOM_ENV || process.env.NODE_ENV;
export const IS_PRODUCTION = CALCOM_ENV === "production";
export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";
/** https://app.cal.com */
export const WEBAPP_URL =
process.env.NEXT_PUBLIC_WEBAPP_URL ||
VERCEL_URL ||
+24 -26
View File
@@ -15,19 +15,16 @@ export async function getTeamWithMembers(args: {
slug?: string;
userId?: number;
orgSlug?: string | null;
isTeamView?: boolean;
isOrgView?: boolean;
}) {
const { id, slug, userId, orgSlug } = args;
const { id, slug, userId, orgSlug, isTeamView, isOrgView } = args;
const userSelect = Prisma.validator<Prisma.UserSelect>()({
username: true,
email: true,
name: true,
id: true,
bio: true,
destinationCalendar: {
select: {
externalId: true,
},
},
teams: {
select: {
team: {
@@ -37,7 +34,6 @@ export async function getTeamWithMembers(args: {
},
},
},
selectedCalendars: true,
credentials: {
select: {
app: {
@@ -58,7 +54,6 @@ export async function getTeamWithMembers(args: {
id: true,
name: true,
slug: true,
logo: true,
bio: true,
hideBranding: true,
hideBookATeamMember: true,
@@ -136,8 +131,9 @@ export async function getTeamWithMembers(args: {
// This should improve performance saving already app data found.
const appDataMap = new Map();
const members = team.members.map((obj) => {
const { credentials, ...restUser } = obj.user;
return {
...obj.user,
...restUser,
role: obj.role,
accepted: obj.accepted,
disableImpersonation: obj.disableImpersonation,
@@ -145,24 +141,26 @@ export async function getTeamWithMembers(args: {
? obj.user.teams.filter((obj) => obj.team.slug !== orgSlug).map((obj) => obj.team.slug)
: null,
avatar: `${WEBAPP_URL}/${obj.user.username}/avatar.png`,
connectedApps: obj?.user?.credentials?.map((cred) => {
const appSlug = cred.app?.slug;
let appData = appDataMap.get(appSlug);
connectedApps: !isTeamView
? credentials?.map((cred) => {
const appSlug = cred.app?.slug;
let appData = appDataMap.get(appSlug);
if (!appData) {
appData = getAppFromSlug(appSlug);
appDataMap.set(appSlug, appData);
}
if (!appData) {
appData = getAppFromSlug(appSlug);
appDataMap.set(appSlug, appData);
}
const isCalendar = cred?.app?.categories?.includes("calendar") ?? false;
const externalId = isCalendar ? cred.destinationCalendars?.[0]?.externalId : null;
return {
name: appData?.name ?? null,
logo: appData?.logo ?? null,
app: cred.app,
externalId: externalId ?? null,
};
}),
const isCalendar = cred?.app?.categories?.includes("calendar") ?? false;
const externalId = isCalendar ? cred.destinationCalendars?.[0]?.externalId : null;
return {
name: appData?.name ?? null,
logo: appData?.logo ?? null,
app: cred.app,
externalId: externalId ?? null,
};
})
: null,
};
});
@@ -182,7 +180,7 @@ export async function getTeamWithMembers(args: {
token.expires > new Date(new Date().setHours(24))
),
metadata: teamMetadataSchema.parse(team.metadata),
eventTypes,
eventTypes: !isOrgView ? eventTypes : null,
members,
};
}
@@ -22,8 +22,13 @@ export function UnpublishedEntity(props: UnpublishedEntityProps) {
}
headline={t("team_is_unpublished", {
team: props.name,
defaultValue: `${props.name} is unpublished`,
})}
description={t(`${props.orgSlug ? "org" : "team"}_is_unpublished_description`, {
defaultValue: `This ${
props.orgSlug ? "organization" : "team"
} link is currently not available. Please contact the organization owner or ask them to publish it.`,
})}
description={t(`${props.orgSlug ? "org" : "team"}_is_unpublished_description`)}
/>
</div>
);