
* create Apps view * create more app components, generate types and messages * apps refactor, update snapshots * show error message in tooltip when app installation fail * update apps components and view, add apps list to storybook * update defaultMessages * create app details view * update AppListPage with Skeleton component * create app activate/deactivate dialogs, create app details stories * add AppHeader to AppDetailsPage * update defaultMessages * update AppDetails view and components after review * create custom app details view * refactor webhooks * update webhooks fixtures * update WebhookDetailsPage story * update strings * create CustomAppCreate view and components * update AppListPage story * create AppInstall view and page * handle errors in AppInstall view * update defaultMessages * add AppInstallPage to storybook * add status prop to MessageManager * update defaultMessages * remove service account section * remove service account routes * remove as operator from notify status * add notifications for app installations * update styles for deactivated app * update app installations with local storage * update defaultMessages * AppInstall update * dd delete button to ongoin installations table * fix active installations condition * fix error messages in AppsList * update defaultMessages * add iframe to AppDetailsPage * create AppDetailsSettingsPage * install macaw-ui * apps styles clean up * update schema, fixtures * few apps updates * WebhookCreate - fix onBack button name * WebhookCreatePage story update * rename apps table from external to thirdparty * update defaultMessages * fix test, update snapshots * AppDetailsSettings - add token to headers * fix first number in local apps query * app details settings - use shop domain host * add onSettingsRowClick to InstalledApps * resolve conflicts * update changelog and messages * add noopener noreferrer do app privacy link * update snapshots * update snapshots * updates after review * update defaultMessages * CustomAppDetails - add missing notify status
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
import { MuiThemeProvider } from "@material-ui/core/styles";
|
|
import {
|
|
ExtensionMessageType,
|
|
sendMessageToExtension,
|
|
ThemeChangeMessage
|
|
} from "@saleor/macaw-ui/extensions";
|
|
import React, { useEffect } from "react";
|
|
import Helmet from "react-helmet";
|
|
|
|
import Baseline from "../../Baseline";
|
|
import createTheme from "../../theme";
|
|
import { dark, light } from "./themes";
|
|
|
|
interface IThemeContext {
|
|
isDark: boolean;
|
|
sendThemeToExtension: () => void;
|
|
toggleTheme: () => void;
|
|
}
|
|
export const ThemeContext = React.createContext<IThemeContext>({
|
|
isDark: false,
|
|
sendThemeToExtension: () => undefined,
|
|
toggleTheme: () => undefined
|
|
});
|
|
|
|
interface ThemeProviderProps {
|
|
isDefaultDark?: boolean;
|
|
}
|
|
const ThemeProvider: React.FC<ThemeProviderProps> = ({
|
|
children,
|
|
isDefaultDark
|
|
}) => {
|
|
const [isDark, setDark] = React.useState(isDefaultDark);
|
|
const sendThemeToExtension = () =>
|
|
sendMessageToExtension<ThemeChangeMessage>(
|
|
{
|
|
theme: isDark ? "dark" : "light",
|
|
type: ExtensionMessageType.THEME
|
|
},
|
|
"*"
|
|
);
|
|
|
|
const toggleTheme = () => {
|
|
setDark(!isDark);
|
|
localStorage.setItem("theme", (!isDark).toString());
|
|
};
|
|
|
|
useEffect(() => {
|
|
sendThemeToExtension();
|
|
}, [isDark]);
|
|
|
|
const theme = createTheme(isDark ? dark : light);
|
|
|
|
return (
|
|
<ThemeContext.Provider
|
|
value={{
|
|
isDark,
|
|
sendThemeToExtension,
|
|
toggleTheme
|
|
}}
|
|
>
|
|
<Helmet>
|
|
<meta name="theme-color" content={theme.palette.background.default} />
|
|
</Helmet>
|
|
<MuiThemeProvider theme={theme}>
|
|
<Baseline />
|
|
{children}
|
|
</MuiThemeProvider>
|
|
</ThemeContext.Provider>
|
|
);
|
|
};
|
|
ThemeProvider.defaultProps = {
|
|
isDefaultDark: false
|
|
};
|
|
export default ThemeProvider;
|