| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  | import { ArrowRightIcon } from "@heroicons/react/outline"; | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  | import { ssg } from "@server/ssg"; | 
					
						
							|  |  |  | import { GetStaticPaths, GetStaticPropsContext } from "next"; | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  | import Link from "next/link"; | 
					
						
							| 
									
										
										
										
											2021-08-05 12:41:20 +00:00
										 |  |  | import React from "react"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import useTheme from "@lib/hooks/useTheme"; | 
					
						
							|  |  |  | import prisma from "@lib/prisma"; | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  | import { trpc } from "@lib/trpc"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import { inferSSRProps } from "@lib/types/inferSSRProps"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  | import EventTypeDescription from "@components/eventtype/EventTypeDescription"; | 
					
						
							| 
									
										
										
										
											2021-09-22 19:52:38 +00:00
										 |  |  | import { HeadSeo } from "@components/seo/head-seo"; | 
					
						
							|  |  |  | import Avatar from "@components/ui/Avatar"; | 
					
						
							| 
									
										
										
										
											2021-03-22 13:48:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  | export default function User(props: inferSSRProps<typeof getStaticProps>) { | 
					
						
							|  |  |  |   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; | 
					
						
							| 
									
										
										
										
											2021-07-09 22:59:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-11 19:35:56 +00:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |     <> | 
					
						
							| 
									
										
										
										
											2021-08-27 12:35:20 +00:00
										 |  |  |       <HeadSeo | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |         title={user.name || user.username} | 
					
						
							|  |  |  |         description={user.name || user.username} | 
					
						
							|  |  |  |         name={user.name || user.username} | 
					
						
							|  |  |  |         avatar={user.avatar} | 
					
						
							| 
									
										
										
										
											2021-08-27 12:35:20 +00:00
										 |  |  |       /> | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |       {isReady && ( | 
					
						
							| 
									
										
										
										
											2021-09-30 11:41:13 +00:00
										 |  |  |         <div className="bg-neutral-50 dark:bg-black h-screen"> | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |           <main className="max-w-3xl mx-auto py-24 px-4"> | 
					
						
							|  |  |  |             <div className="mb-8 text-center"> | 
					
						
							| 
									
										
										
										
											2021-08-22 13:16:42 +00:00
										 |  |  |               <Avatar | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |                 imageSrc={user.avatar} | 
					
						
							|  |  |  |                 displayName={user.name} | 
					
						
							| 
									
										
										
										
											2021-08-22 13:16:42 +00:00
										 |  |  |                 className="mx-auto w-24 h-24 rounded-full mb-4" | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2021-09-23 20:48:27 +00:00
										 |  |  |               <h1 className="font-cal text-3xl font-bold text-neutral-900 dark:text-white mb-1"> | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |                 {user.name || user.username} | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |               </h1> | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |               <p className="text-neutral-500 dark:text-white">{user.bio}</p> | 
					
						
							| 
									
										
										
										
											2021-08-05 12:41:20 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |             <div className="space-y-6" data-testid="event-types"> | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |               {eventTypes.map((type) => ( | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |                 <div | 
					
						
							|  |  |  |                   key={type.id} | 
					
						
							|  |  |  |                   className="group relative dark:bg-neutral-900 dark:border-0 dark:hover:border-neutral-600 bg-white hover:bg-gray-50 border border-neutral-200 hover:border-black rounded-sm"> | 
					
						
							|  |  |  |                   <ArrowRightIcon className="absolute transition-opacity h-4 w-4 right-3 top-3 text-black dark:text-white opacity-0 group-hover:opacity-100" /> | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |                   <Link href={`/${user.username}/${type.slug}`}> | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |                     <a className="block px-6 py-4"> | 
					
						
							|  |  |  |                       <h2 className="font-semibold text-neutral-900 dark:text-white">{type.title}</h2> | 
					
						
							| 
									
										
										
										
											2021-09-14 08:45:28 +00:00
										 |  |  |                       <EventTypeDescription eventType={type} /> | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |                     </a> | 
					
						
							|  |  |  |                   </Link> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               ))} | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |             {eventTypes.length === 0 && ( | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |               <div className="shadow overflow-hidden rounded-sm"> | 
					
						
							|  |  |  |                 <div className="p-8 text-center text-gray-400 dark:text-white"> | 
					
						
							| 
									
										
										
										
											2021-09-22 21:23:19 +00:00
										 |  |  |                   <h2 className="font-cal font-semibold text-3xl text-gray-600 dark:text-white">Uh oh!</h2> | 
					
						
							| 
									
										
										
										
											2021-08-12 17:05:46 +00:00
										 |  |  |                   <p className="max-w-md mx-auto">This user hasn't set up any event types yet.</p> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |           </main> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |     </> | 
					
						
							| 
									
										
										
										
											2021-06-22 17:42:32 +00:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-03-22 13:48:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  | export const getStaticPaths: GetStaticPaths = async () => { | 
					
						
							|  |  |  |   const allUsers = await prisma.user.findMany({ | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |     select: { | 
					
						
							|  |  |  |       username: true, | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |     where: { | 
					
						
							|  |  |  |       // will statically render everyone on the PRO plan
 | 
					
						
							|  |  |  |       // the rest will be statically rendered on first visit
 | 
					
						
							|  |  |  |       plan: "PRO", | 
					
						
							| 
									
										
										
										
											2021-09-06 13:51:15 +00:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |   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) { | 
					
						
							| 
									
										
										
										
											2021-06-22 17:42:32 +00:00
										 |  |  |     return { | 
					
						
							|  |  |  |       notFound: true, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     props: { | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |       trpcState: ssg.dehydrate(), | 
					
						
							|  |  |  |       username, | 
					
						
							| 
									
										
										
										
											2021-06-22 17:42:32 +00:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-09-27 16:09:19 +00:00
										 |  |  |     revalidate: 1, | 
					
						
							| 
									
										
										
										
											2021-06-22 17:42:32 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | } |