import { ArrowRightIcon } from "@heroicons/react/outline"; import { GetStaticPaths, GetStaticPropsContext } from "next"; import Link from "next/link"; import React from "react"; import useTheme from "@lib/hooks/useTheme"; import prisma from "@lib/prisma"; import { trpc } from "@lib/trpc"; 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 { ssg } from "@server/ssg"; export default function User(props: inferSSRProps) { const { username } = props; // data of query below will be will be prepopulated b/c of `getStaticProps` const query = trpc.useQuery(["booking.userEventTypes", { username }]); const { isReady } = useTheme(query.data?.user.theme); if (!query.data) { // this shold never happen as we do `blocking: true` return <>...; } const { user, eventTypes } = query.data; return ( <> {isReady && (

{user.name || user.username}

{user.bio}

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

Uh oh!

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

)}
)} ); } export const getStaticPaths: GetStaticPaths = async () => { const allUsers = await prisma.user.findMany({ select: { username: true, }, where: { // will statically render everyone on the PRO plan // the rest will be statically rendered on first visit plan: "PRO", }, }); const usernames = allUsers.flatMap((u) => (u.username ? [u.username] : [])); return { paths: usernames.map((user) => ({ params: { user }, })), // https://nextjs.org/docs/basic-features/data-fetching#fallback-blocking fallback: "blocking", }; }; export async function getStaticProps(context: GetStaticPropsContext<{ user: string }>) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const username = context.params!.user; const data = await ssg.fetchQuery("booking.userEventTypes", { username }); if (!data) { return { notFound: true, }; } return { props: { trpcState: ssg.dehydrate(), username, }, revalidate: 1, }; }