2023-02-21 10:34:30 +00:00
|
|
|
import "@saleor/apps-shared/src/globals.css";
|
2023-02-23 07:22:37 +00:00
|
|
|
import "../styles/globals.css";
|
2023-02-07 18:11:39 +00:00
|
|
|
import { AppBridge, AppBridgeProvider } from "@saleor/app-sdk/app-bridge";
|
|
|
|
import { RoutePropagator } from "@saleor/app-sdk/app-bridge/next";
|
2023-02-23 07:22:37 +00:00
|
|
|
import {
|
|
|
|
dark,
|
|
|
|
light,
|
|
|
|
SaleorThemeColors,
|
|
|
|
ThemeProvider as MacawUIThemeProvider,
|
|
|
|
} from "@saleor/macaw-ui";
|
|
|
|
import React, { PropsWithChildren, useEffect } from "react";
|
2023-02-07 18:11:39 +00:00
|
|
|
import { AppProps } from "next/app";
|
|
|
|
|
|
|
|
import { ThemeSynchronizer } from "../lib/theme-synchronizer";
|
|
|
|
import { NoSSRWrapper } from "../no-ssr-wrapper";
|
2023-02-23 07:22:37 +00:00
|
|
|
import { Theme } from "@material-ui/core/styles";
|
|
|
|
|
|
|
|
type PalettesOverride = Record<"light" | "dark", SaleorThemeColors>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Temporary override of colors, to match new dashboard palette.
|
|
|
|
* Long term this will be replaced with Macaw UI 2.x with up to date design tokens
|
|
|
|
*/
|
|
|
|
const palettes: PalettesOverride = {
|
|
|
|
light: {
|
|
|
|
...light,
|
|
|
|
background: {
|
|
|
|
default: "#fff",
|
|
|
|
paper: "#fff",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dark: {
|
|
|
|
...dark,
|
|
|
|
background: {
|
|
|
|
default: "hsla(211, 42%, 14%, 1)",
|
|
|
|
paper: "hsla(211, 42%, 14%, 1)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2023-02-07 18:11:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure instance is a singleton.
|
|
|
|
* TODO: This is React 18 issue, consider hiding this workaround inside app-sdk
|
|
|
|
*/
|
|
|
|
const appBridgeInstance = typeof window !== "undefined" ? new AppBridge() : undefined;
|
|
|
|
|
2023-02-23 07:22:37 +00:00
|
|
|
/**
|
|
|
|
* That's a hack required by Macaw-UI incompatibility with React@18
|
|
|
|
*/
|
|
|
|
const ThemeProvider = MacawUIThemeProvider as React.FC<
|
|
|
|
PropsWithChildren<{ overrides?: Partial<Theme>; ssr: boolean; palettes: PalettesOverride }>
|
|
|
|
>;
|
|
|
|
|
2023-02-07 18:11:39 +00:00
|
|
|
function NextApp({ Component, pageProps }: AppProps) {
|
|
|
|
/**
|
|
|
|
* Configure JSS (used by MacawUI) for SSR. If Macaw is not used, can be removed.
|
|
|
|
*/
|
|
|
|
useEffect(() => {
|
|
|
|
const jssStyles = document.querySelector("#jss-server-side");
|
|
|
|
if (jssStyles) {
|
|
|
|
jssStyles?.parentElement?.removeChild(jssStyles);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NoSSRWrapper>
|
|
|
|
<AppBridgeProvider appBridgeInstance={appBridgeInstance}>
|
2023-02-23 07:22:37 +00:00
|
|
|
<ThemeProvider ssr palettes={palettes}>
|
2023-02-07 18:11:39 +00:00
|
|
|
<ThemeSynchronizer />
|
|
|
|
<RoutePropagator />
|
|
|
|
<Component {...pageProps} />
|
2023-02-23 07:22:37 +00:00
|
|
|
</ThemeProvider>
|
2023-02-07 18:11:39 +00:00
|
|
|
</AppBridgeProvider>
|
|
|
|
</NoSSRWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NextApp;
|