2019-07-05 14:59:31 +02:00

67 lines
1.7 KiB
JavaScript

import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { Switch, Route } from 'react-router-dom';
import { LoadingIndicatorPage } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
import SettingViewModel from '../SettingViewModel';
import SettingViewGroup from '../SettingViewGroup';
import SettingsView from '../SettingsView';
import reducer from './reducer';
import saga from './saga';
import makeSelectMain from './selectors';
function Main({ isLoading, emitEvent }) {
strapi.useInjectReducer({ key: 'main', reducer, pluginId });
strapi.useInjectSaga({ key: 'main', saga, pluginId });
if (isLoading) {
return <LoadingIndicatorPage />;
}
const renderRoute = (props, Component) => (
<Component emitEvent={emitEvent} {...props} />
);
return (
<Switch>
<Route
path="/plugins/content-manager/ctm-configurations/models/:name/:settingType"
render={props => renderRoute(props, SettingViewModel)}
/>
<Route
path="/plugins/content-manager/ctm-configurations/groups/:name"
component={SettingViewGroup}
/>
<Route
path="/plugins/content-manager/ctm-configurations/:type"
render={props => renderRoute(props, SettingsView)}
/>
</Switch>
);
}
Main.propTypes = {
emitEvent: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
};
const mapStateToProps = makeSelectMain();
export function mapDispatchToProps(dispatch) {
return bindActionCreators({}, dispatch);
}
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(
withConnect,
memo
)(Main);