refactoring: migrating to react-query to manage service-side state.

This commit is contained in:
a.bouhuolia
2021-02-07 08:10:21 +02:00
parent e093be0663
commit adac2386bb
284 changed files with 8255 additions and 6610 deletions

View File

@@ -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);

View File

@@ -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];

View File

@@ -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',