2019-06-19 14:40:52 +00:00
|
|
|
import { parse as parseQs } from "qs";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-23 12:23:59 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
|
2019-08-23 12:23:59 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
|
|
|
customerAddPath,
|
|
|
|
customerAddressesPath,
|
|
|
|
CustomerAddressesUrlQueryParams,
|
|
|
|
customerListPath,
|
|
|
|
CustomerListUrlQueryParams,
|
|
|
|
customerPath,
|
|
|
|
CustomerUrlQueryParams
|
|
|
|
} from "./urls";
|
|
|
|
import CustomerAddressesViewComponent from "./views/CustomerAddresses";
|
|
|
|
import CustomerCreateView from "./views/CustomerCreate";
|
|
|
|
import CustomerDetailsViewComponent from "./views/CustomerDetails";
|
|
|
|
import CustomerListViewComponent from "./views/CustomerList";
|
|
|
|
|
|
|
|
const CustomerListView: React.StatelessComponent<RouteComponentProps<{}>> = ({
|
|
|
|
location
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CustomerListUrlQueryParams = qs;
|
|
|
|
return <CustomerListViewComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface CustomerDetailsRouteParams {
|
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
const CustomerDetailsView: React.StatelessComponent<
|
|
|
|
RouteComponentProps<CustomerDetailsRouteParams>
|
|
|
|
> = ({ location, match }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CustomerUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomerDetailsViewComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface CustomerAddressesRouteParams {
|
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
const CustomerAddressesView: React.StatelessComponent<
|
|
|
|
RouteComponentProps<CustomerAddressesRouteParams>
|
|
|
|
> = ({ match }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CustomerAddressesUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomerAddressesViewComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-08-23 12:23:59 +00:00
|
|
|
export const CustomerSection: React.StatelessComponent<{}> = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.customers)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={customerListPath} component={CustomerListView} />
|
|
|
|
<Route exact path={customerAddPath} component={CustomerCreateView} />
|
|
|
|
<Route
|
|
|
|
path={customerAddressesPath(":id")}
|
|
|
|
component={CustomerAddressesView}
|
|
|
|
/>
|
|
|
|
<Route path={customerPath(":id")} component={CustomerDetailsView} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|