From e24b88eda4d50415c30a1d86fdc484edc169d48a Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Fri, 15 May 2020 01:15:40 +0300 Subject: [PATCH] loadActiveSession --- src/features/server/actionCreators.js | 11 +++++++++++ src/features/server/actionTypes.js | 1 + src/features/server/api.js | 10 ++++++---- src/features/server/components/ServerContainer.js | 9 +++++++-- src/features/server/reducer.js | 7 +++++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/features/server/actionCreators.js b/src/features/server/actionCreators.js index 479717c..81a33a6 100644 --- a/src/features/server/actionCreators.js +++ b/src/features/server/actionCreators.js @@ -23,3 +23,14 @@ export function loadSystemVersion() { } }; } + +export function loadActiveSession() { + return async function (dispatch) { + try { + const data = await dispatch(sendHttpRequest(api.getActiveSession())); + dispatch({ type: types.LOAD_ACTIVE_SESSION_SUCCESS, payload: data }); + } catch (error) { + throw error; + } + }; +} diff --git a/src/features/server/actionTypes.js b/src/features/server/actionTypes.js index c422e2f..0482151 100644 --- a/src/features/server/actionTypes.js +++ b/src/features/server/actionTypes.js @@ -1,2 +1,3 @@ export const LOAD_SYSTEM_DATETIME_SUCCESS = "LOAD_SYSTEM_DATETIME_SUCCESS"; export const LOAD_SYSTEM_VERSION_SUCCESS = "LOAD_SYSTEM_VERSION_SUCCESS"; +export const LOAD_ACTIVE_SESSION_SUCCESS = "LOAD_ACTIVE_SESSION_SUCCESS"; diff --git a/src/features/server/api.js b/src/features/server/api.js index 684b3ac..a015b24 100644 --- a/src/features/server/api.js +++ b/src/features/server/api.js @@ -1,10 +1,12 @@ import { get } from "../../api/axiosApi"; -const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system"; +const baseUrl = process.env.REVERSE_PROXY_API_URL; -const getSystemDateTime = () => get(`${baseUrl}/datetime`); -const getSystemVersion = () => get(`${baseUrl}/version`); +const getSystemDateTime = () => get(`${baseUrl}/system/datetime`); +const getSystemVersion = () => get(`${baseUrl}/system/version`); +const getActiveSession = () => get(`${baseUrl}/server/active-session`); export default { getSystemDateTime, - getSystemVersion + getSystemVersion, + getActiveSession }; diff --git a/src/features/server/components/ServerContainer.js b/src/features/server/components/ServerContainer.js index 047796c..7051525 100644 --- a/src/features/server/components/ServerContainer.js +++ b/src/features/server/components/ServerContainer.js @@ -2,7 +2,11 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import PropTypes from "prop-types"; -import { loadSystemDateTime, loadSystemVersion } from "../actionCreators"; +import { + loadSystemDateTime, + loadSystemVersion, + loadActiveSession +} from "../actionCreators"; import ServerComponent from "./ServerComponent"; import ActiveSessionComponent from "./ActiveSessionComponent"; @@ -10,6 +14,7 @@ const ServerContainer = ({ actions }) => { useEffect(() => { actions.loadSystemDateTime(); actions.loadSystemVersion(); + actions.loadActiveSession(); }, []); return ( @@ -36,7 +41,7 @@ function mapStateToProps(state) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators( - { loadSystemDateTime, loadSystemVersion }, + { loadSystemDateTime, loadSystemVersion, loadActiveSession }, dispatch ) }; diff --git a/src/features/server/reducer.js b/src/features/server/reducer.js index 00c88f2..90d14d5 100644 --- a/src/features/server/reducer.js +++ b/src/features/server/reducer.js @@ -14,6 +14,13 @@ export default function serverReducer(state = initialState.server, action) { ...state, ...action.payload }; + + case types.LOAD_ACTIVE_SESSION_SUCCESS: + return { + ...state, + activeSession: action.payload + }; + default: return state; }