2021-09-06 13:51:15 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
2022-02-07 17:16:20 +00:00
|
|
|
import { BadgeCheckIcon } from "@heroicons/react/solid";
|
2021-10-08 11:43:48 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
2022-02-11 14:34:12 +00:00
|
|
|
import dynamic from "next/dynamic";
|
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-02-01 21:48:40 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { Toaster } from "react-hot-toast";
|
|
|
|
import { JSONObject } from "superjson/dist/types";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-22 19:52:38 +00:00
|
|
|
import useTheme from "@lib/hooks/useTheme";
|
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
|
|
|
|
2022-02-11 14:34:12 +00:00
|
|
|
import { AvatarSSR } from "@components/ui/AvatarSSR";
|
2021-03-22 13:48:48 +00:00
|
|
|
|
2021-10-20 16:00:11 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2022-02-11 14:34:12 +00:00
|
|
|
const EventTypeDescription = dynamic(() => import("@components/eventtype/EventTypeDescription"));
|
|
|
|
const HeadSeo = dynamic(() => import("@components/seo/head-seo").then((mod) => mod.HeadSeo));
|
|
|
|
const CryptoSection = dynamic(() => import("../ee/components/web3/CryptoSection"));
|
2022-02-01 21:48:40 +00:00
|
|
|
|
|
|
|
interface EvtsToVerify {
|
|
|
|
[evtId: string]: boolean;
|
|
|
|
}
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
export default function User(props: inferSSRProps<typeof getServerSideProps>) {
|
2022-02-11 14:34:12 +00:00
|
|
|
const { Theme } = useTheme(props.user.theme);
|
2021-10-12 13:11:33 +00:00
|
|
|
const { user, eventTypes } = props;
|
|
|
|
const { t } = useLocale();
|
2021-12-03 10:15:20 +00:00
|
|
|
const router = useRouter();
|
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-07-09 22:59:21 +00:00
|
|
|
|
2021-10-20 16:00:11 +00:00
|
|
|
const nameOrUsername = user.name || user.username || "";
|
2022-02-01 21:48:40 +00:00
|
|
|
const [evtsToVerify, setEvtsToVerify] = useState<EvtsToVerify>({});
|
2021-07-11 19:35:56 +00:00
|
|
|
return (
|
2021-08-12 17:05:46 +00:00
|
|
|
<>
|
2022-02-10 11:07:14 +00:00
|
|
|
<Theme />
|
2021-08-27 12:35:20 +00:00
|
|
|
<HeadSeo
|
2021-10-20 16:00:11 +00:00
|
|
|
title={nameOrUsername}
|
2022-01-11 08:54:02 +00:00
|
|
|
description={(user.bio as string) || ""}
|
2021-10-20 16:00:11 +00:00
|
|
|
name={nameOrUsername}
|
2022-01-11 08:54:02 +00:00
|
|
|
username={(user.username as string) || ""}
|
|
|
|
// avatar={user.avatar || undefined}
|
2021-08-27 12:35:20 +00:00
|
|
|
/>
|
2022-02-11 14:34:12 +00:00
|
|
|
<div className="h-screen dark:bg-black">
|
|
|
|
<main className="mx-auto max-w-3xl px-4 py-24">
|
|
|
|
<div className="mb-8 text-center">
|
|
|
|
<AvatarSSR user={user} className="mx-auto mb-4 h-24 w-24" alt={nameOrUsername}></AvatarSSR>
|
|
|
|
<h1 className="font-cal mb-1 text-3xl font-bold text-neutral-900 dark:text-white">
|
|
|
|
{nameOrUsername}
|
|
|
|
{user.verified && (
|
2022-02-11 21:47:22 +00:00
|
|
|
<BadgeCheckIcon className="mx-1 -mt-1 inline h-6 w-6 text-blue-500 dark:text-white" />
|
2022-02-11 14:34:12 +00:00
|
|
|
)}
|
|
|
|
</h1>
|
|
|
|
<p className="text-neutral-500 dark:text-white">{user.bio}</p>
|
|
|
|
</div>
|
|
|
|
<div className="space-y-6" data-testid="event-types">
|
|
|
|
{!user.away &&
|
|
|
|
eventTypes.map((type) => (
|
|
|
|
<div
|
|
|
|
key={type.id}
|
|
|
|
style={{ display: "flex" }}
|
|
|
|
className="group hover:border-brand relative rounded-sm border border-neutral-200 bg-white hover:bg-gray-50 dark:border-0 dark:bg-neutral-900 dark:hover:border-neutral-600">
|
|
|
|
<ArrowRightIcon className="absolute right-3 top-3 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,
|
|
|
|
}}>
|
|
|
|
<a
|
|
|
|
onClick={async (e) => {
|
|
|
|
// If a token is required for this event type, add a click listener that checks whether the user verified their wallet or not
|
|
|
|
if (type.metadata.smartContractAddress && !evtsToVerify[type.id]) {
|
|
|
|
const showToast = (await import("@lib/notification")).default;
|
|
|
|
e.preventDefault();
|
|
|
|
showToast(
|
|
|
|
"You must verify a wallet with a token belonging to the specified smart contract first",
|
|
|
|
"error"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="block w-full px-6 py-4"
|
|
|
|
data-testid="event-type-link">
|
|
|
|
<h2 className="grow font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
|
|
|
|
<EventTypeDescription eventType={type} />
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
{type.isWeb3Active && type.metadata.smartContractAddress && (
|
|
|
|
<CryptoSection
|
|
|
|
id={type.id}
|
|
|
|
pathname={`/${user.username}/${type.slug}`}
|
|
|
|
smartContractAddress={type.metadata.smartContractAddress as string}
|
|
|
|
verified={evtsToVerify[type.id]}
|
|
|
|
setEvtsToVerify={setEvtsToVerify}
|
|
|
|
oneStep
|
|
|
|
/>
|
|
|
|
)}
|
2021-08-12 17:05:46 +00:00
|
|
|
</div>
|
2022-02-11 14:34:12 +00:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{eventTypes.length === 0 && (
|
|
|
|
<div className="overflow-hidden rounded-sm shadow">
|
|
|
|
<div className="p-8 text-center text-gray-400 dark:text-white">
|
|
|
|
<h2 className="font-cal text-3xl font-semibold text-gray-600 dark:text-white">
|
|
|
|
{t("uh_oh")}
|
|
|
|
</h2>
|
|
|
|
<p className="mx-auto max-w-md">{t("no_event_types_have_been_setup")}</p>
|
2021-08-12 17:05:46 +00:00
|
|
|
</div>
|
2022-02-11 14:34:12 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</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
|
|
|
}
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2021-10-20 16:00:11 +00:00
|
|
|
const ssr = await ssrInit(context);
|
2022-03-05 15:28:24 +00:00
|
|
|
const crypto = require("crypto");
|
2021-10-20 16:00:11 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
const username = (context.query.user as string).toLowerCase();
|
2022-03-04 10:03:10 +00:00
|
|
|
const dataFetchStart = Date.now();
|
2021-10-08 11:43:48 +00:00
|
|
|
const user = await prisma.user.findUnique({
|
|
|
|
where: {
|
|
|
|
username: username.toLowerCase(),
|
|
|
|
},
|
2021-09-06 13:51:15 +00:00
|
|
|
select: {
|
2021-10-08 11:43:48 +00:00
|
|
|
id: true,
|
2021-09-06 13:51:15 +00:00
|
|
|
username: true,
|
2021-10-08 11:43:48 +00:00
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
bio: true,
|
|
|
|
avatar: true,
|
|
|
|
theme: true,
|
|
|
|
plan: true,
|
2022-01-11 10:32:40 +00:00
|
|
|
away: true,
|
2022-02-07 17:16:20 +00:00
|
|
|
verified: true,
|
2021-09-06 13:51:15 +00:00
|
|
|
},
|
|
|
|
});
|
2021-09-27 16:09:19 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
if (!user) {
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
notFound: true,
|
|
|
|
};
|
|
|
|
}
|
2021-10-08 11:43:48 +00:00
|
|
|
|
2022-02-01 21:48:40 +00:00
|
|
|
const credentials = await prisma.credential.findMany({
|
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
type: true,
|
|
|
|
key: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const web3Credentials = credentials.find((credential) => credential.type.includes("_web3"));
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
const eventTypesWithHidden = await prisma.eventType.findMany({
|
|
|
|
where: {
|
|
|
|
AND: [
|
|
|
|
{
|
|
|
|
teamId: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
users: {
|
|
|
|
some: {
|
|
|
|
id: user.id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-11-15 12:25:49 +00:00
|
|
|
orderBy: [
|
|
|
|
{
|
|
|
|
position: "desc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "asc",
|
|
|
|
},
|
|
|
|
],
|
2021-10-08 11:43:48 +00:00
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
slug: true,
|
|
|
|
title: true,
|
|
|
|
length: true,
|
|
|
|
description: true,
|
|
|
|
hidden: true,
|
|
|
|
schedulingType: true,
|
|
|
|
price: true,
|
|
|
|
currency: true,
|
2022-02-01 21:48:40 +00:00
|
|
|
metadata: true,
|
2021-10-08 11:43:48 +00:00
|
|
|
},
|
|
|
|
take: user.plan === "FREE" ? 1 : undefined,
|
|
|
|
});
|
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,
|
|
|
|
metadata: (eventType.metadata || {}) as JSONObject,
|
|
|
|
isWeb3Active:
|
|
|
|
web3Credentials && web3Credentials.key
|
|
|
|
? (((web3Credentials.key as JSONObject).isWeb3Active || false) as boolean)
|
|
|
|
: false,
|
|
|
|
}));
|
2021-10-08 11:43:48 +00:00
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2022-02-11 14:34:12 +00:00
|
|
|
user: {
|
|
|
|
...user,
|
|
|
|
emailMd5: crypto.createHash("md5").update(user.email).digest("hex"),
|
|
|
|
},
|
2021-10-08 11:43:48 +00:00
|
|
|
eventTypes,
|
2021-10-20 16:00:11 +00:00
|
|
|
trpcState: ssr.dehydrate(),
|
2021-06-22 17:42:32 +00:00
|
|
|
},
|
|
|
|
};
|
2021-10-08 11:43:48 +00:00
|
|
|
};
|