add inferSSRProps
utility (#551)
This commit is contained in:
parent
c6fa712b10
commit
52f95eb1c3
3 changed files with 29 additions and 16 deletions
11
lib/types/inferSSRProps.ts
Normal file
11
lib/types/inferSSRProps.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
|
type GetSSRResult<TProps> =
|
||||||
|
//
|
||||||
|
{ props: TProps } | { redirect: any } | { notFound: true };
|
||||||
|
|
||||||
|
type GetSSRFn<TProps> = (...args: any[]) => Promise<GetSSRResult<TProps>>;
|
||||||
|
|
||||||
|
export type inferSSRProps<TFn extends GetSSRFn<any>> = TFn extends GetSSRFn<infer TProps>
|
||||||
|
? NonNullable<TProps>
|
||||||
|
: never;
|
|
@ -1,24 +1,25 @@
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
import { Availability } from "@prisma/client";
|
|
||||||
import Theme from "@components/Theme";
|
|
||||||
import { ChevronDownIcon, ChevronUpIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
|
||||||
import prisma from "@lib/prisma";
|
|
||||||
import * as Collapsible from "@radix-ui/react-collapsible";
|
|
||||||
import dayjs, { Dayjs } from "dayjs";
|
|
||||||
import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
|
|
||||||
import { HeadSeo } from "@components/seo/head-seo";
|
|
||||||
import { useRouter } from "next/router";
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import Avatar from "@components/Avatar";
|
import Avatar from "@components/Avatar";
|
||||||
import AvailableTimes from "@components/booking/AvailableTimes";
|
import AvailableTimes from "@components/booking/AvailableTimes";
|
||||||
import DatePicker from "@components/booking/DatePicker";
|
import DatePicker from "@components/booking/DatePicker";
|
||||||
import TimeOptions from "@components/booking/TimeOptions";
|
import TimeOptions from "@components/booking/TimeOptions";
|
||||||
|
import { HeadSeo } from "@components/seo/head-seo";
|
||||||
|
import Theme from "@components/Theme";
|
||||||
import PoweredByCalendso from "@components/ui/PoweredByCalendso";
|
import PoweredByCalendso from "@components/ui/PoweredByCalendso";
|
||||||
import { timeZone } from "@lib/clock";
|
import { ChevronDownIcon, ChevronUpIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
||||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
|
||||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||||
|
import { timeZone } from "@lib/clock";
|
||||||
|
import prisma from "@lib/prisma";
|
||||||
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
||||||
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
|
import { Availability } from "@prisma/client";
|
||||||
|
import * as Collapsible from "@radix-ui/react-collapsible";
|
||||||
|
import dayjs, { Dayjs } from "dayjs";
|
||||||
|
import { GetServerSidePropsContext } from "next";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function Type(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
export default function Type(props: inferSSRProps<typeof getServerSideProps>) {
|
||||||
// Get router variables
|
// Get router variables
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { rescheduleUid } = router.query;
|
const { rescheduleUid } = router.query;
|
||||||
|
|
|
@ -35,12 +35,13 @@ import { DateRangePicker, OrientationShape, toMomentObject } from "react-dates";
|
||||||
import Switch from "@components/ui/Switch";
|
import Switch from "@components/ui/Switch";
|
||||||
import { Dialog, DialogTrigger } from "@components/Dialog";
|
import { Dialog, DialogTrigger } from "@components/Dialog";
|
||||||
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
|
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
|
||||||
import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
|
import { GetServerSidePropsContext } from "next";
|
||||||
import { useMutation } from "react-query";
|
import { useMutation } from "react-query";
|
||||||
import { EventTypeInput } from "@lib/types/event-type";
|
import { EventTypeInput } from "@lib/types/event-type";
|
||||||
import updateEventType from "@lib/mutations/event-types/update-event-type";
|
import updateEventType from "@lib/mutations/event-types/update-event-type";
|
||||||
import deleteEventType from "@lib/mutations/event-types/delete-event-type";
|
import deleteEventType from "@lib/mutations/event-types/delete-event-type";
|
||||||
import showToast from "@lib/notification";
|
import showToast from "@lib/notification";
|
||||||
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
|
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
|
@ -60,7 +61,7 @@ const PERIOD_TYPES = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const EventTypePage = (props: InferGetServerSidePropsType<typeof getServerSideProps>) => {
|
const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
const { user, eventType, locationOptions, availability } = props;
|
const { user, eventType, locationOptions, availability } = props;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [successModalOpen, setSuccessModalOpen] = useState(false);
|
const [successModalOpen, setSuccessModalOpen] = useState(false);
|
||||||
|
@ -1082,7 +1083,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||||
if (!eventType) {
|
if (!eventType) {
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
};
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
const credentials = await prisma.credential.findMany({
|
const credentials = await prisma.credential.findMany({
|
||||||
|
|
Loading…
Reference in a new issue