import { ArrowRightIcon } from "@heroicons/react/outline"; import { BadgeCheckIcon } from "@heroicons/react/solid"; import { GetServerSidePropsContext } from "next"; import dynamic from "next/dynamic"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { useState } from "react"; import { Toaster } from "react-hot-toast"; import { JSONObject } from "superjson/dist/types"; import { useLocale } from "@lib/hooks/useLocale"; import useTheme from "@lib/hooks/useTheme"; import prisma from "@lib/prisma"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import { AvatarSSR } from "@components/ui/AvatarSSR"; import { ssrInit } from "@server/lib/ssr"; 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")); interface EvtsToVerify { [evtId: string]: boolean; } export default function User(props: inferSSRProps) { const { Theme } = useTheme(props.user.theme); const { user, eventTypes } = props; const { t } = useLocale(); const router = useRouter(); const query = { ...router.query }; delete query.user; // So it doesn't display in the Link (and make tests fail) const nameOrUsername = user.name || user.username || ""; const [evtsToVerify, setEvtsToVerify] = useState({}); return ( <>

{nameOrUsername} {user.verified && ( )}

{user.bio}

{eventTypes.length === 0 && (

{t("uh_oh")}

{t("no_event_types_have_been_setup")}

)}
); } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const ssr = await ssrInit(context); const crypto = require("crypto"); const username = (context.query.user as string).toLowerCase(); const dataFetchStart = Date.now(); const user = await prisma.user.findUnique({ where: { username: username.toLowerCase(), }, select: { id: true, username: true, email: true, name: true, bio: true, avatar: true, theme: true, plan: true, away: true, verified: true, }, }); if (!user) { return { notFound: true, }; } 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")); const eventTypesWithHidden = await prisma.eventType.findMany({ where: { AND: [ { teamId: null, }, { OR: [ { userId: user.id, }, { users: { some: { id: user.id, }, }, }, ], }, ], }, orderBy: [ { position: "desc", }, { id: "asc", }, ], select: { id: true, slug: true, title: true, length: true, description: true, hidden: true, schedulingType: true, price: true, currency: true, metadata: true, }, take: user.plan === "FREE" ? 1 : undefined, }); const dataFetchEnd = Date.now(); if (context.query.log === "1") { context.res.setHeader("X-Data-Fetch-Time", `${dataFetchEnd - dataFetchStart}ms`); } 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, })); return { props: { user: { ...user, emailMd5: crypto.createHash("md5").update(user.email).digest("hex"), }, eventTypes, trpcState: ssr.dehydrate(), }, }; };