@zeniai/client-epic-state 4.19.24-betaRR13 → 4.19.24-betaRR15
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/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryHelpers.d.ts +3 -7
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryHelpers.js +15 -12
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.d.ts +3 -6
- package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +54 -19
- package/package.json +1 -1
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { ID } from '../../../../commonStateTypes/common';
|
|
2
2
|
import { ChargeCardRepaymentStatusCodeType } from '../../../../entity/chargeCardRepayment/chargeCardRepayment';
|
|
3
|
+
import { PaymentHistoryAccountInfo, PaymentHistoryFilters, PaymentHistoryUIState } from './chargeCardPaymentHistory';
|
|
3
4
|
import type { ChargeCardRepaymentWithUser } from './chargeCardPaymentHistorySelector';
|
|
4
|
-
|
|
5
|
-
export declare function getPaymentHistorySourceAccountName(repayment: ChargeCardRepaymentWithUser, accountInfoMap?: Map<ID, {
|
|
6
|
-
depositAccountName?: string;
|
|
7
|
-
}>): string;
|
|
5
|
+
export declare function getPaymentHistorySourceAccountName(repayment: ChargeCardRepaymentWithUser, accountInfoByAccountId?: Record<ID, PaymentHistoryAccountInfo>): string;
|
|
8
6
|
export declare function getPaymentStatusDisplayText(status: ChargeCardRepaymentStatusCodeType): string;
|
|
9
|
-
export declare function applyPaymentHistoryFiltersSearchAndSort(repayments: ChargeCardRepaymentWithUser[], filters: PaymentHistoryFilters, searchText: string, uiState: PaymentHistoryUIState,
|
|
10
|
-
depositAccountName?: string;
|
|
11
|
-
}>): ChargeCardRepaymentWithUser[];
|
|
7
|
+
export declare function applyPaymentHistoryFiltersSearchAndSort(repayments: ChargeCardRepaymentWithUser[], filters: PaymentHistoryFilters, searchText: string, uiState: PaymentHistoryUIState, accountInfoByAccountId?: Record<ID, PaymentHistoryAccountInfo>): ChargeCardRepaymentWithUser[];
|
|
@@ -9,9 +9,12 @@ exports.applyPaymentHistoryFiltersSearchAndSort = applyPaymentHistoryFiltersSear
|
|
|
9
9
|
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
10
10
|
const userSelector_1 = require("../../../../entity/user/userSelector");
|
|
11
11
|
const spendManagementFilterHelpers_1 = require("../../spendManagementFilterHelpers");
|
|
12
|
-
function getPaymentHistorySourceAccountName(repayment,
|
|
13
|
-
var _a, _b
|
|
14
|
-
|
|
12
|
+
function getPaymentHistorySourceAccountName(repayment, accountInfoByAccountId) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const fromMap = repayment.paymentAccountId != null
|
|
15
|
+
? (_a = accountInfoByAccountId === null || accountInfoByAccountId === void 0 ? void 0 : accountInfoByAccountId[repayment.paymentAccountId]) === null || _a === void 0 ? void 0 : _a.depositAccountName
|
|
16
|
+
: undefined;
|
|
17
|
+
return (_b = fromMap !== null && fromMap !== void 0 ? fromMap : repayment.paymentAccountName) !== null && _b !== void 0 ? _b : '';
|
|
15
18
|
}
|
|
16
19
|
function getPaymentStatusDisplayText(status) {
|
|
17
20
|
var _a;
|
|
@@ -25,7 +28,7 @@ function getPaymentStatusDisplayText(status) {
|
|
|
25
28
|
};
|
|
26
29
|
return (_a = statusMap[status]) !== null && _a !== void 0 ? _a : status;
|
|
27
30
|
}
|
|
28
|
-
function getPaymentHistorySortValue(repayment, sortKey,
|
|
31
|
+
function getPaymentHistorySortValue(repayment, sortKey, accountInfoByAccountId) {
|
|
29
32
|
switch (sortKey) {
|
|
30
33
|
case 'paymentDate':
|
|
31
34
|
return repayment.repaymentDate.valueOf();
|
|
@@ -38,12 +41,12 @@ function getPaymentHistorySortValue(repayment, sortKey, accountInfoMap) {
|
|
|
38
41
|
? 'autopay'
|
|
39
42
|
: (0, userSelector_1.getUserName)(repayment.paidByUser);
|
|
40
43
|
case 'sourceAccount':
|
|
41
|
-
return getPaymentHistorySourceAccountName(repayment,
|
|
44
|
+
return getPaymentHistorySourceAccountName(repayment, accountInfoByAccountId);
|
|
42
45
|
default:
|
|
43
46
|
return '';
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
function sortPaymentHistory(repayments, sortKey, sortOrder,
|
|
49
|
+
function sortPaymentHistory(repayments, sortKey, sortOrder, accountInfoByAccountId) {
|
|
47
50
|
const getColumnWiseSortOrder = (sortOrder) => {
|
|
48
51
|
switch (sortKey) {
|
|
49
52
|
case 'sourceAccount':
|
|
@@ -55,9 +58,9 @@ function sortPaymentHistory(repayments, sortKey, sortOrder, accountInfoMap) {
|
|
|
55
58
|
}
|
|
56
59
|
};
|
|
57
60
|
const order = getColumnWiseSortOrder(sortOrder);
|
|
58
|
-
return (0, orderBy_1.default)(repayments, (repayment) => getPaymentHistorySortValue(repayment, sortKey,
|
|
61
|
+
return (0, orderBy_1.default)(repayments, (repayment) => getPaymentHistorySortValue(repayment, sortKey, accountInfoByAccountId), [order]);
|
|
59
62
|
}
|
|
60
|
-
function filterPaymentHistoryBySearchText(repayments, searchText,
|
|
63
|
+
function filterPaymentHistoryBySearchText(repayments, searchText, accountInfoByAccountId) {
|
|
61
64
|
const loweredSearchText = searchText.trim().toLowerCase();
|
|
62
65
|
if (loweredSearchText.length === 0) {
|
|
63
66
|
return repayments;
|
|
@@ -68,16 +71,16 @@ function filterPaymentHistoryBySearchText(repayments, searchText, accountInfoMap
|
|
|
68
71
|
const initiatedByString = repayment.repaymentType === 'scheduled'
|
|
69
72
|
? 'autopay'
|
|
70
73
|
: (0, userSelector_1.getUserName)(repayment.paidByUser);
|
|
71
|
-
const accountNameString = getPaymentHistorySourceAccountName(repayment,
|
|
74
|
+
const accountNameString = getPaymentHistorySourceAccountName(repayment, accountInfoByAccountId).toLowerCase();
|
|
72
75
|
return (amountString.includes(loweredSearchText) ||
|
|
73
76
|
statusString.includes(loweredSearchText) ||
|
|
74
77
|
initiatedByString.toLowerCase().includes(loweredSearchText) ||
|
|
75
78
|
accountNameString.includes(loweredSearchText));
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
|
-
function applyPaymentHistoryFiltersSearchAndSort(repayments, filters, searchText, uiState,
|
|
81
|
+
function applyPaymentHistoryFiltersSearchAndSort(repayments, filters, searchText, uiState, accountInfoByAccountId) {
|
|
79
82
|
let result = (0, spendManagementFilterHelpers_1.applyAdvancedFiltersOnList)('charge_card_payment_history', repayments, filters);
|
|
80
|
-
result = filterPaymentHistoryBySearchText(result, searchText,
|
|
81
|
-
result = sortPaymentHistory(result, uiState.sortKey, uiState.sortOrder,
|
|
83
|
+
result = filterPaymentHistoryBySearchText(result, searchText, accountInfoByAccountId);
|
|
84
|
+
result = sortPaymentHistory(result, uiState.sortKey, uiState.sortOrder, accountInfoByAccountId);
|
|
82
85
|
return result;
|
|
83
86
|
}
|
|
@@ -3,25 +3,22 @@ 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 {
|
|
7
|
-
import { PaymentHistoryFilters, PaymentHistoryUIState } from './chargeCardPaymentHistory';
|
|
6
|
+
import { PaymentHistoryAccountInfo, PaymentHistoryFilters, PaymentHistoryUIState } from './chargeCardPaymentHistory';
|
|
8
7
|
export interface ChargeCardRepaymentWithUser extends ChargeCardRepayment {
|
|
9
8
|
paidByUser?: User;
|
|
10
9
|
}
|
|
11
10
|
export interface ChargeCardPaymentHistorySelectorView extends SelectorView {
|
|
11
|
+
accountInfoByAccountId: Record<ID, PaymentHistoryAccountInfo>;
|
|
12
12
|
creditAccountId: ID;
|
|
13
13
|
currencyCode: string;
|
|
14
14
|
currencySymbol: string;
|
|
15
15
|
filters: PaymentHistoryFilters;
|
|
16
16
|
isAutoPayEnabled: boolean;
|
|
17
17
|
repaymentHistory: ChargeCardRepaymentWithUser[];
|
|
18
|
-
repaymentHistoryFundingAccounts: FundingAccount[];
|
|
19
18
|
repaymentHistoryIds: ID[];
|
|
20
19
|
repaymentHistoryUsers: User[];
|
|
21
20
|
searchText: string;
|
|
22
21
|
totalRepayments: number;
|
|
23
22
|
uiState: PaymentHistoryUIState;
|
|
24
23
|
}
|
|
25
|
-
export declare const getChargeCardPaymentHistoryView: (state: RootState
|
|
26
|
-
depositAccountName?: string;
|
|
27
|
-
}>) => ChargeCardPaymentHistorySelectorView;
|
|
24
|
+
export declare const getChargeCardPaymentHistoryView: (state: RootState) => ChargeCardPaymentHistorySelectorView;
|
|
@@ -5,10 +5,12 @@ const reduceFetchState_1 = require("../../../../commonStateTypes/reduceFetchStat
|
|
|
5
5
|
const chargeCardRepaymentSelector_1 = require("../../../../entity/chargeCardRepayment/chargeCardRepaymentSelector");
|
|
6
6
|
const userSelector_1 = require("../../../../entity/user/userSelector");
|
|
7
7
|
const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
|
|
8
|
+
const depositAccountSelector_1 = require("../../../../entity/depositAccount/depositAccountSelector");
|
|
9
|
+
const paymentAccountSelector_1 = require("../../../../entity/paymentAccount/paymentAccountSelector");
|
|
8
10
|
const depositAccountListSelector_1 = require("../../zeniAccounts/depositAccountList/depositAccountListSelector");
|
|
9
11
|
const paymentAccountListSelector_1 = require("../../zeniAccounts/paymentAccountList/paymentAccountListSelector");
|
|
10
12
|
const chargeCardPaymentHistoryHelpers_1 = require("./chargeCardPaymentHistoryHelpers");
|
|
11
|
-
const getChargeCardPaymentHistoryView = (state
|
|
13
|
+
const getChargeCardPaymentHistoryView = (state) => {
|
|
12
14
|
const { chargeCardPaymentHistoryState, chargeCardRepaymentState, userState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, } = state;
|
|
13
15
|
const { creditAccountId, currencyCode, currencySymbol, filters, isAutoPayEnabled, repaymentHistoryIds, searchText, totalRepayments, uiState, fetchState, error, } = chargeCardPaymentHistoryState;
|
|
14
16
|
// Get the full repayment details from the entity state
|
|
@@ -23,26 +25,59 @@ const getChargeCardPaymentHistoryView = (state, accountInfoMap) => {
|
|
|
23
25
|
});
|
|
24
26
|
// Enrich repayments with paidByUser details
|
|
25
27
|
let repaymentHistoryWithUsers = repaymentHistory.map((repayment) => (Object.assign(Object.assign({}, repayment), { paidByUser: userMap.get(repayment.paidById) })));
|
|
26
|
-
|
|
27
|
-
// Extract unique funding account IDs from repayment history
|
|
28
|
-
const repaymentHistoryFundingAccountIds = Array.from(new Set(repaymentHistoryWithUsers
|
|
29
|
-
.map((repayment) => repayment.paymentAccountId)
|
|
30
|
-
.filter((id) => id !== undefined && id !== null)));
|
|
31
|
-
// Get deposit and payment accounts views for fetch state reduction
|
|
28
|
+
// Get deposit and payment accounts views (used for funding accounts and fetch state)
|
|
32
29
|
const depositAccountsView = (0, depositAccountListSelector_1.getAllDepositAccounts)(depositAccountState, depositAccountListState);
|
|
33
30
|
const paymentAccountsView = (0, paymentAccountListSelector_1.getAllPaymentAccounts)(paymentAccountState, paymentAccountListState);
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
// Extract unique funding account IDs from unfiltered repayment history (for accountInfoMap used in filter/sort)
|
|
32
|
+
const repaymentHistoryFundingAccountIdsForMap = Array.from(new Set(repaymentHistory
|
|
33
|
+
.map((repayment) => repayment.paymentAccountId)
|
|
34
|
+
.filter((id) => id !== undefined && id !== null)));
|
|
35
|
+
let fundingAccountsForMap = [];
|
|
36
|
+
if (repaymentHistoryFundingAccountIdsForMap.length > 0) {
|
|
37
|
+
const hasDepositData = depositAccountsView.fetchState === 'Completed';
|
|
38
|
+
const hasPaymentData = paymentAccountsView.fetchState === 'Completed';
|
|
39
|
+
if (hasDepositData || hasPaymentData) {
|
|
40
|
+
const matchingDepositAccountsForMap = hasDepositData
|
|
41
|
+
? depositAccountsView.depositAccounts.filter((depositAccount) => repaymentHistoryFundingAccountIdsForMap.includes(depositAccount.id))
|
|
42
|
+
: [];
|
|
43
|
+
const matchingPaymentAccountsForMap = hasPaymentData
|
|
44
|
+
? paymentAccountsView.paymentAccounts.filter((paymentAccount) => repaymentHistoryFundingAccountIdsForMap.includes(paymentAccount.paymentAccountId))
|
|
45
|
+
: [];
|
|
46
|
+
fundingAccountsForMap = (0, setupViewSelector_1.getAllFundingAccounts)(matchingDepositAccountsForMap, matchingPaymentAccountsForMap, paymentAccountListState.paymentAccountBalanceFetchStatus, false);
|
|
47
|
+
// Fallback: look up repayment-referenced accounts directly from entity stores
|
|
48
|
+
// in case they're not in the list state (e.g. race condition, stale list)
|
|
49
|
+
const existingIds = new Set(fundingAccountsForMap.map((fa) => fa.id).filter(Boolean));
|
|
50
|
+
for (const accountId of repaymentHistoryFundingAccountIdsForMap) {
|
|
51
|
+
if (existingIds.has(accountId)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const depositAccount = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, accountId);
|
|
55
|
+
if (depositAccount != null) {
|
|
56
|
+
fundingAccountsForMap.push((0, setupViewSelector_1.mapDepositAccToFundingAccount)(depositAccount));
|
|
57
|
+
existingIds.add(accountId);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const paymentAccount = (0, paymentAccountSelector_1.getPaymentAccountByPaymentAccountId)(paymentAccountState, accountId);
|
|
61
|
+
if (paymentAccount != null) {
|
|
62
|
+
fundingAccountsForMap.push((0, setupViewSelector_1.mapPaymentAccToFundingAccount)(paymentAccount, paymentAccountListState.paymentAccountBalanceFetchStatus));
|
|
63
|
+
existingIds.add(accountId);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
45
67
|
}
|
|
68
|
+
const accountInfoByAccountId = {};
|
|
69
|
+
fundingAccountsForMap.forEach((fa) => {
|
|
70
|
+
if (fa.id != null) {
|
|
71
|
+
accountInfoByAccountId[fa.id] = {
|
|
72
|
+
accountId: fa.id,
|
|
73
|
+
accountLogo: fa.logo,
|
|
74
|
+
accountType: fa.accType === 'depositAccount' ? 'depositAccount' : 'paymentAccount',
|
|
75
|
+
depositAccountLast4: fa.accountLast4,
|
|
76
|
+
depositAccountName: fa.label,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
repaymentHistoryWithUsers = (0, chargeCardPaymentHistoryHelpers_1.applyPaymentHistoryFiltersSearchAndSort)(repaymentHistoryWithUsers, filters, searchText, uiState, accountInfoByAccountId);
|
|
46
81
|
const reducedFetchState = (0, reduceFetchState_1.reduceAllFetchState)([
|
|
47
82
|
{ fetchState, error },
|
|
48
83
|
depositAccountsView,
|
|
@@ -50,13 +85,13 @@ const getChargeCardPaymentHistoryView = (state, accountInfoMap) => {
|
|
|
50
85
|
...Object.values(paymentAccountListState.paymentAccountBalanceFetchStatus),
|
|
51
86
|
]);
|
|
52
87
|
return {
|
|
88
|
+
accountInfoByAccountId,
|
|
53
89
|
creditAccountId,
|
|
54
90
|
currencyCode,
|
|
55
91
|
currencySymbol,
|
|
56
92
|
filters,
|
|
57
93
|
isAutoPayEnabled,
|
|
58
94
|
repaymentHistory: repaymentHistoryWithUsers,
|
|
59
|
-
repaymentHistoryFundingAccounts,
|
|
60
95
|
repaymentHistoryIds,
|
|
61
96
|
repaymentHistoryUsers,
|
|
62
97
|
searchText,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "4.19.24-
|
|
3
|
+
"version": "4.19.24-betaRR15",
|
|
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",
|