@zeniai/client-epic-state 4.19.84-betaVR8 → 4.19.84

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 (54) hide show
  1. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  2. package/lib/entity/snackbar/snackbarTypes.js +0 -1
  3. package/lib/epic.d.ts +1 -10
  4. package/lib/epic.js +1 -10
  5. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -1
  6. package/lib/esm/epic.js +1 -10
  7. package/lib/esm/index.js +2 -4
  8. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +1 -177
  9. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +1 -412
  10. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +1 -224
  11. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +0 -6
  12. package/lib/esm/zeniAPI.js +2 -0
  13. package/lib/index.d.ts +3 -5
  14. package/lib/index.js +31 -64
  15. package/lib/tsconfig.typecheck.tsbuildinfo +1 -1
  16. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  17. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +0 -118
  18. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +0 -189
  19. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +3 -70
  20. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +2 -414
  21. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +1 -69
  22. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  23. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +0 -223
  24. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +0 -129
  25. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +1 -7
  26. package/lib/zeniAPI.js +2 -0
  27. package/package.json +1 -1
  28. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +0 -28
  29. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +0 -49
  30. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +0 -40
  31. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +0 -47
  32. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +0 -61
  33. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -34
  34. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +0 -57
  35. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -78
  36. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +0 -59
  37. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +0 -15
  38. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +0 -32
  39. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +0 -7
  40. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +0 -53
  41. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +0 -8
  42. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +0 -44
  43. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +0 -7
  44. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +0 -51
  45. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +0 -8
  46. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +0 -65
  47. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +0 -8
  48. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -38
  49. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +0 -9
  50. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +0 -62
  51. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +0 -14
  52. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -82
  53. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +0 -19
  54. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +0 -64
@@ -1,177 +1 @@
1
- import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
- import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
- // -- Converter functions --
4
- /**
5
- * Maps batch-details API `files[].status` strings to canonical {@link BatchFile} statuses.
6
- * The service may send aliases (`unmatched`, `possible_match`) or different separators; the UI
7
- * only treats `un_matched` / `no_match` as work for the Unmatched tab.
8
- *
9
- * **Unknown values:** Any string not matched below is returned as-is (typed as
10
- * {@link BatchFile} status). Callers should not assume exhaustiveness—treat unknown statuses in
11
- * UI as “other” (e.g. show a generic label or fall back to a safe bucket) until the API contract
12
- * adds an explicit mapping.
13
- */
14
- export function normalizeBatchFileStatus(raw) {
15
- const s = raw.trim().toLowerCase().replace(/-/g, '_');
16
- switch (s) {
17
- case 'un_matched':
18
- case 'unmatched':
19
- return 'un_matched';
20
- case 'no_match':
21
- case 'nomatch':
22
- return 'no_match';
23
- case 'matched':
24
- return 'matched';
25
- case 'failed':
26
- return 'failed';
27
- case 'possible_match':
28
- case 'possiblematch':
29
- return 'un_matched';
30
- default:
31
- return raw;
32
- }
33
- }
34
- export function toBatchFile(payload, filesEndPoint) {
35
- return {
36
- attachmentId: payload.attachment_id,
37
- candidates: payload.candidates?.map((c) => ({
38
- transactionId: c.transaction_id,
39
- matchScore: c.match_score,
40
- })),
41
- fileDownloadUrl: payload.file_id != null && filesEndPoint != null
42
- ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
43
- : null,
44
- fileId: payload.file_id,
45
- filePreviewUrl: payload.file_preview_url,
46
- filename: payload.filename,
47
- matchSource: payload.match_source,
48
- matchedTransactionId: payload.matched_transaction?.transaction_id,
49
- status: normalizeBatchFileStatus(payload.status),
50
- };
51
- }
52
- export function extractTransactionPayloadsFromBatchFiles(files) {
53
- const seen = new Set();
54
- const payloads = [];
55
- for (const file of files) {
56
- if (file.matched_transaction != null) {
57
- const id = file.matched_transaction.transaction_id;
58
- if (!seen.has(id)) {
59
- seen.add(id);
60
- payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
61
- }
62
- }
63
- if (file.candidates != null) {
64
- for (const candidate of file.candidates) {
65
- const id = candidate.transaction_id;
66
- if (!seen.has(id)) {
67
- seen.add(id);
68
- payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
69
- }
70
- }
71
- }
72
- }
73
- return payloads;
74
- }
75
- function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
76
- return {
77
- transaction_id: payload.transaction_id,
78
- transaction_type: payload.transaction_type ?? 'expense',
79
- transaction_date: payload.transaction_date ?? '',
80
- currency_code: payload.currency_code,
81
- total_amount: payload.amount,
82
- vendor_name: payload.vendor_name,
83
- logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
84
- };
85
- }
86
- export function toBatchSummary(payload) {
87
- return {
88
- failed: payload.failed,
89
- matched: payload.matched,
90
- noMatch: payload.no_match,
91
- possibleMatches: payload.possible_matches,
92
- total: payload.total,
93
- };
94
- }
95
- export function toBatchDetails(payload, filesEndPoint) {
96
- return {
97
- batchId: payload.batch_id,
98
- createdAt: payload.created_at,
99
- files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
100
- status: payload.status,
101
- summary: toBatchSummary(payload.summary),
102
- };
103
- }
104
- /** Batch list `status` is a string from the API — compare case-insensitively. */
105
- export function isBatchListStatusCompleted(status) {
106
- return status.toLowerCase() === 'completed';
107
- }
108
- /**
109
- * Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
110
- * `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
111
- * statuses for UI; only `completed` rows should trigger batch-details requests.
112
- */
113
- export function filterBatchListItemsForBatchDetailsFetch(batches) {
114
- return batches.filter((b) => isBatchListStatusCompleted(b.status));
115
- }
116
- /**
117
- * Batch details API response `status` field — only completed payloads should be stored from
118
- * multi-batch fetch paths (list can be briefly stale vs. live processing state).
119
- */
120
- export function isBatchDetailsApiStatusCompleted(status) {
121
- return status.toLowerCase() === 'completed';
122
- }
123
- export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
124
- for (const list of Object.values(batchListByPeriod)) {
125
- const found = list.find((b) => b.batchId === batchId);
126
- if (found != null) {
127
- return found;
128
- }
129
- }
130
- return undefined;
131
- }
132
- /**
133
- * Whether it is appropriate to call `GET .../batches/:id` for details.
134
- * Skips when live batch status or batch list row indicates the batch is not completed yet.
135
- * When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
136
- */
137
- export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
138
- const live = batchStatusById[batchId]?.status;
139
- if (live === 'completed') {
140
- return true;
141
- }
142
- if (live === 'pending' || live === 'processing') {
143
- return false;
144
- }
145
- const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
146
- if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
147
- return false;
148
- }
149
- return true;
150
- }
151
- export function toBatchListItem(payload) {
152
- return {
153
- batchId: payload.batch_id,
154
- createdAt: payload.created_at,
155
- failedCount: payload.failed_count,
156
- matchedCount: payload.matched_count,
157
- noMatchCount: payload.no_match_count,
158
- possibleMatchesCount: payload.possible_matches_count,
159
- status: payload.status,
160
- totalFiles: payload.total_files,
161
- };
162
- }
163
- /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
164
- export function supportedTransactionPayloadToManualSearchResult(payload) {
165
- const amountPayload = getTransactionPayloadAmount(payload);
166
- return {
167
- amount: amountPayload.amount,
168
- currencyCode: amountPayload.currencyCode,
169
- entityId: payload.vendor_id ?? payload.customer_id ?? '',
170
- memo: payload.transaction_memo ?? '',
171
- transactionDate: payload.transaction_date,
172
- transactionId: payload.transaction_id,
173
- transactionType: payload.transaction_type,
174
- vendorName: payload.vendor_name ?? '',
175
- vendorLogo: toURL(payload.logo)?.href,
176
- };
177
- }
1
+ export {};
@@ -1,38 +1,6 @@
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
- };
33
3
  export const initialState = {
34
- bulkUpload: initialBulkUploadState,
35
- pendingMissingReceiptsTabNavigation: null,
36
4
  uploadReceiptStatusById: {},
37
5
  refreshStatus: {
38
6
  fetchState: 'Not-Started',
@@ -152,386 +120,7 @@ const expenseAutomationMissingReceiptsView = createSlice({
152
120
  clearExpenseAutomationMissingReceiptsView(draft) {
153
121
  Object.assign(draft, initialState);
154
122
  },
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 = 'matched';
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 === 'un_matched') {
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
- },
530
123
  },
531
124
  });
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;
125
+ export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView, } = expenseAutomationMissingReceiptsView.actions;
537
126
  export default expenseAutomationMissingReceiptsView.reducer;