Skip to content

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

Refactor link handling

dominik-zeglendfe8461c8aaa
diff --git a/saleor/static/dashboard-next/components/Link.tsx b/saleor/static/dashboard-next/components/Link.tsx
index d03ec4d009..6ee63d1929 100644
--- a/saleor/static/dashboard-next/components/Link.tsx
+++ b/saleor/static/dashboard-next/components/Link.tsx
@@ -31,6 +31,7 @@ interface LinkProps
color?: "primary" | "secondary";
underline?: boolean;
typographyProps?: TypographyProps;
+ onClick: () => void;
}
const Link = withStyles(styles, { name: "Link" })(
@@ -52,7 +53,7 @@ const Link = withStyles(styles, { name: "Link" })(
})}
onClick={event => {
event.preventDefault();
- onClick(event as any);
+ onClick();
}}
{...linkProps}
>
diff --git a/saleor/static/dashboard-next/config.ts b/saleor/static/dashboard-next/config.ts
new file mode 100644
index 0000000000..611186762d
--- /dev/null
+++ b/saleor/static/dashboard-next/config.ts
@@ -0,0 +1,2 @@
+export const APP_MOUNT_URI = "/dashboard/next/";
+export const API_URI = "/graphql/";
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 740f53838b..922e19a513 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -28,6 +28,7 @@ import { MessageManager } from "./components/messages";
import { ShopProvider } from "./components/Shop";
import ThemeProvider from "./components/Theme";
import { WindowTitle } from "./components/WindowTitle";
+import { API_URI, APP_MOUNT_URI } from "./config";
import ConfigurationSection, { configurationMenu } from "./configuration";
import { CustomerSection } from "./customers";
import DiscountSection from "./discounts";
@@ -76,7 +77,7 @@ const linkOptions = {
headers: {
"X-CSRFToken": cookies.get("csrftoken")
},
- uri: "/graphql/"
+ uri: API_URI
};
const uploadLink = createUploadLink(linkOptions);
const batchLink = new BatchHttpLink(linkOptions);
@@ -101,15 +102,13 @@ const apolloClient = new ApolloClient({
link: invalidTokenLink.concat(authLink.concat(link))
});
-export const appMountPoint = "/dashboard/next/";
-
const App: React.FC = () => {
const isDark = localStorage.getItem("theme") === "true";
return (
<FormProvider>
<ApolloProvider client={apolloClient}>
- <BrowserRouter basename={appMountPoint}>
+ <BrowserRouter basename={APP_MOUNT_URI}>
<ThemeProvider isDefaultDark={isDark}>
<DateProvider>
<LocaleProvider>
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index 6940922c88..6f4d6f2606 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -1,8 +1,8 @@
import * as urlJoin from "url-join";
import { MutationFn, MutationResult } from "react-apollo";
-import { appMountPoint } from ".";
import { ConfirmButtonTransitionState } from "./components/ConfirmButton/ConfirmButton";
+import { APP_MOUNT_URI } from "./config";
import { AddressType } from "./customers/types";
import i18n from "./i18n";
import { PartialMutationProviderOutput, UserError } from "./types";
@@ -224,5 +224,5 @@ export function getUserInitials(user?: User) {
}
export function createHref(url: string) {
- return urlJoin(appMountPoint, url);
+ return urlJoin(APP_MOUNT_URI, url);
}