2023-11-20 07:59:54 +00:00
|
|
|
import { FC, ReactNode } from "react";
|
|
|
|
import dynamic from "next/dynamic";
|
|
|
|
import Router from "next/router";
|
|
|
|
import NProgress from "nprogress";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-29 15:03:08 +00:00
|
|
|
import { ThemeProvider } from "next-themes";
|
2023-11-20 07:59:54 +00:00
|
|
|
// mobx store provider
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-11-29 15:03:08 +00:00
|
|
|
// constants
|
|
|
|
import { THEMES } from "constants/themes";
|
|
|
|
// layouts
|
|
|
|
import InstanceLayout from "layouts/instance-layout";
|
|
|
|
// contexts
|
|
|
|
import { ToastContextProvider } from "contexts/toast.context";
|
2023-12-14 14:25:45 +00:00
|
|
|
import { SWRConfig } from "swr";
|
|
|
|
// constants
|
|
|
|
import { SWR_CONFIG } from "constants/swr-config";
|
2023-11-20 07:59:54 +00:00
|
|
|
// dynamic imports
|
|
|
|
const StoreWrapper = dynamic(() => import("lib/wrappers/store-wrapper"), { ssr: false });
|
|
|
|
const PosthogWrapper = dynamic(() => import("lib/wrappers/posthog-wrapper"), { ssr: false });
|
|
|
|
const CrispWrapper = dynamic(() => import("lib/wrappers/crisp-wrapper"), { ssr: false });
|
|
|
|
|
|
|
|
// nprogress
|
|
|
|
NProgress.configure({ showSpinner: false });
|
|
|
|
Router.events.on("routeChangeStart", NProgress.start);
|
|
|
|
Router.events.on("routeChangeError", NProgress.done);
|
|
|
|
Router.events.on("routeChangeComplete", NProgress.done);
|
|
|
|
|
|
|
|
export interface IAppProvider {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AppProvider: FC<IAppProvider> = observer((props) => {
|
|
|
|
const { children } = props;
|
|
|
|
// store
|
|
|
|
const {
|
|
|
|
user: { currentUser, currentWorkspaceRole, currentProjectRole },
|
|
|
|
appConfig: { envConfig },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
return (
|
2023-11-29 15:03:08 +00:00
|
|
|
<ThemeProvider themes={THEMES} defaultTheme="system">
|
|
|
|
<ToastContextProvider>
|
|
|
|
<InstanceLayout>
|
|
|
|
<StoreWrapper>
|
|
|
|
<CrispWrapper user={currentUser}>
|
|
|
|
<PosthogWrapper
|
|
|
|
user={currentUser}
|
|
|
|
workspaceRole={currentWorkspaceRole}
|
|
|
|
projectRole={currentProjectRole}
|
|
|
|
posthogAPIKey={envConfig?.posthog_api_key || null}
|
|
|
|
posthogHost={envConfig?.posthog_host || null}
|
|
|
|
>
|
2023-12-14 14:25:45 +00:00
|
|
|
<SWRConfig value={SWR_CONFIG}>{children}</SWRConfig>
|
2023-11-29 15:03:08 +00:00
|
|
|
</PosthogWrapper>
|
|
|
|
</CrispWrapper>
|
|
|
|
</StoreWrapper>
|
|
|
|
</InstanceLayout>
|
|
|
|
</ToastContextProvider>
|
|
|
|
</ThemeProvider>
|
2023-11-20 07:59:54 +00:00
|
|
|
);
|
|
|
|
});
|