import { GetServerSideProps } from "next"; import Head from "next/head"; import Link from "next/link"; import prisma, { whereAndSelect } from "@lib/prisma"; import Avatar from "../components/Avatar"; import Theme from "@components/Theme"; import { ClockIcon, InformationCircleIcon, UserIcon } from "@heroicons/react/solid"; import React from "react"; import { ArrowRightIcon } from "@heroicons/react/outline"; export default function User(props): User { const { isReady } = Theme(props.user.theme); const eventTypes = props.eventTypes.map((type) => (

{type.title}

)); return ( isReady && (
{props.user.name || props.user.username} | Calendso

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

{props.user.bio}

{eventTypes}
{eventTypes.length == 0 && (

Uh oh!

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

)}
) ); } export const getServerSideProps: GetServerSideProps = async (context) => { const user = await whereAndSelect( prisma.user.findFirst, { username: context.query.user.toLowerCase(), }, ["id", "username", "email", "name", "bio", "avatar", "theme"] ); if (!user) { return { notFound: true, }; } const eventTypes = await prisma.eventType.findMany({ where: { userId: user.id, hidden: false, }, select: { slug: true, title: true, length: true, description: true, }, }); return { props: { user, eventTypes, }, }; }; // Auxiliary methods export function getRandomColorCode(): string { let color = "#"; for (let idx = 0; idx < 6; idx++) { color += Math.floor(Math.random() * 10); } return color; }