diff --git a/src/components/home/HomePage.js b/src/components/home/HomePage.js index 76fc462..8068034 100644 --- a/src/components/home/HomePage.js +++ b/src/components/home/HomePage.js @@ -1,14 +1,41 @@ import React from "react"; import { Link } from "react-router-dom"; +import { connect } from "react-redux"; +import { bindActionCreators } from "redux"; +import { loadSystemDateTime } from "../../features/system/actionCreators"; -const HomePage = () => ( -
-

Pluralsight Administration

-

React, Redux and React Router for ultra-responsive web apps.

- - Learn more - -
-); +const HomePage = ({ actions }) => { + const testButton = () => { + actions.loadSystemDateTime(); + }; -export default HomePage; + return ( +
+

Reverse proxy

+

React, Redux and React Router for ultra-responsive web apps.

+ + Learn more + + + +
+ ); +}; + +function mapStateToProps(state) { + return {}; +} + +function mapDispatchToProps(dispatch) { + return { + actions: bindActionCreators({ loadSystemDateTime }, dispatch) + }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(HomePage); diff --git a/src/features/system/actionCreators.js b/src/features/system/actionCreators.js new file mode 100644 index 0000000..5c4ce58 --- /dev/null +++ b/src/features/system/actionCreators.js @@ -0,0 +1,21 @@ +import * as types from "./actionTypes"; +import * as api from "./api"; +import { + beginApiCall, + apiCallError +} from "../../redux/actions/apiStatusActions"; + +export function loadSystemDateTime() { + return function (dispatch) { + dispatch(beginApiCall()); + return api + .getSystemDateTime() + .then((data) => { + dispatch({ type: types.LOAD_SYSTEM_DATETIME_SUCCESS, payload: data }); + }) + .catch((error) => { + dispatch(apiCallError(error)); + throw error; + }); + }; +} diff --git a/src/features/system/actionTypes.js b/src/features/system/actionTypes.js new file mode 100644 index 0000000..7f989a4 --- /dev/null +++ b/src/features/system/actionTypes.js @@ -0,0 +1 @@ +export const LOAD_SYSTEM_DATETIME_SUCCESS = "LOAD_SYSTEM_DATETIME_SUCCESS"; diff --git a/src/api/systemApi.js b/src/features/system/api.js similarity index 73% rename from src/api/systemApi.js rename to src/features/system/api.js index da56954..0f31ead 100644 --- a/src/api/systemApi.js +++ b/src/features/system/api.js @@ -1,4 +1,4 @@ -import { handleResponse, handleError } from "./apiUtils"; +import { handleResponse, handleError } from "../../api/apiUtils"; const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system"; export function getSystemDateTime() { diff --git a/src/features/system/reducer.js b/src/features/system/reducer.js new file mode 100644 index 0000000..899a8a4 --- /dev/null +++ b/src/features/system/reducer.js @@ -0,0 +1,15 @@ +import * as types from "./actionTypes"; +import initialState from "../../redux/reducers/initialState"; + +export default function systemReducer(state = initialState.system, action) { + switch (action.type) { + case types.LOAD_SYSTEM_DATETIME_SUCCESS: + return { + ...state, + datetime: action.payload + }; + + default: + return state; + } +} diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js index beef339..070debc 100644 --- a/src/redux/reducers/index.js +++ b/src/redux/reducers/index.js @@ -2,8 +2,10 @@ import { combineReducers } from "redux"; import courseReducer from "./courseReducer"; import authorReducer from "./authorReducer"; import apiStatusReducer from "./apiStatusReducer"; +import systemReducer from "../../features/system/reducer"; const rootReducer = combineReducers({ + system: systemReducer, courses: courseReducer, authors: authorReducer, apiCallsInProgress: apiStatusReducer diff --git a/src/redux/reducers/initialState.js b/src/redux/reducers/initialState.js index 5ca860a..c6baead 100644 --- a/src/redux/reducers/initialState.js +++ b/src/redux/reducers/initialState.js @@ -1,4 +1,5 @@ export default { + system: {}, courses: [], authors: [], apiCallsInProgress: 0