Skip to content

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

Move product types views urls to separate file

dominik-zeglen6f5a65501bf7
diff --git a/saleor/static/dashboard-next/productTypes/index.tsx b/saleor/static/dashboard-next/productTypes/index.tsx
index 5edf2a49f3..0355ab1adb 100644
--- a/saleor/static/dashboard-next/productTypes/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/index.tsx
@@ -4,6 +4,7 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
+import { productTypeAddUrl, productTypeListUrl, productTypeUrl } from "./urls";
import ProductTypeCreate from "./views/ProductTypeCreate";
import ProductTypeListComponent, {
ProductTypeListQueryParams
@@ -32,13 +33,13 @@ const ProductTypeUpdate: React.StatelessComponent<
export const ProductTypeRouter: React.StatelessComponent<
RouteComponentProps<any>
-> = ({ match }) => (
+> = () => (
<>
<WindowTitle title={i18n.t("Product types")} />
<Switch>
- <Route exact path={match.url} component={ProductTypeList} />
- <Route exact path={match.url + "/add/"} component={ProductTypeCreate} />
- <Route path={match.url + "/:id/"} component={ProductTypeUpdate} />
+ <Route exact path={productTypeListUrl} component={ProductTypeList} />
+ <Route exact path={productTypeAddUrl} component={ProductTypeCreate} />
+ <Route path={productTypeUrl(":id")} component={ProductTypeUpdate} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/productTypes/urls.ts b/saleor/static/dashboard-next/productTypes/urls.ts
index fba9f40c59..3003774b27 100644
--- a/saleor/static/dashboard-next/productTypes/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/urls.ts
@@ -1,3 +1,6 @@
-export const productTypeAddUrl = "/productTypes/add/";
-export const productTypeDetailsUrl = (id: string) => `/productTypes/${id}/`;
-export const productTypeListUrl = "/productTypes";
+import * as urlJoin from "url-join";
+
+const productTypeSection = "/productTypes/";
+export const productTypeListUrl = productTypeSection;
+export const productTypeAddUrl = urlJoin(productTypeSection, "add");
+export const productTypeUrl = (id: string) => urlJoin(productTypeSection, id);
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
index c6f370765b..e156e9d2d9 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
@@ -11,7 +11,7 @@ import ProductTypeCreatePage, {
import { TypedProductTypeCreateMutation } from "../mutations";
import { TypedProductTypeCreateDataQuery } from "../queries";
import { ProductTypeCreate as ProductTypeCreateMutation } from "../types/ProductTypeCreate";
-import { productTypeDetailsUrl, productTypeListUrl } from "../urls";
+import { productTypeListUrl, productTypeUrl } from "../urls";
export const ProductTypeCreate: React.StatelessComponent = () => (
<Messages>
@@ -26,9 +26,7 @@ export const ProductTypeCreate: React.StatelessComponent = () => (
text: i18n.t("Successfully created product type")
});
navigate(
- productTypeDetailsUrl(
- updateData.productTypeCreate.productType.id
- )
+ productTypeUrl(updateData.productTypeCreate.productType.id)
);
}
};
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
index 815d1b7d34..0830ee9270 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
@@ -6,7 +6,7 @@ import { createPaginationState, Paginator } from "../../components/Paginator";
import { maybe } from "../../misc";
import ProductTypeListPage from "../components/ProductTypeListPage";
import { TypedProductTypeListQuery } from "../queries";
-import { productTypeAddUrl, productTypeDetailsUrl } from "../urls";
+import { productTypeAddUrl, productTypeUrl } from "../urls";
export type ProductTypeListQueryParams = Partial<{
after: string;
@@ -47,7 +47,7 @@ export const ProductTypeList: React.StatelessComponent<
onAdd={() => navigate(productTypeAddUrl)}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
- onRowClick={id => () => navigate(productTypeDetailsUrl(id))}
+ onRowClick={id => () => navigate(productTypeUrl(id))}
/>
)}
</Paginator>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index c0a7e6255c..49d66d2b09 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -20,7 +20,7 @@ import { AttributeDelete } from "../../types/AttributeDelete";
import { AttributeUpdate } from "../../types/AttributeUpdate";
import { ProductTypeDelete } from "../../types/ProductTypeDelete";
import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../../types/ProductTypeUpdate";
-import { productTypeDetailsUrl, productTypeListUrl } from "../../urls";
+import { productTypeListUrl, productTypeUrl } from "../../urls";
import { ProductTypeUpdateErrors } from "./errors";
import { addAttributeUrl, editAttributeUrl } from "./urls";
@@ -40,10 +40,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
<TypedProductTypeDetailsQuery variables={{ id }}>
{({ data, loading: dataLoading }) => {
const closeModal = () => {
- navigate(
- productTypeDetailsUrl(encodeURIComponent(id)),
- true
- );
+ navigate(productTypeUrl(encodeURIComponent(id)), true);
setErrors.addAttributeErrors([]);
setErrors.editAttributeErrors([]);
};
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
index c1ff8c3787..b2fbbec2d1 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
@@ -1,12 +1,14 @@
+import * as urlJoin from "url-join";
+
import { AttributeTypeEnum } from "../../../types/globalTypes";
-import { productTypeDetailsUrl } from "../../urls";
+import { productTypeUrl } from "../../urls";
export const addAttributeUrl = (
productTypeId: string,
type: AttributeTypeEnum
) =>
type === AttributeTypeEnum.PRODUCT
- ? productTypeDetailsUrl(productTypeId) + "attribute/product/add"
- : productTypeDetailsUrl(productTypeId) + "attribute/variant/add";
+ ? urlJoin(productTypeUrl(productTypeId), "attribute/product/add")
+ : urlJoin(productTypeUrl(productTypeId), "attribute/variant/add");
export const editAttributeUrl = (productTypeId: string, attributeId: string) =>
- productTypeDetailsUrl(productTypeId) + "attribute/" + attributeId;
+ urlJoin(productTypeUrl(productTypeId), "attribute", attributeId);
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index 7ce3d95438..6051924c71 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -8,7 +8,7 @@ import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { decimal, maybe } from "../../misc";
-import { productTypeDetailsUrl } from "../../productTypes/urls";
+import { productTypeUrl } from "../../productTypes/urls";
import ProductUpdatePage from "../components/ProductUpdatePage";
import ProductUpdateOperations from "../containers/ProductUpdateOperations";
import { productDetailsQuery, TypedProductDetailsQuery } from "../queries";
@@ -157,7 +157,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
}
onAttributesEdit={() =>
navigate(
- productTypeDetailsUrl(
+ productTypeUrl(
encodeURIComponent(
data.product.productType.id
)