2020-05-14 09:30:32 +00:00
|
|
|
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";
|
2019-08-26 17:48:13 +00:00
|
|
|
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 {
|
|
|
|
pageCreatePath,
|
|
|
|
pageListPath,
|
|
|
|
PageListUrlQueryParams,
|
2020-05-14 09:30:32 +00:00
|
|
|
PageListUrlSortField,
|
2019-06-19 14:40:52 +00:00
|
|
|
pagePath,
|
2020-05-14 09:30:32 +00:00
|
|
|
PageUrlQueryParams
|
2019-06-19 14:40:52 +00:00
|
|
|
} from "./urls";
|
2021-01-12 11:13:02 +00:00
|
|
|
import PageCreateComponent from "./views/PageCreate";
|
2019-06-19 14:40:52 +00:00
|
|
|
import PageDetailsComponent from "./views/PageDetails";
|
|
|
|
import PageListComponent from "./views/PageList";
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const PageList: React.FC<RouteComponentProps<any>> = ({ 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: PageListUrlQueryParams = asSortParams(
|
|
|
|
qs,
|
|
|
|
PageListUrlSortField,
|
|
|
|
PageListUrlSortField.title
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
return <PageListComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2021-01-12 11:13:02 +00:00
|
|
|
const PageCreate: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: PageUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PageCreateComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const PageDetails: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: PageUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PageDetailsComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-08-26 17:48:13 +00:00
|
|
|
const Component = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.pages)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={pageListPath} component={PageList} />
|
|
|
|
<Route exact path={pageCreatePath} component={PageCreate} />
|
|
|
|
<Route path={pagePath(":id")} component={PageDetails} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export default Component;
|