From 67791ffe3e71895303523f8322d30129d634817a Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 6 May 2020 16:29:52 +0300 Subject: [PATCH] loadSystemVersion --- src/components/home/HomePage.js | 11 +++++++++-- src/features/system/actionCreators.js | 13 +++++++++++++ src/features/system/actionTypes.js | 1 + src/features/system/api.js | 6 +++++- src/features/system/reducer.js | 6 ++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/components/home/HomePage.js b/src/components/home/HomePage.js index 8068034..d9e7fc9 100644 --- a/src/components/home/HomePage.js +++ b/src/components/home/HomePage.js @@ -2,11 +2,15 @@ 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"; +import { + loadSystemDateTime, + loadSystemVersion +} from "../../features/system/actionCreators"; const HomePage = ({ actions }) => { const testButton = () => { actions.loadSystemDateTime(); + actions.loadSystemVersion(); }; return ( @@ -34,7 +38,10 @@ function mapStateToProps(state) { function mapDispatchToProps(dispatch) { return { - actions: bindActionCreators({ loadSystemDateTime }, dispatch) + actions: bindActionCreators( + { loadSystemDateTime, loadSystemVersion }, + dispatch + ) }; } diff --git a/src/features/system/actionCreators.js b/src/features/system/actionCreators.js index bb2e779..60958b1 100644 --- a/src/features/system/actionCreators.js +++ b/src/features/system/actionCreators.js @@ -17,3 +17,16 @@ export function loadSystemDateTime() { } }; } + +export function loadSystemVersion() { + return async function (dispatch) { + dispatch(beginApiCall()); + try { + const data = await api.getSystemVersion(); + dispatch({ type: types.LOAD_SYSTEM_VERSION_SUCCESS, payload: data }); + } catch (error) { + dispatch(apiCallError(error)); + throw error; + } + }; +} diff --git a/src/features/system/actionTypes.js b/src/features/system/actionTypes.js index 7f989a4..c422e2f 100644 --- a/src/features/system/actionTypes.js +++ b/src/features/system/actionTypes.js @@ -1 +1,2 @@ export const LOAD_SYSTEM_DATETIME_SUCCESS = "LOAD_SYSTEM_DATETIME_SUCCESS"; +export const LOAD_SYSTEM_VERSION_SUCCESS = "LOAD_SYSTEM_VERSION_SUCCESS"; diff --git a/src/features/system/api.js b/src/features/system/api.js index 4f939ac..3a6ea31 100644 --- a/src/features/system/api.js +++ b/src/features/system/api.js @@ -4,6 +4,10 @@ const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system"; const getSystemDateTime = () => fetch(`${baseUrl}/datetime`).then(handleResponse).catch(handleError); +const getSystemVersion = () => + fetch(`${baseUrl}/version`).then(handleResponse).catch(handleError); + export default { - getSystemDateTime + getSystemDateTime, + getSystemVersion }; diff --git a/src/features/system/reducer.js b/src/features/system/reducer.js index 899a8a4..5ff5409 100644 --- a/src/features/system/reducer.js +++ b/src/features/system/reducer.js @@ -9,6 +9,12 @@ export default function systemReducer(state = initialState.system, action) { datetime: action.payload }; + case types.LOAD_SYSTEM_VERSION_SUCCESS: + return { + ...state, + ...action.payload + }; + default: return state; }