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

86 lines
1.6 KiB
JavaScript
Raw Normal View History

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