feat: if profile only has one public event-type, redirect to it

pull/12158/head
Somay 2023-10-31 10:59:14 +05:30
parent 31f3d9778e
commit ecc635b6c3
4 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { CAL_URL } from "@calcom/lib/constants";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import type { User } from "@calcom/prisma/client";
import { AvatarGroup } from "@calcom/ui";
@ -11,6 +12,7 @@ export function UserAvatarGroup(props: UserAvatarProps) {
<AvatarGroup
{...rest}
items={users.map((user) => ({
href: `${CAL_URL}/${user.username}?redirect=false`,
alt: user.name || "",
title: user.name || "",
image: getUserAvatarUrl(user),

View File

@ -1,4 +1,5 @@
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
import { CAL_URL, WEBAPP_URL } from "@calcom/lib/constants";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import type { Team, User } from "@calcom/prisma/client";
import { AvatarGroup } from "@calcom/ui";
@ -10,8 +11,11 @@ type UserAvatarProps = Omit<React.ComponentProps<typeof AvatarGroup>, "items"> &
export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
const { users, organization, ...rest } = props;
const orgBranding = useOrgBranding();
const baseUrl = `${orgBranding?.fullDomain ?? CAL_URL}`;
const items = [
{
href: baseUrl,
image: `${WEBAPP_URL}/team/${organization.slug}/avatar.png`,
alt: organization.name || undefined,
title: organization.name,
@ -19,6 +23,7 @@ export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
].concat(
users.map((user) => {
return {
href: `${baseUrl}/${user.username}/?redirect=false`,
image: getUserAvatarUrl(user),
alt: user.name || undefined,
title: user.name || user.username || "",

View File

@ -54,6 +54,7 @@ export function UserPage(props: InferGetServerSidePropsType<typeof getServerSide
// So it doesn't display in the Link (and make tests fail)
user: _user,
orgSlug: _orgSlug,
redirect: _redirect,
...query
} = useRouterQuery();
@ -386,6 +387,16 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (cont
descriptionAsSafeHTML: markdownToSafeHTML(eventType.description),
}));
// if profile only has one public event-type, redirect to it
if (eventTypes.length === 1 && context.query.redirect !== "false") {
return {
redirect: {
permanent: false,
destination: `/${user.username}/${eventTypes[0].slug}`,
},
};
}
const safeBio = markdownToSafeHTML(user.bio) || "";
const markdownStrippedBio = stripMarkdown(user?.bio || "");

View File

@ -26,7 +26,7 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
if (team) {
return GSSTeamPage({ ...ctx, query: { slug: ctx.query.user } });
}
return GSSUserPage({ ...ctx, query: { user: ctx.query.user } });
return GSSUserPage({ ...ctx, query: { user: ctx.query.user, redirect: ctx.query.redirect } });
};
type Props = UserPageProps | TeamPageProps;