Web: Client: added field admins and owner to redux, added new actions

This commit is contained in:
Nikita Gopienko 2019-10-29 16:52:37 +03:00
parent 7a8d7368d2
commit 88f364473e
2 changed files with 63 additions and 26 deletions

View File

@ -1,6 +1,8 @@
import * as api from "../services/api";
export const SET_USERS = "SET_USERS";
export const SET_ADMINS = "SET_ADMINS";
export const SET_OWNER = "SET_OWNER";
export function setUsers(users) {
return {
@ -9,9 +11,43 @@ export function setUsers(users) {
};
}
export function getAdminUsers() {
return dispatch => {
return api.getUserList()
.then(users => dispatch(setUsers(users)));
export function setAdmins(admins) {
return {
type: SET_ADMINS,
admins
};
}
export function setOwner(owner) {
return {
type: SET_OWNER,
owner
};
}
export function getListUsers() {
return dispatch => {
return api.getUserList().then(users => dispatch(setUsers(users)));
};
}
export function getListAdmins() {
return dispatch => {
return api.getUserList("admin").then(admins => dispatch(setAdmins(admins)));
};
}
export function changeAdmins(userId, productId, isAdmin) {
return dispatch => {
return api
.changeProductAdmin(userId, productId, isAdmin)
.then(() => dispatch(getListAdmins()));
};
}
export function getUserById(userId) {
return dispatch => {
return api.getUserById(userId)
.then(owner => dispatch(setOwner(owner)));
};
}

View File

@ -1,27 +1,28 @@
import { SET_USERS } from "./actions";
import { SET_USERS, SET_ADMINS, SET_OWNER } from "./actions";
const initialState = {
users: [],
//groups: [],
//selection: [],
//selected: "none",
//selectedGroup: null,
//filter: Filter.getDefault(),
//selector: {
// users: []
//}
};
users: [],
admins: [],
owner: {}
};
const peopleReducer = (state = initialState, action) => {
switch (action.type) {
switch (action.type) {
case SET_USERS:
return Object.assign({}, state, {
users: action.users
});
case SET_ADMINS:
return Object.assign({}, state, {
admins: action.admins
});
case SET_OWNER:
return Object.assign({}, state, {
owner: action.owner
});
default:
return state;
}
};
case SET_USERS:
return Object.assign({}, state, {
users: action.users
});
default:
return state;
}
};
export default peopleReducer;
export default peopleReducer;