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
Sérgio Ramos 355c7d59d9 link service
2017-01-02 22:32:29 +00:00

72 lines
1.4 KiB
JavaScript

const isEmpty = require('lodash.isempty');
const React = require('react');
const ReactRedux = require('react-redux');
const ReactRouter = require('react-router');
const NotFound = require('@containers/not-found');
const PropTypes = require('@root/prop-types');
const Redirect = require('@components/redirect');
const selectors = require('@state/selectors');
const SectionComponents = {
people: require('./people'),
projects: require('./projects'),
settings: require('./settings'),
};
const {
connect
} = ReactRedux;
const {
Match,
Miss
} = ReactRouter;
const {
orgByIdSelector,
orgSectionsSelector
} = selectors;
const Org = ({
org = {},
sections = []
}) => {
if (isEmpty(org)) {
return (
<NotFound />
);
}
const missMatch = !sections.length ? null : (
<Miss component={Redirect(`/${org.id}/${sections[0]}`)} />
);
const navMatches = sections.map((name) => (
<Match
component={SectionComponents[name]}
key={name}
pattern={`/:org/${name}`}
/>
));
return (
<div>
{navMatches}
{missMatch}
</div>
);
};
Org.propTypes = {
org: PropTypes.org,
sections: PropTypes.sections
};
const mapStateToProps = (state, ownProps) => ({
org: orgByIdSelector(ownProps.params.org)(state),
sections: orgSectionsSelector(ownProps.params.org)(state)
});
module.exports = connect(mapStateToProps)(Org);