From cb78de231a66d38f9af0836232d0423ff146fca9 Mon Sep 17 00:00:00 2001 From: Somay Chauhan Date: Sat, 25 Nov 2023 03:24:14 +0530 Subject: [PATCH] feat: if profile only has one public event-type, redirect to it (#12158) Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> --- apps/web/components/ui/avatar/UserAvatarGroup.tsx | 2 ++ .../components/ui/avatar/UserAvatarGroupWithOrg.tsx | 7 ++++++- apps/web/pages/[user].tsx | 11 +++++++++++ apps/web/pages/org/[orgSlug]/[user]/index.tsx | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/web/components/ui/avatar/UserAvatarGroup.tsx b/apps/web/components/ui/avatar/UserAvatarGroup.tsx index ad3909641e..e9346fb401 100644 --- a/apps/web/components/ui/avatar/UserAvatarGroup.tsx +++ b/apps/web/components/ui/avatar/UserAvatarGroup.tsx @@ -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) { ({ + href: `${CAL_URL}/${user.username}?redirect=false`, alt: user.name || "", title: user.name || "", image: getUserAvatarUrl(user), diff --git a/apps/web/components/ui/avatar/UserAvatarGroupWithOrg.tsx b/apps/web/components/ui/avatar/UserAvatarGroupWithOrg.tsx index 9de57a0b57..6b265395d8 100644 --- a/apps/web/components/ui/avatar/UserAvatarGroupWithOrg.tsx +++ b/apps/web/components/ui/avatar/UserAvatarGroupWithOrg.tsx @@ -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, "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 || "", diff --git a/apps/web/pages/[user].tsx b/apps/web/pages/[user].tsx index 7d5cf4f9f7..493b8f3953 100644 --- a/apps/web/pages/[user].tsx +++ b/apps/web/pages/[user].tsx @@ -54,6 +54,7 @@ export function UserPage(props: InferGetServerSidePropsType = 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 || ""); diff --git a/apps/web/pages/org/[orgSlug]/[user]/index.tsx b/apps/web/pages/org/[orgSlug]/[user]/index.tsx index 7174a217d7..df0d6d6b97 100644 --- a/apps/web/pages/org/[orgSlug]/[user]/index.tsx +++ b/apps/web/pages/org/[orgSlug]/[user]/index.tsx @@ -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;