Scheduling infrastructure for absolutely everyone.
CAL-473 Fixes client-side routing for authed pages (#763)
Omar López420daec147dd
diff --git a/lib/app-providers.tsx b/lib/app-providers.tsxindex efe691c9cfb..200e76a0c89 100644--- a/lib/app-providers.tsx+++ b/lib/app-providers.tsx@@ -1,18 +1,26 @@import { Provider } from "next-auth/client";import React from "react";-import { QueryClient, QueryClientProvider } from "react-query";+import { HydrateProps, QueryClient, QueryClientProvider } from "react-query";import { Hydrate } from "react-query/hydration";+import { Session } from "@lib/auth";import { createTelemetryClient, TelemetryProvider } from "@lib/telemetry";export const queryClient = new QueryClient();-const AppProviders: React.FC = (props, pageProps) => {+type AppProviderProps = {+ pageProps: {+ session?: Session;+ dehydratedState?: HydrateProps;+ };+};++const AppProviders: React.FC<AppProviderProps> = ({ pageProps, children }) => {return (<TelemetryProvider value={createTelemetryClient()}><QueryClientProvider client={queryClient}><Hydrate state={pageProps.dehydratedState}>- <Provider session={pageProps.session}>{props.children}</Provider>+ <Provider session={pageProps.session}>{children}</Provider></Hydrate></QueryClientProvider></TelemetryProvider>diff --git a/pages/_app.tsx b/pages/_app.tsxindex 911897bc4c8..99b0c1066d5 100644--- a/pages/_app.tsx+++ b/pages/_app.tsx@@ -15,7 +15,7 @@ export type AppProps = NextAppProps & {function MyApp({ Component, pageProps, err }: AppProps) {return (- <AppProviders>+ <AppProviders pageProps={pageProps}><DefaultSeo {...seoConfig.defaultNextSeo} /><Component {...pageProps} err={err} /></AppProviders>diff --git a/pages/api/availability/[user].ts b/pages/api/availability/[user].tsindex 875f7757e02..8a2663b9674 100644--- a/pages/api/availability/[user].ts+++ b/pages/api/availability/[user].ts@@ -6,6 +6,8 @@ import { asStringOrNull } from "@lib/asStringOrNull";import { getBusyCalendarTimes } from "@lib/calendarClient";import prisma from "@lib/prisma";+import { Prisma } from ".prisma/client";+export default async function handler(req: NextApiRequest, res: NextApiResponse) {const user = asStringOrNull(req.query.user);const dateFrom = dayjs(asStringOrNull(req.query.dateFrom));@@ -32,19 +34,24 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)},});- const eventType = await prisma.eventType.findUnique({- where: { id: eventTypeId },- select: {- timeZone: true,- availability: {- select: {- startTime: true,- endTime: true,- days: true,+ const getEventType = (id: number) =>+ prisma.eventType.findUnique({+ where: { id },+ select: {+ timeZone: true,+ availability: {+ select: {+ startTime: true,+ endTime: true,+ days: true,+ },},},- },- });+ });++ type EventType = Prisma.PromiseReturnType<typeof getEventType>;+ let eventType: EventType | null = null;+ if (eventTypeId) eventType = await getEventType(eventTypeId);if (!rawUser) throw new Error("No user found");diff --git a/pages/availability/index.tsx b/pages/availability/index.tsxindex b2c73cee581..820affbd6d1 100644--- a/pages/availability/index.tsx+++ b/pages/availability/index.tsx@@ -339,6 +339,6 @@ export async function getServerSideProps(context) {},});return {- props: { user, types }, // will be passed to the page component as props+ props: { session, user, types },};}diff --git a/pages/availability/troubleshoot.tsx b/pages/availability/troubleshoot.tsxindex 76a573af8db..47f8141f61f 100644--- a/pages/availability/troubleshoot.tsx+++ b/pages/availability/troubleshoot.tsx@@ -1,24 +1,23 @@import dayjs from "dayjs";import utc from "dayjs/plugin/utc";-import { GetServerSideProps } from "next";+import { GetServerSidePropsContext } from "next";import { useEffect, useState } from "react";import { getSession } from "@lib/auth";import prisma from "@lib/prisma";+import { inferSSRProps } from "@lib/types/inferSSRProps";import Loader from "@components/Loader";import Shell from "@components/Shell";dayjs.extend(utc);-export default function Troubleshoot({ user }) {- // eslint-disable-next-line @typescript-eslint/no-unused-vars+export default function Troubleshoot({ user }: inferSSRProps<typeof getServerSideProps>) {const [loading, setLoading] = useState(true);const [availability, setAvailability] = useState([]);- // eslint-disable-next-line @typescript-eslint/no-unused-vars- const [selectedDate, setSelectedDate] = useState(dayjs());+ const [selectedDate] = useState(dayjs());- function convertMinsToHrsMins(mins) {+ function convertMinsToHrsMins(mins: number) {let h = Math.floor(mins / 60);let m = mins % 60;h = h < 10 ? "0" + h : h;@@ -97,9 +96,9 @@ export default function Troubleshoot({ user }) {);}-export const getServerSideProps: GetServerSideProps = async (context) => {+export const getServerSideProps = async (context: GetServerSidePropsContext) => {const session = await getSession(context);- if (!session) {+ if (!session?.user?.id) {return { redirect: { permanent: false, destination: "/auth/login" } };}@@ -114,7 +113,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {},});+ if (!user) return { redirect: { permanent: false, destination: "/auth/login" } };+return {- props: { user },+ props: { session, user },};};diff --git a/pages/bookings/index.tsx b/pages/bookings/index.tsxindex 55c73190007..05c453e30f0 100644--- a/pages/bookings/index.tsx+++ b/pages/bookings/index.tsx@@ -346,5 +346,5 @@ export async function getServerSideProps(context) {return { ...booking, startTime: booking.startTime.toISOString(), endTime: booking.endTime.toISOString() };});- return { props: { bookings } };+ return { props: { session, bookings } };}diff --git a/pages/event-types/[type].tsx b/pages/event-types/[type].tsxindex ba3ee40db48..ee5401f63d9 100644--- a/pages/event-types/[type].tsx+++ b/pages/event-types/[type].tsx@@ -1350,6 +1350,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>return {props: {+ session,localeProp: locale,eventType: eventTypeObject,locationOptions,diff --git a/pages/event-types/index.tsx b/pages/event-types/index.tsxindex 74b03652090..6802304e506 100644--- a/pages/event-types/index.tsx+++ b/pages/event-types/index.tsx@@ -475,7 +475,7 @@ const CreateNewEventDialog = ({<div className="mt-1"><div className="flex rounded-sm shadow-sm"><span className="inline-flex items-center px-3 text-gray-500 border border-r-0 border-gray-300 rounded-l-md bg-gray-50 sm:text-sm">- {location.hostname}/{router.query.eventPage || profiles[0].slug}/+ {process.env.NEXT_PUBLIC_APP_URL}/{router.query.eventPage || profiles[0].slug}/</span><inputref={slugRef}@@ -723,6 +723,7 @@ export async function getServerSideProps(context) {return {props: {+ session,localeProp: locale,canAddEvents,user: userObj,diff --git a/pages/integrations/[integration].tsx b/pages/integrations/[integration].tsxindex 2777dd16243..76ea2628541 100644--- a/pages/integrations/[integration].tsx+++ b/pages/integrations/[integration].tsx@@ -98,6 +98,6 @@ export async function getServerSideProps(context) {},});return {- props: { integration }, // will be passed to the page component as props+ props: { session, integration },};}diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsxindex 2cac6d28be7..654c75a7057 100644--- a/pages/integrations/index.tsx+++ b/pages/integrations/index.tsx@@ -495,6 +495,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {const integrations = getIntegrations(credentials);return {- props: { integrations },+ props: { session, integrations },};}diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsxindex b05ff27029d..41df34a6079 100644--- a/pages/settings/billing.tsx+++ b/pages/settings/billing.tsx@@ -44,6 +44,6 @@ export async function getServerSideProps(context) {});return {- props: { user }, // will be passed to the page component as props+ props: { session, user },};}diff --git a/pages/settings/embed.tsx b/pages/settings/embed.tsxindex d04b9078988..5e2b1d5f589 100644--- a/pages/settings/embed.tsx+++ b/pages/settings/embed.tsx@@ -1,20 +1,24 @@+import { GetServerSidePropsContext } from "next";import { useSession } from "next-auth/client";import { getSession } from "@lib/auth";import prisma from "@lib/prisma";+import { inferSSRProps } from "@lib/types/inferSSRProps";import Loader from "@components/Loader";import SettingsShell from "@components/Settings";import Shell from "@components/Shell";-export default function Embed(props) {- // eslint-disable-next-line @typescript-eslint/no-unused-vars- const [session, loading] = useSession();+export default function Embed(props: inferSSRProps<typeof getServerSideProps>) {+ const [, loading] = useSession();if (loading) {return <Loader />;}+ const iframeTemplate = `<iframe src="${process.env.NEXT_PUBLIC_APP_URL}/${props.user?.username}" frameborder="0" allowfullscreen></iframe>`;+ const htmlTemplate = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body>${iframeTemplate}</body></html>`;+return (<Shell heading="Embed" subtitle="Integrate with your website using our embed options."><SettingsShell>@@ -33,13 +37,7 @@ export default function Embed(props) {id="iframe"className="h-32 shadow-sm focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-sm"placeholder="Loading..."- defaultValue={- '<iframe src="' +- props.BASE_URL +- "/" +- session.user.username +- '" frameborder="0" allowfullscreen></iframe>'- }+ defaultValue={iframeTemplate}readOnly/></div>@@ -53,13 +51,7 @@ export default function Embed(props) {id="fullscreen"className="h-32 shadow-sm focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-sm"placeholder="Loading..."- defaultValue={- '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Schedule a meeting</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body><iframe src="' +- props.BASE_URL +- "/" +- session.user.username +- '" frameborder="0" allowfullscreen></iframe></body></html>'- }+ defaultValue={htmlTemplate}readOnly/></div>@@ -80,9 +72,9 @@ export default function Embed(props) {);}-export async function getServerSideProps(context) {+export async function getServerSideProps(context: GetServerSidePropsContext) {const session = await getSession(context);- if (!session) {+ if (!session?.user?.email) {return { redirect: { permanent: false, destination: "/auth/login" } };}@@ -102,9 +94,7 @@ export async function getServerSideProps(context) {},});- const BASE_URL = process.env.BASE_URL;-return {- props: { user, BASE_URL }, // will be passed to the page component as props+ props: { session, user },};}diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsxindex 2815d7326a9..fd4c8e64c44 100644--- a/pages/settings/profile.tsx+++ b/pages/settings/profile.tsx@@ -433,6 +433,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>return {props: {+ session,localeProp: locale,localeOptions,localeLabels,diff --git a/pages/settings/security.tsx b/pages/settings/security.tsxindex 0de823b3f20..ace80391754 100644--- a/pages/settings/security.tsx+++ b/pages/settings/security.tsx@@ -46,6 +46,6 @@ export async function getServerSideProps(context) {});return {- props: { user }, // will be passed to the page component as props+ props: { session, user },};}