import Avatar from "@components/ui/Avatar"; import { HeadSeo } from "@components/seo/head-seo"; import useTheme from "@lib/hooks/useTheme"; import { ArrowRightIcon } from "@heroicons/react/outline"; import prisma from "@lib/prisma"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import { GetServerSidePropsContext } from "next"; import Link from "next/link"; import React from "react"; import EventTypeDescription from "@components/eventtype/EventTypeDescription"; export default function User(props: inferSSRProps) { const { isReady } = useTheme(props.user.theme); return ( <> {isReady && (

{props.user.name || props.user.username}

{props.user.bio}

{props.eventTypes.map((type) => ( ))}
{props.eventTypes.length == 0 && (

Uh oh!

This user hasn't set up any event types yet.

)}
)} ); } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const username = (context.query.user as string).toLowerCase(); const user = await prisma.user.findUnique({ where: { username, }, 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: { OR: [ { userId: user.id, }, { users: { some: { id: user.id, }, }, }, ], }, select: { id: true, slug: true, title: true, length: true, description: true, hidden: true, }, take: user.plan === "FREE" ? 1 : undefined, }); const eventTypes = eventTypesWithHidden.filter((evt) => !evt.hidden); return { props: { eventTypes, user, }, }; }; // Auxiliary methods export function getRandomColorCode(): string { let color = "#"; for (let idx = 0; idx < 6; idx++) { color += Math.floor(Math.random() * 10); } return color; }