From 88f364473e0abe6166b2145dd34f399b0eb84882 Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Tue, 29 Oct 2019 16:52:37 +0300 Subject: [PATCH] Web: Client: added field admins and owner to redux, added new actions --- .../src/store/people/actions.js | 44 ++++++++++++++++-- .../src/store/people/reducer.js | 45 ++++++++++--------- 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/web/ASC.Web.Client/src/store/people/actions.js b/web/ASC.Web.Client/src/store/people/actions.js index 78a8f021bb..171829e65f 100644 --- a/web/ASC.Web.Client/src/store/people/actions.js +++ b/web/ASC.Web.Client/src/store/people/actions.js @@ -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))); + }; +} \ No newline at end of file diff --git a/web/ASC.Web.Client/src/store/people/reducer.js b/web/ASC.Web.Client/src/store/people/reducer.js index a088ba4cfa..9f71e7409d 100644 --- a/web/ASC.Web.Client/src/store/people/reducer.js +++ b/web/ASC.Web.Client/src/store/people/reducer.js @@ -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; \ No newline at end of file +export default peopleReducer;