cal.pub0.org/apps/web/pages/_app.tsx

46 lines
1.0 KiB
TypeScript
Raw Normal View History

import type { IncomingMessage } from "http";
import type { AppContextType } from "next/dist/shared/lib/utils";
import React from "react";
import { getLocale } from "@calcom/features/auth/lib/getLocale";
import { trpc } from "@calcom/trpc/react";
2022-03-31 08:45:47 +00:00
import type { AppProps } from "@lib/app-providers";
import "../styles/globals.css";
function MyApp(props: AppProps) {
const { Component, pageProps } = props;
if (Component.PageWrapper !== undefined) return Component.PageWrapper(props);
return <Component {...pageProps} />;
2021-03-10 10:02:39 +00:00
}
declare global {
interface Window {
calNewLocale: string;
}
}
MyApp.getInitialProps = async (ctx: AppContextType) => {
const { req } = ctx.ctx;
let newLocale = "en";
if (req) {
newLocale = await getLocale(req as IncomingMessage & { cookies: Record<string, any> });
} else if (typeof window !== "undefined" && window.calNewLocale) {
newLocale = window.calNewLocale;
}
return {
pageProps: {
newLocale,
},
};
};
const WrappedMyApp = trpc.withTRPC(MyApp);
export default WrappedMyApp;