mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: Merge sales branch
This commit is contained in:
53
client/src/store/Bills/bills.selectors.js
Normal file
53
client/src/store/Bills/bills.selectors.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
const billTableQuery = (state) => state.bills.tableQuery;
|
||||
|
||||
const billPageSelector = (state, props, query) => {
|
||||
const viewId = state.bills.currentViewId;
|
||||
return state.bills.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
const billItemsSelector = (state) => state.bills.items;
|
||||
|
||||
const billByIdSelector = (state, props) => state.bills.items[props.billId];
|
||||
|
||||
const billPaginationSelector = (state, props) => {
|
||||
const viewId = state.bills.currentViewId;
|
||||
return state.bills.views?.[viewId];
|
||||
};
|
||||
|
||||
export const getBillTableQueryFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
billTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Get current page bills items.
|
||||
* @return {Array}
|
||||
*/
|
||||
export const getBillCurrentPageFactory = () =>
|
||||
createSelector(billPageSelector, billItemsSelector, (billPage, billItems) => {
|
||||
return typeof billPage === 'object'
|
||||
? pickItemsFromIds(billItems, billPage.ids) || []
|
||||
: [];
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieve bill details of the given bill id.
|
||||
*/
|
||||
export const getBillByIdFactory = () =>
|
||||
createSelector(billByIdSelector, (bill) => {
|
||||
return bill;
|
||||
});
|
||||
|
||||
export const getBillPaginationMetaFactory = () =>
|
||||
createSelector(billPaginationSelector, (billPage) => {
|
||||
return billPage?.paginationMeta || {};
|
||||
});
|
||||
Reference in New Issue
Block a user