Skip to content

Commit

Permalink
fix: Links on avatar for org events (#12892)
Browse files Browse the repository at this point in the history
* fix: Links on avatar for org events

* Remove noop code

* Fix self review feedbavk
  • Loading branch information
hariombalhara authored Dec 20, 2023
1 parent 2693b30 commit 9a2c2aa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
13 changes: 5 additions & 8 deletions apps/web/components/ui/avatar/UserAvatarGroupWithOrg.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
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,
},
].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} />;
}
47 changes: 42 additions & 5 deletions packages/features/eventtypes/lib/getPublicEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -82,6 +83,11 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
darkBrandColor: true,
theme: true,
organizationId: true,
organization: {
select: {
slug: true,
},
},
metadata: true,
},
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
};
}
2 changes: 1 addition & 1 deletion packages/lib/domainManager/deploymentServices/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9a2c2aa

Please sign in to comment.