2020-07-22 10:54:15 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
|
|
|
import WebhooksRoutes from "@saleor/webhooks";
|
|
|
|
import { parse as parseQs } from "qs";
|
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
|
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
2022-02-02 15:30:34 +00:00
|
|
|
appDetailsPath,
|
2020-07-22 10:54:15 +00:00
|
|
|
AppDetailsUrlQueryParams,
|
|
|
|
appInstallPath,
|
|
|
|
AppInstallUrlQueryParams,
|
|
|
|
AppListUrlQueryParams,
|
|
|
|
appPath,
|
|
|
|
appSettingsPath,
|
|
|
|
appsListPath,
|
|
|
|
customAppAddPath,
|
|
|
|
customAppPath,
|
|
|
|
CustomAppUrlQueryParams
|
|
|
|
} from "./urls";
|
2022-02-02 15:30:34 +00:00
|
|
|
import AppView from "./views/App";
|
2020-07-22 10:54:15 +00:00
|
|
|
import AppDetailsView from "./views/AppDetails";
|
|
|
|
import AppInstallView from "./views/AppInstall";
|
2022-02-02 15:30:34 +00:00
|
|
|
import AppSettingsView from "./views/AppSettings";
|
2020-07-22 10:54:15 +00:00
|
|
|
import AppsListView from "./views/AppsList";
|
|
|
|
import CustomAppCreateView from "./views/CustomAppCreate";
|
|
|
|
import CustomAppDetailsView from "./views/CustomAppDetails";
|
|
|
|
|
|
|
|
const AppDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
|
|
match
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: AppDetailsUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AppDetailsView id={decodeURIComponent(match.params.id)} params={params} />
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
const AppSettings: React.FC<RouteComponentProps<{ id: string }>> = ({
|
2020-07-22 10:54:15 +00:00
|
|
|
match
|
2022-02-02 15:30:34 +00:00
|
|
|
}) => <AppSettingsView id={decodeURIComponent(match.params.id)} />;
|
|
|
|
|
|
|
|
const App: React.FC<RouteComponentProps<{ id: string }>> = ({ match }) => (
|
|
|
|
<AppView id={decodeURIComponent(match.params.id)} />
|
|
|
|
);
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
const AppInstall: React.FC<RouteComponentProps> = props => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: AppInstallUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return <AppInstallView params={params} {...props} />;
|
|
|
|
};
|
|
|
|
|
2021-03-19 12:06:17 +00:00
|
|
|
interface CustomAppDetailsProps extends RouteComponentProps<{ id?: string }> {
|
2020-07-22 10:54:15 +00:00
|
|
|
token: string;
|
|
|
|
onTokenClose: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CustomAppDetails: React.FC<CustomAppDetailsProps> = ({
|
|
|
|
match,
|
|
|
|
token,
|
|
|
|
onTokenClose
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CustomAppUrlQueryParams = qs;
|
2021-03-19 12:06:17 +00:00
|
|
|
const id = match.params.id;
|
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
throw new Error("No ID provided");
|
|
|
|
}
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomAppDetailsView
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
token={token}
|
|
|
|
onTokenClose={onTokenClose}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const AppsList: React.FC<RouteComponentProps> = () => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: AppListUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return <AppsListView params={params} />;
|
|
|
|
};
|
|
|
|
const Component = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const [token, setToken] = React.useState<string>(null);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.apps)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={appsListPath} component={AppsList} />
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={customAppAddPath}
|
|
|
|
render={() => <CustomAppCreateView setToken={setToken} />}
|
|
|
|
/>
|
|
|
|
<Route exact path={appInstallPath} component={AppInstall} />
|
2022-02-02 15:30:34 +00:00
|
|
|
<Route exact path={appDetailsPath(":id")} component={AppDetails} />
|
|
|
|
<Route exact path={appSettingsPath(":id")} component={AppSettings} />
|
|
|
|
<Route path={appPath(":id")} component={App} />
|
2020-07-22 10:54:15 +00:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={customAppPath(":id")}
|
|
|
|
render={props => (
|
|
|
|
<CustomAppDetails
|
|
|
|
{...props}
|
|
|
|
token={token}
|
|
|
|
onTokenClose={() => setToken(null)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<WebhooksRoutes />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Component;
|