@zeniai/client-epic-state 4.19.83 → 4.19.84-betaVR1

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 (113) hide show
  1. package/lib/entity/account/accountPayload.d.ts +2 -0
  2. package/lib/entity/account/accountPayload.js +2 -0
  3. package/lib/entity/account/accountState.d.ts +2 -0
  4. package/lib/entity/company/companyPayload.d.ts +13 -0
  5. package/lib/entity/company/companyPayload.js +21 -0
  6. package/lib/entity/company/companyStateTypes.d.ts +13 -0
  7. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  8. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  9. package/lib/epic.d.ts +12 -1
  10. package/lib/epic.js +12 -1
  11. package/lib/esm/entity/account/accountPayload.js +2 -0
  12. package/lib/esm/entity/chargeCardTransaction/chargeCardTransactionPayload.js +2 -2
  13. package/lib/esm/entity/company/companyPayload.js +21 -0
  14. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  15. package/lib/esm/epic.js +12 -1
  16. package/lib/esm/index.js +12 -8
  17. package/lib/esm/view/companyView/epic/companyPassport/updateCompanyDetailsEpic.js +6 -0
  18. package/lib/esm/view/companyView/types/companyPassport/companyPassportLocalData.js +13 -0
  19. package/lib/esm/view/companyView/types/companyPassportViewPayload.js +55 -12
  20. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +24 -0
  21. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
  22. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
  23. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +47 -0
  24. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
  25. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +34 -0
  26. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +57 -0
  27. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +68 -0
  28. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  29. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +42 -0
  30. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/triggerReviewTabRefetchEpic.js +2 -3
  31. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
  32. package/lib/esm/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -2
  33. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +147 -1
  34. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +401 -1
  35. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +20 -1
  36. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +224 -1
  37. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  38. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  39. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -4
  40. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  41. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  42. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  43. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  44. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  45. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  46. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  47. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  48. package/lib/esm/view/spendManagement/commonSetup/types/businessVerification.js +148 -1
  49. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  50. package/lib/esm/zeniAPI.js +0 -2
  51. package/lib/index.d.ts +14 -9
  52. package/lib/index.js +87 -44
  53. package/lib/view/companyView/epic/companyPassport/updateCompanyDetailsEpic.js +6 -0
  54. package/lib/view/companyView/types/companyPassport/companyDetailsLocalData.d.ts +13 -0
  55. package/lib/view/companyView/types/companyPassport/companyPassportLocalData.js +13 -0
  56. package/lib/view/companyView/types/companyPassportViewPayload.d.ts +1 -1
  57. package/lib/view/companyView/types/companyPassportViewPayload.js +55 -12
  58. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +15 -0
  59. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +28 -0
  60. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
  61. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
  62. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
  63. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
  64. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
  65. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +51 -0
  66. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
  67. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
  68. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
  69. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +38 -0
  70. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
  71. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +62 -0
  72. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
  73. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +72 -0
  74. package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  75. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +13 -0
  76. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +47 -0
  77. package/lib/view/expenseAutomationView/epics/transactionCategorization/triggerReviewTabRefetchEpic.js +2 -3
  78. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
  79. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
  80. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  81. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -2
  82. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +107 -0
  83. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +158 -0
  84. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +70 -3
  85. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +403 -2
  86. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
  87. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +21 -2
  88. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +69 -1
  89. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
  90. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  91. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +223 -0
  92. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  93. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +124 -0
  94. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
  95. package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  96. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +1 -0
  97. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -3
  98. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  99. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  100. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  101. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  102. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.d.ts +1 -1
  103. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  104. package/lib/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  105. package/lib/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  106. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +14 -0
  107. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  108. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +14 -0
  109. package/lib/view/spendManagement/commonSetup/types/businessVerification.d.ts +43 -0
  110. package/lib/view/spendManagement/commonSetup/types/businessVerification.js +150 -0
  111. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  112. package/lib/zeniAPI.js +0 -2
  113. package/package.json +2 -2
@@ -0,0 +1,57 @@
1
+ import { EMPTY, concat, from, of } from 'rxjs';
2
+ import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
5
+ import { extractTransactionPayloadsFromBatchFiles, filterBatchListItemsForBatchDetailsFetch, isBatchDetailsApiStatusCompleted, shouldFetchBatchDetailsForBatchId, toBatchDetails, } from '../../payload/missingReceiptsPayload';
6
+ import { batchDetailFetchFailed, fetchBulkUploadBatchDetails, fetchBulkUploadBatchesSuccess, fetchMoreBatchDetailsComplete, setInitialBatchDetailsLoading, storeBatchDetails, } from '../../reducers/missingReceiptsViewReducer';
7
+ const INITIAL_BATCH_PAGE_SIZE = 1;
8
+ export function fetchBatchDetailsByIds(batchIds, zeniAPI) {
9
+ if (batchIds.length === 0) {
10
+ return EMPTY;
11
+ }
12
+ return from(batchIds).pipe(mergeMap((batchId) => zeniAPI
13
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
14
+ .pipe(mergeMap((response) => {
15
+ if (!isSuccessResponse(response) ||
16
+ response.data == null ||
17
+ !isBatchDetailsApiStatusCompleted(response.data.status)) {
18
+ return EMPTY;
19
+ }
20
+ const actions = [];
21
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
22
+ if (transactionPayloads.length > 0) {
23
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
24
+ }
25
+ actions.push(storeBatchDetails(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
26
+ return from(actions);
27
+ }), catchError((error) => {
28
+ console.error(`Failed to fetch batch details for ${batchId}:`, createZeniAPIStatus('Unexpected Error', 'Fetch batch details errored out: ' +
29
+ JSON.stringify(error)));
30
+ return of(batchDetailFetchFailed({ batchId }));
31
+ })), 5));
32
+ }
33
+ export const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatchesSuccess.match), mergeMap((action) => {
34
+ const batchList = action.payload.batchList;
35
+ const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
36
+ /** Only completed list rows may trigger batch-details API; preserve platform order. */
37
+ const completedBatchesMissingDetails = filterBatchListItemsForBatchDetailsFetch(batchList).filter((batch) => batchDetailsById[batch.batchId] == null);
38
+ const completedBatchIds = completedBatchesMissingDetails.map((batch) => batch.batchId);
39
+ const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
40
+ if (batchIdsToFetch.length === 0) {
41
+ /**
42
+ * List refresh can complete while no row is `completed` yet (multi-fetch skips), or
43
+ * `currentBatchId` may not appear in the filtered list but still needs `GET /batches/:id`.
44
+ * Fall back to the single-batch-details epic so `phase` and details can resolve.
45
+ */
46
+ const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
47
+ const currentId = bulkUpload.currentBatchId;
48
+ if (currentId != null &&
49
+ bulkUpload.phase === 'matching' &&
50
+ bulkUpload.batchDetailsById[currentId] == null &&
51
+ shouldFetchBatchDetailsForBatchId(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentId)) {
52
+ return of(fetchBulkUploadBatchDetails());
53
+ }
54
+ return EMPTY;
55
+ }
56
+ return concat(of(setInitialBatchDetailsLoading()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), of(fetchMoreBatchDetailsComplete()));
57
+ }));
@@ -0,0 +1,68 @@
1
+ import { from, merge, of } from 'rxjs';
2
+ import { catchError, debounceTime, filter, mergeMap, switchMap } from 'rxjs/operators';
3
+ import { convertToPeriod } from '../../../../commonStateTypes/timePeriod';
4
+ import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
6
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
7
+ import { supportedTransactionPayloadToManualSearchResult } from '../../payload/missingReceiptsPayload';
8
+ import { searchTransactionsForManualMatch, searchTransactionsForManualMatchFailure, searchTransactionsForManualMatchSuccess, } from '../../reducers/missingReceiptsViewReducer';
9
+ import { toTransactionsSortKey } from '../../types/transactionsViewState';
10
+ /**
11
+ * `auto_categorized` for manual transaction search (Unmatched).
12
+ * Backend contract TBD — align with `fetchTransactionCategorizationEpic` (`selectedTab === 'autoCategorized'`)
13
+ * when the expense-automation API documents the intended filter for this flow.
14
+ */
15
+ export const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
16
+ export const searchTransactionsForManualMatchEpic = (actions$, state$, zeniAPI) => {
17
+ const searchActions$ = actions$.pipe(filter(searchTransactionsForManualMatch.match));
18
+ const pagination$ = searchActions$.pipe(filter((a) => a.payload.pageToken != null));
19
+ const newSearch$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null), debounceTime(300));
20
+ return merge(pagination$, newSearch$).pipe(switchMap((action) => {
21
+ const { query, pageToken } = action.payload;
22
+ const state = state$.value;
23
+ const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
24
+ const currentTenant = getCurrentTenant(state);
25
+ const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
26
+ if (selectedPeriod == null) {
27
+ return of(searchTransactionsForManualMatchFailure({
28
+ error: createZeniAPIStatus('Unexpected Error', 'Manual search requires a selected accounting period.'),
29
+ }));
30
+ }
31
+ const period = convertToPeriod(selectedPeriod);
32
+ const queryParam = {
33
+ start_date: period.start,
34
+ end_date: period.end,
35
+ auto_categorized: MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED,
36
+ sort_by: toTransactionsSortKey(sortKey),
37
+ sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
38
+ page_token: pageToken ?? null,
39
+ page_size: manualSearch.pageSize,
40
+ search_text: query,
41
+ };
42
+ return zeniAPI
43
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
44
+ .pipe(mergeMap((response) => {
45
+ if (isSuccessResponse(response) && response.data != null) {
46
+ const { transactions, next_page_token, total_count } = response.data;
47
+ const append = pageToken != null;
48
+ const results = transactions.map(supportedTransactionPayloadToManualSearchResult);
49
+ const actionsOut = [
50
+ updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
51
+ searchTransactionsForManualMatchSuccess({
52
+ append,
53
+ nextPageToken: next_page_token ?? null,
54
+ results,
55
+ totalCount: total_count,
56
+ }),
57
+ ];
58
+ return from(actionsOut);
59
+ }
60
+ return of(searchTransactionsForManualMatchFailure({
61
+ error: response.status,
62
+ }));
63
+ }), catchError((error) => of(searchTransactionsForManualMatchFailure({
64
+ error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
65
+ JSON.stringify(error)),
66
+ }))));
67
+ }));
68
+ };
@@ -12,11 +12,13 @@ export const uploadMissingReceiptSuccessEpic = (actions$, state$) => actions$.pi
12
12
  updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
13
13
  if (currentTenant != null) {
14
14
  const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
15
- updateActions.push(fetchMonthEndCloseChecks({
16
- tenantId: currentTenant.tenantId,
17
- period: monthEndChecksPeriod,
18
- refreshViewInBackground: true,
19
- }));
15
+ if (monthEndChecksPeriod != null) {
16
+ updateActions.push(fetchMonthEndCloseChecks({
17
+ tenantId: currentTenant.tenantId,
18
+ period: monthEndChecksPeriod,
19
+ refreshViewInBackground: true,
20
+ }));
21
+ }
20
22
  }
21
23
  return from(updateActions);
22
24
  }));
@@ -0,0 +1,42 @@
1
+ import { EMPTY, from, merge, of, timer } from 'rxjs';
2
+ import { catchError, debounceTime, filter, mergeMap, switchMap, takeUntil, } from 'rxjs/operators';
3
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
+ import { isSuccessResponse } from '../../../../responsePayload';
5
+ import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
6
+ import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, } from '../../reducers/missingReceiptsViewReducer';
7
+ /** First poll after upload; then interval while batch not resolved via Pusher or API. */
8
+ const FALLBACK_FIRST_DELAY_MS = 30000;
9
+ const FALLBACK_POLL_INTERVAL_MS = 10000;
10
+ /**
11
+ * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
12
+ * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
13
+ */
14
+ export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
15
+ fetchBulkUploadBatches({
16
+ cacheOverride: true,
17
+ invalidateBatchDetailsCache: true,
18
+ }),
19
+ requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
20
+ ])));
21
+ export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
22
+ const { batchId } = action.payload;
23
+ return timer(FALLBACK_FIRST_DELAY_MS, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId)), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))), switchMap(() => zeniAPI
24
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
25
+ .pipe(mergeMap((response) => {
26
+ /** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
27
+ if (isSuccessResponse(response) && response.data != null) {
28
+ if (isBatchDetailsApiStatusCompleted(response.data.status)) {
29
+ const actions = [];
30
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
31
+ if (transactionPayloads.length > 0) {
32
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
33
+ }
34
+ actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
35
+ actions.push(fetchBulkUploadBatches(true));
36
+ actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
37
+ return from(actions);
38
+ }
39
+ }
40
+ return EMPTY;
41
+ }), catchError(() => of()))));
42
+ }));
@@ -4,15 +4,14 @@ import { convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/ti
4
4
  import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
5
  import { backgroundRefetchReviewTab, syncTransactionCategorizationFromDetailSave, } from '../../reducers/transactionsViewReducer';
6
6
  export const triggerReviewTabRefetchEpic = (actions$, state$) => actions$.pipe(filter(syncTransactionCategorizationFromDetailSave.match), mergeMap((action) => {
7
- const { pendingReviewLineIds, transactionId, isUncategorizedExpenseCategoryEnabled } = action.payload;
7
+ const { pendingReviewLineIds, transactionId, isUncategorizedExpenseCategoryEnabled, } = action.payload;
8
8
  if (pendingReviewLineIds.length === 0) {
9
9
  return EMPTY;
10
10
  }
11
11
  const state = state$.value;
12
12
  // Only trigger when the transaction was auto-only (not in review tab after reducer ran)
13
13
  const reviewLocalData = state.expenseAutomationTransactionsViewState
14
- .transactionCategorizationView.review
15
- .transactionReviewLocalDataById[transactionId.id];
14
+ .transactionCategorizationView.review.transactionReviewLocalDataById[transactionId.id];
16
15
  if (reviewLocalData != null) {
17
16
  return EMPTY;
18
17
  }
@@ -0,0 +1,24 @@
1
+ import { from } from 'rxjs';
2
+ import { filter, mergeMap } from 'rxjs/operators';
3
+ import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
4
+ import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
5
+ import { fetchMonthEndCloseChecks } from '../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer';
6
+ import { uploadTransactionCategorizationReceiptSuccess } from '../../reducers/transactionsViewReducer';
7
+ export const uploadTransactionReceiptSuccessEpic = (actions$, state$) => actions$.pipe(filter(uploadTransactionCategorizationReceiptSuccess.match), mergeMap((action) => {
8
+ const { transactionPayload, updateType } = action.payload;
9
+ const updateActions = [];
10
+ const currentTenant = getCurrentTenant(state$.value);
11
+ const selectedPeriodByTenantId = state$.value.expenseAutomationViewState.selectedPeriodByTenantId;
12
+ updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
13
+ if (currentTenant != null) {
14
+ const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
15
+ if (monthEndChecksPeriod != null) {
16
+ updateActions.push(fetchMonthEndCloseChecks({
17
+ tenantId: currentTenant.tenantId,
18
+ period: monthEndChecksPeriod,
19
+ refreshViewInBackground: true,
20
+ }));
21
+ }
22
+ }
23
+ return from(updateActions);
24
+ }));
@@ -41,8 +41,8 @@ export const filterAutoTabLineItems = (tabView, transactionId, updatedTransactio
41
41
  if (localData == null) {
42
42
  return;
43
43
  }
44
- const currentAutoLineIds = localData.transactionReviewLocalData.tabSpecificLineItems
45
- .autoCategorized ?? [];
44
+ const currentAutoLineIds = localData.transactionReviewLocalData.tabSpecificLineItems.autoCategorized ??
45
+ [];
46
46
  const linesById = new Map(updatedTransaction.lines?.map((l) => [l.id, l]));
47
47
  const retainedLineIds = currentAutoLineIds.filter((lineId) => {
48
48
  const line = linesById.get(lineId);
@@ -1 +1,147 @@
1
- export {};
1
+ import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
+ import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
+ // -- Converter functions --
4
+ export function toBatchFile(payload, filesEndPoint) {
5
+ return {
6
+ attachmentId: payload.attachment_id,
7
+ candidates: payload.candidates?.map((c) => ({
8
+ transactionId: c.transaction_id,
9
+ matchScore: c.match_score,
10
+ })),
11
+ fileDownloadUrl: payload.file_id != null && filesEndPoint != null
12
+ ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
13
+ : null,
14
+ fileId: payload.file_id,
15
+ filePreviewUrl: payload.file_preview_url,
16
+ filename: payload.filename,
17
+ matchSource: payload.match_source,
18
+ matchedTransactionId: payload.matched_transaction?.transaction_id,
19
+ status: payload.status,
20
+ };
21
+ }
22
+ export function extractTransactionPayloadsFromBatchFiles(files) {
23
+ const seen = new Set();
24
+ const payloads = [];
25
+ for (const file of files) {
26
+ if (file.matched_transaction != null) {
27
+ const id = file.matched_transaction.transaction_id;
28
+ if (!seen.has(id)) {
29
+ seen.add(id);
30
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
31
+ }
32
+ }
33
+ if (file.candidates != null) {
34
+ for (const candidate of file.candidates) {
35
+ const id = candidate.transaction_id;
36
+ if (!seen.has(id)) {
37
+ seen.add(id);
38
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
39
+ }
40
+ }
41
+ }
42
+ }
43
+ return payloads;
44
+ }
45
+ function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
46
+ return {
47
+ transaction_id: payload.transaction_id,
48
+ transaction_type: payload.transaction_type ?? 'expense',
49
+ transaction_date: payload.transaction_date ?? '',
50
+ currency_code: payload.currency_code,
51
+ total_amount: payload.amount,
52
+ vendor_name: payload.vendor_name,
53
+ logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
54
+ };
55
+ }
56
+ export function toBatchSummary(payload) {
57
+ return {
58
+ failed: payload.failed,
59
+ matched: payload.matched,
60
+ noMatch: payload.no_match,
61
+ possibleMatches: payload.possible_matches,
62
+ total: payload.total,
63
+ };
64
+ }
65
+ export function toBatchDetails(payload, filesEndPoint) {
66
+ return {
67
+ batchId: payload.batch_id,
68
+ createdAt: payload.created_at,
69
+ files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
70
+ status: payload.status,
71
+ summary: toBatchSummary(payload.summary),
72
+ };
73
+ }
74
+ /** Batch list `status` is a string from the API — compare case-insensitively. */
75
+ export function isBatchListStatusCompleted(status) {
76
+ return status.toLowerCase() === 'completed';
77
+ }
78
+ /**
79
+ * Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
80
+ * `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
81
+ * statuses for UI; only `completed` rows should trigger batch-details requests.
82
+ */
83
+ export function filterBatchListItemsForBatchDetailsFetch(batches) {
84
+ return batches.filter((b) => isBatchListStatusCompleted(b.status));
85
+ }
86
+ /**
87
+ * Batch details API response `status` field — only completed payloads should be stored from
88
+ * multi-batch fetch paths (list can be briefly stale vs. live processing state).
89
+ */
90
+ export function isBatchDetailsApiStatusCompleted(status) {
91
+ return status.toLowerCase() === 'completed';
92
+ }
93
+ export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
94
+ for (const list of Object.values(batchListByPeriod)) {
95
+ const found = list.find((b) => b.batchId === batchId);
96
+ if (found != null) {
97
+ return found;
98
+ }
99
+ }
100
+ return undefined;
101
+ }
102
+ /**
103
+ * Whether it is appropriate to call `GET .../batches/:id` for details.
104
+ * Skips when live batch status or batch list row indicates the batch is not completed yet.
105
+ * When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
106
+ */
107
+ export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
108
+ const live = batchStatusById[batchId]?.status;
109
+ if (live === 'completed') {
110
+ return true;
111
+ }
112
+ if (live === 'pending' || live === 'processing') {
113
+ return false;
114
+ }
115
+ const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
116
+ if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
117
+ return false;
118
+ }
119
+ return true;
120
+ }
121
+ export function toBatchListItem(payload) {
122
+ return {
123
+ batchId: payload.batch_id,
124
+ createdAt: payload.created_at,
125
+ failedCount: payload.failed_count,
126
+ matchedCount: payload.matched_count,
127
+ noMatchCount: payload.no_match_count,
128
+ possibleMatchesCount: payload.possible_matches_count,
129
+ status: payload.status,
130
+ totalFiles: payload.total_files,
131
+ };
132
+ }
133
+ /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
134
+ export function supportedTransactionPayloadToManualSearchResult(payload) {
135
+ const amountPayload = getTransactionPayloadAmount(payload);
136
+ return {
137
+ amount: amountPayload.amount,
138
+ currencyCode: amountPayload.currencyCode,
139
+ entityId: payload.vendor_id ?? payload.customer_id ?? '',
140
+ memo: payload.transaction_memo ?? '',
141
+ transactionDate: payload.transaction_date,
142
+ transactionId: payload.transaction_id,
143
+ transactionType: payload.transaction_type,
144
+ vendorName: payload.vendor_name ?? '',
145
+ vendorLogo: toURL(payload.logo)?.href,
146
+ };
147
+ }