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

100 lines
2.1 KiB
JavaScript
Raw Normal View History

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');
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-14 00:09:04 +02:00
2016-10-20 22:42:39 +03:00
const {
FormattedMessage
} = ReactIntl;
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-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-15 16:10:36 +02:00
pathname = '/',
user = {}
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
);
});
return (
2016-12-14 00:09:04 +02:00
<div>
<StyledNav>
<Container>
2016-12-15 16:10:36 +02:00
<Ul>
<Li key={pathname}>
<Link activeClassName='active' to={`/${user.id}`}>
2016-12-14 00:09:04 +02:00
<FormattedMessage id='your-dashboard' />
</Link>
2016-12-15 16:10:36 +02:00
</Li>
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-15 16:10:36 +02:00
<Match component={Dashboard} pattern={`/${user.id}/:section?`} />
<Match component={Org} pattern='/:org' />
<Miss component={Redirect(`/${user.id}`)} />
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 = {
orgs: React.PropTypes.arrayOf(React.PropTypes.shape({
2016-12-15 16:10:36 +02:00
id: React.PropTypes.string,
2016-12-14 00:09:04 +02:00
name: React.PropTypes.string
})),
2016-12-15 16:10:36 +02:00
pathname: React.PropTypes.string,
user: React.PropTypes.shape({
id: React.PropTypes.string,
name: React.PropTypes.string
})
2016-12-14 00:09:04 +02:00
};
const mapStateToProps = (state) => ({
2016-12-15 16:10:36 +02:00
orgs: state.session.data.orgs,
user: {
id: state.session.data.name,
name: state.session.data.name
}
2016-12-14 00:09:04 +02:00
});
module.exports = connect(mapStateToProps)(Home);