mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
- fix: store expense payment date with transactions. - fix: Total assets, liabilities and equity on balance sheet. - tweaks: dashboard content and sidebar style. - fix: reset form with contact list on journal entry form. - feat: Add hints to filter accounts in financial statements.
120 lines
2.9 KiB
JavaScript
120 lines
2.9 KiB
JavaScript
import { createReducer } from "@reduxjs/toolkit";
|
|
import { createSelector } from 'reselect';
|
|
import t from 'store/types';
|
|
import { pickItemsFromIds } from 'store/selectors'
|
|
|
|
const initialState = {
|
|
data: {},
|
|
fields: {},
|
|
columns: {},
|
|
resourceFields: {},
|
|
resourceColumns: {},
|
|
|
|
metadata: {
|
|
'accounts': {
|
|
label: 'Accounts',
|
|
baseRoute: '/accounts',
|
|
},
|
|
'items': {
|
|
label: 'Items',
|
|
baseRoute: '/items',
|
|
},
|
|
'manual_journals': {
|
|
label: 'Journals',
|
|
baseRoute: '/manual-journals',
|
|
}
|
|
}
|
|
};
|
|
|
|
export default createReducer(initialState, {
|
|
[t.RESOURCE_COLUMNS_SET]: (state, action) => {
|
|
const _columns = {};
|
|
|
|
action.columns.forEach((column) => {
|
|
_columns[column.id] = column;
|
|
});
|
|
state.columns = {
|
|
...state.columns,
|
|
..._columns,
|
|
};
|
|
state.resourceColumns[action.resource_slug] = action.columns.map(c => c.id);
|
|
},
|
|
|
|
[t.RESOURCE_FIELDS_SET]: (state, action) => {
|
|
const _fields = {};
|
|
|
|
action.fields.forEach((field) => {
|
|
_fields[field.id] = field;
|
|
});
|
|
state.fields = {
|
|
...state.fields,
|
|
..._fields,
|
|
};
|
|
state.resourceFields[action.resource_slug] = action.fields.map(f => f.id);
|
|
},
|
|
|
|
[t.RESOURCE_DATA_SET]: (state, action) => {
|
|
const { data, resource_key: resourceKey } = action.payload;
|
|
const dataMapped = {};
|
|
|
|
data.forEach((item) => { dataMapped[item.id] = item; })
|
|
state.data[resourceKey] = dataMapped;
|
|
},
|
|
});
|
|
|
|
|
|
const resourceFieldsIdsSelector = (state, props) => state.resources.resourceFields[props.resourceName];
|
|
const resourceFieldsItemsSelector = (state) => state.resources.fields;
|
|
|
|
/**
|
|
* Retrieve resource fields of the given resource slug.
|
|
* @param {Object} state
|
|
* @param {String} resourceSlug
|
|
* @return {Array}
|
|
*/
|
|
export const getResourceFieldsFactory = () => createSelector(
|
|
resourceFieldsIdsSelector,
|
|
resourceFieldsItemsSelector,
|
|
(fieldsIds, fieldsItems) => {
|
|
return pickItemsFromIds(fieldsItems, fieldsIds);
|
|
}
|
|
);
|
|
|
|
/**
|
|
* Retrieve resource columns of the given resource slug.
|
|
* @param {State} state
|
|
* @param {String} resourceSlug -
|
|
* @return {Array}
|
|
*/
|
|
export const getResourceColumns = (state, resourceSlug) => {
|
|
const resourceIds = state.resources.resourceColumns[resourceSlug];
|
|
const items = state.resources.columns;
|
|
return pickItemsFromIds(items, resourceIds);
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param {State} state
|
|
* @param {Number} fieldId
|
|
*/
|
|
export const getResourceField = (state, fieldId) => {
|
|
return state.resources.fields[fieldId];
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param {State} state
|
|
* @param {Number} columnId
|
|
*/
|
|
export const getResourceColumn = (state, columnId) => {
|
|
return state.resources.columns[columnId];
|
|
};
|
|
|
|
export const getResourceMetadata = (state, resourceSlug) => {
|
|
return state.resources.metadata[resourceSlug];
|
|
};
|
|
|
|
|
|
export const getResourceData = (state, resourceSlug) => {
|
|
return state.resources.data[resourceSlug] || {};
|
|
}; |