Fix bugs.

This commit is contained in:
Ahmed Bouhuolia
2020-05-12 04:40:42 +02:00
parent 4ab85eaf09
commit 5ffb54992e
22 changed files with 221 additions and 115 deletions

View File

@@ -1,14 +0,0 @@
import ApiService from 'services/ApiService';
export const submitInvite = ({ form, token }) => {
return (dispatch) => {
return ApiService.post(`/invite/accept/${token}`, { ...form });
};
};
export const submitSendInvite = ({ form }) => {
return (dispatch) => {
return ApiService.post('invite', { form });
};
};

View File

@@ -7,7 +7,7 @@ export const submitItemCategory = ({ form }) => {
};
};
export const fetchItemCategories = () => {
export const fetchItemCategories = ({ query }) => {
return (dispatch, getState) => new Promise((resolve, reject) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
@@ -18,7 +18,7 @@ export const fetchItemCategories = () => {
loading: true,
}
});
ApiService.get('item_categories')
ApiService.get('item_categories', { params: { ...query } })
.then((response) => {
dispatch({
type: t.ITEMS_CATEGORY_LIST_SET,
@@ -70,7 +70,7 @@ export const deleteItemCategory = (id) => {
.then((response) => {
dispatch({
type: t.CATEGORY_DELETE,
id,
payload: { id },
});
resolve(response);
})

View File

@@ -24,8 +24,10 @@ export default createReducer(initialState, {
},
[t.CATEGORY_DELETE]: (state, action) => {
if (typeof state.categories[action.id] !== 'undefined') {
delete state.categories[action.id];
const { id } = action.payload;
if (typeof state.categories[id] !== 'undefined') {
delete state.categories[id];
}
},

View File

@@ -20,8 +20,12 @@ export default createReducer(initialState, {
},
[t.CATEGORY_DELETE]: (state, action) => {
if (typeof state.categories[action.id] !== 'undefined') {
delete state.categories[action.id];
const { id } = action.payload;
const categories = { ...state.categories };
if (typeof categories[id] !== 'undefined') {
delete categories[id];
state.categories = categories;
}
}
});

View File

@@ -65,5 +65,14 @@ export const fetchItem = ({ id }) => {
};
export const deleteItem = ({ id }) => {
return dispatch => ApiService.delete(`items/${id}`);
return dispatch => new Promise((resolve, reject) => {
ApiService.delete(`items/${id}`)
.then((response) => {
dispatch({
type: t.ITEM_DELETE,
payload: { id },
});
resolve(response);
}).catch((error) => { reject(error); });
});
};

View File

@@ -77,14 +77,14 @@ const itemsReducer = createReducer(initialState, {
},
[t.ITEM_DELETE]: (state, action) => {
const { itemId } = action;
const { id } = action.payload;
const items = { ...state.items };
if (state.items[itemId]) {
const item = state.items[itemId];
const itemPageNumber = item._page_number;
delete state.items[itemId];
if (items[id]) {
const item = items[id];
delete items[id];
state.items = items;
}
},