Skip to content

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

Simplify code

dominik-zeglenc9090e76d61c
diff --git a/saleor/static/dashboard-next/components/Navigator.tsx b/saleor/static/dashboard-next/components/Navigator.tsx
index bd087620fc..0b3e86f598 100644
--- a/saleor/static/dashboard-next/components/Navigator.tsx
+++ b/saleor/static/dashboard-next/components/Navigator.tsx
@@ -16,8 +16,10 @@ const Navigator: React.StatelessComponent<NavigatorProps> = (
) => {
invariant(router, "You should not use <Navigator> outside a <Router>");
const { history } = router;
- const navigate = (url, replace = false) =>
+ const navigate = (url, replace = false) => {
replace ? history.replace(url) : history.push(url);
+ window.scrollTo({ top: 0, behavior: "smooth" });
+ };
if (typeof children === "function") {
return children(navigate);
diff --git a/saleor/static/dashboard-next/components/ScrollToTop.tsx b/saleor/static/dashboard-next/components/ScrollToTop.tsx
deleted file mode 100644
index 13ff1d8499..0000000000
--- a/saleor/static/dashboard-next/components/ScrollToTop.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import * as React from "react";
-import { RouteComponentProps, withRouter } from "react-router-dom";
-
-class ScrollToTop extends React.Component<RouteComponentProps<{}>> {
- componentDidUpdate(prevProps) {
- if (this.props.location !== prevProps.location) {
- window.scrollTo(0, 0);
- }
- }
-
- render() {
- return this.props.children;
- }
-}
-
-export default withRouter(ScrollToTop);
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index d67cbd98e4..3c375a73ac 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -22,7 +22,6 @@ import "./i18n";
import PageSection from "./pages";
import ProductSection from "./products";
import theme from "./theme";
-import ScrollToTop from "./components/ScrollToTop";
const cookies = new Cookies();
@@ -75,16 +74,11 @@ render(
{({ isAuthenticated }) =>
isAuthenticated ? (
<AppRoot>
- <ScrollToTop>
- <Switch>
- <Route
- path="/categories"
- component={CategorySection}
- />
- <Route path="/pages" component={PageSection} />
- <Route path="/products" component={ProductSection} />
- </Switch>
- </ScrollToTop>
+ <Switch>
+ <Route path="/categories" component={CategorySection} />
+ <Route path="/pages" component={PageSection} />
+ <Route path="/products" component={ProductSection} />
+ </Switch>
</AppRoot>
) : (
<Route component={Auth} />