feat: if profile only has one public event-type, redirect to it
parent
31f3d9778e
commit
ecc635b6c3
|
@ -1,3 +1,4 @@
|
||||||
|
import { CAL_URL } from "@calcom/lib/constants";
|
||||||
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||||
import type { User } from "@calcom/prisma/client";
|
import type { User } from "@calcom/prisma/client";
|
||||||
import { AvatarGroup } from "@calcom/ui";
|
import { AvatarGroup } from "@calcom/ui";
|
||||||
|
@ -11,6 +12,7 @@ export function UserAvatarGroup(props: UserAvatarProps) {
|
||||||
<AvatarGroup
|
<AvatarGroup
|
||||||
{...rest}
|
{...rest}
|
||||||
items={users.map((user) => ({
|
items={users.map((user) => ({
|
||||||
|
href: `${CAL_URL}/${user.username}?redirect=false`,
|
||||||
alt: user.name || "",
|
alt: user.name || "",
|
||||||
title: user.name || "",
|
title: user.name || "",
|
||||||
image: getUserAvatarUrl(user),
|
image: getUserAvatarUrl(user),
|
||||||
|
|
|
@ -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 { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||||
import type { Team, User } from "@calcom/prisma/client";
|
import type { Team, User } from "@calcom/prisma/client";
|
||||||
import { AvatarGroup } from "@calcom/ui";
|
import { AvatarGroup } from "@calcom/ui";
|
||||||
|
@ -10,8 +11,11 @@ type UserAvatarProps = Omit<React.ComponentProps<typeof AvatarGroup>, "items"> &
|
||||||
|
|
||||||
export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
|
export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
|
||||||
const { users, organization, ...rest } = props;
|
const { users, organization, ...rest } = props;
|
||||||
|
const orgBranding = useOrgBranding();
|
||||||
|
const baseUrl = `${orgBranding?.fullDomain ?? CAL_URL}`;
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
|
href: baseUrl,
|
||||||
image: `${WEBAPP_URL}/team/${organization.slug}/avatar.png`,
|
image: `${WEBAPP_URL}/team/${organization.slug}/avatar.png`,
|
||||||
alt: organization.name || undefined,
|
alt: organization.name || undefined,
|
||||||
title: organization.name,
|
title: organization.name,
|
||||||
|
@ -19,6 +23,7 @@ export function UserAvatarGroupWithOrg(props: UserAvatarProps) {
|
||||||
].concat(
|
].concat(
|
||||||
users.map((user) => {
|
users.map((user) => {
|
||||||
return {
|
return {
|
||||||
|
href: `${baseUrl}/${user.username}/?redirect=false`,
|
||||||
image: getUserAvatarUrl(user),
|
image: getUserAvatarUrl(user),
|
||||||
alt: user.name || undefined,
|
alt: user.name || undefined,
|
||||||
title: user.name || user.username || "",
|
title: user.name || user.username || "",
|
||||||
|
|
|
@ -54,6 +54,7 @@ export function UserPage(props: InferGetServerSidePropsType<typeof getServerSide
|
||||||
// So it doesn't display in the Link (and make tests fail)
|
// So it doesn't display in the Link (and make tests fail)
|
||||||
user: _user,
|
user: _user,
|
||||||
orgSlug: _orgSlug,
|
orgSlug: _orgSlug,
|
||||||
|
redirect: _redirect,
|
||||||
...query
|
...query
|
||||||
} = useRouterQuery();
|
} = useRouterQuery();
|
||||||
|
|
||||||
|
@ -386,6 +387,16 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (cont
|
||||||
descriptionAsSafeHTML: markdownToSafeHTML(eventType.description),
|
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 safeBio = markdownToSafeHTML(user.bio) || "";
|
||||||
|
|
||||||
const markdownStrippedBio = stripMarkdown(user?.bio || "");
|
const markdownStrippedBio = stripMarkdown(user?.bio || "");
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
||||||
if (team) {
|
if (team) {
|
||||||
return GSSTeamPage({ ...ctx, query: { slug: ctx.query.user } });
|
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;
|
type Props = UserPageProps | TeamPageProps;
|
||||||
|
|
Loading…
Reference in New Issue