saleor-dashboard/src/services/index.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-09-25 14:11:45 +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";
import { WindowTitle } from "../components/WindowTitle";
import {
2019-09-27 12:21:38 +00:00
serviceAddPath,
2019-09-25 14:11:45 +00:00
serviceListPath,
2019-09-27 10:17:23 +00:00
ServiceListUrlQueryParams,
servicePath,
ServiceUrlQueryParams
2019-09-25 14:11:45 +00:00
} from "./urls";
2019-09-27 12:21:38 +00:00
import ServiceCreate from "./views/ServiceCreate";
2019-09-27 10:17:23 +00:00
import ServiceDetailsComponent from "./views/ServiceDetails";
2019-09-25 14:11:45 +00:00
import ServiceListComponent from "./views/ServiceList";
2019-09-27 10:17:23 +00:00
const ServiceList: React.FC<RouteComponentProps> = ({ location }) => {
2019-09-25 14:11:45 +00:00
const qs = parseQs(location.search.substr(1));
const params: ServiceListUrlQueryParams = qs;
2019-09-27 10:17:23 +00:00
2019-09-25 14:11:45 +00:00
return <ServiceListComponent params={params} />;
};
2019-09-27 10:17:23 +00:00
const ServiceDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
match
}) => {
const qs = parseQs(location.search.substr(1));
const params: ServiceUrlQueryParams = qs;
return (
<ServiceDetailsComponent
id={decodeURIComponent(match.params.id)}
params={params}
/>
);
};
const ServiceSection = () => {
2019-09-25 14:11:45 +00:00
const intl = useIntl();
2019-09-27 10:17:23 +00:00
2019-09-25 14:11:45 +00:00
return (
<>
<WindowTitle title={intl.formatMessage(sectionNames.serviceAccounts)} />
<Switch>
2019-09-27 10:17:23 +00:00
<Route exact path={serviceListPath} component={ServiceList} />
2019-09-27 12:21:38 +00:00
<Route exact path={serviceAddPath} component={ServiceCreate} />
2019-09-27 10:17:23 +00:00
<Route path={servicePath(":id")} component={ServiceDetails} />
2019-09-25 14:11:45 +00:00
</Switch>
</>
);
};
2019-09-27 10:17:23 +00:00
export default ServiceSection;