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 React from "react";
import { Link } from "react-router-dom"; 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 }) => {
<div className="jumbotron"> const testButton = () => {
<h1>Pluralsight Administration</h1> actions.loadSystemDateTime();
<p>React, Redux and React Router for ultra-responsive web apps.</p> };
<Link to="about" className="btn btn-primary btn-lg">
Learn more
</Link>
</div>
);
export default HomePage; return (
<div className="jumbotron">
<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>
);
};
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"; const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system";
export function getSystemDateTime() { 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 courseReducer from "./courseReducer";
import authorReducer from "./authorReducer"; import authorReducer from "./authorReducer";
import apiStatusReducer from "./apiStatusReducer"; import apiStatusReducer from "./apiStatusReducer";
import systemReducer from "../../features/system/reducer";
const rootReducer = combineReducers({ const rootReducer = combineReducers({
system: systemReducer,
courses: courseReducer, courses: courseReducer,
authors: authorReducer, authors: authorReducer,
apiCallsInProgress: apiStatusReducer apiCallsInProgress: apiStatusReducer

View File

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