add tRPC (#614)
* add trpc * trpc specific * fix deps * lint fix * upgrade prisma * nativeTypes * nope, not needed * fix app propviders * Revert "upgrade prisma" This reverts commit e6f2d2542a01ec82c80aa2fe367ae12c68ded1a5. * rev * up trpc * simplify * wip - bookings page with trpc * bookings using trpc * fix `Shell` props * call it viewerRouter instead * cleanuop * ssg helper * fix lint * fix types * skip * add `useRedirectToLoginIfUnauthenticated` * exhaustive-deps * fix callbackUrl * rewrite `/availability` using trpc Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
0938f6f4b2
commit
34300650e4
18 files changed
+483
-216
No files matched your search
+42
-23
@@ -1,37 +1,56 @@
|
||||
import { IdProvider } from "@radix-ui/react-id";
|
||||
import { httpBatchLink } from "@trpc/client/links/httpBatchLink";
|
||||
import { loggerLink } from "@trpc/client/links/loggerLink";
|
||||
import { withTRPC } from "@trpc/next";
|
||||
import { Provider } from "next-auth/client";
|
||||
import { AppProps } from "next/dist/shared/lib/router/router";
|
||||
import React from "react";
|
||||
import { HydrateProps, QueryClient, QueryClientProvider } from "react-query";
|
||||
import { Hydrate } from "react-query/hydration";
|
||||
|
||||
import DynamicIntercomProvider from "@ee/lib/intercom/providerDynamic";
|
||||
|
||||
import { Session } from "@lib/auth";
|
||||
import { createTelemetryClient, TelemetryProvider } from "@lib/telemetry";
|
||||
|
||||
export const queryClient = new QueryClient();
|
||||
|
||||
type AppProviderProps = {
|
||||
pageProps: {
|
||||
session?: Session;
|
||||
dehydratedState?: HydrateProps;
|
||||
};
|
||||
};
|
||||
|
||||
const AppProviders: React.FC<AppProviderProps> = ({ pageProps, children }) => {
|
||||
const AppProviders = (props: AppProps) => {
|
||||
return (
|
||||
<TelemetryProvider value={createTelemetryClient()}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<IdProvider>
|
||||
<DynamicIntercomProvider>
|
||||
<Hydrate state={pageProps.dehydratedState}>
|
||||
<Provider session={pageProps.session}>{children}</Provider>
|
||||
</Hydrate>
|
||||
</DynamicIntercomProvider>
|
||||
</IdProvider>
|
||||
</QueryClientProvider>
|
||||
<IdProvider>
|
||||
<DynamicIntercomProvider>
|
||||
<Provider session={props.pageProps.session}>{props.children}</Provider>
|
||||
</DynamicIntercomProvider>
|
||||
</IdProvider>
|
||||
</TelemetryProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppProviders;
|
||||
export default withTRPC({
|
||||
config() {
|
||||
/**
|
||||
* If you want to use SSR, you need to use the server's full URL
|
||||
* @link https://trpc.io/docs/ssr
|
||||
*/
|
||||
return {
|
||||
/**
|
||||
* @link https://trpc.io/docs/links
|
||||
*/
|
||||
links: [
|
||||
// adds pretty logs to your console in development and logs errors in production
|
||||
loggerLink({
|
||||
enabled: (opts) =>
|
||||
process.env.NODE_ENV === "development" ||
|
||||
(opts.direction === "down" && opts.result instanceof Error),
|
||||
}),
|
||||
httpBatchLink({
|
||||
url: `/api/trpc`,
|
||||
}),
|
||||
],
|
||||
/**
|
||||
* @link https://react-query.tanstack.com/reference/QueryClient
|
||||
*/
|
||||
// queryClientConfig: { defaultOptions: { queries: { staleTime: 6000 } } },
|
||||
};
|
||||
},
|
||||
/**
|
||||
* @link https://trpc.io/docs/ssr
|
||||
*/
|
||||
ssr: false,
|
||||
})(AppProviders);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// ℹ️ Type-only import:
|
||||
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
|
||||
import type { AppRouter } from "@server/routers/_app";
|
||||
import { createReactQueryHooks } from "@trpc/react";
|
||||
import type { inferProcedureOutput, inferProcedureInput } from "@trpc/server";
|
||||
|
||||
/**
|
||||
* A set of strongly-typed React hooks from your `AppRouter` type signature with `createReactQueryHooks`.
|
||||
* @link https://trpc.io/docs/react#3-create-trpc-hooks
|
||||
*/
|
||||
export const trpc = createReactQueryHooks<AppRouter>();
|
||||
|
||||
// export const transformer = superjson;
|
||||
/**
|
||||
* This is a helper method to infer the output of a query resolver
|
||||
* @example type HelloOutput = inferQueryOutput<'hello'>
|
||||
*/
|
||||
export type inferQueryOutput<TRouteKey extends keyof AppRouter["_def"]["queries"]> = inferProcedureOutput<
|
||||
AppRouter["_def"]["queries"][TRouteKey]
|
||||
>;
|
||||
|
||||
export type inferQueryInput<TRouteKey extends keyof AppRouter["_def"]["queries"]> = inferProcedureInput<
|
||||
AppRouter["_def"]["queries"][TRouteKey]
|
||||
>;
|
||||
|
||||
export type inferMutationInput<TRouteKey extends keyof AppRouter["_def"]["mutations"]> = inferProcedureInput<
|
||||
AppRouter["_def"]["mutations"][TRouteKey]
|
||||
>;
|
||||
Reference in new issue
Block a user