import { ArrowRightIcon } from "@heroicons/react/outline"; import { GetServerSidePropsContext } from "next"; import Link from "next/link"; import { useRouter } from "next/router"; import React from "react"; import { useLocale } from "@lib/hooks/useLocale"; import useTheme from "@lib/hooks/useTheme"; import prisma from "@lib/prisma"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import EventTypeDescription from "@components/eventtype/EventTypeDescription"; import { HeadSeo } from "@components/seo/head-seo"; import Avatar from "@components/ui/Avatar"; import { ssrInit } from "@server/lib/ssr"; export default function User(props: inferSSRProps) { const { isReady } = useTheme(props.user.theme); const { user, eventTypes } = props; const { t } = useLocale(); const router = useRouter(); const nameOrUsername = user.name || user.username || ""; return ( <> {isReady && (

{nameOrUsername}

{user.bio}

{eventTypes.map((type) => ( ))}
{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 username = (context.query.user as string).toLowerCase(); 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, }, }); if (!user) { return { notFound: true, }; } 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, }, take: user.plan === "FREE" ? 1 : undefined, }); const eventTypes = eventTypesWithHidden.filter((evt) => !evt.hidden); return { props: { user, eventTypes, trpcState: ssr.dehydrate(), }, }; };