@zeniai/client-epic-state 5.0.72 → 5.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonStateTypes/cacheOverrideFetchReducer.d.ts +17 -0
- package/lib/commonStateTypes/cacheOverrideFetchReducer.js +20 -0
- package/lib/commonStateTypes/filterPrimitives.d.ts +23 -0
- package/lib/commonStateTypes/filterPrimitives.js +21 -0
- package/lib/commonStateTypes/pusherActions.d.ts +11 -0
- package/lib/commonStateTypes/pusherActions.js +6 -0
- package/lib/coreEpics.js +1 -1
- package/lib/entity/account/accountSelector.d.ts +27 -1
- package/lib/entity/account/accountSelector.js +47 -1
- package/lib/entity/account/accountState.d.ts +6 -1
- package/lib/entity/account/accountState.js +11 -4
- package/lib/entity/account/subAccountSelector.d.ts +1 -1
- package/lib/entity/aiAccountantCustomer/aiAccountantCustomerPayload.js +1 -3
- package/lib/entity/aiAccountantCustomer/aiAccountantCustomerReducer.js +1 -2
- package/lib/entity/aiAccountantCustomer/aiAccountantCustomerSelector.d.ts +1 -1
- package/lib/entity/chargeCard/chargeCardReducer.d.ts +19 -2
- package/lib/entity/chargeCard/chargeCardReducer.js +35 -2
- package/lib/entity/chargeCardTransaction/chargeCardTransactionReducer.d.ts +14 -1
- package/lib/entity/chargeCardTransaction/chargeCardTransactionReducer.js +36 -2
- package/lib/entity/class/classSelector.d.ts +35 -0
- package/lib/entity/class/classSelector.js +50 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.d.ts +2 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +2 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +2 -0
- package/lib/entity/sectionProjectView/sectionProjectViewReducer.d.ts +1 -1
- package/lib/entity/sectionProjectView/sectionProjectViewSelector.js +1 -1
- package/lib/entity/tenant/SessionManager.js +6 -3
- package/lib/entity/tenant/clearAllEpic.d.ts +2 -2
- package/lib/entity/tenant/clearAllEpic.js +2 -2
- package/lib/entity/tenant/epic/saveAPIKeyConnectionEpic.js +6 -2
- package/lib/entity/tenant/epic/saveOAuthConnectionEpic.js +6 -2
- package/lib/entity/tenant/tenantReducer.js +6 -1
- package/lib/entity/transaction/payloadTypes/transactionLinePayload.js +3 -1
- package/lib/epic.d.ts +9 -9
- package/lib/epic.js +10 -10
- package/lib/esm/commonStateTypes/cacheOverrideFetchReducer.js +16 -0
- package/lib/esm/commonStateTypes/filterPrimitives.js +20 -0
- package/lib/esm/commonStateTypes/pusherActions.js +3 -0
- package/lib/esm/coreEpics.js +1 -1
- package/lib/esm/entity/account/accountSelector.js +46 -1
- package/lib/esm/entity/account/accountState.js +7 -1
- package/lib/esm/entity/aiAccountantCustomer/aiAccountantCustomerPayload.js +1 -3
- package/lib/esm/entity/aiAccountantCustomer/aiAccountantCustomerReducer.js +1 -2
- package/lib/esm/entity/chargeCard/chargeCardReducer.js +34 -1
- package/lib/esm/entity/chargeCardTransaction/chargeCardTransactionReducer.js +35 -1
- package/lib/esm/entity/class/classSelector.js +48 -0
- package/lib/esm/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +2 -0
- package/lib/esm/entity/sectionProjectView/sectionProjectViewSelector.js +1 -1
- package/lib/esm/entity/tenant/SessionManager.js +4 -1
- package/lib/esm/entity/tenant/clearAllEpic.js +2 -2
- package/lib/esm/entity/tenant/epic/saveAPIKeyConnectionEpic.js +6 -2
- package/lib/esm/entity/tenant/epic/saveOAuthConnectionEpic.js +6 -2
- package/lib/esm/entity/tenant/tenantReducer.js +6 -1
- package/lib/esm/entity/transaction/payloadTypes/transactionLinePayload.js +3 -1
- package/lib/esm/epic.js +10 -10
- package/lib/esm/index.js +26 -16
- package/lib/esm/reducer.js +2 -2
- package/lib/esm/view/aiAccountantView/epics/fetchAiAccountantCustomersEpic.js +2 -5
- package/lib/esm/view/aiAccountantView/epics/fetchAiAccountantJobsEpic.js +2 -5
- package/lib/esm/view/aiAccountantView/epics/triggerAiAccountantJobEpic.js +4 -1
- package/lib/esm/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
- package/lib/esm/view/companyTaskManagerView/companyTaskManagerViewSelector.js +1 -1
- package/lib/esm/view/companyTaskManagerView/epics/fetchTaskManagerMetricsEpic.js +1 -1
- package/lib/esm/view/companyView/helpers/cockpitHelpers.js +1 -1
- package/lib/esm/view/companyView/selector/companyManagementViewSelector.js +1 -1
- package/lib/esm/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +2 -2
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +2 -1
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +8 -6
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +7 -1
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +11 -1
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +2 -1
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +137 -1
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +89 -13
- package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +258 -0
- package/lib/esm/view/expenseAutomationView/types/completedSubTab.js +17 -0
- package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +0 -2
- package/lib/esm/view/financeStatement/financeStatementSelector.js +1 -1
- package/lib/esm/view/spendManagement/chargeCards/cashbackDetail/cashbackDetailReducer.js +3 -2
- package/lib/esm/view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer.js +3 -2
- package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/chargeCardDetailReducer.js +55 -18
- package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailEpic.js +16 -2
- package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailPageEpic.js +5 -4
- package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListReducer.js +26 -9
- package/lib/esm/view/spendManagement/chargeCards/chargeCardList/fetchChargeCardListPageEpic.js +9 -6
- package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryReducer.js +3 -2
- package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/fetchChargeCardPaymentPageEpic.js +1 -1
- package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailReducer.js +7 -3
- package/lib/esm/view/spendManagement/spendManagementFilterHelpers.js +4 -2
- package/lib/esm/view/subscriptionView/subscriptionViewSelector.js +1 -1
- package/lib/esm/view/taskManager/cannedResponsesView/epics/fetchCannedResponsesEpic.js +1 -1
- package/lib/esm/view/taskManager/cannedResponsesView/epics/saveCannedResponseEpic.js +1 -1
- package/lib/esm/view/taskManager/taskDetailView/epics/unsnoozeTaskEpic.js +1 -1
- package/lib/esm/view/taskManager/taskListView/taskListReducer.js +1 -1
- package/lib/esm/view/transactionDetail/transactionDetailSelector.js +7 -1
- package/lib/index.d.ts +25 -19
- package/lib/index.js +81 -58
- package/lib/reducer.d.ts +2 -2
- package/lib/reducer.js +2 -2
- package/lib/view/aiAccountantView/aiAccountantViewPayload.d.ts +2 -2
- package/lib/view/aiAccountantView/aiAccountantViewReducer.d.ts +1 -1
- package/lib/view/aiAccountantView/epics/fetchAiAccountantCustomersEpic.js +2 -5
- package/lib/view/aiAccountantView/epics/fetchAiAccountantJobsEpic.js +2 -5
- package/lib/view/aiAccountantView/epics/triggerAiAccountantJobEpic.js +4 -1
- package/lib/view/companyHealthMetricView/companyHealthMetricViewSelector.js +1 -1
- package/lib/view/companyTaskManagerView/companyTaskManagerViewSelector.d.ts +1 -1
- package/lib/view/companyTaskManagerView/companyTaskManagerViewSelector.js +1 -1
- package/lib/view/companyView/helpers/cockpitHelpers.js +1 -1
- package/lib/view/companyView/selector/companyManagementViewSelector.js +1 -1
- package/lib/view/companyView/selector/companyPortfolioViewSelector.js +1 -1
- package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +2 -2
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +2 -1
- package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +8 -6
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +7 -1
- package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +10 -0
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +21 -0
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +2 -1
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +2 -1
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +14 -4
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +138 -2
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +2 -1
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +14 -0
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +4 -1
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +91 -13
- package/lib/view/expenseAutomationView/transactionFilterHelpers.d.ts +66 -0
- package/lib/view/expenseAutomationView/transactionFilterHelpers.js +262 -0
- package/lib/view/expenseAutomationView/types/completedSubTab.d.ts +10 -0
- package/lib/view/expenseAutomationView/types/completedSubTab.js +21 -0
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +1 -2
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +1 -4
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +43 -2
- package/lib/view/financeStatement/financeStatementSelector.js +1 -1
- package/lib/view/profitAndLossProjectView/profitAndLossProjectViewSelectorTypes.d.ts +1 -1
- package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
- package/lib/view/spendManagement/chargeCards/cashbackDetail/cashbackDetailReducer.d.ts +3 -1
- package/lib/view/spendManagement/chargeCards/cashbackDetail/cashbackDetailReducer.js +3 -2
- package/lib/view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer.d.ts +3 -1
- package/lib/view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer.js +3 -2
- package/lib/view/spendManagement/chargeCards/chargeCardDetail/chargeCardDetailReducer.js +55 -18
- package/lib/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailEpic.js +16 -2
- package/lib/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailPageEpic.js +5 -4
- package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListReducer.d.ts +18 -3
- package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListReducer.js +27 -10
- package/lib/view/spendManagement/chargeCards/chargeCardList/fetchChargeCardListPageEpic.js +9 -6
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistory.d.ts +1 -1
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryReducer.d.ts +3 -1
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryReducer.js +3 -2
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/fetchChargeCardPaymentPageEpic.js +1 -1
- package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailReducer.d.ts +3 -1
- package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailReducer.js +7 -3
- package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +1 -1
- package/lib/view/spendManagement/spendManagementFilterHelpers.d.ts +12 -3
- package/lib/view/spendManagement/spendManagementFilterHelpers.js +4 -2
- package/lib/view/subscriptionView/subscriptionViewSelector.js +1 -1
- package/lib/view/taskManager/taskListView/taskList.d.ts +1 -1
- package/lib/view/taskManager/taskListView/taskListReducer.js +1 -1
- package/lib/view/transactionDetail/transactionDetailSelector.js +7 -1
- package/lib/view/zeniOAuthView/zeniOAuthSelector.d.ts +1 -1
- package/package.json +9 -4
- package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrowing type-guard for "has a non-empty string here". Used in place of
|
|
3
|
+
* raw `if (foo)` truthiness checks on `string | null | undefined` values so
|
|
4
|
+
* the `@typescript-eslint/strict-boolean-expressions` lint stays clean —
|
|
5
|
+
* empty strings should explicitly fall through to the next candidate
|
|
6
|
+
* (vendorName → customerName → localData.vendor.name → ...) rather than
|
|
7
|
+
* being implicitly coerced to falsy.
|
|
8
|
+
*/
|
|
9
|
+
const isNonEmptyString = (s) => s != null && s !== '';
|
|
10
|
+
/**
|
|
11
|
+
* First line item in UI order. `lineItemById` is a Record whose iteration
|
|
12
|
+
* order is not guaranteed to match what the user sees; `sortedLineItems`
|
|
13
|
+
* is the canonical ordering used by the categorization list/detail views.
|
|
14
|
+
*/
|
|
15
|
+
const getFirstLineItemFromReviewLocalData = (localData) => {
|
|
16
|
+
const { sortedLineItems, lineItemById } = localData;
|
|
17
|
+
if (sortedLineItems.length > 0) {
|
|
18
|
+
return lineItemById[sortedLineItems[0]];
|
|
19
|
+
}
|
|
20
|
+
const lineItems = Object.values(lineItemById);
|
|
21
|
+
return lineItems.length > 0 ? lineItems[0] : undefined;
|
|
22
|
+
};
|
|
23
|
+
export const TRANSACTION_FILTER_CATEGORIES = [
|
|
24
|
+
{ value: 'payment_account_name', type: 'dropdown' },
|
|
25
|
+
{ value: 'payment_account_type', type: 'dropdown' },
|
|
26
|
+
{ value: 'payee', type: 'searchAutocomplete' },
|
|
27
|
+
{ value: 'category', type: 'dropdown' },
|
|
28
|
+
{ value: 'class', type: 'dropdown' },
|
|
29
|
+
{ value: 'amount', type: 'numberRange' },
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the comparable value for a transaction against a given filter field.
|
|
33
|
+
* Returns undefined when the transaction doesn't carry the field — callers
|
|
34
|
+
* decide whether absence counts as a match (for 'not_equal' it does).
|
|
35
|
+
*/
|
|
36
|
+
const getCategoryValueForTransaction = (key, transaction) => {
|
|
37
|
+
switch (key) {
|
|
38
|
+
case 'amount': {
|
|
39
|
+
// Prefer transactionLocalData line items (sum). Fall back to lines on
|
|
40
|
+
// the transaction itself. Final fallback: transaction-level amount.
|
|
41
|
+
const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
42
|
+
if (localDataForAmount?.lineItemById) {
|
|
43
|
+
const lineItems = Object.values(localDataForAmount.lineItemById);
|
|
44
|
+
if (lineItems.length > 0) {
|
|
45
|
+
return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (transaction.transaction.lines &&
|
|
49
|
+
transaction.transaction.lines.length > 0) {
|
|
50
|
+
return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
|
|
51
|
+
}
|
|
52
|
+
return transaction.amount.amount;
|
|
53
|
+
}
|
|
54
|
+
case 'payee': {
|
|
55
|
+
if (isNonEmptyString(transaction.vendorName)) {
|
|
56
|
+
return transaction.vendorName;
|
|
57
|
+
}
|
|
58
|
+
if (isNonEmptyString(transaction.customerName)) {
|
|
59
|
+
return transaction.customerName;
|
|
60
|
+
}
|
|
61
|
+
const localData = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
62
|
+
const vendorName = localData?.vendor?.name;
|
|
63
|
+
if (isNonEmptyString(vendorName)) {
|
|
64
|
+
return vendorName;
|
|
65
|
+
}
|
|
66
|
+
const customerName = localData?.customer?.name;
|
|
67
|
+
if (isNonEmptyString(customerName)) {
|
|
68
|
+
return customerName;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
case 'payment_account_name': {
|
|
73
|
+
// Match what TransactionCategorizationListRow renders for the cell.
|
|
74
|
+
return transaction.transaction.account?.accountName;
|
|
75
|
+
}
|
|
76
|
+
case 'payment_account_type': {
|
|
77
|
+
// Raw `paymentType` enum ("credit_card" / "check" / "cash"). Dropdown
|
|
78
|
+
// option values use the same enum; row uses `paymentTypeName` for the
|
|
79
|
+
// human label.
|
|
80
|
+
return transaction.transaction.paymentType;
|
|
81
|
+
}
|
|
82
|
+
case 'category': {
|
|
83
|
+
const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
84
|
+
if (localDataForCategory != null) {
|
|
85
|
+
const firstLineItem = getFirstLineItemFromReviewLocalData(localDataForCategory);
|
|
86
|
+
const accountId = firstLineItem?.account?.accountId;
|
|
87
|
+
if (isNonEmptyString(accountId)) {
|
|
88
|
+
return accountId;
|
|
89
|
+
}
|
|
90
|
+
const qboId = firstLineItem?.account?.qboId;
|
|
91
|
+
if (isNonEmptyString(qboId)) {
|
|
92
|
+
return qboId;
|
|
93
|
+
}
|
|
94
|
+
const accountName = firstLineItem?.account?.accountName;
|
|
95
|
+
if (isNonEmptyString(accountName)) {
|
|
96
|
+
return accountName;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const firstLineForCategory = transaction.transaction.lines?.[0];
|
|
100
|
+
if (firstLineForCategory?.type ===
|
|
101
|
+
'transaction_with_account_and_class_line' ||
|
|
102
|
+
firstLineForCategory?.type ===
|
|
103
|
+
'transaction_with_product_or_service_line' ||
|
|
104
|
+
firstLineForCategory?.type === 'journal_entry_transaction_line') {
|
|
105
|
+
const account = firstLineForCategory.account;
|
|
106
|
+
return account?.accountId ?? account?.qboId ?? account?.accountName;
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
case 'class': {
|
|
111
|
+
const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
|
|
112
|
+
if (localDataForClass != null) {
|
|
113
|
+
const firstLineItemForClass = getFirstLineItemFromReviewLocalData(localDataForClass);
|
|
114
|
+
const classId = firstLineItemForClass?.class?.classId;
|
|
115
|
+
if (isNonEmptyString(classId)) {
|
|
116
|
+
return classId;
|
|
117
|
+
}
|
|
118
|
+
const qboId = firstLineItemForClass?.class?.qboId;
|
|
119
|
+
if (isNonEmptyString(qboId)) {
|
|
120
|
+
return qboId;
|
|
121
|
+
}
|
|
122
|
+
const className = firstLineItemForClass?.class?.className;
|
|
123
|
+
if (isNonEmptyString(className)) {
|
|
124
|
+
return className;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const firstLineForClass = transaction.transaction.lines?.[0];
|
|
128
|
+
if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
|
|
129
|
+
firstLineForClass?.type ===
|
|
130
|
+
'transaction_with_product_or_service_line' ||
|
|
131
|
+
firstLineForClass?.type === 'journal_entry_transaction_line') {
|
|
132
|
+
const classData = firstLineForClass.class;
|
|
133
|
+
return classData?.classId ?? classData?.qboId ?? classData?.className;
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* TC-only amount matcher. Supports all five operators TC defines, including
|
|
143
|
+
* the legacy "1000<->5000" range-string form (kept for backward compatibility
|
|
144
|
+
* with persisted filter state that may still contain that encoding).
|
|
145
|
+
*
|
|
146
|
+
* The `'equal' | 'not_equal'` branch matches if `amount` equals ANY of the
|
|
147
|
+
* configured values (consistent with how non-amount filters interpret a
|
|
148
|
+
* multi-value `values` array). `.some()` over the values array also makes
|
|
149
|
+
* the empty-values case behave correctly — empty array → `matched = false`
|
|
150
|
+
* — though in practice `applyTransactionFilters` strips empty-values
|
|
151
|
+
* categories before they reach this matcher. The trailing
|
|
152
|
+
* `op === 'not_equal' ? !matched : matched` line inverts for `not_equal`.
|
|
153
|
+
*/
|
|
154
|
+
const matchAmount = (amount, category) => {
|
|
155
|
+
const op = category.matchingOperator;
|
|
156
|
+
const values = category.values;
|
|
157
|
+
let matched = false;
|
|
158
|
+
if (op === 'in_between') {
|
|
159
|
+
if (values.length >= 2) {
|
|
160
|
+
const min = Number(values[0]);
|
|
161
|
+
const max = Number(values[1]);
|
|
162
|
+
matched = amount >= min && amount <= max;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (op === 'less_than') {
|
|
166
|
+
if (values.length >= 1) {
|
|
167
|
+
matched = amount < Number(values[0]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (op === 'greater_than') {
|
|
171
|
+
if (values.length >= 1) {
|
|
172
|
+
matched = amount > Number(values[0]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (op === 'equal' || op === 'not_equal') {
|
|
176
|
+
matched = values.some((v) => {
|
|
177
|
+
const s = String(v);
|
|
178
|
+
// Backward compatibility: legacy "low<->high" range-string form
|
|
179
|
+
// persisted under `matchingOperator: 'equal'`.
|
|
180
|
+
if (s.includes('<->')) {
|
|
181
|
+
const parts = s.split('<->');
|
|
182
|
+
return (amount >= Number(parts[0] ?? '') && amount <= Number(parts[1] ?? ''));
|
|
183
|
+
}
|
|
184
|
+
return amount === Number(v);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return op === 'not_equal' ? !matched : matched;
|
|
188
|
+
};
|
|
189
|
+
const transactionMatchesCategory = (transaction, category) => {
|
|
190
|
+
const value = getCategoryValueForTransaction(category.field, transaction);
|
|
191
|
+
if (value == null) {
|
|
192
|
+
// Absent-value semantics — pinning these down explicitly so the
|
|
193
|
+
// asymmetry isn't surprising:
|
|
194
|
+
//
|
|
195
|
+
// not_equal: a missing value IS NOT EQUAL to any candidate, so the
|
|
196
|
+
// transaction matches the filter (passes through).
|
|
197
|
+
// equal: a missing value is not equal to any candidate, so the
|
|
198
|
+
// transaction does NOT match (filtered out).
|
|
199
|
+
// less_than / greater_than: SQL-style three-valued logic — comparing
|
|
200
|
+
// against a missing value is "unknown", which we treat as
|
|
201
|
+
// "does not match" (filtered out). A user setting
|
|
202
|
+
// "amount < $1000" probably wants transactions with a
|
|
203
|
+
// concrete amount that satisfies the bound, not rows
|
|
204
|
+
// where the amount can't be determined.
|
|
205
|
+
// in_between: same as the single-sided comparators — missing values
|
|
206
|
+
// are filtered out.
|
|
207
|
+
//
|
|
208
|
+
// Only the `not_equal` branch returns `true` here; everything else
|
|
209
|
+
// falls through to the `false` below.
|
|
210
|
+
return category.matchingOperator === 'not_equal';
|
|
211
|
+
}
|
|
212
|
+
if (category.field === 'amount') {
|
|
213
|
+
return matchAmount(Number(value), category);
|
|
214
|
+
}
|
|
215
|
+
const valueStr = value.toString();
|
|
216
|
+
const valueInList = category.values.some((v) => v.toString() === valueStr);
|
|
217
|
+
return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* TC-only equivalent of `applyAdvancedFiltersOnList`. Filters a list of
|
|
221
|
+
* `TransactionView` items against a `TransactionFilters` object using the
|
|
222
|
+
* AND/OR combination semantics from `categoryCombinationOperator`.
|
|
223
|
+
*
|
|
224
|
+
* Independent of `view/spendManagement` — keeps the TC filter pipeline cleanly
|
|
225
|
+
* inside the Expense Automation feature group.
|
|
226
|
+
*/
|
|
227
|
+
export const applyTransactionFilters = (transactions, filters) => {
|
|
228
|
+
if (filters?.categories == null || filters.categories.length === 0) {
|
|
229
|
+
return transactions;
|
|
230
|
+
}
|
|
231
|
+
// Mirrors the predicate used by `getTransactionAppliedFiltersCount` on the
|
|
232
|
+
// webc side. A half-filled category — e.g. `in_between` with only the
|
|
233
|
+
// `min` typed — would otherwise survive the filter pass and produce zero
|
|
234
|
+
// matches because `Number("")` collapses to `0`, artificially emptying
|
|
235
|
+
// the list while editing. Skipping such categories keeps the filtered
|
|
236
|
+
// view stable while the user finishes typing.
|
|
237
|
+
const activeCategories = filters.categories.filter((c) => {
|
|
238
|
+
if (c.field == null || c.values.length === 0) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (c.field === 'amount' && c.matchingOperator === 'in_between') {
|
|
242
|
+
return (c.values.length >= 2 &&
|
|
243
|
+
String(c.values[0] ?? '').trim() !== '' &&
|
|
244
|
+
String(c.values[1] ?? '').trim() !== '');
|
|
245
|
+
}
|
|
246
|
+
return String(c.values[0] ?? '').trim() !== '';
|
|
247
|
+
});
|
|
248
|
+
if (activeCategories.length === 0) {
|
|
249
|
+
return transactions;
|
|
250
|
+
}
|
|
251
|
+
const op = filters.categoryCombinationOperator;
|
|
252
|
+
return transactions.filter((txn) => {
|
|
253
|
+
if (op === 'AND') {
|
|
254
|
+
return activeCategories.every((cat) => transactionMatchesCategory(txn, cat));
|
|
255
|
+
}
|
|
256
|
+
return activeCategories.some((cat) => transactionMatchesCategory(txn, cat));
|
|
257
|
+
});
|
|
258
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { stringToUnion } from '../../../commonStateTypes/stringToUnion';
|
|
2
|
+
/**
|
|
3
|
+
* Sub-tabs that can appear under any "Completed" tab in the Expense Automation
|
|
4
|
+
* surface (Transaction Categorization Completed and Missing Receipts Completed
|
|
5
|
+
* both use this exact union). Forwarded verbatim to listing APIs as `sub_tab`
|
|
6
|
+
* / `match_type`. `'all'` preserves parent-tab semantics on the backend.
|
|
7
|
+
*/
|
|
8
|
+
const COMPLETED_SUB_TABS = ['all', 'ai_accountant', 'manual'];
|
|
9
|
+
export const toCompletedSubTab = (v) => stringToUnion(v.trim().toLowerCase(), COMPLETED_SUB_TABS);
|
|
10
|
+
/**
|
|
11
|
+
* "No sub-tab filter" sentinel — single source of truth for the default
|
|
12
|
+
* value of {@link CompletedSubTab}. Use this constant in initial slice
|
|
13
|
+
* state and at any call site that needs to fall back to the parent-tab
|
|
14
|
+
* listing semantics (review tab requests, manual-search overrides, etc.)
|
|
15
|
+
* so a future rename of the union doesn't require chasing literals.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_COMPLETED_SUB_TAB = 'all';
|
|
@@ -39,8 +39,6 @@ const BULK_UPLOAD_RESULTS_TABS = ['completed', 'unmatched'];
|
|
|
39
39
|
export const toBulkUploadResultsTab = (v) => stringToUnion(v.trim().toLowerCase(), BULK_UPLOAD_RESULTS_TABS);
|
|
40
40
|
const MISSING_RECEIPTS_TABS = ['missing', 'completed', 'unmatched'];
|
|
41
41
|
export const toMissingReceiptsTab = (v) => stringToUnion(v.trim().toLowerCase(), MISSING_RECEIPTS_TABS);
|
|
42
|
-
const COMPLETED_SUB_TABS = ['all', 'ai_accountant', 'manual'];
|
|
43
|
-
export const toCompletedSubTab = (v) => stringToUnion(v.trim().toLowerCase(), COMPLETED_SUB_TABS);
|
|
44
42
|
const MATCH_SOURCES = ['ai', 'manual'];
|
|
45
43
|
export const toMatchSource = (v) => stringToUnion(v.trim().toLowerCase(), MATCH_SOURCES);
|
|
46
44
|
const BULK_UPLOAD_SORT_KEYS = [
|
|
@@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
|
|
|
2
2
|
import { stripCompareAdditionalBalanceTypes } from '../../commonStateTypes/coaBalance/coaBalanceType';
|
|
3
3
|
import { newBalancesFilter, newBalancesFilterForDateRange, } from '../../commonStateTypes/coaBalance/coaBalancesFilter';
|
|
4
4
|
import { newBalancesFilterClassesView } from '../../commonStateTypes/coaBalance/coaBalancesFilterClassesView';
|
|
5
|
+
import { newBalancesFilterProjectView } from '../../commonStateTypes/coaBalance/coaBalancesFilterProjectView';
|
|
5
6
|
import { getNumberOfPeriods, } from '../../commonStateTypes/dataAvailable';
|
|
6
7
|
import { reduceAnyCompletedFetchState } from '../../commonStateTypes/reduceFetchState';
|
|
7
8
|
import { toTimeframeTick, } from '../../commonStateTypes/timeframeTick';
|
|
@@ -9,7 +10,6 @@ import { extractThisPeriod } from '../../commonStateTypes/viewAndReport/thisPeri
|
|
|
9
10
|
import { getBalanceSheet } from '../balanceSheet/balanceSheetSelector';
|
|
10
11
|
import { getCashFlow } from '../cashFlow/cashFlowSelector';
|
|
11
12
|
import { getProfitAndLossReport, } from '../profitAndLoss/profitAndLossSelector';
|
|
12
|
-
import { newBalancesFilterProjectView } from '../../commonStateTypes/coaBalance/coaBalancesFilterProjectView';
|
|
13
13
|
import { getProfitAndLossClassesHorizontalView } from '../profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector';
|
|
14
14
|
import { getProfitAndLossClassesView } from '../profitAndLossClassesView/profitAndLossClassesViewSelector';
|
|
15
15
|
import { getProfitAndLossProjectView } from '../profitAndLossProjectView/profitAndLossProjectViewSelector';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { mapCurrencyPayloadToCurrency } from '../../../../commonPayloadTypes/v2/viewAndReportPayloadv2';
|
|
3
3
|
import { toAmount } from '../../../../commonStateTypes/amount';
|
|
4
|
+
import { createCacheOverrideFetchReducer } from '../../../../commonStateTypes/cacheOverrideFetchReducer';
|
|
4
5
|
import { initialCashbackAnalytics, } from './cashbackDetailState';
|
|
5
6
|
export const initialState = {
|
|
6
7
|
fetchState: 'Not-Started',
|
|
@@ -27,10 +28,10 @@ const cashbackDetail = createSlice({
|
|
|
27
28
|
name: 'cashbackDetail',
|
|
28
29
|
initialState,
|
|
29
30
|
reducers: {
|
|
30
|
-
fetchCashbackDetail(draft) {
|
|
31
|
+
fetchCashbackDetail: createCacheOverrideFetchReducer((draft) => {
|
|
31
32
|
draft.fetchState = 'In-Progress';
|
|
32
33
|
draft.error = undefined;
|
|
33
|
-
},
|
|
34
|
+
}),
|
|
34
35
|
updateCashbackDetail(draft, action) {
|
|
35
36
|
draft.cashbackByPeriod = toCashbackByPeriod(action.payload);
|
|
36
37
|
draft.cashbackSummary = toCashbackSummary(action.payload);
|
package/lib/esm/view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { toAmount } from '../../../../commonStateTypes/amount';
|
|
3
|
+
import { createCacheOverrideFetchReducer } from '../../../../commonStateTypes/cacheOverrideFetchReducer';
|
|
3
4
|
import { toCreditLimitFrequencyCodeType } from '../../../../entity/chargeCard/chargeCard';
|
|
4
5
|
import { toCreditTerm, toRePaymentInfo, } from './chargeCardConfigPayload';
|
|
5
6
|
export const initialState = {
|
|
@@ -30,10 +31,10 @@ const chargeCardConfig = createSlice({
|
|
|
30
31
|
name: 'chargeCardConfig',
|
|
31
32
|
initialState,
|
|
32
33
|
reducers: {
|
|
33
|
-
fetchChargeCardConfig(draft) {
|
|
34
|
+
fetchChargeCardConfig: createCacheOverrideFetchReducer((draft) => {
|
|
34
35
|
draft.fetchState = 'In-Progress';
|
|
35
36
|
draft.error = undefined;
|
|
36
|
-
},
|
|
37
|
+
}),
|
|
37
38
|
updateChargeCardConfig(draft, action) {
|
|
38
39
|
const { payload } = action;
|
|
39
40
|
draft.creditLimitFrequency =
|
package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/chargeCardDetailReducer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { mapSortOrderPayloadToSortOrder, } from '../../../../commonPayloadTypes/sortOrderPayload';
|
|
3
|
+
import { addChargeCardTransactionFromPusher, addDeclinedChargeCardTransactionFromPusher, } from '../../../../commonStateTypes/pusherActions';
|
|
3
4
|
import { toAttachment, } from '../../../../entity/transaction/payloadTypes/attachmentPayload';
|
|
4
5
|
import { emptyChargeCardDetail, mapChargeCardTransactionStatisticsPayloadToChargeCardTransactionStatistics, toChargeCardTransactionSortKeyType, } from './chargeCardDetail';
|
|
5
6
|
export const initialState = {
|
|
@@ -64,19 +65,30 @@ const chargeCardDetail = createSlice({
|
|
|
64
65
|
},
|
|
65
66
|
fetchChargeCardTransactionList: {
|
|
66
67
|
reducer(draft, action) {
|
|
67
|
-
const { chargeCardId, pageToken, pageTokenType } = action.payload;
|
|
68
|
+
const { chargeCardId, pageToken, pageTokenType, cacheOverride } = action.payload;
|
|
68
69
|
const existingCardDetail = draft.detailById[chargeCardId] ?? emptyChargeCardDetail;
|
|
70
|
+
const existingUi = existingCardDetail.transactionList.uiState;
|
|
71
|
+
// cacheOverride=true (Pusher): preserve fetchState, error, and scroll
|
|
72
|
+
// to avoid skeleton flash. Normal fetches reset as before.
|
|
69
73
|
draft.detailById[chargeCardId] = {
|
|
70
74
|
...existingCardDetail,
|
|
71
75
|
transactionList: {
|
|
72
76
|
...existingCardDetail.transactionList,
|
|
73
|
-
fetchState:
|
|
74
|
-
|
|
77
|
+
fetchState: cacheOverride
|
|
78
|
+
? existingCardDetail.transactionList.fetchState
|
|
79
|
+
: 'In-Progress',
|
|
80
|
+
error: cacheOverride
|
|
81
|
+
? existingCardDetail.transactionList.error
|
|
82
|
+
: undefined,
|
|
75
83
|
uiState: {
|
|
76
|
-
...
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
...existingUi,
|
|
85
|
+
// Preserve scroll on silent refresh so users aren't snapped
|
|
86
|
+
// away from their reading position.
|
|
87
|
+
scrollYOffset: cacheOverride
|
|
88
|
+
? existingUi.scrollYOffset
|
|
89
|
+
: existingUi.pageToken === null
|
|
90
|
+
? 0
|
|
91
|
+
: existingUi.scrollYOffset,
|
|
80
92
|
pageToken: pageToken,
|
|
81
93
|
pageTokenType: pageTokenType,
|
|
82
94
|
},
|
|
@@ -93,18 +105,24 @@ const chargeCardDetail = createSlice({
|
|
|
93
105
|
const { chargeCardId, data, cacheOverride } = action.payload;
|
|
94
106
|
const existingCardDetail = draft.detailById[chargeCardId] ?? emptyChargeCardDetail;
|
|
95
107
|
const newTransactionIds = data.transactions.map((tran) => tran.transaction_id);
|
|
108
|
+
const existingIds = existingCardDetail.transactionList.transactionIds;
|
|
109
|
+
// cacheOverride (Pusher): refresh page 1 but keep page 2+ IDs.
|
|
110
|
+
// Normal pagination: append new page, deduped.
|
|
111
|
+
const newIdSet = new Set(newTransactionIds);
|
|
112
|
+
const mergedTransactionIds = cacheOverride
|
|
113
|
+
? [
|
|
114
|
+
...newTransactionIds,
|
|
115
|
+
...existingIds.filter((id) => !newIdSet.has(id)),
|
|
116
|
+
]
|
|
117
|
+
: [
|
|
118
|
+
...existingIds,
|
|
119
|
+
...newTransactionIds.filter((id) => !existingIds.includes(id)),
|
|
120
|
+
];
|
|
96
121
|
draft.detailById[chargeCardId] = {
|
|
97
122
|
...existingCardDetail,
|
|
98
123
|
transactionList: {
|
|
99
124
|
...existingCardDetail.transactionList,
|
|
100
|
-
transactionIds:
|
|
101
|
-
...new Set([
|
|
102
|
-
...(cacheOverride
|
|
103
|
-
? []
|
|
104
|
-
: existingCardDetail.transactionList.transactionIds),
|
|
105
|
-
...newTransactionIds,
|
|
106
|
-
]),
|
|
107
|
-
],
|
|
125
|
+
transactionIds: mergedTransactionIds,
|
|
108
126
|
fetchState: 'Completed',
|
|
109
127
|
error: undefined,
|
|
110
128
|
uiState: {
|
|
@@ -116,9 +134,12 @@ const chargeCardDetail = createSlice({
|
|
|
116
134
|
limit: data.query.limit,
|
|
117
135
|
pageToken: data.query.page_token,
|
|
118
136
|
pageTokenType: data.query.page_token_type,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
137
|
+
// Preserve scroll on silent refresh; reset on user-triggered first page.
|
|
138
|
+
scrollYOffset: cacheOverride
|
|
139
|
+
? existingCardDetail.transactionList.uiState.scrollYOffset
|
|
140
|
+
: existingCardDetail.transactionList.uiState.pageToken === null
|
|
141
|
+
? 0
|
|
142
|
+
: existingCardDetail.transactionList.uiState.scrollYOffset,
|
|
122
143
|
},
|
|
123
144
|
},
|
|
124
145
|
};
|
|
@@ -632,6 +653,22 @@ const chargeCardDetail = createSlice({
|
|
|
632
653
|
Object.assign(draft, initialState);
|
|
633
654
|
},
|
|
634
655
|
},
|
|
656
|
+
extraReducers: (builder) => {
|
|
657
|
+
const prependTransaction = (draft, cardId, txId) => {
|
|
658
|
+
const detail = draft.detailById[cardId];
|
|
659
|
+
if (detail != null &&
|
|
660
|
+
!detail.transactionList.transactionIds.includes(txId)) {
|
|
661
|
+
detail.transactionList.transactionIds.unshift(txId);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
builder
|
|
665
|
+
.addCase(addChargeCardTransactionFromPusher, (draft, action) => {
|
|
666
|
+
prependTransaction(draft, action.payload.cardId, action.payload.transaction.transaction_id);
|
|
667
|
+
})
|
|
668
|
+
.addCase(addDeclinedChargeCardTransactionFromPusher, (draft, action) => {
|
|
669
|
+
prependTransaction(draft, action.payload.cardId, action.payload.transaction.transaction_id);
|
|
670
|
+
});
|
|
671
|
+
},
|
|
635
672
|
});
|
|
636
673
|
export const { fetchChargeCardDetailPage, fetchChargeCardDetail, updateChargeCardDetailFetchState, fetchChargeCardTransactionList, updateChargeCardDetailUIState, updateChargeCardTransactionList, updateChargeCardTransactionUploadReceiptsFetchStatus, fetchChargeCardTransactionAttachments, updateChargeCardTransactionIsViewReceiptClicked, updateChargeCardTransactionAttachmentsFailure, updatePhysicalChargeCardAttemptSuccessOrFailure, updatePhysicalChargeCardAttempt, updateDebitCardPinAttempt, updateDebitCardPinAttemptSuccessOrFailure, updateChargeCardTransactionReceiptsShowTickFetchStatus, updateChargeCardTransactionAttachmentsInCardDetail, updateChargeCardTransactionListFailure, updateChargeCardDetail, startCVVActivationWait, completeCVVActivationWait, startDebitCardSetPinWait, completeDebitCardSetPinWait, updateChargeCardDetailUpdateStatus, updateChargeCardSpendLimit, updateChargeCardSpendLimitSuccessOrFailure, updateChargeCardName, updateChargeCardNameSuccessOrFailure, lockChargeCard, lockChargeCardSuccessOrFailure, unlockChargeCard, unlockChargeCardSuccessOrFailure, closeChargeCard, closeChargeCardSuccessOrFailure, fetchDepositAccountLimit, updateDepositAccountLimitFetchStatus, fetchChargeCardTransactionStatistics, updateChargeCardTransactionStatistics, updateChargeCardTransactionStatisticsFetchState, fetchChargeCardsRecurringExpenses, updateChargeCardsRecurringExpenses, updateChargeCardsRecurringExpensesFetchState, sendOtpCardHolder, resendOtpCardHolder, sendOtpCardHolderSuccess, sendOtpCardHolderFailure, verifyOtpCardHolder, verifyOtpCardHolderSuccess, verifyOtpCardHolderFailure, clearChargeCardDetail, } = chargeCardDetail.actions;
|
|
637
674
|
export default chargeCardDetail.reducer;
|
package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailEpic.js
CHANGED
|
@@ -13,13 +13,24 @@ export const fetchChargeCardDetailEpic = (actions$, state$, zeniAPI) => actions$
|
|
|
13
13
|
const chargeCardAction = [];
|
|
14
14
|
const state = state$.value;
|
|
15
15
|
const chargeCardDetail = recordGet(state.chargeCardDetailState.detailById, chargeCardId, undefined);
|
|
16
|
+
// Skip if a user-triggered fetch is already in-flight (not applicable
|
|
17
|
+
// to cacheOverride/Pusher refreshes, which always proceed).
|
|
16
18
|
if (cacheOverride === true ||
|
|
17
19
|
chargeCardDetail == null ||
|
|
18
20
|
chargeCardDetail.fetchState !== 'In-Progress') {
|
|
21
|
+
// Silent refresh: preserve fetchState to avoid skeleton flash.
|
|
22
|
+
// Discriminate via fetchState (not null-check) because the reducer
|
|
23
|
+
// always creates an entry before the epic runs.
|
|
24
|
+
const isSilentRefresh = cacheOverride === true &&
|
|
25
|
+
chargeCardDetail != null &&
|
|
26
|
+
chargeCardDetail.fetchState !== 'Not-Started';
|
|
19
27
|
chargeCardAction.push(updateChargeCardDetailFetchState({
|
|
20
28
|
chargeCardId,
|
|
21
|
-
isRefreshingViewInBackground:
|
|
22
|
-
fetchState:
|
|
29
|
+
isRefreshingViewInBackground: isSilentRefresh,
|
|
30
|
+
fetchState: isSilentRefresh
|
|
31
|
+
? chargeCardDetail.fetchState
|
|
32
|
+
: 'In-Progress',
|
|
33
|
+
error: isSilentRefresh ? chargeCardDetail.error : undefined,
|
|
23
34
|
}));
|
|
24
35
|
const query = {
|
|
25
36
|
is_include_card_activation_events: true,
|
|
@@ -37,6 +48,8 @@ export const fetchChargeCardDetailEpic = (actions$, state$, zeniAPI) => actions$
|
|
|
37
48
|
}));
|
|
38
49
|
}
|
|
39
50
|
else {
|
|
51
|
+
// Surface errors even on silent refresh so the user
|
|
52
|
+
// knows data is stale (follow-up: consider toast instead).
|
|
40
53
|
return of(updateChargeCardDetailFetchState({
|
|
41
54
|
chargeCardId,
|
|
42
55
|
fetchState: 'Error',
|
|
@@ -45,6 +58,7 @@ export const fetchChargeCardDetailEpic = (actions$, state$, zeniAPI) => actions$
|
|
|
45
58
|
}));
|
|
46
59
|
}
|
|
47
60
|
}), catchError((error) => {
|
|
61
|
+
// Surface network failures even on silent refresh.
|
|
48
62
|
return of(updateChargeCardDetailFetchState({
|
|
49
63
|
chargeCardId,
|
|
50
64
|
fetchState: 'Error',
|
package/lib/esm/view/spendManagement/chargeCards/chargeCardDetail/fetchChargeCardDetailPageEpic.js
CHANGED
|
@@ -15,15 +15,16 @@ export const fetchChargeCardDetailPageEpic = (actions$, state$) => actions$.pipe
|
|
|
15
15
|
? exsitingChargeCardDetail.transactionList.uiState.pageTokenType
|
|
16
16
|
: null;
|
|
17
17
|
if (cacheOverride === true) {
|
|
18
|
+
// Forward cacheOverride to all sub-fetches to prevent skeleton flash.
|
|
18
19
|
chargeCardTransactionListAction.push(fetchChargeCardDetail(chargeCardId, cacheOverride));
|
|
19
20
|
//latest transactions need to be fetched hence removing pageToken and pageTokenType
|
|
20
|
-
chargeCardTransactionListAction.push(fetchChargeCardTransactionList(chargeCardId, null, null));
|
|
21
|
-
chargeCardTransactionListAction.push(fetchChargeCardConfig());
|
|
21
|
+
chargeCardTransactionListAction.push(fetchChargeCardTransactionList(chargeCardId, null, null, true));
|
|
22
|
+
chargeCardTransactionListAction.push(fetchChargeCardConfig(true));
|
|
22
23
|
if (doFetchCreditAccounts && isCreditCardEnabled) {
|
|
23
|
-
chargeCardTransactionListAction.push(fetchCreditAccount());
|
|
24
|
+
chargeCardTransactionListAction.push(fetchCreditAccount(true));
|
|
24
25
|
}
|
|
25
26
|
if (doFetchCreditAccounts && isCreditCardEnabled) {
|
|
26
|
-
chargeCardTransactionListAction.push(fetchCreditAccountRepayment());
|
|
27
|
+
chargeCardTransactionListAction.push(fetchCreditAccountRepayment(true));
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { toAmount } from '../../../../commonStateTypes/amount';
|
|
3
|
+
import { createCacheOverrideFetchReducer } from '../../../../commonStateTypes/cacheOverrideFetchReducer';
|
|
3
4
|
import { date } from '../../../../zeniDayJS';
|
|
4
5
|
import { initialCreditAcc, initialCreditAccountRepayment, initialDebitCardSummaries, initialResendRevokeCardInvite, toCreditAccountStatusType, } from './chargeCardList';
|
|
5
6
|
export const initialState = {
|
|
@@ -43,6 +44,10 @@ export const initialState = {
|
|
|
43
44
|
revokeCardInvite: initialResendRevokeCardInvite,
|
|
44
45
|
creditAccountRepayment: initialCreditAccountRepayment,
|
|
45
46
|
};
|
|
47
|
+
// Silent-Pusher-refresh contract: when cacheOverride=true, fetch reducers
|
|
48
|
+
// leave fetchState and error unchanged so the list page's reduceFetchState
|
|
49
|
+
// selector stays 'Completed' and doesn't flash ChargeCardListLoading.
|
|
50
|
+
// See createCacheOverrideFetchReducer for details.
|
|
46
51
|
const chargeCardList = createSlice({
|
|
47
52
|
name: 'chargeCardList',
|
|
48
53
|
initialState,
|
|
@@ -62,10 +67,10 @@ const chargeCardList = createSlice({
|
|
|
62
67
|
};
|
|
63
68
|
},
|
|
64
69
|
},
|
|
65
|
-
fetchCreditAccountRepayment(draft) {
|
|
70
|
+
fetchCreditAccountRepayment: createCacheOverrideFetchReducer((draft) => {
|
|
66
71
|
draft.creditAccountRepayment.fetchState = 'In-Progress';
|
|
67
72
|
draft.creditAccountRepayment.error = undefined;
|
|
68
|
-
},
|
|
73
|
+
}),
|
|
69
74
|
updateCreditAccountRepaymentAmountAndDate(draft, action) {
|
|
70
75
|
draft.creditAccountRepayment.initiatedRepayments = action.payload.amount;
|
|
71
76
|
draft.creditAccountRepayment.initiatedRepaymentDate = action.payload.date;
|
|
@@ -83,10 +88,10 @@ const chargeCardList = createSlice({
|
|
|
83
88
|
updateRowActionCardId(draft, action) {
|
|
84
89
|
draft.rowActionCardId = action.payload;
|
|
85
90
|
},
|
|
86
|
-
fetchCreditAccount(draft) {
|
|
91
|
+
fetchCreditAccount: createCacheOverrideFetchReducer((draft) => {
|
|
87
92
|
draft.creditAccount.fetchState = 'In-Progress';
|
|
88
93
|
draft.creditAccount.error = undefined;
|
|
89
|
-
},
|
|
94
|
+
}),
|
|
90
95
|
updateCreditAccount(draft, action) {
|
|
91
96
|
if (action.payload.length > 0) {
|
|
92
97
|
draft.creditAccount = toCreditAccount(action.payload[0]);
|
|
@@ -99,10 +104,10 @@ const chargeCardList = createSlice({
|
|
|
99
104
|
error: action.payload,
|
|
100
105
|
};
|
|
101
106
|
},
|
|
102
|
-
fetchDebitCardSummary(draft) {
|
|
107
|
+
fetchDebitCardSummary: createCacheOverrideFetchReducer((draft) => {
|
|
103
108
|
draft.debitCardSummaries.fetchState = 'In-Progress';
|
|
104
109
|
draft.debitCardSummaries.error = undefined;
|
|
105
|
-
},
|
|
110
|
+
}),
|
|
106
111
|
updateDebitCardSummary(draft, action) {
|
|
107
112
|
draft.debitCardSummaries = toDebitCardSummaries(action.payload);
|
|
108
113
|
},
|
|
@@ -113,10 +118,10 @@ const chargeCardList = createSlice({
|
|
|
113
118
|
error: action.payload,
|
|
114
119
|
};
|
|
115
120
|
},
|
|
116
|
-
fetchChargeCardList(draft) {
|
|
121
|
+
fetchChargeCardList: createCacheOverrideFetchReducer((draft) => {
|
|
117
122
|
draft.fetchState = 'In-Progress';
|
|
118
123
|
draft.error = undefined;
|
|
119
|
-
},
|
|
124
|
+
}),
|
|
120
125
|
updateChargeCardList(draft, action) {
|
|
121
126
|
const { cards, unassigned_credit } = action.payload.chargeCardListPayload;
|
|
122
127
|
const newCard = cards.map((card) => card.card_id);
|
|
@@ -152,6 +157,18 @@ const chargeCardList = createSlice({
|
|
|
152
157
|
draft.uiState.scrollYOffset = action.payload.uiState.scrollYOffset;
|
|
153
158
|
}
|
|
154
159
|
},
|
|
160
|
+
updateCreditAccountBalanceFromPusher(draft, action) {
|
|
161
|
+
const { currencyCode, currencySymbol } = action.payload;
|
|
162
|
+
const amt = (v) => v !== undefined ? toAmount(v, currencyCode, currencySymbol) : undefined;
|
|
163
|
+
draft.creditAccount.available =
|
|
164
|
+
amt(action.payload.available) ?? draft.creditAccount.available;
|
|
165
|
+
draft.creditAccount.balance =
|
|
166
|
+
amt(action.payload.balance) ?? draft.creditAccount.balance;
|
|
167
|
+
draft.creditAccount.hold =
|
|
168
|
+
amt(action.payload.hold) ?? draft.creditAccount.hold;
|
|
169
|
+
draft.creditAccount.cashback =
|
|
170
|
+
amt(action.payload.cashback) ?? draft.creditAccount.cashback;
|
|
171
|
+
},
|
|
155
172
|
clearChargeCardList(draft) {
|
|
156
173
|
Object.assign(draft, initialState);
|
|
157
174
|
},
|
|
@@ -307,7 +324,7 @@ const chargeCardList = createSlice({
|
|
|
307
324
|
},
|
|
308
325
|
},
|
|
309
326
|
});
|
|
310
|
-
export const { fetchChargeCardListPage, fetchCreditAccountRepayment, updateCreditAccountRepayment, updateCreditAccountRepaymentFailure, updateCreditAccountRepaymentAmountAndDate, updateRowActionCardId, fetchCreditAccount, updateCreditAccount, updateCreditAccountFailure, fetchDebitCardSummary, updateDebitCardSummary, updateDebitCardSummaryFailure, fetchChargeCardList, updateChargeCardList, updateChargeCardListFailure, updateSearchText, updateBulkActionCardIds, updateChargeCardListUIState, clearChargeCardList, resendCardInvite, resendCardInviteSuccess, resendCardInviteFailure, revokeCardInvite, revokeCardInviteSuccess, revokeCardInviteFailure, updateChargeCardsSpendLimit, updateChargeCardsSpendLimitSuccessOrFailure, lockChargeCards, lockChargeCardsSuccessOrFailure, unlockChargeCards, unlockChargeCardsSuccessOrFailure, closeChargeCards, closeChargeCardsSuccessOrFailure, revokeChargeCardsInvite, revokeChargeCardsInviteSuccessOrFailure, } = chargeCardList.actions;
|
|
327
|
+
export const { fetchChargeCardListPage, fetchCreditAccountRepayment, updateCreditAccountRepayment, updateCreditAccountRepaymentFailure, updateCreditAccountRepaymentAmountAndDate, updateRowActionCardId, fetchCreditAccount, updateCreditAccount, updateCreditAccountFailure, fetchDebitCardSummary, updateDebitCardSummary, updateDebitCardSummaryFailure, fetchChargeCardList, updateChargeCardList, updateChargeCardListFailure, updateSearchText, updateBulkActionCardIds, updateChargeCardListUIState, updateCreditAccountBalanceFromPusher, clearChargeCardList, resendCardInvite, resendCardInviteSuccess, resendCardInviteFailure, revokeCardInvite, revokeCardInviteSuccess, revokeCardInviteFailure, updateChargeCardsSpendLimit, updateChargeCardsSpendLimitSuccessOrFailure, lockChargeCards, lockChargeCardsSuccessOrFailure, unlockChargeCards, unlockChargeCardsSuccessOrFailure, closeChargeCards, closeChargeCardsSuccessOrFailure, revokeChargeCardsInvite, revokeChargeCardsInviteSuccessOrFailure, } = chargeCardList.actions;
|
|
311
328
|
export default chargeCardList.reducer;
|
|
312
329
|
// helper
|
|
313
330
|
const toCreditAccount = (payload) => ({
|