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

128 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-12-14 00:09:04 +02:00
const paramCase = require('param-case');
const React = require('react');
2016-10-20 22:42:39 +03:00
const ReactIntl = require('react-intl');
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');
const Dashboard = require('@containers/dashboard');
const fns = require('@ui/shared/functions');
const Org = require('@containers/org');
2016-10-20 22:42:39 +03:00
const {
FormattedMessage
} = ReactIntl;
2016-12-14 00:09:04 +02:00
const {
connect
} = ReactRedux;
const {
Link,
Match
} = ReactRouter;
2016-12-12 12:56:48 +02:00
const {
default: styled
} = Styled;
2016-12-14 00:09:04 +02:00
const {
remcalc
} = fns;
const StyledNav = styled.div`
background-color: #f2f2f2;
2016-12-12 12:56:48 +02:00
`;
2016-12-14 00:09:04 +02:00
const StyledUl = styled.ul`
list-style-type: none;
`;
const StyledLi = styled.li`
display: inline-block;
margin-right: ${remcalc(10)};
padding-top: ${remcalc(10)};
padding-bottom: ${remcalc(10)};
& a.active {
cursor: default;
color: #373A3C;
text-decoration: none;
}
`;
const Home = ({
orgs = [],
pathname = '/'
}) => {
const parent = pathname.replace(/\/$/, '');
const links = orgs.map((org) => `${parent}/${paramCase(org.name)}`);
const isDashboardActive = (location) => {
return !links.some((link) => location.pathname.indexOf(link) >= 0);
};
const navLinks = orgs.map(({
name
}) => {
const to = `${parent}/${paramCase(name)}`;
return (
<StyledLi key={to}>
<Link
activeClassName='active'
to={to}
>
{name}
</Link>
</StyledLi>
);
});
return (
2016-12-14 00:09:04 +02:00
<div>
<StyledNav>
<Container>
<StyledUl>
<StyledLi key={pathname}>
<Link
activeClassName='active'
isActive={isDashboardActive}
to={pathname}
>
<FormattedMessage id='your-dashboard' />
</Link>
</StyledLi>
{navLinks}
</StyledUl>
</Container>
</StyledNav>
<Container>
<Match
exactly
pattern={parent}
render={Dashboard}
/>
<Match
component={Org}
pattern={`${parent}/:org`}
/>
</Container>
</div>
);
};
2016-10-25 22:15:33 +03:00
2016-12-14 00:09:04 +02:00
Home.propTypes = {
orgs: React.PropTypes.arrayOf(React.PropTypes.shape({
name: React.PropTypes.string
})),
pathname: React.PropTypes.string
};
const mapStateToProps = (state) => ({
orgs: state.session.data.orgs
});
module.exports = connect(mapStateToProps)(Home);