2022-12-02 10:55:56 +00:00
|
|
|
/* eslint-disable react/jsx-props-no-spreading */
|
2023-03-29 14:43:27 +02:00
|
|
|
import { useState } from "react";
|
2022-12-02 10:55:56 +00:00
|
|
|
import { AppProps } from "next/app";
|
|
|
|
|
import { SessionProvider } from "next-auth/react";
|
|
|
|
|
import { CssBaseline } from "@mui/material";
|
|
|
|
|
import { CacheProvider, EmotionCache } from "@emotion/react";
|
|
|
|
|
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFns";
|
|
|
|
|
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
|
|
|
|
|
import createEmotionCache from "lib/createEmotionCache";
|
|
|
|
|
import "@fontsource/poppins/400.css";
|
|
|
|
|
import "@fontsource/poppins/700.css";
|
|
|
|
|
import "@fontsource/roboto/400.css";
|
|
|
|
|
import "@fontsource/roboto/700.css";
|
|
|
|
|
import "@fontsource/playfair-display/900.css";
|
|
|
|
|
import "styles/global.css";
|
|
|
|
|
import { LicenseInfo } from "@mui/x-data-grid-pro";
|
2023-03-29 14:43:27 +02:00
|
|
|
import { SWRConfig } from "swr";
|
|
|
|
|
import { GraphQLClient } from "graphql-request";
|
2022-12-02 10:55:56 +00:00
|
|
|
|
|
|
|
|
LicenseInfo.setLicenseKey(
|
|
|
|
|
"fd009c623acc055adb16370731be92e4T1JERVI6NDA3NTQsRVhQSVJZPTE2ODAyNTAwMTUwMDAsS0VZVkVSU0lPTj0x"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const clientSideEmotionCache: any = createEmotionCache();
|
|
|
|
|
|
|
|
|
|
interface LinkWebProps extends AppProps {
|
|
|
|
|
// eslint-disable-next-line react/require-default-props
|
|
|
|
|
emotionCache?: EmotionCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LinkWeb = (props: LinkWebProps) => {
|
|
|
|
|
const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
|
2023-03-29 14:43:27 +02:00
|
|
|
const [csrfToken, setCsrfToken] = useState("");
|
|
|
|
|
const origin = typeof window !== 'undefined' && window.location.origin
|
|
|
|
|
? window.location.origin : null;
|
|
|
|
|
const client = new GraphQLClient(`${origin}/graphql`, {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Accept": "application/json",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const graphQLFetcher = async ({ document, variables }: any) => {
|
|
|
|
|
const requestHeaders = {
|
|
|
|
|
"X-CSRF-Token": csrfToken,
|
|
|
|
|
};
|
|
|
|
|
const { data, headers } = await client.rawRequest(
|
|
|
|
|
document,
|
|
|
|
|
variables,
|
|
|
|
|
requestHeaders
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const token = headers.get('CSRF-Token');
|
|
|
|
|
setCsrfToken(token);
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
};
|
2022-12-02 10:55:56 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SessionProvider session={(pageProps as any).session}>
|
|
|
|
|
<CacheProvider value={emotionCache}>
|
2023-03-29 14:43:27 +02:00
|
|
|
<SWRConfig value={{ fetcher: graphQLFetcher }}>
|
|
|
|
|
<CssBaseline />
|
|
|
|
|
<LocalizationProvider dateAdapter={AdapterDateFns}>
|
|
|
|
|
<Component {...pageProps} />
|
|
|
|
|
</LocalizationProvider>
|
|
|
|
|
</SWRConfig>
|
2022-12-02 10:55:56 +00:00
|
|
|
</CacheProvider>
|
|
|
|
|
</SessionProvider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default LinkWeb;
|