2021-06-22 17:42:32 +00:00
|
|
|
import { GetServerSideProps } from "next";
|
2021-08-27 12:35:20 +00:00
|
|
|
import { HeadSeo } from "@components/seo/head-seo";
|
2021-06-22 17:42:32 +00:00
|
|
|
import Link from "next/link";
|
2021-07-11 19:35:56 +00:00
|
|
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
2021-08-22 13:16:42 +00:00
|
|
|
import Avatar from "@components/Avatar";
|
2021-07-09 22:59:21 +00:00
|
|
|
import Theme from "@components/Theme";
|
2021-08-05 12:41:20 +00:00
|
|
|
import { ClockIcon, InformationCircleIcon, UserIcon } from "@heroicons/react/solid";
|
|
|
|
import React from "react";
|
2021-08-05 18:49:05 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
2021-03-22 13:48:48 +00:00
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
export default function User(props): User {
|
2021-07-09 22:59:21 +00:00
|
|
|
const { isReady } = Theme(props.user.theme);
|
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
const eventTypes = props.eventTypes.map((type) => (
|
2021-08-05 12:41:20 +00:00
|
|
|
<div
|
2021-07-09 11:34:00 +00:00
|
|
|
key={type.id}
|
2021-08-08 16:17:17 +00:00
|
|
|
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">
|
2021-08-05 18:49:05 +00:00
|
|
|
<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-06-22 17:42:32 +00:00
|
|
|
<Link href={`/${props.user.username}/${type.slug}`}>
|
|
|
|
<a className="block px-6 py-4">
|
2021-08-05 12:41:20 +00:00
|
|
|
<h2 className="font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
|
|
|
|
<div className="mt-2 flex space-x-4">
|
2021-08-05 18:49:05 +00:00
|
|
|
<div className="flex text-sm text-neutral-500">
|
|
|
|
<ClockIcon
|
2021-08-08 16:17:17 +00:00
|
|
|
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
2021-08-05 18:49:05 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2021-08-08 16:17:17 +00:00
|
|
|
<p className="dark:text-white">{type.length}m</p>
|
2021-08-05 12:41:20 +00:00
|
|
|
</div>
|
2021-08-05 18:49:05 +00:00
|
|
|
<div className="flex text-sm min-w-16 text-neutral-500">
|
2021-08-08 16:17:17 +00:00
|
|
|
<UserIcon
|
|
|
|
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
<p className="dark:text-white">1-on-1</p>
|
2021-08-05 12:41:20 +00:00
|
|
|
</div>
|
2021-08-05 18:49:05 +00:00
|
|
|
<div className="flex text-sm text-neutral-500">
|
2021-08-05 12:41:20 +00:00
|
|
|
<InformationCircleIcon
|
2021-08-08 16:17:17 +00:00
|
|
|
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
2021-08-05 12:41:20 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2021-08-08 16:17:17 +00:00
|
|
|
<p className="dark:text-white">{type.description}</p>
|
2021-08-05 12:41:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-22 17:42:32 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-08-05 12:41:20 +00:00
|
|
|
</div>
|
2021-06-22 17:42:32 +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
|
|
|
|
title={props.user.name || props.user.username}
|
|
|
|
description={props.user.name || props.user.username}
|
|
|
|
name={props.user.name || props.user.username}
|
|
|
|
avatar={props.user.avatar}
|
|
|
|
/>
|
2021-08-12 17:05:46 +00:00
|
|
|
{isReady && (
|
|
|
|
<div className="bg-neutral-50 dark:bg-black h-screen">
|
|
|
|
<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
|
|
|
|
imageSrc={props.user.avatar}
|
|
|
|
displayName={props.user.name}
|
|
|
|
className="mx-auto w-24 h-24 rounded-full mb-4"
|
|
|
|
/>
|
2021-08-12 17:05:46 +00:00
|
|
|
<h1 className="text-3xl font-bold text-neutral-900 dark:text-white mb-1">
|
|
|
|
{props.user.name || props.user.username}
|
|
|
|
</h1>
|
|
|
|
<p className="text-neutral-500 dark:text-white">{props.user.bio}</p>
|
2021-08-05 12:41:20 +00:00
|
|
|
</div>
|
2021-08-12 17:05:46 +00:00
|
|
|
<div className="space-y-6">{eventTypes}</div>
|
|
|
|
{eventTypes.length == 0 && (
|
|
|
|
<div className="shadow overflow-hidden rounded-sm">
|
|
|
|
<div className="p-8 text-center text-gray-400 dark:text-white">
|
2021-08-22 12:48:33 +00:00
|
|
|
<h2 className="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-06-22 17:42:32 +00:00
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
2021-07-11 19:35:56 +00:00
|
|
|
const user = await whereAndSelect(
|
|
|
|
prisma.user.findFirst,
|
|
|
|
{
|
2021-07-09 22:59:21 +00:00
|
|
|
username: context.query.user.toLowerCase(),
|
2021-07-11 19:35:56 +00:00
|
|
|
},
|
2021-07-15 14:10:26 +00:00
|
|
|
["id", "username", "email", "name", "bio", "avatar", "theme"]
|
2021-07-09 22:59:21 +00:00
|
|
|
);
|
2021-06-22 17:42:32 +00:00
|
|
|
if (!user) {
|
|
|
|
return {
|
|
|
|
notFound: true,
|
|
|
|
};
|
|
|
|
}
|
2021-04-08 15:51:13 +00:00
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
const eventTypes = await prisma.eventType.findMany({
|
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
hidden: false,
|
|
|
|
},
|
2021-07-15 14:10:26 +00:00
|
|
|
select: {
|
|
|
|
slug: true,
|
|
|
|
title: true,
|
2021-08-05 12:41:20 +00:00
|
|
|
length: true,
|
2021-07-15 14:10:26 +00:00
|
|
|
description: true,
|
|
|
|
},
|
2021-06-22 17:42:32 +00:00
|
|
|
});
|
2021-04-28 09:23:30 +00:00
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
user,
|
|
|
|
eventTypes,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2021-05-13 17:35:28 +00:00
|
|
|
|
|
|
|
// Auxiliary methods
|
2021-06-22 17:42:32 +00:00
|
|
|
export function getRandomColorCode(): string {
|
|
|
|
let color = "#";
|
|
|
|
for (let idx = 0; idx < 6; idx++) {
|
|
|
|
color += Math.floor(Math.random() * 10);
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|