mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
WIP
This commit is contained in:
46
client/src/store/users/users.actions.js
Normal file
46
client/src/store/users/users.actions.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import ApiService from "services/ApiService";
|
||||
import t from 'store/types';
|
||||
|
||||
export const fetchUsers = () => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`users`).then((response) => {
|
||||
dispatch({
|
||||
type: t.USERS_LIST_SET,
|
||||
users: response.data.users,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchUser = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`users/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.USER_DETAILS_SET,
|
||||
user: response.data.user,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteUser = ({ id }) => {
|
||||
return (dispatch) => ApiService.delete(`users/${id}`);
|
||||
};
|
||||
|
||||
export const submitUser = ({ form }) => {
|
||||
return (dispatch) => ApiService.post(`users`, form);
|
||||
};
|
||||
|
||||
export const editUser = ({ form, id }) => {
|
||||
return (dispatch) => ApiService.post(`users/${id}`, form);
|
||||
};
|
||||
|
||||
export const inactiveUser = ({ id }) => {
|
||||
return (dispatch) => ApiService.post(`users/${id}/inactive`);
|
||||
};
|
||||
|
||||
export const activeUser = ({ id }) => {
|
||||
return (dispatch) => ApiService.post(`users/${id}/active`);
|
||||
}
|
||||
26
client/src/store/users/users.reducer.js
Normal file
26
client/src/store/users/users.reducer.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createReducer } from "@reduxjs/toolkit";
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
list: {},
|
||||
userById: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.USERS_LIST_SET]: (state, action) => {
|
||||
state.list = action.users;
|
||||
},
|
||||
|
||||
[t.USER_DETAILS_SET]: (state, action) => {
|
||||
state.userById[action.user.id] = action.user;
|
||||
},
|
||||
})
|
||||
|
||||
/**
|
||||
* Retrieve the user details of the given user id,
|
||||
* @param {Object} state
|
||||
* @param {Numeric} id
|
||||
*/
|
||||
export const getUserDetails = (state, id) => {
|
||||
return state.users.userById[id];
|
||||
};
|
||||
5
client/src/store/users/users.types.js
Normal file
5
client/src/store/users/users.types.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
export default {
|
||||
USERS_LIST_SET: 'USERS_LIST_SET',
|
||||
USER_DETAILS_SET: 'USER_DETAILS_SET',
|
||||
};
|
||||
Reference in New Issue
Block a user