mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix bugs in items form.
This commit is contained in:
@@ -10,8 +10,14 @@ export const editItem = ({ id, form }) => {
|
||||
};
|
||||
|
||||
export const fetchItems = ({ query }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`items`).then(response => {
|
||||
return (dispatch, getState) => new Promise((resolve, reject) => {
|
||||
const pageQuery = getState().accounts.tableQuery;
|
||||
|
||||
dispatch({
|
||||
type: t.ITEMS_TABLE_LOADING,
|
||||
payload: { loading: true },
|
||||
});
|
||||
ApiService.get(`items`, { params: { ...pageQuery, ...query } }).then(response => {
|
||||
dispatch({
|
||||
type: t.ITEMS_SET,
|
||||
items: response.data.items.results,
|
||||
@@ -22,6 +28,10 @@ export const fetchItems = ({ query }) => {
|
||||
customViewId: response.data.customViewId,
|
||||
paginationMeta: response.data.items.pagination,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ITEMS_TABLE_LOADING,
|
||||
payload: { loading: false },
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createReducer } from '@reduxjs/toolkit';
|
||||
import {
|
||||
getItemsViewPages,
|
||||
} from 'store/items/items.selectors';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
@@ -10,10 +11,12 @@ const initialState = {
|
||||
itemsRelation: {},
|
||||
currentPage: 1,
|
||||
currentViewId: -1,
|
||||
tableQuery: {},
|
||||
bulkActions: {},
|
||||
loading: false,
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
const itemsReducer = createReducer(initialState, {
|
||||
[t.ITEMS_SET]: (state, action) => {
|
||||
const _items = {};
|
||||
|
||||
@@ -83,10 +86,16 @@ export default createReducer(initialState, {
|
||||
delete state.items[itemId];
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
[t.ITEMS_TABLE_LOADING]: (state, action) => {
|
||||
const { loading } = action.payload;
|
||||
state.loading = !!loading;
|
||||
},
|
||||
});
|
||||
|
||||
export default createTableQueryReducers('items', itemsReducer);
|
||||
|
||||
export const getItemById = (state, id) => {
|
||||
return state.items.items[id];
|
||||
};
|
||||
|
||||
@@ -6,4 +6,9 @@ export default {
|
||||
ITEM_DELETE: 'ITEM_DELETE',
|
||||
ITEM_BULK_ACTION_ADD: 'ITEM_BULK_ACTION_ADD',
|
||||
ITEM_BULK_ACTION_REMOVE: 'ITEM_BULK_ACTION_REMOVE',
|
||||
|
||||
ITEMS_TABLE_QUERY_SET: 'ITEMS_TABLE_QUERY_SET',
|
||||
ITEMS_TABLE_QUERIES_ADD: 'ITEMS_TABLE_QUERIES_ADD',
|
||||
|
||||
ITEMS_TABLE_LOADING: 'ITEMS_TABLE_LOADING',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user