2021-09-22 19:52:38 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/solid";
|
2021-09-29 21:33:18 +00:00
|
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
import { GetServerSidePropsContext } from "next";
|
2021-09-14 08:45:28 +00:00
|
|
|
import Link from "next/link";
|
2021-09-22 19:52:38 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-14 08:45:28 +00:00
|
|
|
import useTheme from "@lib/hooks/useTheme";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { useToggleQuery } from "@lib/hooks/useToggleQuery";
|
2021-09-14 08:45:28 +00:00
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
import { defaultAvatarSrc } from "@lib/profile";
|
2021-09-29 21:33:18 +00:00
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
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";
|
2021-09-14 08:45:28 +00:00
|
|
|
import Team from "@components/team/screens/Team";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
2021-09-14 08:45:28 +00:00
|
|
|
import AvatarGroup from "@components/ui/AvatarGroup";
|
2021-09-14 13:27:41 +00:00
|
|
|
import Button from "@components/ui/Button";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Text from "@components/ui/Text";
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
function TeamPage({ team }: inferSSRProps<typeof getServerSideProps>) {
|
2021-09-14 08:45:28 +00:00
|
|
|
const { isReady } = useTheme();
|
|
|
|
const showMembers = useToggleQuery("members");
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
const eventTypes = (
|
|
|
|
<ul className="space-y-3">
|
|
|
|
{team.eventTypes.map((type) => (
|
|
|
|
<li
|
|
|
|
key={type.id}
|
2021-11-04 14:30:37 +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-brand rounded-sm">
|
2021-09-14 08:45:28 +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" />
|
|
|
|
<Link href={`${team.slug}/${type.slug}`}>
|
2021-09-14 13:27:41 +00:00
|
|
|
<a className="px-6 py-4 flex justify-between">
|
2021-09-14 08:45:28 +00:00
|
|
|
<div className="flex-shrink">
|
2021-09-22 21:23:19 +00:00
|
|
|
<h2 className="font-cal font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
|
2021-10-12 13:11:33 +00:00
|
|
|
<EventTypeDescription className="text-sm" eventType={type} />
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
2021-09-14 13:27:41 +00:00
|
|
|
<div className="mt-1">
|
|
|
|
<AvatarGroup
|
|
|
|
truncateAfter={4}
|
|
|
|
className="flex-shrink-0"
|
|
|
|
size={10}
|
|
|
|
items={type.users.map((user) => ({
|
2021-09-29 21:33:18 +00:00
|
|
|
alt: user.name || "",
|
|
|
|
image: user.avatar || "",
|
2021-09-14 13:27:41 +00:00
|
|
|
}))}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-09-14 08:45:28 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
const teamName = team.name || "Nameless Team";
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
return (
|
|
|
|
isReady && (
|
|
|
|
<div>
|
2021-09-29 21:33:18 +00:00
|
|
|
<HeadSeo title={teamName} description={teamName} />
|
2021-09-14 08:45:28 +00:00
|
|
|
<div className="pt-24 pb-12 px-4">
|
|
|
|
<div className="mb-8 text-center">
|
2021-09-29 21:33:18 +00:00
|
|
|
<Avatar alt={teamName} imageSrc={team.logo} className="mx-auto w-20 h-20 rounded-full mb-4" />
|
|
|
|
<Text variant="headline">{teamName}</Text>
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
2021-10-12 13:11:33 +00:00
|
|
|
{(showMembers.isOn || !team.eventTypes.length) && <Team team={team} />}
|
2021-09-30 09:24:02 +00:00
|
|
|
{!showMembers.isOn && team.eventTypes.length > 0 && (
|
2021-09-14 08:45:28 +00:00
|
|
|
<div className="mx-auto max-w-3xl">
|
|
|
|
{eventTypes}
|
2021-09-14 13:27:41 +00:00
|
|
|
|
|
|
|
<div className="relative mt-12">
|
|
|
|
<div className="absolute inset-0 flex items-center" aria-hidden="true">
|
|
|
|
<div className="w-full border-t border-gray-200 dark:border-gray-900" />
|
|
|
|
</div>
|
|
|
|
<div className="relative flex justify-center">
|
2021-11-04 14:30:37 +00:00
|
|
|
<span className="px-2 bg-gray-100 text-sm text-gray-500 dark:bg-brand dark:text-gray-500">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("or")}
|
2021-09-14 13:27:41 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
<aside className="text-center dark:text-white mt-8">
|
2021-09-14 13:27:41 +00:00
|
|
|
<Button
|
|
|
|
color="secondary"
|
|
|
|
EndIcon={ArrowRightIcon}
|
|
|
|
href={`/team/${team.slug}?members=1`}
|
|
|
|
shallow={true}>
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("book_a_team_member")}
|
2021-09-14 13:27:41 +00:00
|
|
|
</Button>
|
2021-09-14 08:45:28 +00:00
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2021-09-14 08:45:28 +00:00
|
|
|
const slug = Array.isArray(context.query?.slug) ? context.query.slug.pop() : context.query.slug;
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
const userSelect = Prisma.validator<Prisma.UserSelect>()({
|
|
|
|
username: true,
|
|
|
|
avatar: true,
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
id: true,
|
|
|
|
bio: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const teamSelect = Prisma.validator<Prisma.TeamSelect>()({
|
2021-09-14 08:45:28 +00:00
|
|
|
id: true,
|
|
|
|
name: true,
|
|
|
|
slug: true,
|
|
|
|
logo: true,
|
|
|
|
members: {
|
|
|
|
select: {
|
|
|
|
user: {
|
2021-09-29 21:33:18 +00:00
|
|
|
select: userSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eventTypes: {
|
|
|
|
where: {
|
|
|
|
hidden: false,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
slug: true,
|
|
|
|
schedulingType: true,
|
2021-09-29 21:33:18 +00:00
|
|
|
price: true,
|
|
|
|
currency: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
users: {
|
2021-09-29 21:33:18 +00:00
|
|
|
select: userSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-29 21:33:18 +00:00
|
|
|
});
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
const team = await prisma.team.findUnique({
|
|
|
|
where: {
|
|
|
|
slug,
|
|
|
|
},
|
2021-09-29 21:33:18 +00:00
|
|
|
select: teamSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
});
|
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
if (!team) return { notFound: true };
|
2021-09-14 08:45:28 +00:00
|
|
|
|
|
|
|
team.eventTypes = team.eventTypes.map((type) => ({
|
|
|
|
...type,
|
|
|
|
users: type.users.map((user) => ({
|
|
|
|
...user,
|
2021-09-29 21:33:18 +00:00
|
|
|
avatar: user.avatar || defaultAvatarSrc({ email: user.email || "" }),
|
2021-09-14 08:45:28 +00:00
|
|
|
})),
|
|
|
|
}));
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
team,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TeamPage;
|