import { ArrowRightIcon } from "@heroicons/react/solid"; import { Prisma } from "@prisma/client"; import { GetServerSidePropsContext } from "next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Link from "next/link"; import React from "react"; import { getOrSetUserLocaleFromHeaders } from "@lib/core/i18n/i18n.utils"; import { useLocale } from "@lib/hooks/useLocale"; import useTheme from "@lib/hooks/useTheme"; import { useToggleQuery } from "@lib/hooks/useToggleQuery"; import prisma from "@lib/prisma"; import { defaultAvatarSrc } from "@lib/profile"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import EventTypeDescription from "@components/eventtype/EventTypeDescription"; import { HeadSeo } from "@components/seo/head-seo"; import Team from "@components/team/screens/Team"; import Avatar from "@components/ui/Avatar"; import AvatarGroup from "@components/ui/AvatarGroup"; import Button from "@components/ui/Button"; import Text from "@components/ui/Text"; function TeamPage({ team }: inferSSRProps) { const { isReady } = useTheme(); const showMembers = useToggleQuery("members"); const { t } = useLocale(); const eventTypes = ( ); const teamName = team.name || "Nameless Team"; return ( isReady && (
{teamName}
{(showMembers.isOn || !team.eventTypes.length) && } {!showMembers.isOn && team.eventTypes.length > 0 && (
{eventTypes}
)}
) ); } export const getServerSideProps = async (context: GetServerSidePropsContext) => { const locale = await getOrSetUserLocaleFromHeaders(context.req); const slug = Array.isArray(context.query?.slug) ? context.query.slug.pop() : context.query.slug; const userSelect = Prisma.validator()({ username: true, avatar: true, email: true, name: true, id: true, bio: true, }); const teamSelect = Prisma.validator()({ id: true, name: true, slug: true, logo: true, members: { select: { user: { select: userSelect, }, }, }, eventTypes: { where: { hidden: false, }, select: { id: true, title: true, description: true, length: true, slug: true, schedulingType: true, price: true, currency: true, users: { select: userSelect, }, }, }, }); const team = await prisma.team.findUnique({ where: { slug, }, select: teamSelect, }); if (!team) return { notFound: true }; team.eventTypes = team.eventTypes.map((type) => ({ ...type, users: type.users.map((user) => ({ ...user, avatar: user.avatar || defaultAvatarSrc({ email: user.email || "" }), })), })); return { props: { localeProp: locale, team, ...(await serverSideTranslations(locale, ["common"])), }, }; }; export default TeamPage;