2022-06-02 16:19:01 +00:00
|
|
|
import { EventCollectionProvider } from "next-collect/client";
|
2021-08-27 12:35:20 +00:00
|
|
|
import { DefaultSeo } from "next-seo";
|
2022-03-24 16:51:37 +00:00
|
|
|
import Head from "next/head";
|
2021-10-07 15:43:20 +00:00
|
|
|
import superjson from "superjson";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-03-31 08:45:47 +00:00
|
|
|
import "@calcom/embed-core/src/embed-iframe";
|
2022-05-26 17:07:14 +00:00
|
|
|
import LicenseRequired from "@ee/components/LicenseRequired";
|
2022-03-31 08:45:47 +00:00
|
|
|
|
2021-10-20 16:00:11 +00:00
|
|
|
import AppProviders, { AppProps } from "@lib/app-providers";
|
2021-08-27 12:35:20 +00:00
|
|
|
import { seoConfig } from "@lib/config/next-seo.config";
|
2022-07-15 05:47:37 +00:00
|
|
|
import useTheme from "@lib/hooks/useTheme";
|
2021-03-10 10:02:39 +00:00
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
import I18nLanguageHandler from "@components/I18nLanguageHandler";
|
|
|
|
|
2021-10-07 15:43:20 +00:00
|
|
|
import type { AppRouter } from "@server/routers/_app";
|
2021-11-24 11:45:09 +00:00
|
|
|
import { httpBatchLink } from "@trpc/client/links/httpBatchLink";
|
2022-06-19 15:02:00 +00:00
|
|
|
import { httpLink } from "@trpc/client/links/httpLink";
|
2021-10-14 19:22:01 +00:00
|
|
|
import { loggerLink } from "@trpc/client/links/loggerLink";
|
2022-06-19 15:02:00 +00:00
|
|
|
import { splitLink } from "@trpc/client/links/splitLink";
|
2021-10-14 19:22:01 +00:00
|
|
|
import { withTRPC } from "@trpc/next";
|
|
|
|
import type { TRPCClientErrorLike } from "@trpc/react";
|
|
|
|
import { Maybe } from "@trpc/server";
|
2021-10-07 15:43:20 +00:00
|
|
|
|
2022-02-01 21:48:40 +00:00
|
|
|
import { ContractsProvider } from "../contexts/contractsContext";
|
2021-11-04 13:56:02 +00:00
|
|
|
import "../styles/fonts.css";
|
2021-09-22 19:52:38 +00:00
|
|
|
import "../styles/globals.css";
|
|
|
|
|
2021-09-27 14:47:55 +00:00
|
|
|
function MyApp(props: AppProps) {
|
2022-04-08 05:33:24 +00:00
|
|
|
const { Component, pageProps, err, router } = props;
|
|
|
|
let pageStatus = "200";
|
2022-07-15 05:47:37 +00:00
|
|
|
const { Theme } = useTheme("light");
|
|
|
|
|
2022-04-08 05:33:24 +00:00
|
|
|
if (router.pathname === "/404") {
|
|
|
|
pageStatus = "404";
|
|
|
|
} else if (router.pathname === "/500") {
|
|
|
|
pageStatus = "500";
|
|
|
|
}
|
2021-03-24 15:03:04 +00:00
|
|
|
return (
|
2022-06-02 16:19:01 +00:00
|
|
|
<EventCollectionProvider options={{ apiPath: "/api/collect-events" }}>
|
|
|
|
<ContractsProvider>
|
|
|
|
<AppProviders {...props}>
|
|
|
|
<DefaultSeo {...seoConfig.defaultNextSeo} />
|
|
|
|
<I18nLanguageHandler />
|
|
|
|
<Head>
|
2022-07-13 21:14:16 +00:00
|
|
|
<script dangerouslySetInnerHTML={{ __html: `window.CalComPageStatus = '${pageStatus}'` }} />
|
2022-06-02 16:19:01 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
|
|
|
|
</Head>
|
2022-07-15 05:47:37 +00:00
|
|
|
<Theme />
|
2022-06-02 16:19:01 +00:00
|
|
|
{Component.requiresLicense ? (
|
|
|
|
<LicenseRequired>
|
|
|
|
<Component {...pageProps} err={err} />
|
|
|
|
</LicenseRequired>
|
|
|
|
) : (
|
2022-05-26 17:07:14 +00:00
|
|
|
<Component {...pageProps} err={err} />
|
2022-06-02 16:19:01 +00:00
|
|
|
)}
|
|
|
|
</AppProviders>
|
|
|
|
</ContractsProvider>
|
|
|
|
</EventCollectionProvider>
|
2021-04-11 17:12:18 +00:00
|
|
|
);
|
2021-03-10 10:02:39 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:33:14 +00:00
|
|
|
export default withTRPC<AppRouter>({
|
2021-09-30 12:28:30 +00:00
|
|
|
config() {
|
2022-06-19 15:02:00 +00:00
|
|
|
const url =
|
|
|
|
typeof window !== "undefined"
|
|
|
|
? "/api/trpc"
|
|
|
|
: process.env.VERCEL_URL
|
|
|
|
? `https://${process.env.VERCEL_URL}/api/trpc`
|
|
|
|
: `http://${process.env.NEXT_PUBLIC_WEBAPP_URL}/api/trpc`;
|
|
|
|
|
2021-09-30 12:28:30 +00:00
|
|
|
/**
|
|
|
|
* 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) =>
|
2022-02-23 16:37:41 +00:00
|
|
|
!!process.env.NEXT_PUBLIC_DEBUG || (opts.direction === "down" && opts.result instanceof Error),
|
2021-09-30 12:28:30 +00:00
|
|
|
}),
|
2022-06-19 15:02:00 +00:00
|
|
|
splitLink({
|
|
|
|
// check for context property `skipBatch`
|
2022-06-29 16:50:32 +00:00
|
|
|
condition: (op) => {
|
|
|
|
// i18n should never be clubbed with other queries, so that it's caching can be managed independently
|
|
|
|
// We intend to not cache i18n query
|
|
|
|
return op.context.skipBatch === true || op.path === "viewer.public.i18n";
|
|
|
|
},
|
2022-06-19 15:02:00 +00:00
|
|
|
// when condition is true, use normal request
|
|
|
|
true: httpLink({ url }),
|
|
|
|
// when condition is false, use batching
|
|
|
|
false: httpBatchLink({
|
|
|
|
url,
|
|
|
|
/** @link https://github.com/trpc/trpc/issues/2008 */
|
|
|
|
// maxBatchSize: 7
|
|
|
|
}),
|
2021-09-30 12:28:30 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
/**
|
|
|
|
* @link https://react-query.tanstack.com/reference/QueryClient
|
|
|
|
*/
|
2021-10-01 14:33:14 +00:00
|
|
|
queryClientConfig: {
|
|
|
|
defaultOptions: {
|
|
|
|
queries: {
|
|
|
|
/**
|
|
|
|
* 1s should be enough to just keep identical query waterfalls low
|
|
|
|
* @example if one page components uses a query that is also used further down the tree
|
|
|
|
*/
|
|
|
|
staleTime: 1000,
|
|
|
|
/**
|
|
|
|
* Retry `useQuery()` calls depending on this function
|
|
|
|
*/
|
|
|
|
retry(failureCount, _err) {
|
|
|
|
const err = _err as never as Maybe<TRPCClientErrorLike<AppRouter>>;
|
|
|
|
const code = err?.data?.code;
|
|
|
|
if (code === "BAD_REQUEST" || code === "FORBIDDEN" || code === "UNAUTHORIZED") {
|
|
|
|
// if input data is wrong or you're not authorized there's no point retrying a query
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const MAX_QUERY_RETRIES = 3;
|
|
|
|
return failureCount < MAX_QUERY_RETRIES;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-07 15:43:20 +00:00
|
|
|
/**
|
|
|
|
* @link https://trpc.io/docs/data-transformers
|
|
|
|
*/
|
|
|
|
transformer: superjson,
|
2021-09-30 12:28:30 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @link https://trpc.io/docs/ssr
|
|
|
|
*/
|
|
|
|
ssr: false,
|
2021-10-14 10:57:49 +00:00
|
|
|
})(MyApp);
|