1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-04 09:00:05 +02:00
copilot/frontend/src/containers/org/index.js

100 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-12-15 16:10:36 +02:00
const isEmpty = require('lodash.isempty');
2016-12-14 00:09:04 +02:00
const React = require('react');
const ReactIntl = require('react-intl');
2016-12-15 16:10:36 +02:00
const ReactRedux = require('react-redux');
const ReactRouter = require('react-router');
const H1 = require('@ui/components/h1');
const Li = require('@ui/components/horizontal-list/li');
const Ul = require('@ui/components/horizontal-list/ul');
const NotFound = require('@containers/not-found');
const People = require('./people');
const Projects = require('./projects');
const Settings = require('./settings');
2016-12-14 00:09:04 +02:00
const {
FormattedMessage
} = ReactIntl;
2016-12-15 16:10:36 +02:00
const {
connect
} = ReactRedux;
const {
Link,
Match,
Miss,
Redirect
} = ReactRouter;
2016-12-14 00:09:04 +02:00
const Org = ({
2016-12-15 16:10:36 +02:00
org = {},
params = {},
user = {}
2016-12-14 00:09:04 +02:00
}) => {
2016-12-15 16:10:36 +02:00
if (user.id === params.org) {
return null;
}
if (isEmpty(org)) {
return (
<NotFound />
);
}
2016-12-14 00:09:04 +02:00
return (
2016-12-15 16:10:36 +02:00
<div>
<H1>{org.name}</H1>
<Ul>
<Li>
<Link activeClassName='active' to={`/${org.id}/projects`}>
<FormattedMessage id='projects' />
</Link>
</Li>
<Li>
<Link activeClassName='active' to={`/${org.id}/people`}>
<FormattedMessage id='people' />
</Link>
</Li>
<Li>
<Link activeClassName='active' to={`/${org.id}/settings`}>
<FormattedMessage id='settings' />
</Link>
</Li>
</Ul>
<Match component={Projects} pattern='/:org/projects' />
<Match component={People} pattern='/:org/people' />
<Match component={Settings} pattern='/:org/settings' />
<Miss component={Redirect(`/${org.id}/projects`)} />
</div>
2016-12-14 00:09:04 +02:00
);
};
Org.propTypes = {
2016-12-15 16:10:36 +02:00
org: React.PropTypes.shape({
id: React.PropTypes.string,
name: React.PropTypes.string
}),
2016-12-14 00:09:04 +02:00
params: React.PropTypes.shape({
org: React.PropTypes.string
2016-12-15 16:10:36 +02:00
}),
user: React.PropTypes.shape({
id: React.PropTypes.string,
name: React.PropTypes.string
2016-12-14 00:09:04 +02:00
})
};
2016-12-15 16:10:36 +02:00
const mapStateToProps = (state, ownProps) => ({
org: state.session.data.orgs.filter((org) => {
return org.id === ownProps.params.org;
}).pop(),
user: {
id: state.session.data.name,
name: state.session.data.name
}
});
module.exports = connect(mapStateToProps)(Org);