import { GetServerSideProps } from "next";
import Head from "next/head";
import Link from "next/link";
import prisma from "../lib/prisma";
import Avatar from "../components/Avatar";
export default function User(props): User {
const eventTypes = props.eventTypes.map((type) => (
{type.title}
{type.description}
));
return (
{props.user.name || props.user.username} | Calendso
{props.user.name || props.user.username}
{props.user.bio}
{eventTypes.length == 0 && (
Uh oh!
This user hasn't set up any event types yet.
)}
);
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const user = await prisma.user.findFirst({
where: {
username: context.query.user.toLowerCase(),
},
select: {
id: true,
username: true,
email: true,
name: true,
bio: true,
avatar: true,
eventTypes: true,
},
});
if (!user) {
return {
notFound: true,
};
}
const eventTypes = await prisma.eventType.findMany({
where: {
userId: user.id,
hidden: false,
},
});
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;
}