saleor-dashboard/src/services/index.tsx

78 lines
2 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-30 16:46:48 +00:00
interface ServiceDetailsProps extends RouteComponentProps<{ id: string }> {
token: string;
onTokenClose: () => void;
}
const ServiceDetails: React.FC<ServiceDetailsProps> = ({
match,
token,
onTokenClose
2019-09-27 10:17:23 +00:00
}) => {
const qs = parseQs(location.search.substr(1));
const params: ServiceUrlQueryParams = qs;
return (
<ServiceDetailsComponent
id={decodeURIComponent(match.params.id)}
params={params}
2019-09-30 16:46:48 +00:00
token={token}
onTokenClose={onTokenClose}
2019-09-27 10:17:23 +00:00
/>
);
};
const ServiceSection = () => {
2019-09-25 14:11:45 +00:00
const intl = useIntl();
2019-09-30 16:46:48 +00:00
const [token, setToken] = React.useState<string>(null);
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-30 16:46:48 +00:00
<Route
exact
path={serviceAddPath}
render={() => <ServiceCreate setToken={setToken} />}
/>
<Route
path={servicePath(":id")}
render={props => (
<ServiceDetails
{...props}
token={token}
onTokenClose={() => setToken(null)}
/>
)}
/>
2019-09-25 14:11:45 +00:00
</Switch>
</>
);
};
2019-09-27 10:17:23 +00:00
export default ServiceSection;