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

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 (116) 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 +13 -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 +28 -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 +78 -0
  28. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  29. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +59 -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 +173 -1
  34. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +412 -1
  35. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +20 -1
  36. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +225 -1
  37. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  38. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +10 -0
  39. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  40. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -4
  41. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  42. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  43. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  44. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  45. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  46. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  47. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  48. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  49. package/lib/esm/view/spendManagement/commonSetup/types/businessVerification.js +148 -1
  50. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  51. package/lib/esm/zeniAPI.js +0 -2
  52. package/lib/index.d.ts +14 -9
  53. package/lib/index.js +90 -45
  54. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  55. package/lib/view/companyView/epic/companyPassport/updateCompanyDetailsEpic.js +6 -0
  56. package/lib/view/companyView/types/companyPassport/companyDetailsLocalData.d.ts +13 -0
  57. package/lib/view/companyView/types/companyPassport/companyPassportLocalData.js +13 -0
  58. package/lib/view/companyView/types/companyPassportViewPayload.d.ts +1 -1
  59. package/lib/view/companyView/types/companyPassportViewPayload.js +55 -12
  60. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +15 -0
  61. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +32 -0
  62. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
  63. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
  64. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
  65. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
  66. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
  67. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +51 -0
  68. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
  69. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
  70. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
  71. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +38 -0
  72. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
  73. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +62 -0
  74. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
  75. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +82 -0
  76. package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  77. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +19 -0
  78. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +64 -0
  79. package/lib/view/expenseAutomationView/epics/transactionCategorization/triggerReviewTabRefetchEpic.js +2 -3
  80. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
  81. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
  82. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  83. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -2
  84. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +118 -0
  85. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +185 -0
  86. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +70 -3
  87. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +414 -2
  88. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
  89. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +21 -2
  90. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +69 -1
  91. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
  92. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  93. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +224 -0
  94. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  95. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +131 -0
  96. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +12 -1
  97. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
  98. package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  99. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +1 -0
  100. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -3
  101. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  102. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  103. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  104. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  105. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.d.ts +1 -1
  106. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  107. package/lib/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  108. package/lib/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  109. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +14 -0
  110. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  111. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +14 -0
  112. package/lib/view/spendManagement/commonSetup/types/businessVerification.d.ts +43 -0
  113. package/lib/view/spendManagement/commonSetup/types/businessVerification.js +150 -0
  114. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  115. package/lib/zeniAPI.js +0 -2
  116. package/package.json +1 -1
@@ -1,6 +1,38 @@
1
1
  import { 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
+ uploadProgress: 0,
31
+ uploadStatus: { fetchState: 'Not-Started', error: undefined },
32
+ };
3
33
  export const initialState = {
34
+ bulkUpload: initialBulkUploadState,
35
+ pendingMissingReceiptsTabNavigation: null,
4
36
  uploadReceiptStatusById: {},
5
37
  refreshStatus: {
6
38
  fetchState: 'Not-Started',
@@ -120,7 +152,386 @@ const expenseAutomationMissingReceiptsView = createSlice({
120
152
  clearExpenseAutomationMissingReceiptsView(draft) {
121
153
  Object.assign(draft, initialState);
122
154
  },
155
+ // -- Bulk Upload Actions --
156
+ bulkUploadReceipts: {
157
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
158
+ reducer(draft, _action) {
159
+ draft.bulkUpload.phase = 'uploading';
160
+ draft.bulkUpload.uploadProgress = 0;
161
+ draft.bulkUpload.uploadStatus = {
162
+ fetchState: 'In-Progress',
163
+ error: undefined,
164
+ };
165
+ },
166
+ prepare(files) {
167
+ return { payload: { files } };
168
+ },
169
+ },
170
+ updateBulkUploadProgress(draft, action) {
171
+ draft.bulkUpload.uploadProgress = action.payload;
172
+ },
173
+ bulkUploadReceiptsSuccess(draft, action) {
174
+ draft.bulkUpload.currentBatchId = action.payload.batchId;
175
+ draft.bulkUpload.uploadStatus = {
176
+ fetchState: 'Completed',
177
+ error: undefined,
178
+ };
179
+ draft.bulkUpload.phase = 'matching';
180
+ },
181
+ bulkUploadReceiptsFailure(draft, action) {
182
+ draft.bulkUpload.uploadStatus = {
183
+ fetchState: 'Error',
184
+ error: action.payload.error,
185
+ };
186
+ draft.bulkUpload.phase = 'idle';
187
+ },
188
+ pusherBatchStatusUpdate(draft, action) {
189
+ const batchStatus = action.payload;
190
+ draft.bulkUpload.batchStatusById[batchStatus.batchId] = batchStatus;
191
+ /**
192
+ * Auto-matching banner (`phase === 'matching'`) must clear when the server reports this
193
+ * upload batch is done — otherwise the Missing tab keeps MatchingProgressBanner until
194
+ * batch-details APIs run; EmailUploadBanner should show again for the next upload.
195
+ */
196
+ if (batchStatus.status === 'completed' &&
197
+ draft.bulkUpload.phase === 'matching' &&
198
+ draft.bulkUpload.currentBatchId === batchStatus.batchId) {
199
+ draft.bulkUpload.phase = 'completed';
200
+ }
201
+ },
202
+ requestMissingReceiptsTabNavigation(draft, action) {
203
+ draft.pendingMissingReceiptsTabNavigation = action.payload.tab;
204
+ },
205
+ clearMissingReceiptsTabNavigation(draft) {
206
+ draft.pendingMissingReceiptsTabNavigation = null;
207
+ },
208
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
209
+ fetchBulkUploadBatchDetails(_draft) {
210
+ // trigger epic, no state change needed
211
+ },
212
+ fetchBulkUploadBatchDetailsSuccess(draft, action) {
213
+ const details = action.payload;
214
+ draft.bulkUpload.batchDetailsById[details.batchId] = details;
215
+ draft.bulkUpload.phase = 'completed';
216
+ },
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
+ fetchBulkUploadBatchDetailsFailure(draft, _action) {
219
+ draft.bulkUpload.phase = 'completed';
220
+ },
221
+ storeBatchDetails(draft, action) {
222
+ const details = action.payload;
223
+ draft.bulkUpload.batchDetailsById[details.batchId] = details;
224
+ /**
225
+ * Multi-batch fetch paths use `storeBatchDetails` (not `fetchBulkUploadBatchDetailsSuccess`).
226
+ * Without this, `phase` stays `matching` after upload forever and the Unmatched tab keeps
227
+ * showing the skeleton (`bulkUploadPhase === 'matching'` in web-components).
228
+ */
229
+ if (draft.bulkUpload.phase === 'matching' &&
230
+ draft.bulkUpload.currentBatchId === details.batchId) {
231
+ draft.bulkUpload.phase = 'completed';
232
+ }
233
+ },
234
+ batchDetailFetchFailed(draft, action) {
235
+ const { batchId } = action.payload;
236
+ if (!draft.bulkUpload.failedBatchDetailIds.includes(batchId)) {
237
+ draft.bulkUpload.failedBatchDetailIds.push(batchId);
238
+ }
239
+ if (draft.bulkUpload.phase === 'matching' &&
240
+ draft.bulkUpload.currentBatchId === batchId) {
241
+ draft.bulkUpload.phase = 'completed';
242
+ }
243
+ },
244
+ setInitialBatchDetailsLoading(draft) {
245
+ draft.bulkUpload.batchDetailsPaginationState = {
246
+ fetchState: 'In-Progress',
247
+ error: undefined,
248
+ };
249
+ },
250
+ fetchMoreBatchDetails(_draft) {
251
+ _draft.bulkUpload.batchDetailsPaginationState = {
252
+ fetchState: 'In-Progress',
253
+ error: undefined,
254
+ };
255
+ },
256
+ fetchMoreBatchDetailsComplete(draft) {
257
+ draft.bulkUpload.batchDetailsPaginationState = {
258
+ fetchState: 'Completed',
259
+ error: undefined,
260
+ };
261
+ const currentId = draft.bulkUpload.currentBatchId;
262
+ const currentDetails = currentId != null
263
+ ? draft.bulkUpload.batchDetailsById[currentId]
264
+ : undefined;
265
+ if (draft.bulkUpload.phase === 'matching' &&
266
+ currentId != null &&
267
+ currentDetails?.status === 'completed') {
268
+ draft.bulkUpload.phase = 'completed';
269
+ }
270
+ },
271
+ fetchMoreBatchDetailsFailure(draft, action) {
272
+ draft.bulkUpload.batchDetailsPaginationState = {
273
+ fetchState: 'Error',
274
+ error: action.payload.error,
275
+ };
276
+ },
277
+ fetchBulkUploadBatches: {
278
+ reducer(draft, action) {
279
+ if (action.payload.invalidateBatchDetailsCache === true) {
280
+ draft.bulkUpload.batchDetailsById = {};
281
+ draft.bulkUpload.failedBatchDetailIds = [];
282
+ }
283
+ draft.bulkUpload.batchListFetchState = {
284
+ fetchState: 'In-Progress',
285
+ error: undefined,
286
+ };
287
+ },
288
+ prepare(input) {
289
+ const o = input ?? {};
290
+ return {
291
+ payload: {
292
+ cacheOverride: o.cacheOverride === true,
293
+ invalidateBatchDetailsCache: o.invalidateBatchDetailsCache === true,
294
+ },
295
+ };
296
+ },
297
+ },
298
+ fetchBulkUploadBatchesSuccess(draft, action) {
299
+ const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
300
+ draft.bulkUpload.batchListByPeriod[periodId] = action.payload.batchList;
301
+ draft.bulkUpload.batchListFetchState = {
302
+ fetchState: 'Completed',
303
+ error: undefined,
304
+ };
305
+ /**
306
+ * When the multi-batch-details epic has nothing to fetch (e.g. list rows not `completed`
307
+ * yet, or details already present), `phase` can stay `matching` even though we already
308
+ * have completed details for `currentBatchId` (from polling / Pusher). Sync so the UI can
309
+ * dismiss the Unmatched skeleton.
310
+ */
311
+ const currentId = draft.bulkUpload.currentBatchId;
312
+ if (draft.bulkUpload.phase === 'matching' &&
313
+ currentId != null) {
314
+ const existing = draft.bulkUpload.batchDetailsById[currentId];
315
+ if (existing?.status === 'completed') {
316
+ draft.bulkUpload.phase = 'completed';
317
+ }
318
+ }
319
+ },
320
+ fetchBulkUploadBatchesFailure(draft, action) {
321
+ draft.bulkUpload.batchListFetchState = {
322
+ fetchState: 'Error',
323
+ error: action.payload.error,
324
+ };
325
+ },
326
+ confirmBulkUploadMatch: {
327
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
328
+ reducer(draft, _action) {
329
+ draft.bulkUpload.confirmMatchStatus = {
330
+ fetchState: 'In-Progress',
331
+ error: undefined,
332
+ };
333
+ },
334
+ prepare(batchId, attachmentId, transactionId, transactionType, fileName) {
335
+ return { payload: { batchId, attachmentId, transactionId, transactionType, fileName } };
336
+ },
337
+ },
338
+ confirmBulkUploadMatchSuccess(draft, action) {
339
+ const { batchId, attachmentId, transactionId } = action.payload;
340
+ draft.bulkUpload.confirmMatchStatus = {
341
+ fetchState: 'Completed',
342
+ error: undefined,
343
+ };
344
+ const details = draft.bulkUpload.batchDetailsById[batchId];
345
+ if (details != null) {
346
+ const file = details.files.find((f) => f.attachmentId === attachmentId);
347
+ if (file != null) {
348
+ const originalStatus = file.status;
349
+ file.status = 'exact_match';
350
+ file.matchedTransactionId = transactionId;
351
+ file.candidates = undefined;
352
+ details.summary.matched += 1;
353
+ if (originalStatus === 'no_match') {
354
+ details.summary.noMatch = Math.max(0, details.summary.noMatch - 1);
355
+ }
356
+ else if (originalStatus === 'possible_matches') {
357
+ details.summary.possibleMatches = Math.max(0, details.summary.possibleMatches - 1);
358
+ }
359
+ }
360
+ }
361
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
362
+ draft.bulkUpload.manualSearchUiResetKey += 1;
363
+ },
364
+ confirmBulkUploadMatchFailure(draft, action) {
365
+ draft.bulkUpload.confirmMatchStatus = {
366
+ fetchState: 'Error',
367
+ error: action.payload.error,
368
+ };
369
+ },
370
+ setBulkUploadResultsTab(draft, action) {
371
+ draft.bulkUpload.currentResultsTab = action.payload;
372
+ },
373
+ setBulkUploadCompletedSubTab(draft, action) {
374
+ draft.bulkUpload.completedSubTab = action.payload;
375
+ },
376
+ setBulkUploadSortConfig(draft, action) {
377
+ draft.bulkUpload.sortKey = action.payload.sortKey;
378
+ draft.bulkUpload.sortOrder = action.payload.sortOrder;
379
+ },
380
+ clearBulkUpload(draft) {
381
+ Object.assign(draft.bulkUpload, initialBulkUploadState);
382
+ draft.pendingMissingReceiptsTabNavigation = null;
383
+ },
384
+ searchTransactionsForManualMatch: {
385
+ reducer(draft, action) {
386
+ const { query, pageToken } = action.payload;
387
+ const isLoadMore = pageToken != null;
388
+ const trimmed = query.trim();
389
+ /**
390
+ * Cleared or too-short query: no API (see epic). Reset fully (no In-Progress).
391
+ * Only bump `manualSearchUiResetKey` when clearing a real search — not when the UI
392
+ * dispatches `""` on every keystroke while length is below MIN (web-components always sends
393
+ * `onSearch("")` in that case), or ReceiptCard remounts and the input loses focus.
394
+ */
395
+ if (!isLoadMore &&
396
+ trimmed.length < MIN_MANUAL_TRANSACTION_SEARCH_LENGTH) {
397
+ const hadActiveSearch = draft.bulkUpload.manualSearch.searchQuery.trim().length >=
398
+ MIN_MANUAL_TRANSACTION_SEARCH_LENGTH ||
399
+ draft.bulkUpload.manualSearch.results.length > 0;
400
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
401
+ if (hadActiveSearch) {
402
+ draft.bulkUpload.manualSearchUiResetKey += 1;
403
+ }
404
+ return;
405
+ }
406
+ draft.bulkUpload.manualSearch.searchQuery = query;
407
+ if (isLoadMore) {
408
+ draft.bulkUpload.manualSearch.isLoadingMore = true;
409
+ }
410
+ else {
411
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
412
+ draft.bulkUpload.manualSearch.results = [];
413
+ draft.bulkUpload.manualSearch.nextPageToken = null;
414
+ draft.bulkUpload.manualSearch.totalCount = 0;
415
+ draft.bulkUpload.manualSearch.fetchState = {
416
+ fetchState: 'In-Progress',
417
+ error: undefined,
418
+ };
419
+ }
420
+ },
421
+ prepare(query, pageToken) {
422
+ return { payload: { query, pageToken: pageToken ?? undefined } };
423
+ },
424
+ },
425
+ searchTransactionsForManualMatchSuccess(draft, action) {
426
+ const { append, nextPageToken, results, totalCount } = action.payload;
427
+ if (append) {
428
+ const merged = [...draft.bulkUpload.manualSearch.results, ...results];
429
+ const byId = new Map(merged.map((r) => [r.transactionId, r]));
430
+ draft.bulkUpload.manualSearch.results = Array.from(byId.values());
431
+ }
432
+ else {
433
+ draft.bulkUpload.manualSearch.results = results;
434
+ }
435
+ draft.bulkUpload.manualSearch.nextPageToken = nextPageToken;
436
+ draft.bulkUpload.manualSearch.totalCount = totalCount;
437
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
438
+ draft.bulkUpload.manualSearch.fetchState = {
439
+ fetchState: 'Completed',
440
+ error: undefined,
441
+ };
442
+ },
443
+ searchTransactionsForManualMatchFailure(draft, action) {
444
+ draft.bulkUpload.manualSearch.isLoadingMore = false;
445
+ draft.bulkUpload.manualSearch.fetchState = {
446
+ fetchState: 'Error',
447
+ error: action.payload.error,
448
+ };
449
+ },
450
+ clearManualSearchResults(draft) {
451
+ draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
452
+ draft.bulkUpload.manualSearchUiResetKey += 1;
453
+ },
454
+ acknowledgeBulkUploadConfirmMatchComplete(draft) {
455
+ draft.bulkUpload.confirmMatchStatus = {
456
+ fetchState: 'Not-Started',
457
+ error: undefined,
458
+ };
459
+ },
460
+ // -- Completed Transactions Actions --
461
+ fetchCompletedTransactions: {
462
+ reducer(draft, action) {
463
+ const { pageToken } = action.payload;
464
+ if (pageToken != null) {
465
+ const periods = draft.bulkUpload.completedTransactionsByPeriod;
466
+ for (const entry of Object.values(periods)) {
467
+ if (entry.nextPageToken === pageToken) {
468
+ entry.fetchState = {
469
+ fetchState: 'In-Progress',
470
+ error: undefined,
471
+ };
472
+ break;
473
+ }
474
+ }
475
+ }
476
+ },
477
+ prepare(pageToken, cacheOverride) {
478
+ return { payload: { pageToken, cacheOverride } };
479
+ },
480
+ },
481
+ fetchCompletedTransactionsSuccess(draft, action) {
482
+ const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad } = action.payload;
483
+ const periodId = toMonthYearPeriodId(selectedPeriod);
484
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
485
+ if (isInitialLoad) {
486
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
487
+ transactionIds,
488
+ nextPageToken,
489
+ totalCount,
490
+ fetchState: { fetchState: 'Completed', error: undefined },
491
+ };
492
+ }
493
+ else {
494
+ const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
495
+ if (existing != null) {
496
+ existing.transactionIds.push(...transactionIds);
497
+ existing.nextPageToken = nextPageToken;
498
+ existing.totalCount = totalCount;
499
+ existing.fetchState = { fetchState: 'Completed', error: undefined };
500
+ }
501
+ else {
502
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
503
+ transactionIds,
504
+ nextPageToken,
505
+ totalCount,
506
+ fetchState: { fetchState: 'Completed', error: undefined },
507
+ };
508
+ }
509
+ }
510
+ },
511
+ fetchCompletedTransactionsFailure(draft, action) {
512
+ const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
513
+ const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
514
+ const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
515
+ if (existing != null) {
516
+ existing.fetchState = {
517
+ fetchState: 'Error',
518
+ error: action.payload.error,
519
+ };
520
+ }
521
+ else {
522
+ draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
523
+ fetchState: { fetchState: 'Error', error: action.payload.error },
524
+ nextPageToken: null,
525
+ totalCount: 0,
526
+ transactionIds: [],
527
+ };
528
+ }
529
+ },
123
530
  },
124
531
  });
125
- export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView, } = expenseAutomationMissingReceiptsView.actions;
532
+ export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView,
533
+ // Bulk Upload
534
+ bulkUploadReceipts, updateBulkUploadProgress, bulkUploadReceiptsSuccess, bulkUploadReceiptsFailure, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, clearMissingReceiptsTabNavigation, fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatchDetailsFailure, storeBatchDetails, batchDetailFetchFailed, setInitialBatchDetailsLoading, fetchMoreBatchDetails, fetchMoreBatchDetailsComplete, fetchMoreBatchDetailsFailure, fetchBulkUploadBatches, fetchBulkUploadBatchesSuccess, fetchBulkUploadBatchesFailure, confirmBulkUploadMatch, confirmBulkUploadMatchSuccess, confirmBulkUploadMatchFailure, setBulkUploadResultsTab, setBulkUploadCompletedSubTab, setBulkUploadSortConfig, clearBulkUpload, searchTransactionsForManualMatch, searchTransactionsForManualMatchSuccess, searchTransactionsForManualMatchFailure, clearManualSearchResults, acknowledgeBulkUploadConfirmMatchComplete,
535
+ // Completed Transactions
536
+ fetchCompletedTransactions, fetchCompletedTransactionsSuccess, fetchCompletedTransactionsFailure, } = expenseAutomationMissingReceiptsView.actions;
126
537
  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,24 @@ 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] = { fetchState: 'Completed', error: undefined };
716
+ },
717
+ prepare(selectedTab, transactionPayload, updateType = 'merge') {
718
+ return { payload: { selectedTab, transactionPayload, updateType } };
719
+ },
720
+ },
702
721
  syncTransactionCategorizationFromDetailSave: {
703
722
  prepare(transactionId, updatedTransaction, pendingReviewLineIds, uncategorizedIncomeExpense, isUncategorizedExpenseCategoryEnabled) {
704
723
  return {
@@ -770,5 +789,5 @@ const expenseAutomationTransactionsView = createSlice({
770
789
  },
771
790
  },
772
791
  });
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;
792
+ 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
793
  export default expenseAutomationTransactionsView.reducer;