2022-04-25 04:33:00 +00:00
|
|
|
import classNames from "classnames";
|
2023-01-25 01:08:10 +00:00
|
|
|
import MarkdownIt from "markdown-it";
|
2021-10-08 11:43:48 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2021-09-06 13:51:15 +00:00
|
|
|
import Link from "next/link";
|
2021-12-03 10:15:20 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-09-15 09:33:34 +00:00
|
|
|
import { useEffect } from "react";
|
2022-02-01 21:48:40 +00:00
|
|
|
import { Toaster } from "react-hot-toast";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-05-27 15:37:02 +00:00
|
|
|
import {
|
|
|
|
sdkActionManager,
|
|
|
|
useEmbedNonStylesConfig,
|
|
|
|
useEmbedStyles,
|
|
|
|
useIsEmbed,
|
|
|
|
} from "@calcom/embed-core/embed-iframe";
|
2022-12-22 19:06:26 +00:00
|
|
|
import { EventTypeDescriptionLazy as EventTypeDescription } from "@calcom/features/eventtypes/components";
|
2022-10-24 22:20:41 +00:00
|
|
|
import EmptyPage from "@calcom/features/eventtypes/components/EmptyPage";
|
2022-07-23 00:39:50 +00:00
|
|
|
import CustomBranding from "@calcom/lib/CustomBranding";
|
2022-04-06 17:20:30 +00:00
|
|
|
import defaultEvents, {
|
|
|
|
getDynamicEventDescription,
|
2022-04-25 04:33:00 +00:00
|
|
|
getGroupName,
|
2022-04-06 17:20:30 +00:00
|
|
|
getUsernameList,
|
|
|
|
getUsernameSlugLink,
|
|
|
|
} from "@calcom/lib/defaultEvents";
|
2022-03-31 08:45:47 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-28 19:58:26 +00:00
|
|
|
import useTheme from "@calcom/lib/hooks/useTheme";
|
|
|
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { baseEventTypeSelect } from "@calcom/prisma/selects";
|
2022-10-14 16:24:43 +00:00
|
|
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { HeadSeo, AvatarGroup, Avatar } from "@calcom/ui";
|
|
|
|
import { BadgeCheckIcon, FiArrowRight } from "@calcom/ui/components/icon";
|
2022-03-31 08:45:47 +00:00
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
2022-10-19 21:25:03 +00:00
|
|
|
import { EmbedProps } from "@lib/withEmbedSsr";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-20 16:00:11 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2023-01-25 01:08:10 +00:00
|
|
|
const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
|
|
|
|
|
2022-10-19 21:25:03 +00:00
|
|
|
export default function User(props: inferSSRProps<typeof getServerSideProps> & EmbedProps) {
|
2022-06-15 20:54:31 +00:00
|
|
|
const { users, profile, eventTypes, isDynamicGroup, dynamicNames, dynamicUsernames, isSingleUser } = props;
|
2022-04-06 17:20:30 +00:00
|
|
|
const [user] = users; //To be used when we only have a single user, not dynamic group
|
2022-07-26 08:27:57 +00:00
|
|
|
useTheme(user.theme);
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
2021-12-03 10:15:20 +00:00
|
|
|
const router = useRouter();
|
2022-06-15 20:54:31 +00:00
|
|
|
|
2023-01-25 01:08:10 +00:00
|
|
|
const isBioEmpty = !user.bio || !user.bio.replace("<p><br></p>", "").length;
|
|
|
|
|
2022-08-12 19:29:29 +00:00
|
|
|
const groupEventTypes = props.users.some((user) => !user.allowDynamicBooking) ? (
|
|
|
|
<div className="space-y-6" data-testid="event-types">
|
|
|
|
<div className="overflow-hidden rounded-sm border dark:border-gray-900">
|
|
|
|
<div className="p-8 text-center text-gray-400 dark:text-white">
|
|
|
|
<h2 className="font-cal mb-2 text-3xl text-gray-600 dark:text-white">{" " + t("unavailable")}</h2>
|
|
|
|
<p className="mx-auto max-w-md">{t("user_dynamic_booking_disabled") as string}</p>
|
2022-04-06 17:20:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-12 19:29:29 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2022-08-24 20:18:42 +00:00
|
|
|
<ul>
|
2022-08-12 19:29:29 +00:00
|
|
|
{eventTypes.map((type, index) => (
|
|
|
|
<li
|
|
|
|
key={index}
|
2023-01-25 01:08:10 +00:00
|
|
|
className="dark:bg-darkgray-100 group relative border-b border-gray-200 bg-white first:rounded-t-md last:rounded-b-md last:border-b-0 hover:bg-gray-50 dark:border-gray-700 dark:hover:border-gray-600">
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiArrowRight className="absolute right-3 top-3 h-4 w-4 text-black opacity-0 transition-opacity group-hover:opacity-100 dark:text-white" />
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
href={getUsernameSlugLink({ users: props.users, slug: type.slug })}
|
|
|
|
className="flex justify-between px-6 py-4"
|
|
|
|
data-testid="event-type-link">
|
|
|
|
<div className="flex-shrink">
|
2023-01-12 16:57:43 +00:00
|
|
|
<p className="dark:text-darkgray-700 text-sm font-semibold text-gray-900">{type.title}</p>
|
2023-01-06 12:13:56 +00:00
|
|
|
<EventTypeDescription className="text-sm" eventType={type} />
|
|
|
|
</div>
|
|
|
|
<div className="mt-1 self-center">
|
|
|
|
<AvatarGroup
|
|
|
|
truncateAfter={4}
|
|
|
|
className="flex flex-shrink-0"
|
2023-01-11 15:00:46 +00:00
|
|
|
size="sm"
|
2023-01-06 12:13:56 +00:00
|
|
|
items={props.users.map((user) => ({
|
|
|
|
alt: user.name || "",
|
|
|
|
image: user.avatar || "",
|
|
|
|
}))}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-12 19:29:29 +00:00
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
|
2022-10-19 21:25:03 +00:00
|
|
|
const isEmbed = useIsEmbed(props.isEmbed);
|
2022-03-31 08:45:47 +00:00
|
|
|
const eventTypeListItemEmbedStyles = useEmbedStyles("eventTypeListItem");
|
2022-04-25 04:33:00 +00:00
|
|
|
const shouldAlignCentrallyInEmbed = useEmbedNonStylesConfig("align") !== "left";
|
|
|
|
const shouldAlignCentrally = !isEmbed || shouldAlignCentrallyInEmbed;
|
2021-12-09 15:51:37 +00:00
|
|
|
const query = { ...router.query };
|
|
|
|
delete query.user; // So it doesn't display in the Link (and make tests fail)
|
2021-10-20 16:00:11 +00:00
|
|
|
const nameOrUsername = user.name || user.username || "";
|
2022-04-14 02:47:34 +00:00
|
|
|
const telemetry = useTelemetry();
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-06-02 16:19:01 +00:00
|
|
|
if (top !== window) {
|
|
|
|
//page_view will be collected automatically by _middleware.ts
|
|
|
|
telemetry.event(telemetryEventTypes.embedView, collectPageParameters("/[user]"));
|
|
|
|
}
|
|
|
|
}, [telemetry, router.asPath]);
|
2022-10-24 22:20:41 +00:00
|
|
|
const isEventListEmpty = eventTypes.length === 0;
|
2021-07-11 19:35:56 +00:00
|
|
|
return (
|
2021-08-12 17:05:46 +00:00
|
|
|
<>
|
2021-08-27 12:35:20 +00:00
|
|
|
<HeadSeo
|
2022-04-07 10:28:52 +00:00
|
|
|
title={isDynamicGroup ? dynamicNames.join(", ") : nameOrUsername}
|
|
|
|
description={
|
|
|
|
isDynamicGroup ? `Book events with ${dynamicUsernames.join(", ")}` : (user.bio as string) || ""
|
|
|
|
}
|
2022-10-18 17:46:22 +00:00
|
|
|
meeting={{
|
|
|
|
title: isDynamicGroup ? "" : `${user.bio}`,
|
|
|
|
profile: { name: `${profile.name}`, image: null },
|
|
|
|
users: isDynamicGroup
|
|
|
|
? dynamicUsernames.map((username, index) => ({ username, name: dynamicNames[index] }))
|
|
|
|
: [{ username: `${user.username}`, name: `${user.name}` }],
|
|
|
|
}}
|
2021-08-27 12:35:20 +00:00
|
|
|
/>
|
2022-04-25 04:33:00 +00:00
|
|
|
<CustomBranding lightVal={profile.brandColor} darkVal={profile.darkBrandColor} />
|
|
|
|
|
2022-08-24 20:18:42 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
shouldAlignCentrally ? "mx-auto" : "",
|
|
|
|
isEmbed ? "max-w-3xl" : "",
|
|
|
|
"dark:bg-darkgray-50"
|
|
|
|
)}>
|
2022-04-25 04:33:00 +00:00
|
|
|
<main
|
|
|
|
className={classNames(
|
|
|
|
shouldAlignCentrally ? "mx-auto" : "",
|
|
|
|
isEmbed
|
2022-08-24 20:18:42 +00:00
|
|
|
? " border-bookinglightest dark:bg-darkgray-50 rounded-md border bg-white sm:dark:border-gray-600"
|
2022-04-25 04:33:00 +00:00
|
|
|
: "",
|
|
|
|
"max-w-3xl py-24 px-4"
|
|
|
|
)}>
|
2022-04-06 17:20:30 +00:00
|
|
|
{isSingleUser && ( // When we deal with a single user, not dynamic group
|
|
|
|
<div className="mb-8 text-center">
|
2023-01-21 11:41:49 +00:00
|
|
|
<Avatar imageSrc={user.avatar} size="xl" alt={nameOrUsername} />
|
2023-01-12 16:57:43 +00:00
|
|
|
<h1 className="font-cal mb-1 text-3xl text-gray-900 dark:text-white">
|
2022-04-06 17:20:30 +00:00
|
|
|
{nameOrUsername}
|
|
|
|
{user.verified && (
|
2023-01-23 23:08:01 +00:00
|
|
|
<BadgeCheckIcon className="mx-1 -mt-1 inline h-6 w-6 text-blue-500 dark:text-white" />
|
2022-04-06 17:20:30 +00:00
|
|
|
)}
|
|
|
|
</h1>
|
2023-01-25 01:08:10 +00:00
|
|
|
{!isBioEmpty && (
|
|
|
|
<>
|
|
|
|
<div
|
2023-01-27 16:03:04 +00:00
|
|
|
className="dark:text-darkgray-600 text-sm text-gray-500 [&_a]:text-blue-500 [&_a]:underline [&_a]:hover:text-blue-600"
|
2023-01-25 01:08:10 +00:00
|
|
|
dangerouslySetInnerHTML={{ __html: md.render(user.bio || "") }}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2022-04-06 17:20:30 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
<div
|
2022-10-24 22:20:41 +00:00
|
|
|
className={classNames(
|
|
|
|
"rounded-md ",
|
2023-01-20 22:04:58 +00:00
|
|
|
!isEventListEmpty && "border border-gray-200 dark:border-gray-700 dark:hover:border-gray-600"
|
2022-10-24 22:20:41 +00:00
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
data-testid="event-types">
|
2022-03-10 19:21:27 +00:00
|
|
|
{user.away ? (
|
|
|
|
<div className="overflow-hidden rounded-sm border dark:border-gray-900">
|
|
|
|
<div className="p-8 text-center text-gray-400 dark:text-white">
|
2022-03-15 16:59:04 +00:00
|
|
|
<h2 className="font-cal mb-2 text-3xl text-gray-600 dark:text-white">
|
2022-03-10 19:21:27 +00:00
|
|
|
😴{" " + t("user_away")}
|
|
|
|
</h2>
|
2022-05-20 07:06:21 +00:00
|
|
|
<p className="mx-auto max-w-md">{t("user_away_description") as string}</p>
|
2022-03-10 19:21:27 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-06 17:20:30 +00:00
|
|
|
) : isDynamicGroup ? ( //When we deal with dynamic group (users > 1)
|
|
|
|
groupEventTypes
|
2022-03-10 19:21:27 +00:00
|
|
|
) : (
|
2022-02-11 14:34:12 +00:00
|
|
|
eventTypes.map((type) => (
|
|
|
|
<div
|
|
|
|
key={type.id}
|
2022-03-31 08:45:47 +00:00
|
|
|
style={{ display: "flex", ...eventTypeListItemEmbedStyles }}
|
2023-02-13 21:02:12 +00:00
|
|
|
className="dark:bg-darkgray-100 dark:hover:bg-darkgray-200 group relative border-b border-gray-200 bg-white first:rounded-t-md last:rounded-b-md last:border-b-0 hover:bg-gray-50 dark:border-gray-700">
|
2023-01-23 23:08:01 +00:00
|
|
|
<FiArrowRight className="absolute right-4 top-4 h-4 w-4 text-black opacity-0 transition-opacity group-hover:opacity-100 dark:text-white" />
|
2022-03-05 15:28:24 +00:00
|
|
|
{/* Don't prefetch till the time we drop the amount of javascript in [user][type] page which is impacting score for [user] page */}
|
2022-02-11 14:34:12 +00:00
|
|
|
<Link
|
2022-03-05 15:28:24 +00:00
|
|
|
prefetch={false}
|
2022-02-11 14:34:12 +00:00
|
|
|
href={{
|
|
|
|
pathname: `/${user.username}/${type.slug}`,
|
|
|
|
query,
|
2023-01-06 12:13:56 +00:00
|
|
|
}}
|
|
|
|
onClick={async () => {
|
|
|
|
sdkActionManager?.fire("eventTypeSelected", {
|
|
|
|
eventType: type,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
className="block w-full p-5"
|
|
|
|
data-testid="event-type-link">
|
|
|
|
<div className="flex flex-wrap items-center">
|
|
|
|
<h2 className="dark:text-darkgray-700 pr-2 text-sm font-semibold text-gray-700">
|
|
|
|
{type.title}
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
<EventTypeDescription eventType={type} />
|
2022-02-11 14:34:12 +00:00
|
|
|
</Link>
|
2021-08-12 17:05:46 +00:00
|
|
|
</div>
|
2022-03-10 19:21:27 +00:00
|
|
|
))
|
|
|
|
)}
|
2022-02-11 14:34:12 +00:00
|
|
|
</div>
|
2022-10-24 22:20:41 +00:00
|
|
|
{isEventListEmpty && <EmptyPage name={user.name ?? "User"} />}
|
2022-02-11 14:34:12 +00:00
|
|
|
</main>
|
|
|
|
<Toaster position="bottom-right" />
|
|
|
|
</div>
|
2021-08-12 17:05:46 +00:00
|
|
|
</>
|
2021-06-22 17:42:32 +00:00
|
|
|
);
|
2021-03-22 13:48:48 +00:00
|
|
|
}
|
2022-07-26 08:27:57 +00:00
|
|
|
User.isThemeSupported = true;
|
2021-03-22 13:48:48 +00:00
|
|
|
|
2022-10-14 16:24:43 +00:00
|
|
|
const getEventTypesWithHiddenFromDB = async (userId: number) => {
|
|
|
|
return (
|
|
|
|
await prisma.eventType.findMany({
|
|
|
|
where: {
|
|
|
|
AND: [
|
|
|
|
{
|
|
|
|
teamId: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
users: {
|
|
|
|
some: {
|
|
|
|
id: userId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
orderBy: [
|
2021-10-08 11:43:48 +00:00
|
|
|
{
|
2022-10-14 16:24:43 +00:00
|
|
|
position: "desc",
|
2021-10-08 11:43:48 +00:00
|
|
|
},
|
|
|
|
{
|
2022-10-14 16:24:43 +00:00
|
|
|
id: "asc",
|
2021-10-08 11:43:48 +00:00
|
|
|
},
|
|
|
|
],
|
2022-10-14 16:24:43 +00:00
|
|
|
select: {
|
|
|
|
...baseEventTypeSelect,
|
|
|
|
metadata: true,
|
2021-11-15 12:25:49 +00:00
|
|
|
},
|
2022-10-14 16:24:43 +00:00
|
|
|
})
|
|
|
|
).map((eventType) => ({
|
|
|
|
...eventType,
|
|
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
|
|
|
}));
|
2022-04-06 17:20:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
|
|
|
const ssr = await ssrInit(context);
|
2022-05-17 20:43:27 +00:00
|
|
|
const crypto = await import("crypto");
|
2022-04-06 17:20:30 +00:00
|
|
|
|
|
|
|
const usernameList = getUsernameList(context.query.user as string);
|
|
|
|
const dataFetchStart = Date.now();
|
|
|
|
const users = await prisma.user.findMany({
|
|
|
|
where: {
|
|
|
|
username: {
|
|
|
|
in: usernameList,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
bio: true,
|
2022-04-25 04:33:00 +00:00
|
|
|
brandColor: true,
|
|
|
|
darkBrandColor: true,
|
2022-04-06 17:20:30 +00:00
|
|
|
avatar: true,
|
|
|
|
theme: true,
|
|
|
|
away: true,
|
|
|
|
verified: true,
|
|
|
|
allowDynamicBooking: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!users.length) {
|
|
|
|
return {
|
|
|
|
notFound: true,
|
2022-10-19 21:25:03 +00:00
|
|
|
} as {
|
|
|
|
notFound: true;
|
2022-04-06 17:20:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const isDynamicGroup = users.length > 1;
|
|
|
|
|
2022-04-25 04:33:00 +00:00
|
|
|
const dynamicNames = isDynamicGroup
|
|
|
|
? users.map((user) => {
|
|
|
|
return user.name || "";
|
|
|
|
})
|
|
|
|
: [];
|
2022-04-06 17:20:30 +00:00
|
|
|
const [user] = users; //to be used when dealing with single user, not dynamic group
|
2022-04-25 04:33:00 +00:00
|
|
|
|
|
|
|
const profile = isDynamicGroup
|
|
|
|
? {
|
|
|
|
name: getGroupName(dynamicNames),
|
|
|
|
image: null,
|
|
|
|
theme: null,
|
|
|
|
weekStart: "Sunday",
|
|
|
|
brandColor: "",
|
|
|
|
darkBrandColor: "",
|
2022-05-26 16:41:05 +00:00
|
|
|
allowDynamicBooking: !users.some((user) => {
|
2022-04-25 04:33:00 +00:00
|
|
|
return !user.allowDynamicBooking;
|
2022-05-26 16:41:05 +00:00
|
|
|
}),
|
2022-04-25 04:33:00 +00:00
|
|
|
}
|
|
|
|
: {
|
|
|
|
name: user.name || user.username,
|
|
|
|
image: user.avatar,
|
|
|
|
theme: user.theme,
|
|
|
|
brandColor: user.brandColor,
|
|
|
|
darkBrandColor: user.darkBrandColor,
|
|
|
|
};
|
2022-04-06 17:20:30 +00:00
|
|
|
|
2022-10-14 16:24:43 +00:00
|
|
|
const eventTypesWithHidden = isDynamicGroup ? [] : await getEventTypesWithHiddenFromDB(user.id);
|
2022-03-04 10:03:10 +00:00
|
|
|
const dataFetchEnd = Date.now();
|
|
|
|
if (context.query.log === "1") {
|
|
|
|
context.res.setHeader("X-Data-Fetch-Time", `${dataFetchEnd - dataFetchStart}ms`);
|
|
|
|
}
|
2022-02-01 21:48:40 +00:00
|
|
|
const eventTypesRaw = eventTypesWithHidden.filter((evt) => !evt.hidden);
|
|
|
|
|
|
|
|
const eventTypes = eventTypesRaw.map((eventType) => ({
|
|
|
|
...eventType,
|
2022-10-14 16:24:43 +00:00
|
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata || {}),
|
2022-02-01 21:48:40 +00:00
|
|
|
}));
|
2021-10-08 11:43:48 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
const isSingleUser = users.length === 1;
|
|
|
|
const dynamicUsernames = isDynamicGroup
|
|
|
|
? users.map((user) => {
|
|
|
|
return user.username || "";
|
|
|
|
})
|
|
|
|
: [];
|
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2022-04-06 17:20:30 +00:00
|
|
|
users,
|
2022-04-25 04:33:00 +00:00
|
|
|
profile,
|
2022-02-11 14:34:12 +00:00
|
|
|
user: {
|
|
|
|
emailMd5: crypto.createHash("md5").update(user.email).digest("hex"),
|
|
|
|
},
|
2022-06-15 20:54:31 +00:00
|
|
|
eventTypes: isDynamicGroup
|
|
|
|
? defaultEvents.map((event) => {
|
|
|
|
event.description = getDynamicEventDescription(dynamicUsernames, event.slug);
|
|
|
|
return event;
|
|
|
|
})
|
|
|
|
: eventTypes,
|
2021-10-20 16:00:11 +00:00
|
|
|
trpcState: ssr.dehydrate(),
|
2022-06-15 20:54:31 +00:00
|
|
|
isDynamicGroup,
|
|
|
|
dynamicNames,
|
|
|
|
dynamicUsernames,
|
|
|
|
isSingleUser,
|
2021-06-22 17:42:32 +00:00
|
|
|
},
|
|
|
|
};
|
2021-10-08 11:43:48 +00:00
|
|
|
};
|