fix: Links on avatar for org events (#12892)

* fix: Links on avatar for org events

* Remove noop code

* Fix self review feedbavk
This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-12-20 14:21:29 +00:00
1 parent 2693b30c51
commit 9a2c2aaca4
3 files changed
+48 -14

No files matched your search

@@ -1,21 +1,19 @@
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
import { CAL_URL, WEBAPP_URL } from "@calcom/lib/constants";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
import type { Team, User } from "@calcom/prisma/client";
import { AvatarGroup } from "@calcom/ui";
type UserAvatarProps = Omit<React.ComponentProps<typeof AvatarGroup>, "items"> & {
users: Pick<User, "organizationId" | "name" | "username">[];
users: (Pick<User, "organizationId" | "name" | "username"> & { bookerUrl: string })[];
organization: Pick<Team, "slug" | "name">;
};
export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
const { users, organization, ...rest } = props;
const orgBranding = useOrgBranding();
const baseUrl = `${orgBranding?.fullDomain ?? CAL_URL}`;
const items = [
{
href: baseUrl,
href: getBookerBaseUrlSync(organization.slug),
image: `${WEBAPP_URL}/team/${organization.slug}/avatar.png`,
alt: organization.name || undefined,
title: organization.name,
@@ -23,13 +21,12 @@ export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
].concat(
users.map((user) => {
return {
href: `${baseUrl}/${user.username}/?redirect=false`,
href: `${user.bookerUrl}/${user.username}?redirect=false`,
image: getUserAvatarUrl(user),
alt: user.name || undefined,
title: user.name || user.username || "",
};
})
);
users.unshift();
return <AvatarGroup {...rest} items={items} />;
}
@@ -8,6 +8,7 @@ import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/
import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/orgDomains";
import { isRecurringEvent, parseRecurringEvent } from "@calcom/lib";
import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
import type { PrismaClient } from "@calcom/prisma";
import type { BookerLayoutSettings } from "@calcom/prisma/zod-utils";
@@ -82,6 +83,11 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
darkBrandColor: true,
theme: true,
organizationId: true,
organization: {
select: {
slug: true,
},
},
metadata: true,
},
},
@@ -172,7 +178,11 @@ export const getPublicEvent = async (
...defaultEvent,
bookingFields: getBookingFieldsWithSystemFields({ ...defaultEvent, disableBookingTitle }),
// Clears meta data since we don't want to send this in the public api.
users: users.map((user) => ({ ...user, metadata: undefined })),
users: users.map((user) => ({
...user,
metadata: undefined,
bookerUrl: getBookerBaseUrlSync(user.organization?.slug ?? null),
})),
locations: privacyFilteredLocations(locations),
profile: {
username: users[0].username,
@@ -299,23 +309,50 @@ function getUsersFromEvent(event: Event) {
return null;
}
const { username, name, weekStart, organizationId } = owner;
return [{ username, name, weekStart, organizationId }];
return [
{
username,
name,
weekStart,
organizationId,
bookerUrl: getBookerBaseUrlSync(owner.organization?.slug ?? null),
},
];
}
async function getOwnerFromUsersArray(prisma: PrismaClient, eventTypeId: number) {
const { users } = await prisma.eventType.findUniqueOrThrow({
where: { id: eventTypeId },
select: { users: { select: { username: true, name: true, weekStart: true, organizationId: true } } },
select: {
users: {
select: {
username: true,
name: true,
weekStart: true,
organizationId: true,
organization: {
select: {
slug: true,
},
},
},
},
},
});
if (!users.length) return null;
return [users[0]];
return [{ ...users[0], bookerUrl: getBookerBaseUrlSync(users[0].organization?.slug ?? null) }];
}
function mapHostsToUsers(host: { user: Pick<User, "username" | "name" | "weekStart" | "organizationId"> }) {
function mapHostsToUsers(host: {
user: Pick<User, "username" | "name" | "weekStart" | "organizationId"> & {
organization: { slug: string | null } | null;
};
}) {
return {
username: host.user.username,
name: host.user.name,
weekStart: host.user.weekStart,
organizationId: host.user.organizationId,
bookerUrl: getBookerBaseUrlSync(host.user.organization?.slug ?? null),
};
}
@@ -93,7 +93,7 @@ function handleDomainCreationError(error: { code?: string | null; domain?: strin
return true;
}
const errorMessage = `Failed to take action for domain: ${error.domain}`;
const errorMessage = `Failed to create domain on Vercel: ${error.domain}`;
logger.error(safeStringify({ errorMessage, vercelError: error }));
throw new HttpError({
message: errorMessage,