reverse-proxy-frontend/src/features/system/components/SystemContainer.js

45 lines
1.1 KiB
JavaScript

import React, { useEffect } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import PropTypes from "prop-types";
import { loadSystemData } from "../actionCreators";
import SystemComponent from "./SystemComponent";
import { withRouter } from "react-router-dom";
const SystemContainer = ({ actions, data, history }) => {
useEffect(() => {
actions.loadSystemData();
}, []);
const handleRedirect = (route, callback) => event => {
history.push(route);
event.preventDefault();
callback && callback();
};
return <SystemComponent data={data} onRedirect={handleRedirect} />;
};
SystemContainer.propTypes = {
actions: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
};
function mapStateToProps(state) {
return {
data: state.system.data
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({ loadSystemData }, dispatch)
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(withRouter(SystemContainer));