saleor-dashboard/src/plugins/index.tsx

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-08-21 14:30:56 +00:00
import { parse as parseQs } from "qs";
import React from "react";
2019-08-30 13:10:07 +00:00
import { useIntl } from "react-intl";
2019-08-21 14:30:56 +00:00
import { Route, RouteComponentProps, Switch } from "react-router-dom";
2019-08-30 13:10:07 +00:00
import { sectionNames } from "@saleor/intl";
2019-12-17 17:13:56 +00:00
import { asSortParams } from "@saleor/utils/sort";
2019-08-21 14:30:56 +00:00
import { WindowTitle } from "../components/WindowTitle";
import {
2019-12-17 17:13:56 +00:00
pluginListPath,
PluginListUrlQueryParams,
pluginPath,
PluginUrlQueryParams,
PluginListUrlSortField
2019-08-21 14:30:56 +00:00
} from "./urls";
import PluginsDetailsComponent from "./views/PluginsDetails";
2019-12-17 17:13:56 +00:00
import PluginsListComponent from "./views/PluginList";
2019-08-21 14:30:56 +00:00
const PluginList: React.FC<RouteComponentProps<any>> = ({ location }) => {
2019-08-21 14:30:56 +00:00
const qs = parseQs(location.search.substr(1));
2019-12-17 17:13:56 +00:00
const params: PluginListUrlQueryParams = asSortParams(
qs,
PluginListUrlSortField
);
2019-08-21 14:30:56 +00:00
return <PluginsListComponent params={params} />;
};
const PageDetails: React.FC<RouteComponentProps<any>> = ({ match }) => {
2019-08-26 17:08:32 +00:00
const qs = parseQs(location.search.substr(1));
2019-12-17 17:13:56 +00:00
const params: PluginUrlQueryParams = qs;
2019-08-21 14:30:56 +00:00
2019-08-26 17:08:32 +00:00
return (
<PluginsDetailsComponent
id={decodeURIComponent(match.params.id)}
params={params}
/>
);
};
2019-08-21 14:30:56 +00:00
2019-08-30 13:10:07 +00:00
const Component = () => {
const intl = useIntl();
return (
<>
<WindowTitle title={intl.formatMessage(sectionNames.plugins)} />
<Switch>
2019-12-17 17:13:56 +00:00
<Route exact path={pluginListPath} component={PluginList} />
<Route path={pluginPath(":id")} component={PageDetails} />
2019-08-30 13:10:07 +00:00
</Switch>
</>
);
};
2019-08-21 14:30:56 +00:00
export default Component;