- feat: Highlight inactive accounts in data-table.

- feat: Separate accounts list and table order.
This commit is contained in:
Ahmed Bouhuolia
2020-07-04 15:30:24 +02:00
parent 273834b13e
commit 3fc390652d
13 changed files with 116 additions and 49 deletions

View File

@@ -19,32 +19,29 @@ export const fetchAccountTypes = () => {
});
};
export const fetchAccountsList = ({ query } = {}) => {
export const fetchAccountsList = () => {
return (dispatch) =>
new Promise((resolve, reject) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
const query = { column_sort_by: 'name', sort_order: 'asc' };
ApiService.get('accounts', { params: query })
.then((response) => {
dispatch({
type: t.ACCOUNTS_PAGE_SET,
accounts: response.data.accounts,
customViewId: response.data.customViewId,
});
dispatch({
type: t.ACCOUNTS_ITEMS_SET,
accounts: response.data.accounts,
});
dispatch({
type: t.ACCOUNTS_LIST_SET,
payload: {
accounts: response.data.accounts,
}
})
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
resolve(response);
})
.catch((error) => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
reject(error);
});
});

View File

@@ -5,6 +5,7 @@ import { createTableQueryReducers } from 'store/queryReducers';
const initialState = {
items: {},
views: {},
list: [],
accountsTypes: [],
accountsById: {},
tableQuery: {
@@ -40,6 +41,11 @@ const accountsReducer = createReducer(initialState, {
};
},
[t.ACCOUNTS_LIST_SET]: (state, action) => {
const { accounts } = action.payload;
state.list = accounts.map(account => account.id);
},
[t.ACCOUNT_TYPES_LIST_SET]: (state, action) => {
state.accountsTypes = action.account_types;
},

View File

@@ -6,6 +6,9 @@ const accountsDataSelector = (state) => state.accounts.items;
const accountsCurrentViewSelector = (state) => state.accounts.currentViewId;
const accountIdPropSelector = (state, props) => props.accountId;
const accountsListSelector = state => state.accounts.list;
export const getAccountsItems = createSelector(
accountsViewsSelector,
accountsDataSelector,
@@ -19,6 +22,14 @@ export const getAccountsItems = createSelector(
},
);
export const getAccountsListFactory = () => createSelector(
accountsListSelector,
accountsDataSelector,
(accounts, accountsItems) => {
return pickItemsFromIds(accountsItems, accounts);
},
)
export const getAccountById = createSelector(
accountsDataSelector,
accountIdPropSelector,

View File

@@ -3,6 +3,7 @@
export default {
ACCOUNT_TYPES_LIST_SET: 'ACCOUNT_TYPES_LIST_SET',
ACCOUNTS_PAGE_SET: 'ACCOUNTS_PAGE_SET',
ACCOUNTS_LIST_SET: 'ACCOUNTS_LIST_SET',
ACCOUNTS_ITEMS_SET: 'ACCOUNTS_ITEMS_SET',
ACCOUNT_SET: 'ACCOUNT_SET',
ACCOUNT_DELETE: 'ACCOUNT_DELETE',