mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
WIP / Feature & Fix Expense /Customer
This commit is contained in:
@@ -2,93 +2,101 @@ import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const submitItem = ({ form }) => {
|
||||
return dispatch => ApiService.post(`items`, form);
|
||||
return (dispatch) => ApiService.post(`items`, form);
|
||||
};
|
||||
|
||||
export const editItem = ({ id, form }) => {
|
||||
return dispatch => ApiService.post(`items/${id}`, form);
|
||||
return (dispatch) => ApiService.post(`items/${id}`, form);
|
||||
};
|
||||
|
||||
export const fetchItems = ({ query }) => {
|
||||
return (dispatch, getState) => new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().items.tableQuery;
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().items.tableQuery;
|
||||
|
||||
dispatch({
|
||||
type: t.ITEMS_TABLE_LOADING,
|
||||
payload: { loading: true },
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
ApiService.get(`items`, { params: { ...pageQuery, ...query } }).then(response => {
|
||||
dispatch({
|
||||
type: t.ITEMS_SET,
|
||||
items: response.data.items.results,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ITEMS_PAGE_SET,
|
||||
items: response.data.items.results,
|
||||
customViewId: response.data.customViewId,
|
||||
paginationMeta: response.data.items.pagination,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ITEMS_TABLE_LOADING,
|
||||
payload: { loading: false },
|
||||
payload: { loading: true },
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
reject(error);
|
||||
ApiService.get(`items`, { params: { ...pageQuery, ...query } })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.ITEMS_SET,
|
||||
items: response.data.items.results,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ITEMS_PAGE_SET,
|
||||
items: response.data.items.results,
|
||||
customViewId: response.data.customViewId,
|
||||
paginationMeta: response.data.items.pagination,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ITEMS_TABLE_LOADING,
|
||||
payload: { loading: false },
|
||||
});
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch({
|
||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||
});
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchItem = ({ id }) => {
|
||||
return dispatch =>
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get(`items/${id}`)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.ITEM_SET,
|
||||
item: response.data.item
|
||||
item: response.data.item,
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteItem = ({ id }) => {
|
||||
return dispatch => new Promise((resolve, reject) => {
|
||||
ApiService.delete(`items/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.ITEM_DELETE,
|
||||
payload: { 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);
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => { reject(error); });
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const deleteBulkItems = ({ ids }) => {
|
||||
return dispatch => new Promise((resolve, reject) => {
|
||||
ApiService.delete(`items`, { params: { ids }}).then((response) => {
|
||||
dispatch({
|
||||
type: t.ITEMS_BULK_DELETE,
|
||||
payload: { ids }
|
||||
});
|
||||
resolve(response);
|
||||
}).catch((error) => {
|
||||
reject(error);
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.delete('items', { params: { ids } })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.ITEMS_BULK_DELETE,
|
||||
payload: { ids },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import {
|
||||
getItemsViewPages,
|
||||
} from 'store/items/items.selectors';
|
||||
import { getItemsViewPages } from 'store/items/items.selectors';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
|
||||
const initialState = {
|
||||
@@ -20,7 +18,7 @@ const itemsReducer = createReducer(initialState, {
|
||||
[t.ITEMS_SET]: (state, action) => {
|
||||
const _items = {};
|
||||
|
||||
action.items.forEach(item => {
|
||||
action.items.forEach((item) => {
|
||||
_items[item.id] = item;
|
||||
});
|
||||
state.items = {
|
||||
@@ -43,11 +41,11 @@ const itemsReducer = createReducer(initialState, {
|
||||
if (typeof itemRelation === 'undefined') {
|
||||
state.itemsRelation[item.id] = [];
|
||||
}
|
||||
const filteredRelation = state.itemsRelation[item.id]
|
||||
.filter((relation) => (
|
||||
const filteredRelation = state.itemsRelation[item.id].filter(
|
||||
(relation) =>
|
||||
relation.viewId === viewId &&
|
||||
relation.pageNumber === paginationMeta.page
|
||||
));
|
||||
relation.pageNumber === paginationMeta.page,
|
||||
);
|
||||
|
||||
filteredRelation.push({
|
||||
viewId,
|
||||
@@ -61,10 +59,10 @@ const itemsReducer = createReducer(initialState, {
|
||||
pages: {
|
||||
...viewPages,
|
||||
[paginationMeta.page]: {
|
||||
ids: items.map(i => i.id),
|
||||
ids: items.map((i) => i.id),
|
||||
meta: paginationMeta,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -93,9 +91,21 @@ const itemsReducer = createReducer(initialState, {
|
||||
state.loading = !!loading;
|
||||
},
|
||||
|
||||
[t.ITEMS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
[t.ITEMS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
state.currentViewId = action.currentViewId;
|
||||
},
|
||||
|
||||
[t.ITEMS_BULK_DELETE]: (state, action) => {
|
||||
const { ids } = action.payload;
|
||||
const items = { ...state.items };
|
||||
|
||||
ids.forEach((id) => {
|
||||
if (typeof items[id] !== 'undefined') {
|
||||
delete items[id];
|
||||
}
|
||||
});
|
||||
state.items = items;
|
||||
},
|
||||
});
|
||||
|
||||
export default createTableQueryReducers('items', itemsReducer);
|
||||
|
||||
Reference in New Issue
Block a user