Skip to content

Instantly share code, notes, and snippets.

@steniowagner
Created December 19, 2018 17:36
Show Gist options
  • Save steniowagner/099e2ebecc20a1ddebdb0f0133b4bba6 to your computer and use it in GitHub Desktop.
Save steniowagner/099e2ebecc20a1ddebdb0f0133b4bba6 to your computer and use it in GitHub Desktop.
// @flow
import React, { Fragment } from 'react';
import { BrowserRouter as ApplicationRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import NavigationMenu from './navigation-menu';
import HeaderBar from './header-bar';
import Router from '../Router';
import Login from './login';
const renderLogin = (): Object => (
<Login />
);
const renderDashboard = (): Object => (
<ApplicationRouter>
<Fragment>
<HeaderBar />
<NavigationMenu />
<Router />
</Fragment>
</ApplicationRouter>
);
type Props = {
auth: Object,
};
const Root = ({ auth }: Props): Object => {
const { isAuthenticated } = auth;
return (
<Fragment>
{isAuthenticated ? renderDashboard() : renderLogin()}
</Fragment>
);
};
const mapStateToProps = state => ({
auth: state.auth,
});
export default connect(mapStateToProps)(Root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment