From f72784c3d68cf75f55df8e73df5d8466e2f3f0ca Mon Sep 17 00:00:00 2001 From: Lukas Brabec Date: Sep 10 2020 07:39:23 +0000 Subject: use redux in wizard --- diff --git a/src/actions/reduxActions.js b/src/actions/reduxActions.js index 4ba919e..80a3461 100644 --- a/src/actions/reduxActions.js +++ b/src/actions/reduxActions.js @@ -20,3 +20,24 @@ export const loadData = payload => dispatch => { console.error('Error:', error); }); } + +export const loadWizardDataResp = payload => ({ + type: ActionTypes.LOAD_WIZARD_DATA_RESP, + payload: payload +}) + +export const loadWizardData = payload => dispatch => { + dispatch({ + type: ActionTypes.LOAD_WIZARD_DATA, + payload: payload + }); + + fetch(window.env.ORACULUM_API_URL_v1 + "actions/all") + .then(blob => blob.json()) + .then(data => { + dispatch(loadWizardDataResp(data)) + }) + .catch((error) => { + console.error('Error:', error); + }); +} diff --git a/src/constants/index.js b/src/constants/index.js index 4b9068d..c6bfe99 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -1,4 +1,6 @@ export default { LOAD_DATA: 'LOAD_DATA', LOAD_DATA_RESP: 'LOAD_DATA_RESP', + LOAD_WIZARD_DATA: 'LOAD_WIZARD_DATA', + LOAD_WIZARD_DATA_RESP: 'LOAD_WIZARD_DATA_RESP', } diff --git a/src/reducers/index.js b/src/reducers/index.js index d8bee08..5e628e0 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,4 +1,4 @@ -import ActionTypes from '../constants'; +import ActionTypes from "../constants" const defaultState = { landing_page: { @@ -11,6 +11,11 @@ const defaultState = { config_mode: false, enabled_components: ["events", "blockers", "minutes"], }, + wizard: { + actions: [], + providers: [], + all_actions: [], + }, } export default (state = defaultState, action) => { @@ -18,7 +23,17 @@ export default (state = defaultState, action) => { case ActionTypes.LOAD_DATA_RESP: return { ...state, - landing_page: action.payload + landing_page: action.payload, + } + + case ActionTypes.LOAD_WIZARD_DATA_RESP: + return { + ...state, + wizard: { + ...state.wizard, + providers: action.payload.providers, + all_actions: action.payload.actions, + }, } default: diff --git a/src/wizard/Wizard.js b/src/wizard/Wizard.js index db947e9..a9ecb3e 100644 --- a/src/wizard/Wizard.js +++ b/src/wizard/Wizard.js @@ -5,13 +5,14 @@ import { oraculumApiUrl_v1 } from "../config" import Actions from "./Actions" import { Container, Row } from "reactstrap" +import { connect } from "react-redux" +import { loadWizardData } from "../actions/reduxActions" + class Wizard extends Component { constructor(props) { super(props) this.state = { actions: [], - providers: [], - all_actions: [], } } @@ -24,6 +25,8 @@ class Wizard extends Component { all_actions: data.actions, }) }) + + this.props.dispatch(loadWizardData()) } show_actions(actions) { @@ -36,10 +39,9 @@ class Wizard extends Component {

Nothing sparked joy?

@@ -60,4 +62,10 @@ class Wizard extends Component { } } -export default Wizard +const mapStateToProps = (state) => { + return { + ...state.wizard, + } +} + +export default connect(mapStateToProps)(Wizard)