mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { getExpensesCurrentPageFactory } from 'store/users/users.selectors';
|
||||||
|
|
||||||
export default (mapState) => {
|
export default (mapState) => {
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
const mapped = {
|
const mapped = {
|
||||||
usersList: state.users.list,
|
usersList: getExpensesCurrentPageFactory(state, props),
|
||||||
usersLoading: state.users.loading,
|
usersLoading: state.users.loading,
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ export const fetchUsers = () => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.USERS_LIST_SET,
|
type: t.USERS_LIST_SET,
|
||||||
users: response.data.users,
|
payload: {
|
||||||
|
users: response.data.users,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.USERS_TABLE_LOADING,
|
type: t.USERS_TABLE_LOADING,
|
||||||
@@ -34,7 +36,10 @@ export const fetchUser = ({ id }) => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.USER_DETAILS_SET,
|
type: t.USER_DETAILS_SET,
|
||||||
user: response.data.user,
|
payload: {
|
||||||
|
id,
|
||||||
|
user: response.data.user,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
@@ -45,24 +50,49 @@ export const fetchUser = ({ id }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const deleteUser = ({ id }) => {
|
export const deleteUser = ({ id }) => {
|
||||||
return (dispatch) => ApiService.delete(`users/${id}`);
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.delete(`users/${id}`)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({ type: t.USER_DELETE, id });
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error.response.data.errors || []);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const submitInvite = ({ form }) => {
|
export const submitInvite = ({ form }) => {
|
||||||
return (dispatch) => new Promise((resolve, reject) => {
|
return (dispatch) =>
|
||||||
ApiService.post(`invite/send`, form)
|
new Promise((resolve, reject) => {
|
||||||
.then((response) => { resolve(response); })
|
ApiService.post(`invite/send`, form)
|
||||||
.catch((error) => {
|
.then((response) => {
|
||||||
const { response } = error;
|
resolve(response);
|
||||||
const { data } = response;
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
|
||||||
reject(data?.errors);
|
reject(data?.errors);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editUser = ({ form, id }) => {
|
export const editUser = ({ form, id }) => {
|
||||||
return (dispatch) => ApiService.post(`users/${id}`, form);
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.post(`users/${id}`, form)
|
||||||
|
.then((response) => {
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
|
||||||
|
reject(data?.errors);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const inactiveUser = ({ id }) => {
|
export const inactiveUser = ({ id }) => {
|
||||||
|
|||||||
@@ -1,25 +1,41 @@
|
|||||||
import { createReducer } from '@reduxjs/toolkit';
|
import { createReducer } from '@reduxjs/toolkit';
|
||||||
|
import { createTableQueryReducers } from 'store/queryReducers';
|
||||||
import t from 'store/types';
|
import t from 'store/types';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
list: {},
|
items: {},
|
||||||
userById: {},
|
userById: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(initialState, {
|
export default createReducer(initialState, {
|
||||||
[t.USERS_LIST_SET]: (state, action) => {
|
[t.USERS_LIST_SET]: (state, action) => {
|
||||||
state.list = action.users;
|
const { users } = action.payload;
|
||||||
|
const _users = {};
|
||||||
|
|
||||||
|
users.forEach((user) => {
|
||||||
|
_users[user.id] = {
|
||||||
|
...user,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
state.items = {
|
||||||
|
...state.items,
|
||||||
|
..._users,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
[t.USER_DETAILS_SET]: (state, action) => {
|
[t.USER_DETAILS_SET]: (state, action) => {
|
||||||
state.userById[action.user.id] = action.user;
|
const { id, user } = action.payload;
|
||||||
|
const _user = state.items[id] || {};
|
||||||
|
state.items[id] = { ..._user, ...user };
|
||||||
},
|
},
|
||||||
|
|
||||||
[t.USERS_TABLE_LOADING]: (state, action) => {
|
[t.USERS_TABLE_LOADING]: (state, action) => {
|
||||||
const { loading } = action.payload;
|
const { loading } = action.payload;
|
||||||
state.loading = !!loading;
|
state.loading = loading;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
...createTableQueryReducers('USERS'),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
21
client/src/store/users/users.selectors.js
Normal file
21
client/src/store/users/users.selectors.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { pickItemsFromIds, getItemById } from 'store/selectors';
|
||||||
|
|
||||||
|
const usersItemsSelector = (state) => state.users.items;
|
||||||
|
const userIdPropSelector = (state, props) => props.userId;
|
||||||
|
|
||||||
|
export const getExpensesCurrentPageFactory = createSelector(
|
||||||
|
usersItemsSelector,
|
||||||
|
(users) => {
|
||||||
|
return Object.values(users);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
export const getUserByIdFactory = () => createSelector(
|
||||||
|
usersItemsSelector,
|
||||||
|
userIdPropSelector,
|
||||||
|
(users, userId) => {
|
||||||
|
return getItemById(users, userId);
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -2,4 +2,5 @@ export default {
|
|||||||
USERS_LIST_SET: 'USERS_LIST_SET',
|
USERS_LIST_SET: 'USERS_LIST_SET',
|
||||||
USERS_TABLE_LOADING: 'USERS_TABLE_LOADING',
|
USERS_TABLE_LOADING: 'USERS_TABLE_LOADING',
|
||||||
USER_DETAILS_SET: 'USER_DETAILS_SET',
|
USER_DETAILS_SET: 'USER_DETAILS_SET',
|
||||||
|
USER_DELETE: 'USER_DELETE',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user