Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Save used theme to localStorage

dominik-zeglen2ebe2dac5027
diff --git a/saleor/static/dashboard-next/components/Theme/ThemeProvider.tsx b/saleor/static/dashboard-next/components/Theme/ThemeProvider.tsx
index c57d262af4..1e7a6be9ad 100644
--- a/saleor/static/dashboard-next/components/Theme/ThemeProvider.tsx
+++ b/saleor/static/dashboard-next/components/Theme/ThemeProvider.tsx
@@ -59,12 +59,16 @@ const ThemeProvider: React.FC<ThemeProviderProps> = ({
isDefaultDark
}) => {
const [isDark, setDark] = React.useState(isDefaultDark);
+ const toggleTheme = () => {
+ setDark(!isDark);
+ localStorage.setItem("theme", (!isDark).toString());
+ };
return (
<ThemeContext.Provider
value={{
isDark,
- toggleTheme: () => setDark(!isDark)
+ toggleTheme
}}
>
<MuiThemeProvider theme={createTheme(isDark ? dark : light)}>
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 2b2553096e..23241cc82b 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -102,119 +102,127 @@ const apolloClient = new ApolloClient({
export const appMountPoint = "/dashboard/next/";
-const App: React.FC = () => (
- <FormProvider>
- <ApolloProvider client={apolloClient}>
- <BrowserRouter basename={appMountPoint}>
- <ThemeProvider>
- <DateProvider>
- <LocaleProvider>
- <MessageManager>
- <AppProgressProvider>
- <ShopProvider>
- <WindowTitle title={i18n.t("Dashboard")} />
- {/* FIXME: #3424 */}
- {/* <ConfirmFormLeaveDialog /> */}
- <AuthProvider>
- {({
- hasToken,
- isAuthenticated,
- tokenAuthLoading,
- tokenVerifyLoading,
- user
- }) => {
- return isAuthenticated &&
- !tokenAuthLoading &&
- !tokenVerifyLoading ? (
- <Switch>
- <SectionRoute exact path="/" component={HomePage} />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_PRODUCTS]}
- path="/categories"
- component={CategorySection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_PRODUCTS]}
- path="/collections"
- component={CollectionSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_USERS]}
- path="/customers"
- component={CustomerSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_DISCOUNTS]}
- path="/discounts"
- component={DiscountSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_PAGES]}
- path="/pages"
- component={PageSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_ORDERS]}
- path="/orders"
- component={OrdersSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_PRODUCTS]}
- path="/products"
- component={ProductSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_PRODUCTS]}
- path="/product-types"
- component={ProductTypesSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_STAFF]}
- path="/staff"
- component={StaffSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_SETTINGS]}
- path="/site-settings"
- component={SiteSettingsSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_SETTINGS]}
- path="/taxes"
- component={TaxesSection}
- />
- <SectionRoute
- permissions={[PermissionEnum.MANAGE_SHIPPING]}
- path="/shipping"
- component={ShippingSection}
- />
- {configurationMenu.filter(menuItem =>
- hasPermission(menuItem.permission, user)
- ).length > 0 && (
+const App: React.FC = () => {
+ const isDark = localStorage.getItem("theme") === "true";
+
+ return (
+ <FormProvider>
+ <ApolloProvider client={apolloClient}>
+ <BrowserRouter basename={appMountPoint}>
+ <ThemeProvider isDefaultDark={isDark}>
+ <DateProvider>
+ <LocaleProvider>
+ <MessageManager>
+ <AppProgressProvider>
+ <ShopProvider>
+ <WindowTitle title={i18n.t("Dashboard")} />
+ {/* FIXME: #3424 */}
+ {/* <ConfirmFormLeaveDialog /> */}
+ <AuthProvider>
+ {({
+ hasToken,
+ isAuthenticated,
+ tokenAuthLoading,
+ tokenVerifyLoading,
+ user
+ }) => {
+ return isAuthenticated &&
+ !tokenAuthLoading &&
+ !tokenVerifyLoading ? (
+ <Switch>
<SectionRoute
exact
- path="/configuration"
- component={ConfigurationSection}
+ path="/"
+ component={HomePage}
/>
- )}
- <Route component={NotFound} />
- </Switch>
- ) : hasToken && tokenVerifyLoading ? (
- <LoginLoading />
- ) : (
- <Login loading={tokenAuthLoading} />
- );
- }}
- </AuthProvider>
- </ShopProvider>
- </AppProgressProvider>
- </MessageManager>
- </LocaleProvider>
- </DateProvider>
- </ThemeProvider>
- </BrowserRouter>
- </ApolloProvider>
- </FormProvider>
-);
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_PRODUCTS]}
+ path="/categories"
+ component={CategorySection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_PRODUCTS]}
+ path="/collections"
+ component={CollectionSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_USERS]}
+ path="/customers"
+ component={CustomerSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_DISCOUNTS]}
+ path="/discounts"
+ component={DiscountSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_PAGES]}
+ path="/pages"
+ component={PageSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_ORDERS]}
+ path="/orders"
+ component={OrdersSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_PRODUCTS]}
+ path="/products"
+ component={ProductSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_PRODUCTS]}
+ path="/product-types"
+ component={ProductTypesSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_STAFF]}
+ path="/staff"
+ component={StaffSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_SETTINGS]}
+ path="/site-settings"
+ component={SiteSettingsSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_SETTINGS]}
+ path="/taxes"
+ component={TaxesSection}
+ />
+ <SectionRoute
+ permissions={[PermissionEnum.MANAGE_SHIPPING]}
+ path="/shipping"
+ component={ShippingSection}
+ />
+ {configurationMenu.filter(menuItem =>
+ hasPermission(menuItem.permission, user)
+ ).length > 0 && (
+ <SectionRoute
+ exact
+ path="/configuration"
+ component={ConfigurationSection}
+ />
+ )}
+ <Route component={NotFound} />
+ </Switch>
+ ) : hasToken && tokenVerifyLoading ? (
+ <LoginLoading />
+ ) : (
+ <Login loading={tokenAuthLoading} />
+ );
+ }}
+ </AuthProvider>
+ </ShopProvider>
+ </AppProgressProvider>
+ </MessageManager>
+ </LocaleProvider>
+ </DateProvider>
+ </ThemeProvider>
+ </BrowserRouter>
+ </ApolloProvider>
+ </FormProvider>
+ );
+};
render(<App />, document.querySelector("#dashboard-app"));