system data

master
Tudor Stanciu 2020-05-06 16:12:11 +03:00
parent c4e49c0262
commit 5b0de19ae4
7 changed files with 78 additions and 11 deletions

View File

@ -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 = () => (
const HomePage = ({ actions }) => {
const testButton = () => {
actions.loadSystemDateTime();
};
return (
<div className="jumbotron">
<h1>Pluralsight Administration</h1>
<h1>Reverse proxy</h1>
<p>React, Redux and React Router for ultra-responsive web apps.</p>
<Link to="about" className="btn btn-primary btn-lg">
Learn more
</Link>
<button
style={{ marginBottom: 20 }}
className="btn btn-primary add-course"
onClick={testButton}
>
Test
</button>
</div>
);
};
export default HomePage;
function mapStateToProps(state) {
return {};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({ loadSystemDateTime }, dispatch)
};
}
export default connect(mapStateToProps, mapDispatchToProps)(HomePage);

View File

@ -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;
});
};
}

View File

@ -0,0 +1 @@
export const LOAD_SYSTEM_DATETIME_SUCCESS = "LOAD_SYSTEM_DATETIME_SUCCESS";

View File

@ -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() {

View File

@ -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;
}
}

View File

@ -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

View File

@ -1,4 +1,5 @@
export default {
system: {},
courses: [],
authors: [],
apiCallsInProgress: 0