feat: add due bills reducer and selector.

This commit is contained in:
Ahmed Bouhuolia
2020-10-28 18:29:51 +02:00
parent bc9638c9a2
commit 8a20deacf3
6 changed files with 64 additions and 1 deletions

View File

@@ -9,8 +9,18 @@ const billPageSelector = (state, props, query) => {
};
const billItemsSelector = (state) => state.bills.items;
/**
* Retrieve bill details.
* @return {IBill}
*/
const billByIdSelector = (state, props) => state.bills.items[props.billId];
/**
* Retrieve vendor due bills ids.
* @return {number[]}
*/
const billsDueVendorSelector = (state, props) => state.bills.dueBills[props.vendorId];
const billPaginationSelector = (state, props) => {
const viewId = state.bills.currentViewId;
return state.bills.views?.[viewId];
@@ -51,3 +61,17 @@ export const getBillPaginationMetaFactory = () =>
createSelector(billPaginationSelector, (billPage) => {
return billPage?.paginationMeta || {};
});
/**
* Retrieve due bills of specific vendor.
*/
export const getVendorDueBillsFactory = () =>
createSelector(
billItemsSelector,
billsDueVendorSelector,
(billsItems, dueBillsIds) => {
return Array.isArray(dueBillsIds)
? pickItemsFromIds(billsItems, dueBillsIds) || []
: [];
},
);