2016-10-20 19:47:29 +03:00
|
|
|
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-10-20 19:47:29 +03:00
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const selectors = require('@state/selectors');
|
|
|
|
|
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');
|
2016-12-15 16:10:36 +02:00
|
|
|
const Redirect = require('@components/redirect');
|
|
|
|
const Ul = require('@ui/components/horizontal-list/ul');
|
2016-12-16 14:28:27 +02:00
|
|
|
const NotFound = require('@containers/not-found');
|
2016-10-20 19:47:29 +03: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;
|
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
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 = ({
|
2016-12-16 14:28:27 +02:00
|
|
|
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
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const notFound = !orgs.length
|
|
|
|
? <NotFound />
|
|
|
|
: Redirect(`/${orgs[0].id}`);
|
|
|
|
|
2016-10-20 19:47:29 +03:00
|
|
|
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>
|
2016-12-16 14:28:27 +02:00
|
|
|
<Match component={Org} pattern='/:org/:section?' />
|
|
|
|
<Miss component={notFound} />
|
2016-12-14 00:09:04 +02:00
|
|
|
</Container>
|
|
|
|
</div>
|
2016-10-20 19:47:29 +03:00
|
|
|
);
|
|
|
|
};
|
2016-10-25 22:15:33 +03:00
|
|
|
|
2016-12-14 00:09:04 +02:00
|
|
|
Home.propTypes = {
|
2016-12-16 14:28:27 +02:00
|
|
|
orgs: React.PropTypes.arrayOf(
|
|
|
|
React.PropTypes.shape({
|
|
|
|
owner: React.PropTypes.string,
|
|
|
|
uuid: React.PropTypes.string,
|
|
|
|
id: React.PropTypes.string,
|
|
|
|
name: React.PropTypes.string
|
|
|
|
})
|
|
|
|
)
|
2016-12-14 00:09:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
2016-12-16 14:28:27 +02:00
|
|
|
orgs: orgsSelector(state)
|
2016-12-14 00:09:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(Home);
|