1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 07:40:07 +02:00
copilot/frontend/src/containers/home/index.js
Sérgio Ramos 355c7d59d9 link service
2017-01-02 22:32:29 +00:00

86 lines
1.6 KiB
JavaScript

const React = require('react');
const ReactRedux = require('react-redux');
const ReactRouter = require('react-router');
const Styled = require('styled-components');
const Container = require('@ui/components/container');
const Li = require('@ui/components/horizontal-list/li');
const Org = require('@containers/org');
const PropTypes = require('@root/prop-types');
const Redirect = require('@components/redirect');
const selectors = require('@state/selectors');
const Ul = require('@ui/components/horizontal-list/ul');
const NotFound = require('@containers/not-found');
const {
connect
} = ReactRedux;
const {
Link,
Match,
Miss
} = ReactRouter;
const {
default: styled
} = Styled;
const {
orgsSelector
} = selectors;
const StyledNav = styled.div`
background-color: #f2f2f2;
`;
const Home = ({
orgs = []
}) => {
const navLinks = orgs.map(({
id,
name
}) => {
const to = `/${id}`;
return (
<Li key={to}>
<Link activeClassName='active' to={to}>
{name}
</Link>
</Li>
);
});
const notFound = !orgs.length
? <NotFound />
: Redirect(`/${orgs[0].id}`);
return (
<div>
<StyledNav>
<Container>
<Ul>
{navLinks}
</Ul>
</Container>
</StyledNav>
<Container>
<Match component={Org} pattern='/:org/:section?' />
<Miss component={notFound} />
</Container>
</div>
);
};
Home.propTypes = {
orgs: React.PropTypes.arrayOf(PropTypes.org)
};
const mapStateToProps = (state) => ({
orgs: orgsSelector(state)
});
module.exports = connect(mapStateToProps)(Home);