mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: Merge sales branch
This commit is contained in:
51
client/src/store/Estimate/estimates.selectors.js
Normal file
51
client/src/store/Estimate/estimates.selectors.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createSelector } from '@reduxjs/toolkit';
|
||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||
|
||||
const estimateTableQuery = (state) => state.sales_estimates.tableQuery;
|
||||
|
||||
const estimateByIdSelector = (state, props) =>
|
||||
state.sales_estimates.items[props.estimateId];
|
||||
|
||||
const estimatesCurrentViewSelector = (state, props) => {
|
||||
const viewId = state.sales_estimates.currentViewId;
|
||||
return state.sales_estimates.views?.[viewId];
|
||||
};
|
||||
const estimateItemsSelector = (state) => state.sales_estimates.items;
|
||||
|
||||
const estimatesPageSelector = (state, props, query) => {
|
||||
const viewId = state.sales_estimates.currentViewId;
|
||||
return state.sales_estimates.views?.[viewId]?.pages?.[query.page];
|
||||
};
|
||||
|
||||
export const getEstimatesTableQueryFactory = () =>
|
||||
createSelector(
|
||||
paginationLocationQuery,
|
||||
estimateTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const getEstimateCurrentPageFactory = () =>
|
||||
createSelector(
|
||||
estimatesPageSelector,
|
||||
estimateItemsSelector,
|
||||
(estimatePage, estimateItems) => {
|
||||
return typeof estimatePage === 'object'
|
||||
? pickItemsFromIds(estimateItems, estimatePage.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
export const getEstimateByIdFactory = () =>
|
||||
createSelector(estimateByIdSelector, (estimate) => {
|
||||
return estimate;
|
||||
});
|
||||
|
||||
export const getEstimatesPaginationMetaFactory = () =>
|
||||
createSelector(estimatesCurrentViewSelector, (estimateView) => {
|
||||
return estimateView?.paginationMeta || {};
|
||||
});
|
||||
Reference in New Issue
Block a user