Files
SCM-Manager/scm-ui/src/containers/App.js

58 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { Component } from "react";
import Navigation from "./Navigation";
import Main from "./Main";
import Login from "./Login";
2018-07-09 11:38:13 +02:00
import { getIsAuthenticated } from "../modules/login";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
type Props = {
2018-07-09 11:38:13 +02:00
login: boolean,
username: string,
getAuthState: () => void,
loading: boolean
2018-07-05 16:48:56 +02:00
};
class App extends Component<Props> {
componentDidMount() {
2018-07-09 11:38:13 +02:00
this.props.getAuthState();
}
render() {
const { login, username, loading } = this.props;
if (loading) {
return <div>Loading...</div>;
} else if (!login) {
return (
<div>
2018-07-05 16:48:56 +02:00
<Login />
</div>
);
2018-07-05 16:48:56 +02:00
} else {
return (
2018-07-05 16:48:56 +02:00
<div className="App">
2018-07-09 11:38:13 +02:00
<h2>Welcome, {username}!</h2>
2018-07-05 16:48:56 +02:00
<Navigation />
<Main />
</div>
);
}
}
}
2018-07-09 11:38:13 +02:00
const mapDispatchToProps = dispatch => {
return {
getAuthState: () => dispatch(getIsAuthenticated())
};
};
const mapStateToProps = state => {
return state.login || {};
2018-07-09 11:38:13 +02:00
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(App)
);