2020-05-14 09:30:32 +00:00
|
|
|
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";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
|
2019-12-17 17:13:56 +00:00
|
|
|
import {
|
|
|
|
menuListPath,
|
|
|
|
MenuListUrlQueryParams,
|
2020-05-14 09:30:32 +00:00
|
|
|
MenuListUrlSortField,
|
|
|
|
menuPath
|
2019-12-17 17:13:56 +00:00
|
|
|
} from "./urls";
|
2019-06-19 14:40:52 +00:00
|
|
|
import MenuDetailsComponent from "./views/MenuDetails";
|
|
|
|
import MenuListComponent from "./views/MenuList";
|
|
|
|
|
|
|
|
const MenuList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
2019-12-17 17:13:56 +00:00
|
|
|
const params: MenuListUrlQueryParams = asSortParams(qs, MenuListUrlSortField);
|
|
|
|
|
|
|
|
return <MenuListComponent params={params} />;
|
2019-06-19 14:40:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MenuDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
|
|
location,
|
|
|
|
match
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
2019-12-17 17:13:56 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
return (
|
|
|
|
<MenuDetailsComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={qs}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const NavigationRouter: React.FC = () => (
|
|
|
|
<Switch>
|
|
|
|
<Route exact component={MenuList} path={menuListPath} />
|
|
|
|
<Route component={MenuDetails} path={menuPath(":id")} />
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default NavigationRouter;
|