saleor-dashboard/src/customers/index.tsx

86 lines
2.4 KiB
TypeScript
Raw Normal View History

import { sectionNames } from "@saleor/intl";
import { asSortParams } from "@saleor/utils/sort";
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";
import { useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import {
customerAddPath,
customerAddressesPath,
CustomerAddressesUrlQueryParams,
customerListPath,
CustomerListUrlQueryParams,
CustomerListUrlSortField,
2019-06-19 14:40:52 +00:00
customerPath,
CustomerUrlQueryParams
2019-06-19 14:40:52 +00:00
} 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.FC<RouteComponentProps<{}>> = ({ location }) => {
2019-06-19 14:40:52 +00:00
const qs = parseQs(location.search.substr(1));
2019-12-17 17:13:56 +00:00
const params: CustomerListUrlQueryParams = asSortParams(
qs,
CustomerListUrlSortField
);
2019-06-19 14:40:52 +00:00
return <CustomerListViewComponent params={params} />;
};
interface CustomerDetailsRouteParams {
id: string;
}
2019-12-17 17:13:56 +00:00
const CustomerDetailsView: React.FC<RouteComponentProps<
CustomerDetailsRouteParams
>> = ({ location, match }) => {
2019-06-19 14:40:52 +00:00
const qs = parseQs(location.search.substr(1));
const params: CustomerUrlQueryParams = qs;
return (
<CustomerDetailsViewComponent
id={decodeURIComponent(match.params.id)}
params={params}
/>
);
};
interface CustomerAddressesRouteParams {
id: string;
}
2019-12-17 17:13:56 +00:00
const CustomerAddressesView: React.FC<RouteComponentProps<
CustomerAddressesRouteParams
>> = ({ match }) => {
2019-06-19 14:40:52 +00:00
const qs = parseQs(location.search.substr(1));
const params: CustomerAddressesUrlQueryParams = qs;
return (
<CustomerAddressesViewComponent
id={decodeURIComponent(match.params.id)}
params={params}
/>
);
};
export const CustomerSection: React.FC<{}> = () => {
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>
</>
);
};