@zeniai/client-epic-state 4.20.7 → 4.20.8

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 (178) hide show
  1. package/lib/commonStateTypes/coaBalance/additionalBalances/getSummationBalance.d.ts +1 -1
  2. package/lib/commonStateTypes/coaBalance/coaBalanceType.d.ts +2 -0
  3. package/lib/commonStateTypes/coaBalance/coaBalanceType.js +6 -0
  4. package/lib/commonStateTypes/currencyHelper.d.ts +3 -0
  5. package/lib/commonStateTypes/currencyHelper.js +6 -1
  6. package/lib/commonStateTypes/reduceFetchState.d.ts +9 -0
  7. package/lib/commonStateTypes/reduceFetchState.js +26 -0
  8. package/lib/entity/account/accountPayload.d.ts +2 -0
  9. package/lib/entity/account/accountPayload.js +2 -0
  10. package/lib/entity/account/accountState.d.ts +2 -0
  11. package/lib/entity/customer/customerState.d.ts +0 -2
  12. package/lib/entity/customer/customerState.js +0 -5
  13. package/lib/entity/depositAccount/depositAccount.d.ts +1 -1
  14. package/lib/entity/depositAccount/depositAccount.js +8 -1
  15. package/lib/entity/reimbursement/reimbursementPayload.d.ts +2 -0
  16. package/lib/entity/reimbursement/reimbursementPayload.js +7 -0
  17. package/lib/entity/reimbursement/reimbursementState.d.ts +2 -0
  18. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  19. package/lib/entity/snackbar/snackbarTypes.js +2 -0
  20. package/lib/entity/task/taskPayload.d.ts +1 -0
  21. package/lib/entity/task/taskPayload.js +1 -0
  22. package/lib/entity/task/taskState.d.ts +1 -0
  23. package/lib/entity/userGroups/userGroupsPayload.d.ts +7 -0
  24. package/lib/entity/userGroups/userGroupsPayload.js +10 -0
  25. package/lib/entity/userGroups/userGroupsReducer.d.ts +8 -0
  26. package/lib/entity/userGroups/userGroupsReducer.js +29 -0
  27. package/lib/entity/userGroups/userGroupsSelector.d.ts +4 -0
  28. package/lib/entity/userGroups/userGroupsSelector.js +12 -0
  29. package/lib/entity/userGroups/userGroupsState.d.ts +9 -0
  30. package/lib/entity/userGroups/userGroupsState.js +2 -0
  31. package/lib/epic.d.ts +15 -1
  32. package/lib/epic.js +15 -1
  33. package/lib/esm/commonStateTypes/coaBalance/coaBalanceType.js +5 -0
  34. package/lib/esm/commonStateTypes/currencyHelper.js +5 -0
  35. package/lib/esm/commonStateTypes/reduceFetchState.js +25 -0
  36. package/lib/esm/entity/account/accountPayload.js +2 -0
  37. package/lib/esm/entity/customer/customerState.js +1 -4
  38. package/lib/esm/entity/depositAccount/depositAccount.js +8 -1
  39. package/lib/esm/entity/reimbursement/reimbursementPayload.js +7 -0
  40. package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
  41. package/lib/esm/entity/task/taskPayload.js +1 -0
  42. package/lib/esm/entity/userGroups/userGroupsPayload.js +7 -0
  43. package/lib/esm/entity/userGroups/userGroupsReducer.js +25 -0
  44. package/lib/esm/entity/userGroups/userGroupsSelector.js +8 -0
  45. package/lib/esm/entity/userGroups/userGroupsState.js +1 -0
  46. package/lib/esm/epic.js +15 -1
  47. package/lib/esm/index.js +19 -10
  48. package/lib/esm/reducer.js +6 -0
  49. package/lib/esm/view/arAgingView/arAgingReport/arAgingReducer.js +1 -1
  50. package/lib/esm/view/arAgingView/arAgingReport/arAgingSelector.js +1 -1
  51. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +33 -0
  52. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +29 -0
  53. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
  54. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
  55. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +49 -0
  56. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
  57. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +33 -0
  58. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +56 -0
  59. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +12 -0
  60. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +98 -0
  61. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +71 -0
  62. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  63. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +86 -0
  64. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
  65. package/lib/esm/view/expenseAutomationView/helpers/bulkUploadTiming.js +16 -0
  66. package/lib/esm/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +13 -0
  67. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +198 -1
  68. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +456 -2
  69. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +23 -1
  70. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +245 -1
  71. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  72. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +44 -0
  73. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  74. package/lib/esm/view/financeStatement/financeStatementReducer.js +11 -8
  75. package/lib/esm/view/financeStatement/financeStatementSelector.js +24 -9
  76. package/lib/esm/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +17 -0
  77. package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +331 -0
  78. package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +9 -0
  79. package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +6 -1
  80. package/lib/esm/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
  81. package/lib/esm/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
  82. package/lib/esm/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +262 -0
  83. package/lib/esm/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +9 -7
  84. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  85. package/lib/esm/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
  86. package/lib/esm/view/taskManager/taskListView/taskListSelector.js +3 -1
  87. package/lib/esm/view/userGroupListView/userGroupListViewReducer.js +65 -0
  88. package/lib/esm/view/userGroupListView/userGroupListViewSelector.js +16 -0
  89. package/lib/esm/view/userGroupListView/userGroupListViewState.js +1 -0
  90. package/lib/esm/view/userListView/fetchUserListByTypeEpic.js +11 -0
  91. package/lib/esm/zeniAPI.js +0 -2
  92. package/lib/index.d.ts +20 -12
  93. package/lib/index.js +97 -34
  94. package/lib/reducer.d.ts +6 -0
  95. package/lib/reducer.js +6 -0
  96. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  97. package/lib/view/arAgingView/arAgingReport/arAgingReducer.js +2 -2
  98. package/lib/view/arAgingView/arAgingReport/arAgingSelector.js +5 -5
  99. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.d.ts +13 -0
  100. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadMatchResultToastEpic.js +37 -0
  101. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +18 -0
  102. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +33 -0
  103. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
  104. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
  105. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
  106. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
  107. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
  108. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +53 -0
  109. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
  110. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
  111. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
  112. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +37 -0
  113. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
  114. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +61 -0
  115. package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.d.ts +10 -0
  116. package/lib/view/expenseAutomationView/epics/missingReceipts/refetchCompletedTransactionsOnBulkUploadSortEpic.js +16 -0
  117. package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.d.ts +18 -0
  118. package/lib/view/expenseAutomationView/epics/missingReceipts/restoreBulkUploadAutomatchingOnMountEpic.js +102 -0
  119. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
  120. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +75 -0
  121. package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  122. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +25 -0
  123. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +92 -0
  124. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
  125. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
  126. package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.d.ts +16 -0
  127. package/lib/view/expenseAutomationView/helpers/bulkUploadTiming.js +19 -0
  128. package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.d.ts +7 -0
  129. package/lib/view/expenseAutomationView/helpers/rollingCalendarDateRangeInclusive.js +16 -0
  130. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  131. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +123 -0
  132. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +211 -0
  133. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +86 -3
  134. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +457 -2
  135. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
  136. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +24 -2
  137. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +70 -1
  138. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
  139. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  140. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +244 -0
  141. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  142. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +146 -0
  143. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +54 -1
  144. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
  145. package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  146. package/lib/view/financeStatement/financeStatementReducer.js +11 -8
  147. package/lib/view/financeStatement/financeStatementSelector.d.ts +2 -0
  148. package/lib/view/financeStatement/financeStatementSelector.js +24 -9
  149. package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.d.ts +9 -0
  150. package/lib/view/profitAndLossClassesView/horizontalSectionEmptyBalancesSlice.js +20 -0
  151. package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.d.ts +15 -0
  152. package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelector.js +335 -0
  153. package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.d.ts +111 -0
  154. package/lib/view/profitAndLossClassesView/profitAndLossClassesByClassHorizontalSelectorTypes.js +13 -0
  155. package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.d.ts +4 -2
  156. package/lib/view/profitAndLossClassesView/profitAndLossClassesViewReducer.js +7 -2
  157. package/lib/view/profitAndLossClassesView/profitAndLossClassesViewSelector.js +2 -29
  158. package/lib/view/profitAndLossClassesView/profitAndLossClassesViewState.d.ts +4 -0
  159. package/lib/view/profitAndLossClassesView/profitAndLossForTimeframeClassesViewEpic.js +7 -5
  160. package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.d.ts +6 -0
  161. package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +265 -0
  162. package/lib/view/reportUIOptions/updateReportUIOptionCOABalancesRangeEpic.js +8 -6
  163. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  164. package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.d.ts +1 -0
  165. package/lib/view/taskManager/taskListView/epics/bulkUpdateTaskListEpic.js +1 -0
  166. package/lib/view/taskManager/taskListView/taskListSelector.d.ts +2 -0
  167. package/lib/view/taskManager/taskListView/taskListSelector.js +3 -1
  168. package/lib/view/userGroupListView/userGroupListViewReducer.d.ts +23 -0
  169. package/lib/view/userGroupListView/userGroupListViewReducer.js +69 -0
  170. package/lib/view/userGroupListView/userGroupListViewSelector.d.ts +7 -0
  171. package/lib/view/userGroupListView/userGroupListViewSelector.js +20 -0
  172. package/lib/view/userGroupListView/userGroupListViewState.d.ts +8 -0
  173. package/lib/view/userGroupListView/userGroupListViewState.js +2 -0
  174. package/lib/view/userListView/fetchUserListByTypeEpic.d.ts +3 -1
  175. package/lib/view/userListView/fetchUserListByTypeEpic.js +11 -0
  176. package/lib/view/userListView/userListViewPayload.d.ts +2 -0
  177. package/lib/zeniAPI.js +0 -2
  178. package/package.json +3 -3
@@ -1,6 +1,39 @@
1
- import { createSlice } from '@reduxjs/toolkit';
1
+ import { createAction, createSlice } from '@reduxjs/toolkit';
2
2
  import { toMonthYearPeriodId } from '../../../commonStateTypes/timePeriod';
3
+ import { MIN_MANUAL_TRANSACTION_SEARCH_LENGTH, } from '../types/missingReceiptsViewState';
4
+ export const getCompletedTransactionsCacheKey = (periodId, sortKey, sortOrder, subTab) => `completed-${subTab}-${sortKey}-${sortOrder === 'ascending' ? 'asc' : 'desc'}-${periodId}`;
5
+ export const initialBulkUploadState = {
6
+ batchDetailsById: {},
7
+ batchDetailsPaginationState: { fetchState: 'Not-Started', error: undefined },
8
+ batchListByPeriod: {},
9
+ batchListFetchState: { fetchState: 'Not-Started', error: undefined },
10
+ batchStatusById: {},
11
+ completedSubTab: 'all',
12
+ completedTransactionsByPeriod: {},
13
+ confirmMatchStatus: { fetchState: 'Not-Started', error: undefined },
14
+ currentBatchId: undefined,
15
+ currentResultsTab: 'unmatched',
16
+ failedBatchDetailIds: [],
17
+ manualSearchUiResetKey: 0,
18
+ manualSearch: {
19
+ fetchState: { fetchState: 'Not-Started', error: undefined },
20
+ isLoadingMore: false,
21
+ nextPageToken: null,
22
+ pageSize: 25,
23
+ results: [],
24
+ searchQuery: '',
25
+ totalCount: 0,
26
+ },
27
+ phase: 'idle',
28
+ sortKey: 'date',
29
+ sortOrder: 'descending',
30
+ uploadedFileCount: 0,
31
+ uploadProgress: 0,
32
+ uploadStatus: { fetchState: 'Not-Started', error: undefined },
33
+ };
3
34
  export const initialState = {
35
+ bulkUpload: initialBulkUploadState,
36
+ pendingMissingReceiptsTabNavigation: null,
4
37
  uploadReceiptStatusById: {},
5
38
  refreshStatus: {
6
39
  fetchState: 'Not-Started',
@@ -19,6 +52,14 @@ export const initialState = {
19
52
  return this.fetchState == 'Completed';
20
53
  },
21
54
  };
55
+ /** Epic trigger only; batch-details fetch is handled in epics. */
56
+ export const fetchBulkUploadBatchDetails = createAction('expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetails');
57
+ /**
58
+ * Epic trigger only. Dispatched from the screen on missing-receipts entry / period switch so the
59
+ * automatching banner is restored for the logged-in user even when they sit on the Missing tab
60
+ * after a hard refresh. The epic owns the list + details API calls end-to-end.
61
+ */
62
+ export const restoreBulkUploadAutomatchingOnMount = createAction('expenseAutomationMissingReceiptsView/restoreBulkUploadAutomatchingOnMount');
22
63
  const expenseAutomationMissingReceiptsView = createSlice({
23
64
  name: 'expenseAutomationMissingReceiptsView',
24
65
  initialState,
@@ -120,7 +161,420 @@ const expenseAutomationMissingReceiptsView = createSlice({
120
161
  clearExpenseAutomationMissingReceiptsView(draft) {
121
162
  Object.assign(draft, initialState);
122
163
  },
164
+ // -- Bulk Upload Actions --
165
+ bulkUploadReceipts: {
166
+ reducer(draft, action) {
167
+ draft.bulkUpload.phase = 'uploading';
168
+ draft.bulkUpload.uploadProgress = 0;
169
+ draft.bulkUpload.uploadedFileCount = action.payload.fileCount;
170
+ draft.bulkUpload.uploadStatus = {
171
+ fetchState: 'In-Progress',
172
+ error: undefined,
173
+ };
174
+ },
175
+ prepare(files) {
176
+ return { payload: { files, fileCount: files.length } };
177
+ },
178
+ },
179
+ updateBulkUploadProgress(draft, action) {
180
+ draft.bulkUpload.uploadProgress = action.payload;
181
+ },
182
+ /**
183
+ * Sync file count when bulk upload uses direct HTTP (`bulkUploadReceipts` Redux action is not
184
+ * dispatched, so `bulkUploadReceipts` reducer never runs).
185
+ */
186
+ setBulkUploadUploadedFileCount(draft, action) {
187
+ draft.bulkUpload.uploadedFileCount = action.payload;
188
+ },
189
+ bulkUploadReceiptsSuccess(draft, action) {
190
+ draft.bulkUpload.currentBatchId = action.payload.batchId;
191
+ draft.bulkUpload.uploadProgress = 100;
192
+ draft.bulkUpload.uploadStatus = {
193
+ fetchState: 'Completed',
194
+ error: undefined,
195
+ };
196
+ draft.bulkUpload.phase = 'matching';
197
+ },
198
+ bulkUploadReceiptsFailure(draft, action) {
199
+ draft.bulkUpload.uploadStatus = {
200
+ fetchState: 'Error',
201
+ error: action.payload.error,
202
+ };
203
+ draft.bulkUpload.phase = 'idle';
204
+ },
205
+ restoreBulkUploadMatchingState(draft, action) {
206
+ if (draft.bulkUpload.phase !== 'idle') {
207
+ return;
208
+ }
209
+ draft.bulkUpload.currentBatchId = action.payload.batchId;
210
+ draft.bulkUpload.uploadedFileCount = action.payload.totalFiles;
211
+ draft.bulkUpload.phase = 'matching';
212
+ },
213
+ bulkUploadAutomatchingTimedOut: {
214
+ reducer(draft, action) {
215
+ if (draft.bulkUpload.phase !== 'matching' ||
216
+ draft.bulkUpload.currentBatchId !== action.payload.batchId) {
217
+ return;
218
+ }
219
+ draft.bulkUpload.phase = 'completed';
220
+ },
221
+ prepare(batchId) {
222
+ return { payload: { batchId } };
223
+ },
224
+ },
225
+ pusherBatchStatusUpdate(draft, action) {
226
+ const batchStatus = action.payload;
227
+ draft.bulkUpload.batchStatusById[batchStatus.batchId] = batchStatus;
228
+ /**
229
+ * Auto-matching banner (`phase === 'matching'`) must clear when the server reports this
230
+ * upload batch is done — otherwise the Missing tab keeps MatchingProgressBanner until
231
+ * batch-details APIs run; EmailUploadBanner should show again for the next upload.
232
+ */
233
+ if (batchStatus.status === 'completed' &&
234
+ draft.bulkUpload.phase === 'matching' &&
235
+ draft.bulkUpload.currentBatchId === batchStatus.batchId) {
236
+ draft.bulkUpload.phase = 'completed';
237
+ }
238
+ },
239
+ requestMissingReceiptsTabNavigation(draft, action) {
240
+ draft.pendingMissingReceiptsTabNavigation = action.payload.tab;
241
+ },
242
+ clearMissingReceiptsTabNavigation(draft) {
243
+ draft.pendingMissingReceiptsTabNavigation = null;
244
+ },
245
+ fetchBulkUploadBatchDetailsSuccess(draft, action) {
246
+ const details = action.payload;
247
+ draft.bulkUpload.batchDetailsById[details.batchId] = details;
248
+ draft.bulkUpload.phase = 'completed';
249
+ },
250
+ fetchBulkUploadBatchDetailsFailure: {
251
+ reducer(draft) {
252
+ draft.bulkUpload.phase = 'completed';
253
+ },
254
+ prepare(payload) {
255
+ return { payload };
256
+ },
257
+ },
258
+ storeBatchDetails(draft, action) {
259
+ const details = action.payload;
260
+ draft.bulkUpload.batchDetailsById[details.batchId] = details;
261
+ /**
262
+ * Multi-batch fetch paths use `storeBatchDetails` (not `fetchBulkUploadBatchDetailsSuccess`).
263
+ * Without this, `phase` stays `matching` after upload forever and the Unmatched tab keeps
264
+ * showing the skeleton (`bulkUploadPhase === 'matching'` in web-components).
265
+ */
266
+ if (draft.bulkUpload.phase === 'matching' &&
267
+ draft.bulkUpload.currentBatchId === details.batchId) {
268
+ draft.bulkUpload.phase = 'completed';
269
+ }
270
+ },
271
+ batchDetailFetchFailed(draft, action) {
272
+ const { batchId } = action.payload;
273
+ if (!draft.bulkUpload.failedBatchDetailIds.includes(batchId)) {
274
+ draft.bulkUpload.failedBatchDetailIds.push(batchId);
275
+ }
276
+ if (draft.bulkUpload.phase === 'matching' &&
277
+ draft.bulkUpload.currentBatchId === batchId) {
278
+ draft.bulkUpload.phase = 'completed';
279
+ }
280
+ },
281
+ setInitialBatchDetailsLoading(draft) {
282
+ draft.bulkUpload.batchDetailsPaginationState = {
283
+ fetchState: 'In-Progress',
284
+ error: undefined,
285
+ };
286
+ },
287
+ fetchMoreBatchDetails(draft) {
288
+ draft.bulkUpload.batchDetailsPaginationState = {
289
+ fetchState: 'In-Progress',
290
+ error: undefined,
291
+ };
292
+ },
293
+ fetchMoreBatchDetailsComplete(draft) {
294
+ draft.bulkUpload.batchDetailsPaginationState = {
295
+ fetchState: 'Completed',
296
+ error: undefined,
297
+ };
298
+ const currentId = draft.bulkUpload.currentBatchId;
299
+ const currentDetails = currentId != null
300
+ ? draft.bulkUpload.batchDetailsById[currentId]
301
+ : undefined;
302
+ if (draft.bulkUpload.phase === 'matching' &&
303
+ currentId != null &&
304
+ currentDetails?.status === 'completed') {
305
+ draft.bulkUpload.phase = 'completed';
306
+ }
307
+ },
308
+ fetchMoreBatchDetailsFailure(draft, action) {
309
+ draft.bulkUpload.batchDetailsPaginationState = {
310
+ fetchState: 'Error',
311
+ error: action.payload.error,
312
+ };
313
+ },
314
+ fetchBulkUploadBatches: {
315
+ reducer(draft, action) {
316
+ if (action.payload.invalidateBatchDetailsCache === true) {
317
+ draft.bulkUpload.batchDetailsById = {};
318
+ draft.bulkUpload.failedBatchDetailIds = [];
319
+ }
320
+ draft.bulkUpload.batchListFetchState = {
321
+ fetchState: 'In-Progress',
322
+ error: undefined,
323
+ };
324
+ },
325
+ prepare(input) {
326
+ const fetchOptions = input ?? {};
327
+ return {
328
+ payload: {
329
+ cacheOverride: fetchOptions.cacheOverride === true,
330
+ invalidateBatchDetailsCache: fetchOptions.invalidateBatchDetailsCache === true,
331
+ },
332
+ };
333
+ },
334
+ },
335
+ fetchBulkUploadBatchesSuccess(draft, action) {
336
+ const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
337
+ draft.bulkUpload.batchListByPeriod[periodId] = action.payload.batchList;
338
+ draft.bulkUpload.batchListFetchState = {
339
+ fetchState: 'Completed',
340
+ error: undefined,
341
+ };
342
+ /**
343
+ * When the multi-batch-details epic has nothing to fetch (e.g. list rows not `completed`
344
+ * yet, or details already present), `phase` can stay `matching` even though we already
345
+ * have completed details for `currentBatchId` (from polling / Pusher). Sync so the UI can
346
+ * dismiss the Unmatched skeleton.
347
+ */
348
+ const currentId = draft.bulkUpload.currentBatchId;
349
+ if (draft.bulkUpload.phase === 'matching' && currentId != null) {
350
+ const existing = draft.bulkUpload.batchDetailsById[currentId];
351
+ if (existing?.status === 'completed') {
352
+ draft.bulkUpload.phase = 'completed';
353
+ }
354
+ }
355
+ },
356
+ fetchBulkUploadBatchesFailure(draft, action) {
357
+ draft.bulkUpload.batchListFetchState = {
358
+ fetchState: 'Error',
359
+ error: action.payload.error,
360
+ };
361
+ },
362
+ confirmBulkUploadMatch: {
363
+ reducer(draft) {
364
+ draft.bulkUpload.confirmMatchStatus = {
365
+ fetchState: 'In-Progress',
366
+ error: undefined,
367
+ };
368
+ },
369
+ prepare(batchId, attachmentId, transactionId, transactionType, fileName) {
370
+ return {
371
+ payload: {
372
+ batchId,
373
+ attachmentId,
374
+ transactionId,
375
+ transactionType,
376
+ fileName,
377
+ },
378
+ };
379
+ },
380
+ },
381
+ confirmBulkUploadMatchSuccess(draft, action) {
382
+ const { batchId, attachmentId, transactionId } = action.payload;
383
+ draft.bulkUpload.confirmMatchStatus = {
384
+ fetchState: 'Completed',
385
+ error: undefined,
386
+ };
387
+ const details = draft.bulkUpload.batchDetailsById[batchId];
388
+ if (details != null) {
389
+ const file = details.files.find((batchFile) => batchFile.attachmentId === attachmentId);
390
+ if (file != null) {
391
+ const originalStatus = file.status;
392
+ file.status = 'exact_match';
393
+ file.matchedTransactionId = transactionId;
394
+ file.candidates = undefined;
395
+ details.summary.matched += 1;
396
+ if (originalStatus === 'no_match') {
397
+ details.summary.noMatch = Math.max(0, details.summary.noMatch - 1);
398
+ }
399
+ else if (originalStatus === 'possible_matches') {
400
+ details.summary.possibleMatches = Math.max(0, details.summary.possibleMatches - 1);
401
+ }
402
+ }
403
+ }
404
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
405
+ draft.bulkUpload.manualSearchUiResetKey += 1;
406
+ },
407
+ confirmBulkUploadMatchFailure(draft, action) {
408
+ draft.bulkUpload.confirmMatchStatus = {
409
+ fetchState: 'Error',
410
+ error: action.payload.error,
411
+ };
412
+ },
413
+ setBulkUploadResultsTab(draft, action) {
414
+ draft.bulkUpload.currentResultsTab = action.payload;
415
+ },
416
+ setBulkUploadCompletedSubTab(draft, action) {
417
+ draft.bulkUpload.completedSubTab = action.payload;
418
+ },
419
+ setBulkUploadSortConfig(draft, action) {
420
+ draft.bulkUpload.sortKey = action.payload.sortKey;
421
+ draft.bulkUpload.sortOrder = action.payload.sortOrder;
422
+ },
423
+ clearBulkUpload(draft) {
424
+ Object.assign(draft.bulkUpload, initialBulkUploadState);
425
+ draft.pendingMissingReceiptsTabNavigation = null;
426
+ },
427
+ searchTransactionsForManualMatch: {
428
+ reducer(draft, action) {
429
+ const { query, pageToken } = action.payload;
430
+ const isLoadMore = pageToken != null;
431
+ const trimmed = query.trim();
432
+ /**
433
+ * Cleared or too-short query: no API (see epic). Reset fully (no In-Progress).
434
+ * Only bump `manualSearchUiResetKey` when clearing a real search — not when the UI
435
+ * dispatches `""` on every keystroke while length is below MIN (web-components always sends
436
+ * `onSearch("")` in that case), or ReceiptCard remounts and the input loses focus.
437
+ */
438
+ if (!isLoadMore &&
439
+ trimmed.length < MIN_MANUAL_TRANSACTION_SEARCH_LENGTH) {
440
+ const hadActiveSearch = draft.bulkUpload.manualSearch.searchQuery.trim().length >=
441
+ MIN_MANUAL_TRANSACTION_SEARCH_LENGTH ||
442
+ draft.bulkUpload.manualSearch.results.length > 0;
443
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
444
+ if (hadActiveSearch) {
445
+ draft.bulkUpload.manualSearchUiResetKey += 1;
446
+ }
447
+ return;
448
+ }
449
+ draft.bulkUpload.manualSearch.searchQuery = query;
450
+ if (isLoadMore) {
451
+ draft.bulkUpload.manualSearch.isLoadingMore = true;
452
+ }
453
+ else {
454
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
455
+ draft.bulkUpload.manualSearch.results = [];
456
+ draft.bulkUpload.manualSearch.nextPageToken = null;
457
+ draft.bulkUpload.manualSearch.totalCount = 0;
458
+ draft.bulkUpload.manualSearch.fetchState = {
459
+ fetchState: 'In-Progress',
460
+ error: undefined,
461
+ };
462
+ }
463
+ },
464
+ prepare(query, pageToken) {
465
+ return { payload: { query, pageToken: pageToken ?? undefined } };
466
+ },
467
+ },
468
+ searchTransactionsForManualMatchSuccess(draft, action) {
469
+ const { append, nextPageToken, results, totalCount } = action.payload;
470
+ if (append) {
471
+ const merged = [...draft.bulkUpload.manualSearch.results, ...results];
472
+ const byId = new Map(merged.map((result) => [result.transactionId, result]));
473
+ draft.bulkUpload.manualSearch.results = Array.from(byId.values());
474
+ }
475
+ else {
476
+ draft.bulkUpload.manualSearch.results = results;
477
+ }
478
+ draft.bulkUpload.manualSearch.nextPageToken = nextPageToken;
479
+ draft.bulkUpload.manualSearch.totalCount = totalCount;
480
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
481
+ draft.bulkUpload.manualSearch.fetchState = {
482
+ fetchState: 'Completed',
483
+ error: undefined,
484
+ };
485
+ },
486
+ searchTransactionsForManualMatchFailure(draft, action) {
487
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
488
+ draft.bulkUpload.manualSearch.fetchState = {
489
+ fetchState: 'Error',
490
+ error: action.payload.error,
491
+ };
492
+ },
493
+ clearManualSearchResults(draft) {
494
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
495
+ draft.bulkUpload.manualSearchUiResetKey += 1;
496
+ },
497
+ acknowledgeBulkUploadConfirmMatchComplete(draft) {
498
+ draft.bulkUpload.confirmMatchStatus = {
499
+ fetchState: 'Not-Started',
500
+ error: undefined,
501
+ };
502
+ },
503
+ // -- Completed Transactions Actions --
504
+ fetchCompletedTransactions: {
505
+ reducer(draft, action) {
506
+ const { pageToken } = action.payload;
507
+ if (pageToken != null) {
508
+ const periods = draft.bulkUpload.completedTransactionsByPeriod;
509
+ for (const entry of Object.values(periods)) {
510
+ if (entry.nextPageToken === pageToken) {
511
+ entry.fetchState = {
512
+ fetchState: 'In-Progress',
513
+ error: undefined,
514
+ };
515
+ break;
516
+ }
517
+ }
518
+ }
519
+ },
520
+ prepare(pageToken, cacheOverride) {
521
+ return { payload: { pageToken, cacheOverride } };
522
+ },
523
+ },
524
+ fetchCompletedTransactionsSuccess(draft, action) {
525
+ const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, } = action.payload;
526
+ const periodId = toMonthYearPeriodId(selectedPeriod);
527
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
528
+ if (isInitialLoad) {
529
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
530
+ transactionIds,
531
+ nextPageToken,
532
+ totalCount,
533
+ fetchState: { fetchState: 'Completed', error: undefined },
534
+ };
535
+ }
536
+ else {
537
+ const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
538
+ if (existing != null) {
539
+ existing.transactionIds.push(...transactionIds);
540
+ existing.nextPageToken = nextPageToken;
541
+ existing.totalCount = totalCount;
542
+ existing.fetchState = { fetchState: 'Completed', error: undefined };
543
+ }
544
+ else {
545
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
546
+ transactionIds,
547
+ nextPageToken,
548
+ totalCount,
549
+ fetchState: { fetchState: 'Completed', error: undefined },
550
+ };
551
+ }
552
+ }
553
+ },
554
+ fetchCompletedTransactionsFailure(draft, action) {
555
+ const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
556
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
557
+ const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
558
+ if (existing != null) {
559
+ existing.fetchState = {
560
+ fetchState: 'Error',
561
+ error: action.payload.error,
562
+ };
563
+ }
564
+ else {
565
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
566
+ fetchState: { fetchState: 'Error', error: action.payload.error },
567
+ nextPageToken: null,
568
+ totalCount: 0,
569
+ transactionIds: [],
570
+ };
571
+ }
572
+ },
123
573
  },
124
574
  });
125
- export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView, } = expenseAutomationMissingReceiptsView.actions;
575
+ export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView,
576
+ // Bulk Upload
577
+ bulkUploadReceipts, updateBulkUploadProgress, setBulkUploadUploadedFileCount, bulkUploadReceiptsSuccess, bulkUploadReceiptsFailure, restoreBulkUploadMatchingState, bulkUploadAutomatchingTimedOut, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, clearMissingReceiptsTabNavigation, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatchDetailsFailure, storeBatchDetails, batchDetailFetchFailed, setInitialBatchDetailsLoading, fetchMoreBatchDetails, fetchMoreBatchDetailsComplete, fetchMoreBatchDetailsFailure, fetchBulkUploadBatches, fetchBulkUploadBatchesSuccess, fetchBulkUploadBatchesFailure, confirmBulkUploadMatch, confirmBulkUploadMatchSuccess, confirmBulkUploadMatchFailure, setBulkUploadResultsTab, setBulkUploadCompletedSubTab, setBulkUploadSortConfig, clearBulkUpload, searchTransactionsForManualMatch, searchTransactionsForManualMatchSuccess, searchTransactionsForManualMatchFailure, clearManualSearchResults, acknowledgeBulkUploadConfirmMatchComplete,
578
+ // Completed Transactions
579
+ fetchCompletedTransactions, fetchCompletedTransactionsSuccess, fetchCompletedTransactionsFailure, } = expenseAutomationMissingReceiptsView.actions;
126
580
  export default expenseAutomationMissingReceiptsView.reducer;
@@ -36,6 +36,7 @@ export const initialTransactionTabViewState = {
36
36
  transactionIdsBySelectedPeriod: {},
37
37
  selectedCheckBoxTransactionIds: [],
38
38
  transactionIdsWithUnsavedData: [],
39
+ uploadReceiptStatusById: {},
39
40
  selectedTransactionId: undefined,
40
41
  selectedTransactionLineId: undefined,
41
42
  };
@@ -699,6 +700,27 @@ const expenseAutomationTransactionsView = createSlice({
699
700
  clearExpenseAutomationTransactionsView(draft) {
700
701
  Object.assign(draft, initialState);
701
702
  },
703
+ updateTransactionCategorizationUploadReceiptState: {
704
+ reducer(draft, action) {
705
+ const { transactionId, fetchStatus, selectedTab } = action.payload;
706
+ draft.transactionCategorizationView[selectedTab].uploadReceiptStatusById[transactionId] = fetchStatus;
707
+ },
708
+ prepare(selectedTab, transactionId, fetchStatus) {
709
+ return { payload: { selectedTab, transactionId, fetchStatus } };
710
+ },
711
+ },
712
+ uploadTransactionCategorizationReceiptSuccess: {
713
+ reducer(draft, action) {
714
+ const { transactionPayload, selectedTab } = action.payload;
715
+ draft.transactionCategorizationView[selectedTab].uploadReceiptStatusById[transactionPayload.transaction_id] = {
716
+ fetchState: 'Completed',
717
+ error: undefined,
718
+ };
719
+ },
720
+ prepare(selectedTab, transactionPayload, updateType = 'merge') {
721
+ return { payload: { selectedTab, transactionPayload, updateType } };
722
+ },
723
+ },
702
724
  syncTransactionCategorizationFromDetailSave: {
703
725
  prepare(transactionId, updatedTransaction, pendingReviewLineIds, uncategorizedIncomeExpense, isUncategorizedExpenseCategoryEnabled) {
704
726
  return {
@@ -770,5 +792,5 @@ const expenseAutomationTransactionsView = createSlice({
770
792
  },
771
793
  },
772
794
  });
773
- export const { fetchTransactionCategorization, updateTransactionCategorizationUIState, initializeTransactionCategorizationViewLocalData, saveTransactionCategorizationLocalData, fetchTransactionCategorizationFailure, saveTransactionCategorization, updateTransactionCategorization, updateCurrentSelectedTransactionCategorizationTab, updateTransactionCategorizationSaveStatus, markTransactionAsNotMiscategorized, updateStatusForTransactionNotMiscategorizedUpdateForCategorization, updateSelectedVendorForTransaction, updateSelectedCustomerForTransaction, setAllItemsToCategoryClassInLocalDataForCategorization, updateTotalCountForTransactionCategorization, fetchTransactionCategorizationSuccess, resetOtherTabsFetchState, fetchTransactionCategorizationView, updateSelectedCheckboxTransactionIds, clearExpenseAutomationTransactionsViewPerTabView, clearExpenseAutomationTransactionsView, setEntityRecommendationForLineIdsForCategorization, updateSelectedTransactionId, syncTransactionCategorizationFromDetailSave, backgroundRefetchReviewTab, } = expenseAutomationTransactionsView.actions;
795
+ export const { fetchTransactionCategorization, updateTransactionCategorizationUIState, initializeTransactionCategorizationViewLocalData, saveTransactionCategorizationLocalData, fetchTransactionCategorizationFailure, saveTransactionCategorization, updateTransactionCategorization, updateCurrentSelectedTransactionCategorizationTab, updateTransactionCategorizationSaveStatus, markTransactionAsNotMiscategorized, updateStatusForTransactionNotMiscategorizedUpdateForCategorization, updateSelectedVendorForTransaction, updateSelectedCustomerForTransaction, setAllItemsToCategoryClassInLocalDataForCategorization, updateTotalCountForTransactionCategorization, fetchTransactionCategorizationSuccess, resetOtherTabsFetchState, fetchTransactionCategorizationView, updateSelectedCheckboxTransactionIds, clearExpenseAutomationTransactionsViewPerTabView, clearExpenseAutomationTransactionsView, setEntityRecommendationForLineIdsForCategorization, updateSelectedTransactionId, syncTransactionCategorizationFromDetailSave, backgroundRefetchReviewTab, updateTransactionCategorizationUploadReceiptState, uploadTransactionCategorizationReceiptSuccess, } = expenseAutomationTransactionsView.actions;
774
796
  export default expenseAutomationTransactionsView.reducer;