Files
SCM-Manager/scm-ui/ui-webapp/src/containers/Main.tsx

109 lines
4.6 KiB
TypeScript
Raw Normal View History

/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React from "react";
2018-07-02 14:50:13 +02:00
import { Redirect, Route, Switch, withRouter } from "react-router-dom";
2020-08-04 11:41:00 +02:00
import { Links, Me } from "@scm-manager/ui-types";
2018-07-02 14:50:13 +02:00
import Overview from "../repos/containers/Overview";
import Users from "../users/containers/Users";
import Login from "../containers/Login";
import Logout from "../containers/Logout";
2018-07-12 11:35:28 +02:00
import { ProtectedRoute } from "@scm-manager/ui-components";
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
import CreateUser from "../users/containers/CreateUser";
import SingleUser from "../users/containers/SingleUser";
import RepositoryRoot from "../repos/containers/RepositoryRoot";
import Create from "../repos/containers/Create";
2018-07-02 14:50:13 +02:00
import Groups from "../groups/containers/Groups";
import SingleGroup from "../groups/containers/SingleGroup";
import CreateGroup from "../groups/containers/CreateGroup";
import Admin from "../admin/containers/Admin";
import Profile from "./Profile";
2018-08-09 09:38:55 +02:00
2018-07-02 14:50:13 +02:00
type Props = {
2020-08-04 11:41:00 +02:00
me: Me;
authenticated?: boolean;
links: Links;
2018-07-11 14:59:01 +02:00
};
2018-07-02 14:50:13 +02:00
class Main extends React.Component<Props> {
render() {
2020-08-04 11:41:00 +02:00
const { authenticated, me, links } = this.props;
const redirectUrlFactory = binder.getExtension("main.redirect", this.props);
2020-08-04 11:41:00 +02:00
let url = "/";
if (authenticated) {
url = "/repos/";
}
if (redirectUrlFactory) {
2019-02-05 08:45:03 +01:00
url = redirectUrlFactory(this.props);
}
2020-08-10 09:28:54 +02:00
if (!me) {
url = "/login";
}
2018-07-02 14:50:13 +02:00
return (
2019-03-14 10:12:34 +01:00
<div className="main">
<Switch>
<Redirect exact from="/" to={url} />
2019-03-14 10:12:34 +01:00
<Route exact path="/login" component={Login} />
<Route path="/logout" component={Logout} />
2019-08-27 11:09:53 +02:00
<Redirect exact strict from="/repos" to="/repos/" />
2019-10-21 10:57:56 +02:00
<ProtectedRoute exact path="/repos/" component={Overview} authenticated={authenticated} />
<ProtectedRoute exact path="/repos/create" component={Create} authenticated={authenticated} />
<ProtectedRoute exact path="/repos/:page" component={Overview} authenticated={authenticated} />
<ProtectedRoute path="/repo/:namespace/:name" component={RepositoryRoot} authenticated={authenticated} />
<Redirect exact strict from="/users" to="/users/" />
2019-10-21 10:57:56 +02:00
<ProtectedRoute exact path="/users/" component={Users} authenticated={authenticated} />
<ProtectedRoute authenticated={authenticated} path="/users/create" component={CreateUser} />
<ProtectedRoute exact path="/users/:page" component={Users} authenticated={authenticated} />
<ProtectedRoute authenticated={authenticated} path="/user/:name" component={SingleUser} />
<Redirect exact strict from="/groups" to="/groups/" />
2019-10-21 10:57:56 +02:00
<ProtectedRoute exact path="/groups/" component={Groups} authenticated={authenticated} />
<ProtectedRoute authenticated={authenticated} path="/group/:name" component={SingleGroup} />
<ProtectedRoute authenticated={authenticated} path="/groups/create" component={CreateGroup} />
<ProtectedRoute exact path="/groups/:page" component={Groups} authenticated={authenticated} />
<ProtectedRoute path="/admin" component={Admin} authenticated={authenticated} />
<ProtectedRoute path="/me" component={Profile} authenticated={authenticated} />
2019-03-14 10:12:34 +01:00
<ExtensionPoint
name="main.route"
renderAll={true}
props={{
authenticated,
2020-08-10 09:28:54 +02:00
me,
links
}}
2019-03-14 10:12:34 +01:00
/>
</Switch>
</div>
2018-07-02 14:50:13 +02:00
);
}
}
export default withRouter(Main);