cal.pub0.org/pages/[user].tsx

119 lines
4.2 KiB
TypeScript
Raw Normal View History

import { ArrowRightIcon } from "@heroicons/react/outline";
2021-09-27 16:09:19 +00:00
import { ssg } from "@server/ssg";
import { GetStaticPaths, GetStaticPropsContext } from "next";
import Link from "next/link";
2021-08-05 12:41:20 +00:00
import React from "react";
import useTheme from "@lib/hooks/useTheme";
import prisma from "@lib/prisma";
2021-09-27 16:09:19 +00:00
import { trpc } from "@lib/trpc";
import { inferSSRProps } from "@lib/types/inferSSRProps";
Feature/round robin (#613) * Heavy WIP * More WIP * Playing with backwards compat * Moar wip * wip * Email changes for group feature * Committing in redundant migrations for reference * Combine all WIP migrations into a single feature migration * Make backup of current version of radio area pending refactor * Improved accessibility through keyboard * Cleanup in seperate commit so I can cherrypick later * Added RadioArea component * wip * Ignore .yarn file * Kinda stable * Getting closer... * Hide header when there are only personal events * Added uid to event create, updated EventTypeDescription * Delete redundant migration * Committing new team related migrations * Optimising & implemented backwards compatibility * Removed now redundant pages * Undid prototyping to calendarClient I did not end up using * Properly typed Select & fixed lint throughout * How'd that get here, removed. * TODO: investigate why userData is not compatible with passed type * This likely matches the event type that is created for a user * Few bugfixes * Adding datepicker optimisations * Fixed new event type spacing, initial profile should always be there * Gave NEXT_PUBLIC_BASE_URL a try but I think it's not the right solution * Updated EventTypeDescription to account for long titles, added logo to team page. * Added logo to team query * Added cancel Cypress test because an upcoming merge contains changes * Fix for when the event type description is long * Turned Theme into the useTheme hook, and made it fully compatible with teams pages * Built AvatarGroup ui component + moved Avatar to ui * Give the avatar some space fom the description * Fixed timeZone selector * Disabled tooltip +1-... Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
2021-09-14 08:45:28 +00:00
import EventTypeDescription from "@components/eventtype/EventTypeDescription";
import { HeadSeo } from "@components/seo/head-seo";
import Avatar from "@components/ui/Avatar";
2021-03-22 13:48:48 +00:00
2021-09-27 16:09:19 +00:00
export default function User(props: inferSSRProps<typeof getStaticProps>) {
const { username } = props;
// data of query below will be will be prepopulated b/c of `getStaticProps`
const query = trpc.useQuery(["booking.userEventTypes", { username }]);
const { isReady } = useTheme(query.data?.user.theme);
if (!query.data) {
// this shold never happen as we do `blocking: true`
return <>...</>;
}
const { user, eventTypes } = query.data;
2021-07-11 19:35:56 +00:00
return (
<>
<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}
/>
{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">
<Avatar
2021-09-27 16:09:19 +00:00
imageSrc={user.avatar}
displayName={user.name}
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}
</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>
<div className="space-y-6" data-testid="event-types">
2021-09-27 16:09:19 +00:00
{eventTypes.map((type) => (
<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}`}>
<a className="block px-6 py-4">
<h2 className="font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
Feature/round robin (#613) * Heavy WIP * More WIP * Playing with backwards compat * Moar wip * wip * Email changes for group feature * Committing in redundant migrations for reference * Combine all WIP migrations into a single feature migration * Make backup of current version of radio area pending refactor * Improved accessibility through keyboard * Cleanup in seperate commit so I can cherrypick later * Added RadioArea component * wip * Ignore .yarn file * Kinda stable * Getting closer... * Hide header when there are only personal events * Added uid to event create, updated EventTypeDescription * Delete redundant migration * Committing new team related migrations * Optimising & implemented backwards compatibility * Removed now redundant pages * Undid prototyping to calendarClient I did not end up using * Properly typed Select & fixed lint throughout * How'd that get here, removed. * TODO: investigate why userData is not compatible with passed type * This likely matches the event type that is created for a user * Few bugfixes * Adding datepicker optimisations * Fixed new event type spacing, initial profile should always be there * Gave NEXT_PUBLIC_BASE_URL a try but I think it's not the right solution * Updated EventTypeDescription to account for long titles, added logo to team page. * Added logo to team query * Added cancel Cypress test because an upcoming merge contains changes * Fix for when the event type description is long * Turned Theme into the useTheme hook, and made it fully compatible with teams pages * Built AvatarGroup ui component + moved Avatar to ui * Give the avatar some space fom the description * Fixed timeZone selector * Disabled tooltip +1-... Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
2021-09-14 08:45:28 +00:00
<EventTypeDescription eventType={type} />
</a>
</Link>
</div>
))}
</div>
2021-09-27 16:09:19 +00:00
{eventTypes.length === 0 && (
<div className="shadow overflow-hidden rounded-sm">
<div className="p-8 text-center text-gray-400 dark:text-white">
<h2 className="font-cal font-semibold text-3xl text-gray-600 dark:text-white">Uh oh!</h2>
<p className="max-w-md mx-auto">This user hasn&apos;t set up any event types yet.</p>
</div>
</div>
)}
</main>
</div>
)}
</>
);
2021-03-22 13:48:48 +00:00
}
2021-09-27 16:09:19 +00:00
export const getStaticPaths: GetStaticPaths = async () => {
const allUsers = await prisma.user.findMany({
select: {
username: true,
2021-09-27 16:09:19 +00:00
},
where: {
// will statically render everyone on the PRO plan
// the rest will be statically rendered on first visit
plan: "PRO",
},
});
2021-09-27 16:09:19 +00:00
const usernames = allUsers.flatMap((u) => (u.username ? [u.username] : []));
return {
paths: usernames.map((user) => ({
params: { user },
})),
// https://nextjs.org/docs/basic-features/data-fetching#fallback-blocking
fallback: "blocking",
};
};
export async function getStaticProps(context: GetStaticPropsContext<{ user: string }>) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const username = context.params!.user;
const data = await ssg.fetchQuery("booking.userEventTypes", { username });
if (!data) {
return {
notFound: true,
};
}
return {
props: {
2021-09-27 16:09:19 +00:00
trpcState: ssg.dehydrate(),
username,
},
2021-09-27 16:09:19 +00:00
revalidate: 1,
};
}