Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Links on avatar for org events #12892

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useOrgBranding gives the org details for the logged in user and not the organizer being booked.

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} />;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why it was there, but unshift without argument doesn't do anything.

}
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}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved the error message in the PR as I saw the error while testing and it wasn't clear enough

logger.error(safeStringify({ errorMessage, vercelError: error }));
throw new HttpError({
message: errorMessage,
Expand Down
Loading