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');
|
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const selectors = require('@state/selectors');
|
|
|
|
|
2016-12-15 16:10:36 +02:00
|
|
|
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');
|
2016-12-16 14:28:27 +02:00
|
|
|
const Redirect = require('@components/redirect');
|
2016-12-15 16:10:36 +02:00
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const SectionComponents = {
|
|
|
|
people: require('./people'),
|
|
|
|
projects: require('./projects'),
|
|
|
|
settings: require('./settings'),
|
|
|
|
};
|
2016-12-15 16:10:36 +02:00
|
|
|
|
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,
|
2016-12-16 14:28:27 +02:00
|
|
|
Miss
|
2016-12-15 16:10:36 +02:00
|
|
|
} = ReactRouter;
|
2016-12-14 00:09:04 +02:00
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const {
|
|
|
|
orgByIdSelector,
|
|
|
|
orgSectionsSelector
|
|
|
|
} = selectors;
|
|
|
|
|
2016-12-14 00:09:04 +02:00
|
|
|
const Org = ({
|
2016-12-15 16:10:36 +02:00
|
|
|
org = {},
|
2016-12-16 14:28:27 +02:00
|
|
|
sections = []
|
2016-12-14 00:09:04 +02:00
|
|
|
}) => {
|
2016-12-15 16:10:36 +02:00
|
|
|
if (isEmpty(org)) {
|
|
|
|
return (
|
|
|
|
<NotFound />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:28:27 +02:00
|
|
|
const navLinks = sections.map((name) => (
|
|
|
|
<Li key={name}>
|
|
|
|
<Link activeClassName='active' to={`/${org.id}/${name}`}>
|
|
|
|
<FormattedMessage id={name} />
|
|
|
|
</Link>
|
|
|
|
</Li>
|
|
|
|
));
|
|
|
|
|
|
|
|
const navMatches = sections.map((name) => (
|
|
|
|
<Match
|
|
|
|
component={SectionComponents[name]}
|
|
|
|
key={name}
|
|
|
|
pattern={`/:org/${name}`}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
const missMatch = !sections.length ? null : (
|
|
|
|
<Miss component={Redirect(`/${org.id}/${sections[0]}`)} />
|
|
|
|
);
|
|
|
|
|
2016-12-14 00:09:04 +02:00
|
|
|
return (
|
2016-12-15 16:10:36 +02:00
|
|
|
<div>
|
|
|
|
<H1>{org.name}</H1>
|
|
|
|
<Ul>
|
2016-12-16 14:28:27 +02:00
|
|
|
{navLinks}
|
2016-12-15 16:10:36 +02:00
|
|
|
</Ul>
|
2016-12-16 14:28:27 +02:00
|
|
|
{navMatches}
|
|
|
|
{missMatch}
|
2016-12-15 16:10:36 +02:00
|
|
|
</div>
|
2016-12-14 00:09:04 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Org.propTypes = {
|
2016-12-15 16:10:36 +02:00
|
|
|
org: React.PropTypes.shape({
|
2016-12-16 14:28:27 +02:00
|
|
|
owner: React.PropTypes.string,
|
|
|
|
uuid: React.PropTypes.string,
|
2016-12-15 16:10:36 +02:00
|
|
|
id: React.PropTypes.string,
|
|
|
|
name: React.PropTypes.string
|
|
|
|
}),
|
2016-12-16 14:28:27 +02:00
|
|
|
sections: React.PropTypes.arrayOf(
|
|
|
|
React.PropTypes.string
|
|
|
|
)
|
2016-12-14 00:09:04 +02:00
|
|
|
};
|
|
|
|
|
2016-12-15 16:10:36 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
2016-12-16 14:28:27 +02:00
|
|
|
org: orgByIdSelector(ownProps.params.org)(state),
|
|
|
|
sections: orgSectionsSelector(ownProps.params.org)(state)
|
2016-12-15 16:10:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps)(Org);
|