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

56 lines
1.0 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: any
2018-07-05 16:48:56 +02:00
};
class App extends Component {
2018-07-09 11:38:13 +02:00
componentWillMount() {
this.props.getAuthState();
}
render() {
2018-07-09 11:38:13 +02:00
const { login, username } = this.props.login;
2018-07-05 16:48:56 +02:00
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 { login: state.login };
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(App)
);