#94 added UserReducer setup on fetch users all fields

parent 6516920b
...@@ -37,6 +37,7 @@ const ProfileBlock = () => { ...@@ -37,6 +37,7 @@ const ProfileBlock = () => {
> >
<MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem> <MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={()=>{logout()}}>Поменять юзера</MenuItem>
<MenuItem onClick={()=>{logout()}}>Logout</MenuItem> <MenuItem onClick={()=>{logout()}}>Logout</MenuItem>
</Menu> </Menu>
</> </>
......
...@@ -11,3 +11,7 @@ export const LOGOUT_USER_FAILURE = "LOGOUT_USER_FAILURE"; ...@@ -11,3 +11,7 @@ export const LOGOUT_USER_FAILURE = "LOGOUT_USER_FAILURE";
export const FETCH_USERS_REQUEST = "FETCH_USERS_REQUEST"; export const FETCH_USERS_REQUEST = "FETCH_USERS_REQUEST";
export const FETCH_USERS_SUCCESS = "FETCH_USERS_SUCCESS"; export const FETCH_USERS_SUCCESS = "FETCH_USERS_SUCCESS";
export const FETCH_USERS_FAILURE = "FETCH_USERS_FAILURE"; export const FETCH_USERS_FAILURE = "FETCH_USERS_FAILURE";
export const FETCH_USERS_ALL_FIELDS_REQUEST = "FETCH_USERS_ALL_FIELDS_REQUEST";
export const FETCH_USERS_ALL_FIELDS_SUCCESS = "FETCH_USERS_ALL_FIELDS_SUCCESS";
export const FETCH_USERS_ALL_FIELDS_FAILURE = "FETCH_USERS_ALL_FIELDS_FAILURE";
\ No newline at end of file
import axios from "../../axiosPlanner"; import axios from "../../axiosPlanner";
import { FETCH_USERS_FAILURE, FETCH_USERS_REQUEST, FETCH_USERS_SUCCESS, LOGIN_USER_FAILURE, LOGIN_USER_SUCCESS, LOGOUT_USER_FAILURE, LOGOUT_USER_SUCCESS, REGISTER_USER_FAILURE, REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS } from "../actionTypes/userActionTypes" import { FETCH_USERS_FAILURE, FETCH_USERS_REQUEST, FETCH_USERS_SUCCESS, LOGIN_USER_FAILURE, LOGIN_USER_SUCCESS, LOGOUT_USER_FAILURE, LOGOUT_USER_SUCCESS, REGISTER_USER_FAILURE, REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS,FETCH_USERS_ALL_FIELDS_REQUEST,
FETCH_USERS_ALL_FIELDS_SUCCESS,
FETCH_USERS_ALL_FIELDS_FAILURE, } from "../actionTypes/userActionTypes"
import { showNotification } from "./commonActions"; import { showNotification } from "./commonActions";
const registerUserRequest = () => { const registerUserRequest = () => {
...@@ -24,6 +26,16 @@ const fetchUsersFailure = () => { ...@@ -24,6 +26,16 @@ const fetchUsersFailure = () => {
return {type: FETCH_USERS_FAILURE} return {type: FETCH_USERS_FAILURE}
}; };
const fetchUsersAllFieldsRequest = () => {
return {type: FETCH_USERS_ALL_FIELDS_REQUEST}
};
const fetchUsersAllFieldsSuccess = (users) => {
return {type: FETCH_USERS_ALL_FIELDS_SUCCESS, users}
};
const fetchUsersAllFieldsFailure = () => {
return {type: FETCH_USERS_ALL_FIELDS_FAILURE}
};
export const registerUser = (userData, navigate) => { export const registerUser = (userData, navigate) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(registerUserRequest()); dispatch(registerUserRequest());
...@@ -110,3 +122,17 @@ export const fetchUsers = () => { ...@@ -110,3 +122,17 @@ export const fetchUsers = () => {
} }
} }
}; };
export const fetchUsersAllFields = () => {
return async dispatch => {
dispatch(fetchUsersAllFieldsRequest());
try {
const response = await axios.get("/users/all-fields/");
dispatch(fetchUsersAllFieldsSuccess(response.data.users));
console.log("users/all-fields/ ",response.data.users)
} catch (e) {
dispatch(fetchUsersAllFieldsFailure(e));
}
}
};
\ No newline at end of file
import { REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS, REGISTER_USER_FAILURE, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE, LOGOUT_USER_SUCCESS, FETCH_USERS_SUCCESS } from "../actionTypes/userActionTypes"; import { REGISTER_USER_REQUEST, REGISTER_USER_SUCCESS, REGISTER_USER_FAILURE, LOGIN_USER_SUCCESS, LOGIN_USER_FAILURE, LOGOUT_USER_SUCCESS, FETCH_USERS_SUCCESS,FETCH_USERS_ALL_FIELDS_SUCCESS } from "../actionTypes/userActionTypes";
const initialState = { const initialState = {
user: null, user: null,
users: [], users: [],
usersAllFields:[],
registerError: null, registerError: null,
loginError: null, loginError: null,
loading: false loading: false
...@@ -27,6 +28,8 @@ const usersReducer = (state = initialState, action) => { ...@@ -27,6 +28,8 @@ const usersReducer = (state = initialState, action) => {
return {...state, user: null}; return {...state, user: null};
case FETCH_USERS_SUCCESS: case FETCH_USERS_SUCCESS:
return {...state, loading: false, users: action.users}; return {...state, loading: false, users: action.users};
case FETCH_USERS_ALL_FIELDS_SUCCESS:
return {...state, loading: false, usersAllFields: action.users};
default: default:
return state; return state;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment