2021-09-06 13:51:15 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
2021-10-08 11:43:48 +00:00
|
|
|
import { GetServerSidePropsContext } from "next";
|
|
|
|
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
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
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { getOrSetUserLocaleFromHeaders } from "@lib/core/i18n/i18n.utils";
|
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-22 19:52:38 +00:00
|
|
|
import useTheme from "@lib/hooks/useTheme";
|
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
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-10-08 11:43:48 +00:00
|
|
|
export default function User(props: inferSSRProps<typeof getServerSideProps>) {
|
|
|
|
const { isReady } = useTheme(props.user.theme);
|
2021-10-12 13:11:33 +00:00
|
|
|
const { user, eventTypes } = props;
|
|
|
|
const { t } = useLocale();
|
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-10-12 13:11:33 +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-10-08 11:43:48 +00:00
|
|
|
<h2 className="font-cal font-semibold text-3xl text-gray-600 dark:text-white">
|
|
|
|
{t("uh_oh")}
|
|
|
|
</h2>
|
|
|
|
<p className="max-w-md mx-auto">{t("no_event_types_have_been_setup")}</p>
|
2021-08-12 17:05:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2021-06-22 17:42:32 +00:00
|
|
|
);
|
2021-03-22 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
|
|
|
const username = (context.query.user as string).toLowerCase();
|
|
|
|
const locale = await getOrSetUserLocaleFromHeaders(context.req);
|
|
|
|
|
|
|
|
const user = await prisma.user.findUnique({
|
|
|
|
where: {
|
|
|
|
username: username.toLowerCase(),
|
|
|
|
},
|
2021-09-06 13:51:15 +00:00
|
|
|
select: {
|
2021-10-08 11:43:48 +00:00
|
|
|
id: true,
|
2021-09-06 13:51:15 +00:00
|
|
|
username: true,
|
2021-10-08 11:43:48 +00:00
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
bio: true,
|
|
|
|
avatar: true,
|
|
|
|
theme: true,
|
|
|
|
plan: true,
|
2021-09-06 13:51:15 +00:00
|
|
|
},
|
|
|
|
});
|
2021-09-27 16:09:19 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
if (!user) {
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
notFound: true,
|
|
|
|
};
|
|
|
|
}
|
2021-10-08 11:43:48 +00:00
|
|
|
|
|
|
|
const eventTypesWithHidden = await prisma.eventType.findMany({
|
|
|
|
where: {
|
|
|
|
AND: [
|
|
|
|
{
|
|
|
|
teamId: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
users: {
|
|
|
|
some: {
|
|
|
|
id: user.id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
slug: true,
|
|
|
|
title: true,
|
|
|
|
length: true,
|
|
|
|
description: true,
|
|
|
|
hidden: true,
|
|
|
|
schedulingType: true,
|
|
|
|
price: true,
|
|
|
|
currency: true,
|
|
|
|
},
|
|
|
|
take: user.plan === "FREE" ? 1 : undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
const eventTypes = eventTypesWithHidden.filter((evt) => !evt.hidden);
|
|
|
|
|
2021-06-22 17:42:32 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2021-10-08 11:43:48 +00:00
|
|
|
localeProp: locale,
|
|
|
|
user,
|
|
|
|
eventTypes,
|
|
|
|
...(await serverSideTranslations(locale, ["common"])),
|
2021-06-22 17:42:32 +00:00
|
|
|
},
|
|
|
|
};
|
2021-10-08 11:43:48 +00:00
|
|
|
};
|