73 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-07-04 11:32:51 +02:00
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';
2019-07-08 17:01:12 +02:00
import ListView from '../ListView';
2019-07-04 18:28:57 +02:00
import SettingViewModel from '../SettingViewModel';
import SettingViewGroup from '../SettingViewGroup';
2019-07-04 11:32:51 +02:00
import SettingsView from '../SettingsView';
import reducer from './reducer';
import saga from './saga';
import makeSelectMain from './selectors';
2019-07-08 17:01:12 +02:00
function Main({ isLoading, emitEvent, layouts }) {
2019-07-04 11:32:51 +02:00
strapi.useInjectReducer({ key: 'main', reducer, pluginId });
strapi.useInjectSaga({ key: 'main', saga, pluginId });
if (isLoading) {
return <LoadingIndicatorPage />;
}
2019-07-05 10:54:34 +02:00
const renderRoute = (props, Component) => (
2019-07-08 17:01:12 +02:00
<Component emitEvent={emitEvent} layouts={layouts} {...props} />
2019-07-04 13:08:31 +02:00
);
2019-07-04 11:32:51 +02:00
return (
<Switch>
2019-07-04 15:56:42 +02:00
<Route
2019-07-08 17:01:12 +02:00
path={`/plugins/${pluginId}/ctm-configurations/models/:name/:settingType`}
2019-07-05 14:59:31 +02:00
render={props => renderRoute(props, SettingViewModel)}
2019-07-04 18:28:57 +02:00
/>
<Route
2019-07-08 17:01:12 +02:00
path={`/plugins/${pluginId}/ctm-configurations/groups/:name`}
2019-07-04 18:28:57 +02:00
component={SettingViewGroup}
2019-07-04 15:56:42 +02:00
/>
2019-07-04 11:32:51 +02:00
<Route
2019-07-08 17:01:12 +02:00
path={`/plugins/${pluginId}/ctm-configurations/:type`}
2019-07-05 10:54:34 +02:00
render={props => renderRoute(props, SettingsView)}
2019-07-04 11:32:51 +02:00
/>
2019-07-08 17:01:12 +02:00
<Route
path={`/plugins/${pluginId}/:slug`}
render={props => renderRoute(props, ListView)}
/>
2019-07-04 11:32:51 +02:00
</Switch>
);
}
Main.propTypes = {
2019-07-04 13:08:31 +02:00
emitEvent: PropTypes.func.isRequired,
2019-07-04 11:32:51 +02:00
isLoading: PropTypes.bool.isRequired,
2019-07-08 17:01:12 +02:00
layouts: PropTypes.object.isRequired,
2019-07-04 11:32:51 +02:00
};
const mapStateToProps = makeSelectMain();
export function mapDispatchToProps(dispatch) {
return bindActionCreators({}, dispatch);
}
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(
withConnect,
memo
)(Main);