mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
refactoring: migrating to react-query to manage service-side state.
This commit is contained in:
@@ -75,12 +75,16 @@ export const fetchAccountsTable = ({ query } = {}) => {
|
||||
type: t.ACCOUNTS_ITEMS_SET,
|
||||
accounts: response.data.accounts,
|
||||
});
|
||||
dispatch({
|
||||
type: t.ACCOUNTS_SET_CURRENT_VIEW,
|
||||
currentViewId: parseInt(response.data?.filter_meta?.view?.custom_view_id, 10),
|
||||
});
|
||||
dispatch({
|
||||
type: t.ACCOUNTS_TABLE_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response);
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer} from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
import { listToTree } from 'utils';
|
||||
import {
|
||||
createTableQueryReducers,
|
||||
} from 'store/journalNumber.reducer';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
@@ -20,7 +22,7 @@ const initialState = {
|
||||
errors: [],
|
||||
};
|
||||
|
||||
const accountsReducer = createReducer(initialState, {
|
||||
export default createReducer(initialState, {
|
||||
[t.ACCOUNTS_ITEMS_SET]: (state, action) => {
|
||||
const _items = {};
|
||||
|
||||
@@ -107,10 +109,10 @@ const accountsReducer = createReducer(initialState, {
|
||||
[t.ACCOUNTS_SELECTED_ROWS_SET]: (state, action) => {
|
||||
const { selectedRows } = action.payload;
|
||||
state.selectedRows = selectedRows;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
export default createTableQueryReducers('accounts', accountsReducer);
|
||||
...createTableQueryReducers('ACCOUNTS'),
|
||||
});
|
||||
|
||||
export const getAccountById = (state, id) => {
|
||||
return state.accounts.accountsById[id];
|
||||
|
||||
@@ -20,7 +20,6 @@ export default {
|
||||
ACCOUNTS_TABLE_QUERIES_SET: 'ACCOUNTS/TABLE_QUERIES_SET',
|
||||
ACCOUNTS_TABLE_QUERIES_ADD:'ACCOUNTS/TABLE_QUERIES_ADD',
|
||||
|
||||
|
||||
ACCOUNTS_TABLE_LOADING: 'ACCOUNTS_TABLE_LOADING',
|
||||
|
||||
ACCOUNT_ERRORS_SET: 'ACCOUNT_ERRORS_SET',
|
||||
|
||||
Reference in New Issue
Block a user