Remove old macaw theme key (#3251)

* Remove old macaw theme key

* Handle cases when mixed values are enabled

* Handle cases when mixed values are enabled

* Handle cases when mixed values are enabled
This commit is contained in:
Patryk Andrzejewski 2023-03-02 15:34:00 +01:00 committed by GitHub
parent 5b7ad12ef0
commit f5c4a5ad49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -1,5 +1,4 @@
import { useUser } from "@dashboard/auth";
import { isDarkTheme } from "@dashboard/misc";
import { staffMemberDetailsUrl } from "@dashboard/staff/urls";
import { useTheme } from "@dashboard/theme";
import { useTheme as useLegacyTheme } from "@saleor/macaw-ui";
@ -21,11 +20,10 @@ import { ThemeSwitcher } from "./ThemeSwitcher";
export const UserControls = () => {
const { user, logout } = useUser();
const { theme, setTheme } = useTheme();
const { themeType: legacyThemeType, setTheme: setLegacyTheme } =
useLegacyTheme();
const { setTheme: setLegacyTheme } = useLegacyTheme();
const handleClick = () => {
setLegacyTheme(isDarkTheme(legacyThemeType) ? "light" : "dark");
setLegacyTheme(theme === "defaultLight" ? "dark" : "light");
setTheme(theme === "defaultLight" ? "defaultDark" : "defaultLight");
};

View file

@ -84,6 +84,23 @@ if (process.env.GTM_ID) {
errorTracker.init();
/*
Handle legacy theming toggle. Since we use new and old macaw,
we need to handle both theme swticher for a while.
*/
const handleLegacyTheming = () => {
const activeTheme = localStorage.getItem("activeMacawUITheme");
if (activeTheme === "defaultDark") {
localStorage.setItem("macaw-ui-theme", "dark");
return;
}
localStorage.setItem("macaw-ui-theme", "light");
};
handleLegacyTheming();
const App: React.FC = () => (
<SaleorProvider client={saleorClient}>
<ApolloProvider client={apolloClient}>