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

View File

@@ -1,5 +1,12 @@
import t from 'store/types';
export function dashboardPageTitle(pageTitle) {
return {
type: t.CHANGE_DASHBOARD_PAGE_TITLE,
pageTitle,
};
}
export function openDialog(name, payload) {
return {
type: t.OPEN_DIALOG,

View File

@@ -24,6 +24,8 @@ export const mapBalanceSheetToTableRows = (accounts) => {
});
};
export const profitLossToTableRowsMapper = () => {};
export const journalToTableRowsMapper = (journal) => {
const TYPES = {
ENTRY: 'ENTRY',
@@ -151,113 +153,3 @@ export const mapTrialBalanceSheetToRows = (sheet) => {
}
return results;
};
export const profitLossToTableRowsMapper = (profitLoss) => {
const results = [];
if (profitLoss.income) {
results.push({
name: 'Income',
total: profitLoss.income.total,
children: [
...profitLoss.income.accounts,
{
name: 'Total Income',
total: profitLoss.income.total,
total_periods: profitLoss.income.total_periods,
rowTypes: ['income_total', 'section_total', 'total'],
},
],
total_periods: profitLoss.income.total_periods,
});
}
if (profitLoss.cost_of_sales) {
results.push({
name: 'Cost of sales',
total: profitLoss.cost_of_sales.total,
children: [
...profitLoss.cost_of_sales.accounts,
{
name: 'Total cost of sales',
total: profitLoss.cost_of_sales.total,
total_periods: profitLoss.cost_of_sales.total_periods,
rowTypes: ['cogs_total', 'section_total', 'total'],
},
],
total_periods: profitLoss.cost_of_sales.total_periods,
});
}
if (profitLoss.gross_profit) {
results.push({
name: 'Gross profit',
total: profitLoss.gross_profit.total,
total_periods: profitLoss.gross_profit.total_periods,
rowTypes: ['gross_total', 'section_total', 'total'],
})
}
if (profitLoss.expenses) {
results.push({
name: 'Expenses',
total: profitLoss.expenses.total,
children: [
...profitLoss.expenses.accounts,
{
name: 'Total Expenses',
total: profitLoss.expenses.total,
total_periods: profitLoss.expenses.total_periods,
rowTypes: ['expenses_total', 'section_total', 'total'],
},
],
total_periods: profitLoss.expenses.total_periods,
})
}
if (profitLoss.operating_profit) {
results.push({
name: 'Net Operating income',
total: profitLoss.operating_profit.total,
total_periods: profitLoss.income.total_periods,
rowTypes: ['net_operating_total', 'section_total', 'total'],
})
}
if (profitLoss.other_income) {
results.push({
name: 'Other Income',
total: profitLoss.other_income.total,
total_periods: profitLoss.other_income.total_periods,
children: [
...profitLoss.other_income.accounts,
{
name: 'Total other income',
total: profitLoss.other_income.total,
total_periods: profitLoss.other_income.total_periods,
rowTypes: ['expenses_total', 'section_total', 'total'],
},
],
});
}
if (profitLoss.other_expenses) {
results.push({
name: 'Other expenses',
total: profitLoss.other_expenses.total,
total_periods: profitLoss.other_expenses.total_periods,
children: [
...profitLoss.other_expenses.accounts,
{
name: 'Total other expenses',
total: profitLoss.other_expenses.total,
total_periods: profitLoss.other_expenses.total_periods,
rowTypes: ['expenses_total', 'section_total', 'total'],
},
],
});
}
if (profitLoss.net_income) {
results.push({
name: 'Net Income',
total: profitLoss.net_income.total,
total_periods: profitLoss.net_income.total_periods,
rowTypes: ['net_income_total', 'section_total', 'total'],
})
};
return results;
};

View File

@@ -16,7 +16,11 @@ export const createTableQueryReducers =
};
case `${RESOURCE_NAME}/TABLE_QUERIES_ADD`:
return {
...state,
tableQuery: {
...state.tableQuery,
...action.payload.query,
}
};
default:
return reducer(state, action);