Skip to content

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

Encode paths in customers views

dominik-zegleneca300be5841
diff --git a/saleor/static/dashboard-next/customers/index.tsx b/saleor/static/dashboard-next/customers/index.tsx
index 530ee95ee4..d3e8abc87d 100644
--- a/saleor/static/dashboard-next/customers/index.tsx
+++ b/saleor/static/dashboard-next/customers/index.tsx
@@ -4,7 +4,7 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { customerAddUrl, customerListUrl, customerUrl } from "./urls";
+import { customerAddPath, customerListPath, customerPath } from "./urls";
import CustomerCreateView from "./views/CustomerCreate";
import CustomerDetailsViewComponent from "./views/CustomerDetails";
import CustomerListViewComponent, {
@@ -35,9 +35,9 @@ export const CustomerSection: React.StatelessComponent<{}> = () => (
<>
<WindowTitle title={i18n.t("Customers")} />
<Switch>
- <Route exact path={customerListUrl} component={CustomerListView} />
- <Route exact path={customerAddUrl} component={CustomerCreateView} />
- <Route path={customerUrl(":id")} component={CustomerDetailsView} />
+ <Route exact path={customerListPath} component={CustomerListView} />
+ <Route exact path={customerAddPath} component={CustomerCreateView} />
+ <Route path={customerPath(":id")} component={CustomerDetailsView} />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/customers/urls.ts b/saleor/static/dashboard-next/customers/urls.ts
index 96104ffad9..c5fccd972d 100644
--- a/saleor/static/dashboard-next/customers/urls.ts
+++ b/saleor/static/dashboard-next/customers/urls.ts
@@ -1,9 +1,17 @@
import * as urlJoin from "url-join";
export const customerSection = "/customers/";
-export const customerListUrl = customerSection;
-export const customerUrl = (id: string) => urlJoin(customerSection, id);
-export const customerAddUrl = urlJoin(customerSection, "add");
+export const customerListPath = customerSection;
+export const customerListUrl = customerListPath;
+
+export const customerPath = (id: string) => urlJoin(customerSection, id);
+export const customerUrl = (id: string) => customerPath(encodeURIComponent(id));
+
+export const customerAddPath = urlJoin(customerSection, "add");
+export const customerAddUrl = customerAddPath;
+
+export const customerRemovePath = (id: string) =>
+ urlJoin(customerPath(id), "remove");
export const customerRemoveUrl = (id: string) =>
- urlJoin(customerUrl(id), "remove");
+ customerRemovePath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
index a3db23033f..4b4c6dc936 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
@@ -17,7 +17,12 @@ import {
import { TypedCustomerDetailsQuery } from "../queries";
import { RemoveCustomer } from "../types/RemoveCustomer";
import { UpdateCustomer } from "../types/UpdateCustomer";
-import { customerListUrl, customerRemoveUrl, customerUrl } from "../urls";
+import {
+ customerListUrl,
+ customerRemovePath,
+ customerRemoveUrl,
+ customerUrl
+} from "../urls";
interface CustomerDetailsViewProps {
id: string;
@@ -87,9 +92,7 @@ export const CustomerDetailsView: React.StatelessComponent<
}
onAddressManageClick={() => undefined} // TODO: add address management #3173
onBack={() => navigate(customerListUrl)}
- onRowClick={id =>
- navigate(orderUrl(encodeURIComponent(id)))
- }
+ onRowClick={id => navigate(orderUrl(id))}
onSubmit={formData =>
updateCustomer({
variables: {
@@ -105,7 +108,7 @@ export const CustomerDetailsView: React.StatelessComponent<
onDelete={() => navigate(customerRemoveUrl(id))}
onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172
/>
- <Route exact path={customerRemoveUrl(id)}>
+ <Route exact path={customerRemovePath(":id")}>
{({ match }) => (
<ActionDialog
onClose={() => navigate(customerUrl(id))}
diff --git a/saleor/static/dashboard-next/customers/views/CustomerList.tsx b/saleor/static/dashboard-next/customers/views/CustomerList.tsx
index afbbe87dfd..3f7c458880 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerList.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerList.tsx
@@ -42,8 +42,7 @@ export const CustomerList: React.StatelessComponent<CustomerListProps> = ({
onAdd={() => navigate(customerAddUrl)}
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
- onRowClick={id => () =>
- navigate(customerUrl(encodeURIComponent(id)))}
+ onRowClick={id => () => navigate(customerUrl(id))}
/>
)}
</Paginator>