@zeniai/client-epic-state 4.19.8-betaRR3 → 4.19.8-betaRR5
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.
|
@@ -3,14 +3,19 @@ import { SelectorView } from '../../../../commonStateTypes/viewAndReport/viewAnd
|
|
|
3
3
|
import { ChargeCardRepayment } from '../../../../entity/chargeCardRepayment/chargeCardRepayment';
|
|
4
4
|
import { User } from '../../../../entity/user/userState';
|
|
5
5
|
import { RootState } from '../../../../reducer';
|
|
6
|
+
import { FundingAccount } from '../../commonSetup/setupViewSelector';
|
|
6
7
|
import { PaymentHistoryFilters, PaymentHistoryUIState } from './chargeCardPaymentHistory';
|
|
8
|
+
export interface ChargeCardRepaymentWithUser extends ChargeCardRepayment {
|
|
9
|
+
paidByUser?: User;
|
|
10
|
+
}
|
|
7
11
|
export interface ChargeCardPaymentHistorySelectorView extends SelectorView {
|
|
8
12
|
creditAccountId: ID;
|
|
9
13
|
currencyCode: string;
|
|
10
14
|
currencySymbol: string;
|
|
11
15
|
filters: PaymentHistoryFilters;
|
|
12
16
|
isAutoPayEnabled: boolean;
|
|
13
|
-
repaymentHistory:
|
|
17
|
+
repaymentHistory: ChargeCardRepaymentWithUser[];
|
|
18
|
+
repaymentHistoryFundingAccounts: FundingAccount[];
|
|
14
19
|
repaymentHistoryIds: ID[];
|
|
15
20
|
repaymentHistoryUsers: User[];
|
|
16
21
|
searchText: string;
|
|
@@ -5,9 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getChargeCardPaymentHistoryView = void 0;
|
|
7
7
|
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
8
|
+
const reduceFetchState_1 = require("../../../../commonStateTypes/reduceFetchState");
|
|
8
9
|
const chargeCardRepaymentSelector_1 = require("../../../../entity/chargeCardRepayment/chargeCardRepaymentSelector");
|
|
9
10
|
const userSelector_1 = require("../../../../entity/user/userSelector");
|
|
11
|
+
const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
|
|
10
12
|
const spendManagementFilterHelpers_1 = require("../../spendManagementFilterHelpers");
|
|
13
|
+
const depositAccountListSelector_1 = require("../../zeniAccounts/depositAccountList/depositAccountListSelector");
|
|
14
|
+
const paymentAccountListSelector_1 = require("../../zeniAccounts/paymentAccountList/paymentAccountListSelector");
|
|
11
15
|
const getPaymentHistorySortValue = (repayment, sortKey, accountInfoMap) => {
|
|
12
16
|
var _a;
|
|
13
17
|
switch (sortKey) {
|
|
@@ -32,45 +36,81 @@ const sortPaymentHistory = (repayments, sortKey, sortOrder, accountInfoMap) => {
|
|
|
32
36
|
return (0, orderBy_1.default)(repayments, (repayment) => getPaymentHistorySortValue(repayment, sortKey, accountInfoMap), [order]);
|
|
33
37
|
};
|
|
34
38
|
const getChargeCardPaymentHistoryView = (state, accountInfoMap) => {
|
|
35
|
-
const { chargeCardPaymentHistoryState, chargeCardRepaymentState, userState } = state;
|
|
39
|
+
const { chargeCardPaymentHistoryState, chargeCardRepaymentState, userState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, } = state;
|
|
36
40
|
const { creditAccountId, currencyCode, currencySymbol, filters, isAutoPayEnabled, repaymentHistoryIds, repaymentHistoryUserIds, searchText, totalRepayments, uiState, fetchState, error, } = chargeCardPaymentHistoryState;
|
|
37
41
|
// Get the full repayment details from the entity state
|
|
38
|
-
|
|
42
|
+
const repaymentHistory = (0, chargeCardRepaymentSelector_1.getChargeCardRepaymentByIds)(chargeCardRepaymentState, repaymentHistoryIds);
|
|
43
|
+
// Get users first to enrich repayments
|
|
44
|
+
const repaymentHistoryUsers = (0, userSelector_1.getUsersByUserIds)(userState, repaymentHistoryUserIds);
|
|
45
|
+
// Create a map of userId -> User for quick lookup
|
|
46
|
+
const userMap = new Map();
|
|
47
|
+
repaymentHistoryUsers.forEach((user) => {
|
|
48
|
+
userMap.set(user.userId, user);
|
|
49
|
+
});
|
|
50
|
+
// Enrich repayments with paidByUser details
|
|
51
|
+
let repaymentHistoryWithUsers = repaymentHistory.map((repayment) => (Object.assign(Object.assign({}, repayment), { paidByUser: userMap.get(repayment.paidById) })));
|
|
39
52
|
// Apply filters
|
|
40
|
-
|
|
53
|
+
repaymentHistoryWithUsers = (0, spendManagementFilterHelpers_1.applyAdvancedFiltersOnList)('charge_card_payment_history', repaymentHistoryWithUsers, filters);
|
|
41
54
|
// Apply search text filtering
|
|
42
55
|
const loweredSearchText = searchText.trim().toLowerCase();
|
|
43
56
|
if (loweredSearchText.length > 0) {
|
|
44
|
-
|
|
57
|
+
repaymentHistoryWithUsers = repaymentHistoryWithUsers.filter((repayment) => {
|
|
45
58
|
var _a, _b;
|
|
46
59
|
const amountString = repayment.amount.amount.toString();
|
|
47
60
|
const statusString = repayment.status.toLowerCase();
|
|
48
|
-
const initiatedByString = repayment.
|
|
61
|
+
const initiatedByString = repayment.repaymentType === 'scheduled'
|
|
62
|
+
? 'autopay'
|
|
63
|
+
: (0, userSelector_1.getUserName)(repayment.paidByUser);
|
|
49
64
|
const accountInfo = accountInfoMap === null || accountInfoMap === void 0 ? void 0 : accountInfoMap.get(repayment.providerDepositAccountId);
|
|
50
65
|
const accountNameString = (_b = (_a = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.depositAccountName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
|
|
51
66
|
return (amountString.includes(loweredSearchText) ||
|
|
52
67
|
statusString.includes(loweredSearchText) ||
|
|
53
|
-
initiatedByString.includes(loweredSearchText) ||
|
|
68
|
+
initiatedByString.toLowerCase().includes(loweredSearchText) ||
|
|
54
69
|
accountNameString.includes(loweredSearchText));
|
|
55
70
|
});
|
|
56
71
|
}
|
|
57
72
|
// Apply sorting
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
repaymentHistoryWithUsers = sortPaymentHistory(repaymentHistoryWithUsers, uiState.sortKey, uiState.sortOrder, accountInfoMap);
|
|
74
|
+
// Extract unique funding account IDs from repayment history
|
|
75
|
+
const repaymentHistoryFundingAccountIds = Array.from(new Set(repaymentHistoryWithUsers
|
|
76
|
+
.map((repayment) => repayment.providerDepositAccountId)
|
|
77
|
+
.filter((id) => id !== undefined && id !== null)));
|
|
78
|
+
// Get deposit and payment accounts views for fetch state reduction
|
|
79
|
+
const depositAccountsView = (0, depositAccountListSelector_1.getAllDepositAccounts)(depositAccountState, depositAccountListState);
|
|
80
|
+
const paymentAccountsView = (0, paymentAccountListSelector_1.getAllPaymentAccounts)(paymentAccountState, paymentAccountListState);
|
|
81
|
+
// Get funding accounts linked to payments
|
|
82
|
+
let repaymentHistoryFundingAccounts = [];
|
|
83
|
+
if (repaymentHistoryFundingAccountIds.length > 0 &&
|
|
84
|
+
depositAccountsView.fetchState === 'Completed' &&
|
|
85
|
+
paymentAccountsView.fetchState === 'Completed') {
|
|
86
|
+
// Filter deposit accounts that match providerDepositAccountIds (by id)
|
|
87
|
+
const matchingDepositAccounts = depositAccountsView.depositAccounts.filter((depositAccount) => repaymentHistoryFundingAccountIds.includes(depositAccount.id));
|
|
88
|
+
// Filter payment accounts that match providerDepositAccountIds (by providerAccountId)
|
|
89
|
+
const matchingPaymentAccounts = paymentAccountsView.paymentAccounts.filter((paymentAccount) => repaymentHistoryFundingAccountIds.includes(paymentAccount.providerAccountId));
|
|
90
|
+
// Convert to FundingAccount[] format
|
|
91
|
+
repaymentHistoryFundingAccounts = (0, setupViewSelector_1.getAllFundingAccounts)(matchingDepositAccounts, matchingPaymentAccounts, paymentAccountListState.paymentAccountBalanceFetchStatus, false);
|
|
92
|
+
}
|
|
93
|
+
const reducedFetchState = (0, reduceFetchState_1.reduceAllFetchState)([
|
|
94
|
+
{ fetchState, error },
|
|
95
|
+
depositAccountsView,
|
|
96
|
+
paymentAccountsView,
|
|
97
|
+
...Object.values(paymentAccountListState.paymentAccountBalanceFetchStatus),
|
|
98
|
+
]);
|
|
60
99
|
return {
|
|
61
100
|
creditAccountId,
|
|
62
101
|
currencyCode,
|
|
63
102
|
currencySymbol,
|
|
64
103
|
filters,
|
|
65
104
|
isAutoPayEnabled,
|
|
66
|
-
repaymentHistory,
|
|
105
|
+
repaymentHistory: repaymentHistoryWithUsers,
|
|
106
|
+
repaymentHistoryFundingAccounts,
|
|
67
107
|
repaymentHistoryIds,
|
|
68
108
|
repaymentHistoryUsers,
|
|
69
109
|
searchText,
|
|
70
110
|
totalRepayments,
|
|
71
111
|
uiState,
|
|
72
|
-
fetchState,
|
|
73
|
-
error,
|
|
112
|
+
fetchState: reducedFetchState.fetchState,
|
|
113
|
+
error: reducedFetchState.error,
|
|
74
114
|
version: 0,
|
|
75
115
|
};
|
|
76
116
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "4.19.8-
|
|
3
|
+
"version": "4.19.8-betaRR5",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|