Scheduling infrastructure for absolutely everyone.
feat: if profile only has one public event-type, redirect to it (#12158)
Somay Chauhancb78de231a66
diff --git a/apps/web/components/ui/avatar/UserAvatarGroup.tsx b/apps/web/components/ui/avatar/UserAvatarGroup.tsxindex ad3909641e4..e9346fb4018 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) {<AvatarGroup{...rest}items={users.map((user) => ({+ 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.tsxindex 9de57a0b578..6b265395d8a 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<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 || "",diff --git a/apps/web/pages/[user].tsx b/apps/web/pages/[user].tsxindex 7d5cf4f9f73..493b8f3953a 100644--- a/apps/web/pages/[user].tsx+++ b/apps/web/pages/[user].tsx@@ -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();@@ -388,6 +389,16 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (contdescriptionAsSafeHTML: 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.tsxindex 7174a217d79..df0d6d6b97b 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;