@zeniai/client-epic-state 5.0.81-betaML5 → 5.0.81-betaRR08

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.
Files changed (76) hide show
  1. package/lib/commonStateTypes/viewAndReport/viewAndReport.d.ts +2 -2
  2. package/lib/commonStateTypes/viewAndReport/viewAndReport.js +0 -2
  3. package/lib/entity/account/accountSelector.d.ts +0 -9
  4. package/lib/entity/account/accountSelector.js +1 -14
  5. package/lib/entity/account/accountState.d.ts +1 -1
  6. package/lib/entity/accountGroup/accountGroupState.d.ts +1 -1
  7. package/lib/entity/class/classReducer.d.ts +4 -4
  8. package/lib/entity/class/classState.d.ts +1 -1
  9. package/lib/entity/forecast/forecastState.d.ts +1 -1
  10. package/lib/entity/sectionAccountsView/sectionAccountsView.d.ts +1 -1
  11. package/lib/entity/sectionClassesViewV2/sectionClassesView.d.ts +1 -1
  12. package/lib/entity/sectionClassesViewV2/sectionClassesViewReducer.d.ts +2 -2
  13. package/lib/entity/sectionProjectView/sectionProjectView.d.ts +1 -1
  14. package/lib/entity/sectionProjectView/sectionProjectViewReducer.d.ts +2 -2
  15. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  16. package/lib/entity/snackbar/snackbarTypes.js +0 -1
  17. package/lib/entity/tenant/clearAllEpic.d.ts +1 -2
  18. package/lib/entity/tenant/clearAllEpic.js +0 -2
  19. package/lib/entity/transaction/payloadTypes/transactionPayload.d.ts +0 -4
  20. package/lib/entity/transaction/payloadTypes/transactionPayload.js +10 -18
  21. package/lib/entity/transaction/stateTypes/transaction.d.ts +0 -3
  22. package/lib/epic.d.ts +1 -3
  23. package/lib/epic.js +1 -3
  24. package/lib/esm/commonStateTypes/viewAndReport/viewAndReport.js +0 -2
  25. package/lib/esm/entity/account/accountSelector.js +0 -11
  26. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -1
  27. package/lib/esm/entity/tenant/clearAllEpic.js +0 -2
  28. package/lib/esm/entity/transaction/payloadTypes/transactionPayload.js +10 -18
  29. package/lib/esm/epic.js +1 -3
  30. package/lib/esm/index.js +4 -5
  31. package/lib/esm/reducer.js +0 -3
  32. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +1 -13
  33. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -9
  34. package/lib/esm/view/transactionDetail/transactionDetailSelector.js +1 -6
  35. package/lib/index.d.ts +4 -5
  36. package/lib/index.js +33 -43
  37. package/lib/reducer.d.ts +0 -3
  38. package/lib/reducer.js +0 -3
  39. package/lib/view/auditReportView/auditReportViewState.d.ts +1 -1
  40. package/lib/view/billPayCard/billPayCardSelector.d.ts +1 -1
  41. package/lib/view/cardBalance/cardBalanceSelector.d.ts +1 -1
  42. package/lib/view/cashBalance/cashBalanceSelector.d.ts +1 -1
  43. package/lib/view/cashInCashOut/cashInCashOutSelector.d.ts +1 -1
  44. package/lib/view/cashPosition/cashPositionSelector.d.ts +1 -1
  45. package/lib/view/dashboard/dashboardReducer.d.ts +2 -2
  46. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  47. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -3
  48. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +2 -14
  49. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -4
  50. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.d.ts +0 -1
  51. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -11
  52. package/lib/view/financeStatement/financeStatementReducer.d.ts +1 -1
  53. package/lib/view/globalMerchantView/globalMerchantViewReducer.d.ts +2 -2
  54. package/lib/view/reimbursementCard/reimbursementCardSelector.d.ts +1 -1
  55. package/lib/view/reportsResync/reportsResyncReducer.d.ts +2 -2
  56. package/lib/view/tasksCard/tasksCardSelector.d.ts +1 -1
  57. package/lib/view/topEx/topExSelector.d.ts +1 -1
  58. package/lib/view/transactionDetail/transactionDetailPayload.d.ts +1 -1
  59. package/lib/view/transactionDetail/transactionDetailSelector.d.ts +1 -6
  60. package/lib/view/transactionDetail/transactionDetailSelector.js +1 -6
  61. package/package.json +1 -1
  62. package/lib/esm/view/createTransferEntry/createTransferEntryReducer.js +0 -82
  63. package/lib/esm/view/createTransferEntry/createTransferEntrySelector.js +0 -64
  64. package/lib/esm/view/createTransferEntry/createTransferEntryState.js +0 -17
  65. package/lib/esm/view/createTransferEntry/epics/createTransferEntryEpic.js +0 -130
  66. package/lib/esm/view/createTransferEntry/epics/fetchTransferAccountsEpic.js +0 -37
  67. package/lib/view/createTransferEntry/createTransferEntryReducer.d.ts +0 -32
  68. package/lib/view/createTransferEntry/createTransferEntryReducer.js +0 -86
  69. package/lib/view/createTransferEntry/createTransferEntrySelector.d.ts +0 -39
  70. package/lib/view/createTransferEntry/createTransferEntrySelector.js +0 -69
  71. package/lib/view/createTransferEntry/createTransferEntryState.d.ts +0 -30
  72. package/lib/view/createTransferEntry/createTransferEntryState.js +0 -20
  73. package/lib/view/createTransferEntry/epics/createTransferEntryEpic.d.ts +0 -11
  74. package/lib/view/createTransferEntry/epics/createTransferEntryEpic.js +0 -134
  75. package/lib/view/createTransferEntry/epics/fetchTransferAccountsEpic.d.ts +0 -14
  76. package/lib/view/createTransferEntry/epics/fetchTransferAccountsEpic.js +0 -41
@@ -15,7 +15,6 @@ const vendorSelector_1 = require("../../entity/vendor/vendorSelector");
15
15
  const zeniDayJS_1 = require("../../zeniDayJS");
16
16
  const accountListSelector_1 = require("../accountList/accountListSelector");
17
17
  const classListSelector_1 = require("../classList/classListSelector");
18
- const createTransferEntrySelector_1 = require("../createTransferEntry/createTransferEntrySelector");
19
18
  const projectListSelector_1 = require("../projectList/projectListSelector");
20
19
  const transactionDetailState_1 = require("./transactionDetailState");
21
20
  // "Any line on this transaction is fetching category/class recommendations?"
@@ -40,7 +39,7 @@ const getDetailInFlightRecommendations = (state, transactionId) => {
40
39
  };
41
40
  exports.getDetailInFlightRecommendations = getDetailInFlightRecommendations;
42
41
  const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = true) => {
43
- const { transactionDetailState, transactionState, vendorState, vendorListState, accountState, classState, classListState, accountListState, createTransferEntryState, projectState, projectListState, } = state;
42
+ const { transactionDetailState, transactionState, vendorState, vendorListState, accountState, classState, classListState, accountListState, projectState, projectListState, } = state;
44
43
  const detailKey = (0, transactionDetailState_1.getTransactionDetailKey)(transactionId);
45
44
  const transactionDetail = (0, get_1.default)(transactionDetailState.transactionDetailById, detailKey);
46
45
  let fetchState = {
@@ -107,7 +106,6 @@ const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = tr
107
106
  : [];
108
107
  const transactionDetailAnyUpdateStatus = reduceUpdateFetchStates(transactionDetail);
109
108
  const vendors = (0, vendorSelector_1.getVendorsByVendorIds)(vendorState, vendorListState.vendorIds);
110
- const { transferAccountsList, creditCardTransferAccountsList } = (0, createTransferEntrySelector_1.getResolvedTransferAccounts)(state);
111
109
  const hasInFlightCategoryClassRecommendations = (0, exports.getDetailInFlightRecommendations)(state, transactionId);
112
110
  return {
113
111
  reportId: 'transaction_detail',
@@ -126,9 +124,6 @@ const getTransactionDetail = (state, transactionId, fetchLinkedTransactions = tr
126
124
  classList: classList,
127
125
  hasInFlightCategoryClassRecommendations,
128
126
  isAccountingClassesEnabled,
129
- createTransferEntryStatus: createTransferEntryState.createTransferEntryStatus,
130
- creditCardTransferAccountsList,
131
- transferAccounts: transferAccountsList,
132
127
  isAccountingProjectsEnabled,
133
128
  projectList,
134
129
  isUpdateNotAllowed: transactionDetail?.isUpdateNotAllowed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.81-betaML5",
3
+ "version": "5.0.81-betaRR08",
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
  "module": "lib/esm/index.js",
@@ -1,82 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- import { initialCreateTransferEntryState, } from './createTransferEntryState';
3
- export const initialState = initialCreateTransferEntryState;
4
- const createTransferEntrySlice = createSlice({
5
- name: 'createTransferEntry',
6
- initialState,
7
- reducers: {
8
- fetchAccountsForTransferFlow(draft, action) {
9
- const slice = draft.transferAccountsByType[action.payload.kind];
10
- // Idempotent: a duplicate dispatch must not briefly downgrade
11
- // 'Completed' back to 'In-Progress' (would clear loaded data from a
12
- // consumer's perspective) nor restart the in-flight epic stream.
13
- // The hook (`useFetchTransferAccountsForFlow`) is the sole caller and
14
- // already dedupes via `store.getState()`; this guard is defense in
15
- // depth for any future caller.
16
- if (slice.fetchState === 'In-Progress' ||
17
- slice.fetchState === 'Completed') {
18
- return;
19
- }
20
- slice.fetchState = 'In-Progress';
21
- },
22
- updateAccountsForTransferFlow(draft, action) {
23
- const slice = draft.transferAccountsByType[action.payload.kind];
24
- slice.fetchState = 'Completed';
25
- slice.accountIds = action.payload.accountIds;
26
- },
27
- updateAccountsForTransferFlowFailure(draft, action) {
28
- draft.transferAccountsByType[action.payload.kind].fetchState = 'Error';
29
- },
30
- createTransferEntry: {
31
- prepare(payload) {
32
- return { payload };
33
- },
34
- /**
35
- * Defense-in-depth: clear any stale `lastTransferEntryReplacement` on a
36
- * fresh dispatch so a second `createTransferEntry` never inherits the
37
- * previous run's replacement signal (e.g. if the prior `timer(0)` cleanup
38
- * never fired). Mirrors the host hook's `consumedReplacementRef` guard
39
- * (see `useTransferEntryRouteReplacement` in zeni-web-app-ui).
40
- */
41
- reducer(draft) {
42
- draft.createTransferEntryStatus = 'In-Progress';
43
- draft.lastTransferEntryReplacement = undefined;
44
- },
45
- },
46
- createTransferEntrySuccess(draft) {
47
- draft.createTransferEntryStatus = 'Completed';
48
- },
49
- createTransferEntryFailure(draft) {
50
- draft.createTransferEntryStatus = 'Error';
51
- },
52
- resetCreateTransferEntryStatus(draft) {
53
- draft.createTransferEntryStatus = 'Not-Started';
54
- },
55
- createTransferEntryReplacedTransaction: {
56
- prepare(previousTransactionId, newTransactionId) {
57
- return { payload: { newTransactionId, previousTransactionId } };
58
- },
59
- reducer(draft, action) {
60
- draft.lastTransferEntryReplacement = action.payload;
61
- },
62
- },
63
- /**
64
- * One-shot acknowledgement: the host has consumed the route-replacement
65
- * signal and navigated to the new transaction url, so we can drop the
66
- * record. Re-dispatching is idempotent.
67
- */
68
- clearTransferEntryRouteReplacement(draft) {
69
- draft.lastTransferEntryReplacement = undefined;
70
- },
71
- /**
72
- * Full slice reset. Dispatched from `clearAllEpic` on tenant switch so
73
- * stale per-tenant state (account-id pools, status, replacement signal)
74
- * doesn't bleed across tenants.
75
- */
76
- clearCreateTransferEntry(draft) {
77
- Object.assign(draft, initialState);
78
- },
79
- },
80
- });
81
- export const { fetchAccountsForTransferFlow, updateAccountsForTransferFlow, updateAccountsForTransferFlowFailure, createTransferEntry, createTransferEntrySuccess, createTransferEntryFailure, resetCreateTransferEntryStatus, createTransferEntryReplacedTransaction, clearTransferEntryRouteReplacement, clearCreateTransferEntry, } = createTransferEntrySlice.actions;
82
- export default createTransferEntrySlice.reducer;
@@ -1,64 +0,0 @@
1
- import { createSelector } from '@reduxjs/toolkit';
2
- import { getAccountBase, getAccountBaseForCreditCardTransferAccounts, getAccountBaseForTransferAccounts, } from '../../entity/account/accountSelector';
3
- import { getAccountList } from '../accountList/accountListSelector';
4
- export function getCreateTransferEntryStatus(state) {
5
- return state.createTransferEntryState.createTransferEntryStatus;
6
- }
7
- export function getLastTransferEntryReplacement(state) {
8
- return state.createTransferEntryState.lastTransferEntryReplacement;
9
- }
10
- /**
11
- * Shared resolver for the credit/debit dropdowns in the transfer drawer.
12
- *
13
- * Resolution policy (intentional):
14
- * 1. Prefer the dedicated API fetch results (`transferEntryEligible` for the
15
- * debit pool, `creditCardOnlyEligible` for the credit-card-payment credit
16
- * pool).
17
- * 2. If the dedicated fetch returns an empty list while the COA is loaded,
18
- * fall back to the COA: the full account list for `transferEntryEligible`,
19
- * and COA accounts filtered to `credit_card` for `creditCardOnlyEligible`.
20
- * This keeps the dropdown populated for older tenants where the dedicated
21
- * endpoints haven't been backfilled yet.
22
- *
23
- * Intent — what this selector deliberately does NOT do:
24
- * - Does NOT distinguish "fetch in-flight" / "fetch errored" / "fetch returned
25
- * empty" — all three collapse to the COA fallback. The product preference
26
- * is "always show something selectable" over "show a spinner that may never
27
- * resolve". Loading/error UI belongs in the view layer; if you need a
28
- * spinner, observe the `fetchState` on `transferAccountsByType[kind]`
29
- * separately rather than changing the resolution policy here.
30
- * - Does NOT enforce "API result is authoritative even if empty" — a tenant
31
- * whose dedicated endpoint is correctly returning `[]` (e.g. no eligible
32
- * transfer destinations) will still see the COA. That trade-off is
33
- * accepted because the alternative blocks the user from picking anything;
34
- * the backend distinguishes "no result" from "endpoint not implemented" by
35
- * surfacing an error response, which the view layer handles separately.
36
- *
37
- * Memoized with reselect so consuming view-models don't recompute on every
38
- * unrelated state change.
39
- */
40
- export const getResolvedTransferAccounts = createSelector([
41
- (state) => state.accountState,
42
- (state) => state.accountListState,
43
- (state) => state.createTransferEntryState.transferAccountsByType
44
- .transferEntryEligible.accountIds,
45
- (state) => state.createTransferEntryState.transferAccountsByType
46
- .creditCardOnlyEligible.accountIds,
47
- ], (accountState, accountListState, transferEligibleIds, creditCardOnlyIds) => {
48
- const accountList = getAccountList(accountState, accountListState, 'accountList');
49
- const transferEligibleFromApi = transferEligibleIds
50
- .map((id) => getAccountBaseForTransferAccounts(accountState, id))
51
- .filter((account) => account != null);
52
- const coaFallbackAllAccounts = accountList.accounts
53
- .map((a) => getAccountBase(accountState, a.accountId, 'account_list'))
54
- .filter((account) => account != null);
55
- const transferAccountsList = transferEligibleFromApi.length > 0
56
- ? transferEligibleFromApi
57
- : coaFallbackAllAccounts;
58
- const creditCardFromApi = creditCardOnlyIds
59
- .map((id) => getAccountBaseForCreditCardTransferAccounts(accountState, id))
60
- .filter((account) => account != null);
61
- const coaFallbackCreditCards = coaFallbackAllAccounts.filter((a) => a.accountType === 'credit_card');
62
- const creditCardTransferAccountsList = creditCardFromApi.length > 0 ? creditCardFromApi : coaFallbackCreditCards;
63
- return { creditCardTransferAccountsList, transferAccountsList };
64
- });
@@ -1,17 +0,0 @@
1
- /** Which pool `fetchAccountsForTransferFlow` / transfer-flow epic should load. */
2
- export const TRANSFER_ACCOUNTS_FETCH_TYPE = [
3
- 'transferEntryEligible',
4
- 'creditCardOnlyEligible',
5
- ];
6
- const initialTransferAccountsState = {
7
- accountIds: [],
8
- fetchState: 'Not-Started',
9
- };
10
- export const initialCreateTransferEntryState = {
11
- createTransferEntryStatus: 'Not-Started',
12
- lastTransferEntryReplacement: undefined,
13
- transferAccountsByType: {
14
- transferEntryEligible: initialTransferAccountsState,
15
- creditCardOnlyEligible: initialTransferAccountsState,
16
- },
17
- };
@@ -1,130 +0,0 @@
1
- import { concat, from, timer } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
4
- import { toTransactionID } from '../../../entity/transaction/payloadTypes/transactionIDPayload';
5
- import { removeTransaction, updateTransaction, } from '../../../entity/transaction/transactionReducer';
6
- import { isSuccessResponse } from '../../../responsePayload';
7
- import { removeTransactionFromAllTabs } from '../../expenseAutomationView/reducers/transactionsViewReducer';
8
- import { initializeTransactionDetailLocalData, removeTransactionDetail, } from '../../transactionDetail/transactionDetailReducer';
9
- import { getTransactionDetailKey } from '../../transactionDetail/transactionDetailState';
10
- import { clearTransferEntryRouteReplacement, createTransferEntry, createTransferEntryFailure, createTransferEntryReplacedTransaction, createTransferEntrySuccess, resetCreateTransferEntryStatus, } from '../createTransferEntryReducer';
11
- // ─── Pure helpers ────────────────────────────────────────────────────────────
12
- function transactionIdsAreEqual(a, b) {
13
- return a.id === b.id && a.type === b.type;
14
- }
15
- const successSnackbar = () => openSnackbar({
16
- messageSection: 'create_transfer_entry',
17
- messageText: 'success',
18
- type: 'success',
19
- });
20
- const failureSnackbar = () => openSnackbar({
21
- messageSection: 'create_transfer_entry',
22
- messageText: 'failed',
23
- type: 'error',
24
- });
25
- function buildFailureActions() {
26
- return [createTransferEntryFailure(), failureSnackbar()];
27
- }
28
- /**
29
- * Defensive guard: a BE response that returns 200 with `transaction != null`
30
- * but where the body lacks a usable id/type is unsafe to seed into the store —
31
- * downstream code would store under a garbage key and the host hook would try
32
- * to navigate to a broken url. Treat that case as failure so the source row
33
- * stays visible and the user can retry.
34
- */
35
- function isWellFormedTransactionPayload(t) {
36
- return (t != null &&
37
- typeof t.transaction_id === 'string' &&
38
- t.transaction_id !== '' &&
39
- typeof t.transaction_type === 'string' &&
40
- t.transaction_type !== '');
41
- }
42
- function buildSuccessSideEffects(sourceTransactionId) {
43
- return [
44
- createTransferEntrySuccess(),
45
- removeTransactionFromAllTabs(sourceTransactionId),
46
- successSnackbar(),
47
- ];
48
- }
49
- function buildPreviousTransactionCleanupActions(previousTransactionId) {
50
- return [
51
- removeTransaction(getTransactionDetailKey(previousTransactionId)),
52
- removeTransactionDetail(previousTransactionId),
53
- clearTransferEntryRouteReplacement(),
54
- ];
55
- }
56
- /**
57
- * Emits `resetCreateTransferEntryStatus()` (and, on the replacement path, the
58
- * follow-up cleanup actions) one scheduler tick after the success actions.
59
- *
60
- * Why the `timer(0)` (and not synchronous emission):
61
- * On the replacement path the host (web-app-ui) watches
62
- * `lastTransferEntryReplacement`, navigates to the new transaction url, and
63
- * then sees `clearTransferEntryRouteReplacement` clear the signal. If we
64
- * dispatched the cleanup actions in the same tick as
65
- * `createTransferEntryReplacedTransaction`, redux subscribers would observe
66
- * `lastTransferEntryReplacement` flicker on then off in a single render, and
67
- * the old transaction's state (which the still-mounted detail view may be
68
- * reading) would be torn down before the host has had a chance to start
69
- * navigating. Deferring by one microtask gives the host exactly one render
70
- * pass to react before we tear down the previous transaction.
71
- */
72
- function delayedResetAndPreviousCleanup(previousTransactionId) {
73
- return timer(0).pipe(mergeMap(() => {
74
- const actions = [resetCreateTransferEntryStatus()];
75
- if (previousTransactionId != null) {
76
- actions.push(...buildPreviousTransactionCleanupActions(previousTransactionId));
77
- }
78
- return from(actions);
79
- }));
80
- }
81
- // ─── Success-path branches ───────────────────────────────────────────────────
82
- function handleSuccessWithoutTransactionBody(transactionId) {
83
- return concat(from(buildSuccessSideEffects(transactionId)), delayedResetAndPreviousCleanup(undefined));
84
- }
85
- function handleSuccessWithTransactionBody(transactionPayload, vendorPayload, previousTransactionId, sourceTransactionId) {
86
- const newTransactionId = toTransactionID(transactionPayload);
87
- const replaced = !transactionIdsAreEqual(previousTransactionId, newTransactionId);
88
- const immediate = [
89
- updateTransaction(getTransactionDetailKey(newTransactionId), transactionPayload),
90
- initializeTransactionDetailLocalData({
91
- transactionId: newTransactionId,
92
- vendorId: vendorPayload?.[0]?.vendor_id,
93
- }),
94
- ...buildSuccessSideEffects(sourceTransactionId),
95
- ];
96
- if (replaced) {
97
- immediate.push(createTransferEntryReplacedTransaction(previousTransactionId, newTransactionId));
98
- }
99
- return concat(from(immediate), delayedResetAndPreviousCleanup(replaced ? previousTransactionId : undefined));
100
- }
101
- // ─── Top-level epic ──────────────────────────────────────────────────────────
102
- export const createTransferEntryEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(createTransferEntry.match), mergeMap((action) => {
103
- const { transactionId, creditAccountIntegrationId, debitAccountIntegrationId, memo, transactionType, sourceTransactionType, } = action.payload;
104
- const previousTransactionId = {
105
- id: transactionId,
106
- type: sourceTransactionType,
107
- };
108
- const payload = {
109
- transaction_type: transactionType,
110
- transaction_id: transactionId,
111
- to_account_integration_id: creditAccountIntegrationId,
112
- from_account_integration_id: debitAccountIntegrationId,
113
- memo,
114
- };
115
- return zeniAPI
116
- .postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/transaction-type-update`, payload)
117
- .pipe(mergeMap((response) => {
118
- if (!isSuccessResponse(response)) {
119
- return from(buildFailureActions());
120
- }
121
- const transaction = response.data?.transaction;
122
- if (transaction != null) {
123
- if (!isWellFormedTransactionPayload(transaction)) {
124
- return from(buildFailureActions());
125
- }
126
- return handleSuccessWithTransactionBody(transaction, response.data?.vendors, previousTransactionId, transactionId);
127
- }
128
- return handleSuccessWithoutTransactionBody(transactionId);
129
- }), catchError(() => from(buildFailureActions())));
130
- }));
@@ -1,37 +0,0 @@
1
- import { of } from 'rxjs';
2
- import { catchError, filter, groupBy, mergeMap, switchMap } from 'rxjs/operators';
3
- import { updateAccounts } from '../../../entity/account/accountReducer';
4
- import { isSuccessResponse } from '../../../responsePayload';
5
- import { fetchAccountsForTransferFlow, updateAccountsForTransferFlow, updateAccountsForTransferFlowFailure, } from '../createTransferEntryReducer';
6
- const REPORT_ID_BY_TYPE = {
7
- transferEntryEligible: 'transfer_accounts',
8
- creditCardOnlyEligible: 'credit_card_transfer_accounts',
9
- };
10
- const QUERY_BY_TYPE = {
11
- transferEntryEligible: { is_only_include_transfer_accounts: true },
12
- creditCardOnlyEligible: { is_include_only_credit_card_accounts: true },
13
- };
14
- /**
15
- * Pools fetched concurrently: `groupBy(kind)` keeps `transferEntryEligible`
16
- * and `creditCardOnlyEligible` in their own streams so a back-to-back dispatch
17
- * of both does not cancel the first. Within a single type, a fresh dispatch
18
- * supersedes any in-flight request (per-group `switchMap`).
19
- */
20
- export const fetchTransferAccountsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchAccountsForTransferFlow.match), groupBy((action) => action.payload.kind), mergeMap((group$) => group$.pipe(switchMap((action) => {
21
- const { kind } = action.payload;
22
- const queryValue = QUERY_BY_TYPE[kind];
23
- const reportId = REPORT_ID_BY_TYPE[kind];
24
- const url = `https://dev.api.zeni.ai/version/accounting/komal/1.0/accounts?query=${encodeURIComponent(JSON.stringify(queryValue))}`;
25
- // const url = `${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accounts?query=${encodeURIComponent(JSON.stringify(queryValue))}`;
26
- return zeniAPI.getJSON(url).pipe(mergeMap((response) => {
27
- if (isSuccessResponse(response) && response.data != null) {
28
- const accountIds = response.data.accounts.map((account) => account.account_id);
29
- const actions = [
30
- updateAccounts(response.data.accounts, reportId),
31
- updateAccountsForTransferFlow({ accountIds, kind }),
32
- ];
33
- return of(...actions);
34
- }
35
- return of(updateAccountsForTransferFlowFailure({ kind }));
36
- }), catchError(() => of(updateAccountsForTransferFlowFailure({ kind }))));
37
- }))));
@@ -1,32 +0,0 @@
1
- import { ID } from '../../commonStateTypes/common';
2
- import { TransactionID } from '../../entity/transaction/stateTypes/transaction';
3
- import { TransactionType } from '../../entity/transaction/stateTypes/transactionType';
4
- import { CreateTransferEntryState, TransferAccountsFetchType } from './createTransferEntryState';
5
- export declare const initialState: CreateTransferEntryState;
6
- export declare const fetchAccountsForTransferFlow: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
7
- kind: TransferAccountsFetchType;
8
- }, "createTransferEntry/fetchAccountsForTransferFlow">, updateAccountsForTransferFlow: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
9
- accountIds: ID[];
10
- kind: TransferAccountsFetchType;
11
- }, "createTransferEntry/updateAccountsForTransferFlow">, updateAccountsForTransferFlowFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
12
- kind: TransferAccountsFetchType;
13
- }, "createTransferEntry/updateAccountsForTransferFlowFailure">, createTransferEntry: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: {
14
- creditAccountIntegrationId: string;
15
- debitAccountIntegrationId: string;
16
- memo: string;
17
- sourceTransactionType: TransactionType;
18
- transactionId: ID;
19
- transactionType: TransactionType;
20
- }], {
21
- creditAccountIntegrationId: string;
22
- debitAccountIntegrationId: string;
23
- memo: string;
24
- sourceTransactionType: TransactionType;
25
- transactionId: ID;
26
- transactionType: TransactionType;
27
- }, "createTransferEntry/createTransferEntry", never, never>, createTransferEntrySuccess: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"createTransferEntry/createTransferEntrySuccess">, createTransferEntryFailure: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"createTransferEntry/createTransferEntryFailure">, resetCreateTransferEntryStatus: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"createTransferEntry/resetCreateTransferEntryStatus">, createTransferEntryReplacedTransaction: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[previousTransactionId: TransactionID, newTransactionId: TransactionID], {
28
- newTransactionId: TransactionID;
29
- previousTransactionId: TransactionID;
30
- }, "createTransferEntry/createTransferEntryReplacedTransaction", never, never>, clearTransferEntryRouteReplacement: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"createTransferEntry/clearTransferEntryRouteReplacement">, clearCreateTransferEntry: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"createTransferEntry/clearCreateTransferEntry">;
31
- declare const _default: import("redux").Reducer<CreateTransferEntryState>;
32
- export default _default;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearCreateTransferEntry = exports.clearTransferEntryRouteReplacement = exports.createTransferEntryReplacedTransaction = exports.resetCreateTransferEntryStatus = exports.createTransferEntryFailure = exports.createTransferEntrySuccess = exports.createTransferEntry = exports.updateAccountsForTransferFlowFailure = exports.updateAccountsForTransferFlow = exports.fetchAccountsForTransferFlow = exports.initialState = void 0;
5
- const toolkit_1 = require("@reduxjs/toolkit");
6
- const createTransferEntryState_1 = require("./createTransferEntryState");
7
- exports.initialState = createTransferEntryState_1.initialCreateTransferEntryState;
8
- const createTransferEntrySlice = (0, toolkit_1.createSlice)({
9
- name: 'createTransferEntry',
10
- initialState: exports.initialState,
11
- reducers: {
12
- fetchAccountsForTransferFlow(draft, action) {
13
- const slice = draft.transferAccountsByType[action.payload.kind];
14
- // Idempotent: a duplicate dispatch must not briefly downgrade
15
- // 'Completed' back to 'In-Progress' (would clear loaded data from a
16
- // consumer's perspective) nor restart the in-flight epic stream.
17
- // The hook (`useFetchTransferAccountsForFlow`) is the sole caller and
18
- // already dedupes via `store.getState()`; this guard is defense in
19
- // depth for any future caller.
20
- if (slice.fetchState === 'In-Progress' ||
21
- slice.fetchState === 'Completed') {
22
- return;
23
- }
24
- slice.fetchState = 'In-Progress';
25
- },
26
- updateAccountsForTransferFlow(draft, action) {
27
- const slice = draft.transferAccountsByType[action.payload.kind];
28
- slice.fetchState = 'Completed';
29
- slice.accountIds = action.payload.accountIds;
30
- },
31
- updateAccountsForTransferFlowFailure(draft, action) {
32
- draft.transferAccountsByType[action.payload.kind].fetchState = 'Error';
33
- },
34
- createTransferEntry: {
35
- prepare(payload) {
36
- return { payload };
37
- },
38
- /**
39
- * Defense-in-depth: clear any stale `lastTransferEntryReplacement` on a
40
- * fresh dispatch so a second `createTransferEntry` never inherits the
41
- * previous run's replacement signal (e.g. if the prior `timer(0)` cleanup
42
- * never fired). Mirrors the host hook's `consumedReplacementRef` guard
43
- * (see `useTransferEntryRouteReplacement` in zeni-web-app-ui).
44
- */
45
- reducer(draft) {
46
- draft.createTransferEntryStatus = 'In-Progress';
47
- draft.lastTransferEntryReplacement = undefined;
48
- },
49
- },
50
- createTransferEntrySuccess(draft) {
51
- draft.createTransferEntryStatus = 'Completed';
52
- },
53
- createTransferEntryFailure(draft) {
54
- draft.createTransferEntryStatus = 'Error';
55
- },
56
- resetCreateTransferEntryStatus(draft) {
57
- draft.createTransferEntryStatus = 'Not-Started';
58
- },
59
- createTransferEntryReplacedTransaction: {
60
- prepare(previousTransactionId, newTransactionId) {
61
- return { payload: { newTransactionId, previousTransactionId } };
62
- },
63
- reducer(draft, action) {
64
- draft.lastTransferEntryReplacement = action.payload;
65
- },
66
- },
67
- /**
68
- * One-shot acknowledgement: the host has consumed the route-replacement
69
- * signal and navigated to the new transaction url, so we can drop the
70
- * record. Re-dispatching is idempotent.
71
- */
72
- clearTransferEntryRouteReplacement(draft) {
73
- draft.lastTransferEntryReplacement = undefined;
74
- },
75
- /**
76
- * Full slice reset. Dispatched from `clearAllEpic` on tenant switch so
77
- * stale per-tenant state (account-id pools, status, replacement signal)
78
- * doesn't bleed across tenants.
79
- */
80
- clearCreateTransferEntry(draft) {
81
- Object.assign(draft, exports.initialState);
82
- },
83
- },
84
- });
85
- _a = createTransferEntrySlice.actions, exports.fetchAccountsForTransferFlow = _a.fetchAccountsForTransferFlow, exports.updateAccountsForTransferFlow = _a.updateAccountsForTransferFlow, exports.updateAccountsForTransferFlowFailure = _a.updateAccountsForTransferFlowFailure, exports.createTransferEntry = _a.createTransferEntry, exports.createTransferEntrySuccess = _a.createTransferEntrySuccess, exports.createTransferEntryFailure = _a.createTransferEntryFailure, exports.resetCreateTransferEntryStatus = _a.resetCreateTransferEntryStatus, exports.createTransferEntryReplacedTransaction = _a.createTransferEntryReplacedTransaction, exports.clearTransferEntryRouteReplacement = _a.clearTransferEntryRouteReplacement, exports.clearCreateTransferEntry = _a.clearCreateTransferEntry;
86
- exports.default = createTransferEntrySlice.reducer;
@@ -1,39 +0,0 @@
1
- import { AccountBase } from '../../entity/account/accountState';
2
- import { RootState } from '../../reducer';
3
- import { TransferEntryRouteReplacement } from './createTransferEntryState';
4
- export declare function getCreateTransferEntryStatus(state: RootState): import("../..").FetchState;
5
- export declare function getLastTransferEntryReplacement(state: RootState): TransferEntryRouteReplacement | undefined;
6
- /**
7
- * Shared resolver for the credit/debit dropdowns in the transfer drawer.
8
- *
9
- * Resolution policy (intentional):
10
- * 1. Prefer the dedicated API fetch results (`transferEntryEligible` for the
11
- * debit pool, `creditCardOnlyEligible` for the credit-card-payment credit
12
- * pool).
13
- * 2. If the dedicated fetch returns an empty list while the COA is loaded,
14
- * fall back to the COA: the full account list for `transferEntryEligible`,
15
- * and COA accounts filtered to `credit_card` for `creditCardOnlyEligible`.
16
- * This keeps the dropdown populated for older tenants where the dedicated
17
- * endpoints haven't been backfilled yet.
18
- *
19
- * Intent — what this selector deliberately does NOT do:
20
- * - Does NOT distinguish "fetch in-flight" / "fetch errored" / "fetch returned
21
- * empty" — all three collapse to the COA fallback. The product preference
22
- * is "always show something selectable" over "show a spinner that may never
23
- * resolve". Loading/error UI belongs in the view layer; if you need a
24
- * spinner, observe the `fetchState` on `transferAccountsByType[kind]`
25
- * separately rather than changing the resolution policy here.
26
- * - Does NOT enforce "API result is authoritative even if empty" — a tenant
27
- * whose dedicated endpoint is correctly returning `[]` (e.g. no eligible
28
- * transfer destinations) will still see the COA. That trade-off is
29
- * accepted because the alternative blocks the user from picking anything;
30
- * the backend distinguishes "no result" from "endpoint not implemented" by
31
- * surfacing an error response, which the view layer handles separately.
32
- *
33
- * Memoized with reselect so consuming view-models don't recompute on every
34
- * unrelated state change.
35
- */
36
- export declare const getResolvedTransferAccounts: (state: RootState) => {
37
- creditCardTransferAccountsList: AccountBase[];
38
- transferAccountsList: AccountBase[];
39
- };
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getResolvedTransferAccounts = void 0;
4
- exports.getCreateTransferEntryStatus = getCreateTransferEntryStatus;
5
- exports.getLastTransferEntryReplacement = getLastTransferEntryReplacement;
6
- const toolkit_1 = require("@reduxjs/toolkit");
7
- const accountSelector_1 = require("../../entity/account/accountSelector");
8
- const accountListSelector_1 = require("../accountList/accountListSelector");
9
- function getCreateTransferEntryStatus(state) {
10
- return state.createTransferEntryState.createTransferEntryStatus;
11
- }
12
- function getLastTransferEntryReplacement(state) {
13
- return state.createTransferEntryState.lastTransferEntryReplacement;
14
- }
15
- /**
16
- * Shared resolver for the credit/debit dropdowns in the transfer drawer.
17
- *
18
- * Resolution policy (intentional):
19
- * 1. Prefer the dedicated API fetch results (`transferEntryEligible` for the
20
- * debit pool, `creditCardOnlyEligible` for the credit-card-payment credit
21
- * pool).
22
- * 2. If the dedicated fetch returns an empty list while the COA is loaded,
23
- * fall back to the COA: the full account list for `transferEntryEligible`,
24
- * and COA accounts filtered to `credit_card` for `creditCardOnlyEligible`.
25
- * This keeps the dropdown populated for older tenants where the dedicated
26
- * endpoints haven't been backfilled yet.
27
- *
28
- * Intent — what this selector deliberately does NOT do:
29
- * - Does NOT distinguish "fetch in-flight" / "fetch errored" / "fetch returned
30
- * empty" — all three collapse to the COA fallback. The product preference
31
- * is "always show something selectable" over "show a spinner that may never
32
- * resolve". Loading/error UI belongs in the view layer; if you need a
33
- * spinner, observe the `fetchState` on `transferAccountsByType[kind]`
34
- * separately rather than changing the resolution policy here.
35
- * - Does NOT enforce "API result is authoritative even if empty" — a tenant
36
- * whose dedicated endpoint is correctly returning `[]` (e.g. no eligible
37
- * transfer destinations) will still see the COA. That trade-off is
38
- * accepted because the alternative blocks the user from picking anything;
39
- * the backend distinguishes "no result" from "endpoint not implemented" by
40
- * surfacing an error response, which the view layer handles separately.
41
- *
42
- * Memoized with reselect so consuming view-models don't recompute on every
43
- * unrelated state change.
44
- */
45
- exports.getResolvedTransferAccounts = (0, toolkit_1.createSelector)([
46
- (state) => state.accountState,
47
- (state) => state.accountListState,
48
- (state) => state.createTransferEntryState.transferAccountsByType
49
- .transferEntryEligible.accountIds,
50
- (state) => state.createTransferEntryState.transferAccountsByType
51
- .creditCardOnlyEligible.accountIds,
52
- ], (accountState, accountListState, transferEligibleIds, creditCardOnlyIds) => {
53
- const accountList = (0, accountListSelector_1.getAccountList)(accountState, accountListState, 'accountList');
54
- const transferEligibleFromApi = transferEligibleIds
55
- .map((id) => (0, accountSelector_1.getAccountBaseForTransferAccounts)(accountState, id))
56
- .filter((account) => account != null);
57
- const coaFallbackAllAccounts = accountList.accounts
58
- .map((a) => (0, accountSelector_1.getAccountBase)(accountState, a.accountId, 'account_list'))
59
- .filter((account) => account != null);
60
- const transferAccountsList = transferEligibleFromApi.length > 0
61
- ? transferEligibleFromApi
62
- : coaFallbackAllAccounts;
63
- const creditCardFromApi = creditCardOnlyIds
64
- .map((id) => (0, accountSelector_1.getAccountBaseForCreditCardTransferAccounts)(accountState, id))
65
- .filter((account) => account != null);
66
- const coaFallbackCreditCards = coaFallbackAllAccounts.filter((a) => a.accountType === 'credit_card');
67
- const creditCardTransferAccountsList = creditCardFromApi.length > 0 ? creditCardFromApi : coaFallbackCreditCards;
68
- return { creditCardTransferAccountsList, transferAccountsList };
69
- });
@@ -1,30 +0,0 @@
1
- import { FetchState, ID } from '../../commonStateTypes/common';
2
- import { TransactionID } from '../../entity/transaction/stateTypes/transaction';
3
- /** Which pool `fetchAccountsForTransferFlow` / transfer-flow epic should load. */
4
- export declare const TRANSFER_ACCOUNTS_FETCH_TYPE: readonly ["transferEntryEligible", "creditCardOnlyEligible"];
5
- export type TransferAccountsFetchType = (typeof TRANSFER_ACCOUNTS_FETCH_TYPE)[number];
6
- export interface TransferAccountsState {
7
- accountIds: ID[];
8
- fetchState: FetchState;
9
- }
10
- export type TransferEntryRouteReplacement = {
11
- newTransactionId: TransactionID;
12
- previousTransactionId: TransactionID;
13
- };
14
- export interface CreateTransferEntryState {
15
- createTransferEntryStatus: FetchState;
16
- /**
17
- * Set when create-transfer returns a new transaction id (the source expense
18
- * has been replaced by a new transfer/credit-card-payment row). The host
19
- * navigates to the new url and then dispatches
20
- * `clearTransferEntryRouteReplacement` to clear this one-shot signal.
21
- */
22
- lastTransferEntryReplacement: TransferEntryRouteReplacement | undefined;
23
- /**
24
- * Per-type fetch state + account-id list for the dropdowns shown in the
25
- * transfer drawer (eligible accounts for `transfer`, credit-card-only
26
- * accounts for `credit_card_payment`).
27
- */
28
- transferAccountsByType: Record<TransferAccountsFetchType, TransferAccountsState>;
29
- }
30
- export declare const initialCreateTransferEntryState: CreateTransferEntryState;