saleor-dashboard/src/webhooks/index.tsx

55 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-10-09 06:01:52 +00:00
import { parse as parseQs } from "qs";
import React from "react";
import { useIntl } from "react-intl";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { sectionNames } from "@saleor/intl";
2019-12-17 17:13:56 +00:00
import { asSortParams } from "@saleor/utils/sort";
2019-10-09 06:01:52 +00:00
import { WindowTitle } from "../components/WindowTitle";
import {
2019-12-06 14:58:28 +00:00
webhookAddUrl,
webhookListPath,
2019-12-17 17:13:56 +00:00
WebhookListUrlQueryParams,
2019-12-06 14:58:28 +00:00
webhookPath,
WebhookUrlQueryParams,
2019-12-17 17:13:56 +00:00
WebhookListUrlSortField
2019-10-09 06:01:52 +00:00
} from "./urls";
2019-10-09 20:50:03 +00:00
import WebhookCreate from "./views/WebhooksCreate";
import WebhooksDetails from "./views/WebhooksDetails";
2019-12-17 17:13:56 +00:00
import WebhooksList from "./views/WebhookList";
2019-10-09 06:01:52 +00:00
const WebhookList: React.FC<RouteComponentProps<any>> = ({ location }) => {
2019-10-09 06:01:52 +00:00
const qs = parseQs(location.search.substr(1));
2019-12-17 17:13:56 +00:00
const params: WebhookListUrlQueryParams = asSortParams(
qs,
WebhookListUrlSortField
);
return <WebhooksList params={params} />;
2019-10-09 06:01:52 +00:00
};
const WebhookDetails: React.FC<RouteComponentProps<any>> = ({ match }) => {
2019-10-09 06:01:52 +00:00
const qs = parseQs(location.search.substr(1));
2019-12-06 14:58:28 +00:00
const params: WebhookUrlQueryParams = qs;
2019-10-09 06:01:52 +00:00
return (
2019-10-09 20:50:03 +00:00
<WebhooksDetails id={decodeURIComponent(match.params.id)} params={params} />
2019-10-09 06:01:52 +00:00
);
};
const Component = () => {
const intl = useIntl();
return (
<>
<WindowTitle title={intl.formatMessage(sectionNames.webhooks)} />
2019-10-09 06:01:52 +00:00
<Switch>
2019-12-06 14:58:28 +00:00
<Route exact path={webhookListPath} component={WebhookList} />
<Route exact path={webhookAddUrl} component={WebhookCreate} />
<Route path={webhookPath(":id")} component={WebhookDetails} />
2019-10-09 06:01:52 +00:00
</Switch>
</>
);
};
export default Component;