This commit is contained in:
Ahmed Bouhuolia
2020-03-16 00:06:15 +02:00
parent 56701951b7
commit 73711384f6
7925 changed files with 18478 additions and 959 deletions

View 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`);
}

View 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];
};

View File

@@ -0,0 +1,5 @@
export default {
USERS_LIST_SET: 'USERS_LIST_SET',
USER_DETAILS_SET: 'USER_DETAILS_SET',
};