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

86 lines
1.6 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');
2016-12-15 16:10:36 +02:00
const ReactRedux = require('react-redux');
const ReactRouter = require('react-router-dom');
2016-12-15 16:10:36 +02:00
const NotFound = require('@containers/not-found');
2017-01-03 00:32:29 +02:00
const PropTypes = require('@root/prop-types');
const Redirect = require('@components/redirect');
2016-12-20 21:06:02 +02:00
const selectors = require('@state/selectors');
2016-12-15 16:10:36 +02:00
const NewProject = require('@containers/new-project');
const SectionComponents = {
people: require('./people'),
projects: require('./projects'),
settings: require('./settings'),
};
2016-12-15 16:10:36 +02:00
const {
connect
} = ReactRedux;
const {
2017-02-06 20:27:10 +02:00
Switch,
Route
2016-12-15 16:10:36 +02:00
} = ReactRouter;
2016-12-14 00:09:04 +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 = {},
sections = []
2016-12-14 00:09:04 +02:00
}) => {
2016-12-15 16:10:36 +02:00
if (isEmpty(org)) {
return (
<NotFound />
);
}
2016-12-20 21:06:02 +02:00
const missMatch = !sections.length ? null : (
2017-02-06 20:27:10 +02:00
<Route
component={Redirect(`/${org.id}/${sections[0]}`)}
exact
path={`/${org.id}`}
/>
2016-12-20 21:06:02 +02:00
);
const navMatches = sections.map((name) => (
2017-02-06 20:27:10 +02:00
<Route
component={SectionComponents[name]}
key={name}
2017-02-06 20:27:10 +02:00
path={`/:org/${name}`}
/>
));
navMatches.push(
2017-02-06 20:27:10 +02:00
<Route
component={NewProject}
key='new-project'
2017-02-06 20:27:10 +02:00
path={'/:org/new-project'}
/>
);
2016-12-14 00:09:04 +02:00
return (
2017-02-06 20:27:10 +02:00
<Switch>
{missMatch}
2017-02-06 20:27:10 +02:00
{navMatches}
</Switch>
2016-12-14 00:09:04 +02:00
);
};
Org.propTypes = {
2017-01-03 00:32:29 +02:00
org: PropTypes.org,
sections: PropTypes.sections
2016-12-14 00:09:04 +02:00
};
2016-12-15 16:10:36 +02:00
const mapStateToProps = (state, ownProps) => ({
2017-02-06 20:27:10 +02:00
org: orgByIdSelector(ownProps.match.params.org)(state),
sections: orgSectionsSelector(ownProps.match.params.org)(state)
2016-12-15 16:10:36 +02:00
});
module.exports = connect(mapStateToProps)(Org);