@zeniai/client-epic-state 4.19.91 → 4.19.93

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 (108) hide show
  1. package/lib/entity/account/accountPayload.d.ts +0 -2
  2. package/lib/entity/account/accountPayload.js +0 -2
  3. package/lib/entity/account/accountState.d.ts +0 -2
  4. package/lib/entity/chargeCardTransaction/chargeCardTransaction.d.ts +1 -1
  5. package/lib/entity/depositAccount/depositAccount.d.ts +1 -1
  6. package/lib/entity/depositAccount/depositAccount.js +1 -8
  7. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +1 -1
  8. package/lib/entity/jeSchedules/jeSchedulesPayload.js +5 -10
  9. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +2 -2
  10. package/lib/entity/jeSchedules/jeSchedulesReducer.js +2 -2
  11. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +2 -1
  12. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +3 -7
  13. package/lib/entity/jeSchedules/jeSchedulesTypes.js +1 -3
  14. package/lib/entity/reimbursement/reimbursementPayload.d.ts +0 -2
  15. package/lib/entity/reimbursement/reimbursementPayload.js +0 -7
  16. package/lib/entity/reimbursement/reimbursementState.d.ts +0 -2
  17. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  18. package/lib/entity/snackbar/snackbarTypes.js +0 -1
  19. package/lib/entity/transaction/transactionReducer.js +2 -3
  20. package/lib/entity/transaction/transactionSelector.d.ts +2 -2
  21. package/lib/entity/transaction/transactionState.d.ts +2 -3
  22. package/lib/epic.d.ts +1 -12
  23. package/lib/epic.js +1 -12
  24. package/lib/esm/entity/account/accountPayload.js +0 -2
  25. package/lib/esm/entity/depositAccount/depositAccount.js +1 -8
  26. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +5 -10
  27. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +3 -3
  28. package/lib/esm/entity/jeSchedules/jeSchedulesTypes.js +0 -1
  29. package/lib/esm/entity/reimbursement/reimbursementPayload.js +0 -7
  30. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -1
  31. package/lib/esm/entity/transaction/transactionReducer.js +2 -3
  32. package/lib/esm/epic.js +1 -12
  33. package/lib/esm/index.js +5 -11
  34. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +5 -7
  35. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +1 -189
  36. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +12 -4
  37. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +2 -433
  38. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +1 -23
  39. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +1 -244
  40. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -2
  41. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +0 -44
  42. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +1 -2
  43. package/lib/esm/view/scheduleView/scheduleDetailView/epics/fetchScheduleDetailsEpic.js +7 -2
  44. package/lib/esm/view/scheduleView/scheduleListView/scheduleListReducer.js +7 -2
  45. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  46. package/lib/esm/zeniAPI.js +2 -0
  47. package/lib/index.d.ts +6 -9
  48. package/lib/index.js +32 -83
  49. package/lib/tsconfig.typecheck.tsbuildinfo +1 -1
  50. package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +5 -7
  51. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  52. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +0 -118
  53. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +0 -201
  54. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +11 -11
  55. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +11 -3
  56. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +3 -76
  57. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +2 -434
  58. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +3 -11
  59. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +2 -24
  60. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +1 -69
  61. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +0 -1
  62. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  63. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +0 -243
  64. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -2
  65. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +0 -142
  66. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +1 -54
  67. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -2
  68. package/lib/view/expenseAutomationView/types/transactionsViewState.js +1 -2
  69. package/lib/view/scheduleView/scheduleDetailView/epics/fetchScheduleDetailsEpic.js +7 -2
  70. package/lib/view/scheduleView/scheduleDetailView/scheduleDetailReducer.d.ts +4 -4
  71. package/lib/view/scheduleView/scheduleListView/scheduleListReducer.js +6 -1
  72. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  73. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  74. package/lib/zeniAPI.js +2 -0
  75. package/package.json +2 -2
  76. package/lib/esm/view/expenseAutomationView/bulkUploadTiming.js +0 -10
  77. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +0 -29
  78. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +0 -49
  79. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +0 -40
  80. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +0 -47
  81. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +0 -61
  82. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -33
  83. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +0 -56
  84. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -77
  85. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +0 -79
  86. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +0 -24
  87. package/lib/view/expenseAutomationView/bulkUploadTiming.d.ts +0 -10
  88. package/lib/view/expenseAutomationView/bulkUploadTiming.js +0 -13
  89. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +0 -18
  90. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +0 -33
  91. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +0 -7
  92. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +0 -53
  93. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +0 -8
  94. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +0 -44
  95. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +0 -7
  96. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +0 -51
  97. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +0 -8
  98. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +0 -65
  99. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +0 -8
  100. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -37
  101. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +0 -9
  102. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +0 -61
  103. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +0 -14
  104. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +0 -81
  105. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +0 -25
  106. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +0 -85
  107. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +0 -7
  108. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +0 -28
@@ -1,189 +1 @@
1
- import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
- import { toAmount } from '../../../commonStateTypes/amount';
3
- import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
4
- import { toBatchFileStatus, toBatchStatusValue, toMatchSource, } from '../types/missingReceiptsViewState';
5
- // -- Converter functions --
6
- /**
7
- * Maps batch-details API `files[].status` strings to canonical {@link BatchFileStatus}.
8
- * Legacy aliases are supported during rollout; unknown strings map to `failed` so Redux never
9
- * holds untyped status values.
10
- */
11
- export function parseBatchFileStatus(raw) {
12
- const normalizedStatus = raw.trim().toLowerCase().replace(/-/g, '_');
13
- switch (normalizedStatus) {
14
- case 'exact_match':
15
- case 'matched':
16
- return 'exact_match';
17
- case 'possible_matches':
18
- case 'possible_match':
19
- case 'possiblematch':
20
- case 'un_matched':
21
- case 'unmatched':
22
- return 'possible_matches';
23
- case 'no_match':
24
- case 'nomatch':
25
- return 'no_match';
26
- case 'failed':
27
- return 'failed';
28
- default:
29
- return 'failed';
30
- }
31
- }
32
- export function toBatchFile(payload, filesEndPoint) {
33
- return {
34
- attachmentId: payload.attachment_id,
35
- candidates: payload.candidates?.map((candidate) => ({
36
- transactionId: candidate.transaction_id,
37
- matchScore: candidate.match_score,
38
- })),
39
- fileDownloadUrl: payload.file_id != null && filesEndPoint != null
40
- ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
41
- : null,
42
- fileId: payload.file_id,
43
- filePreviewUrl: payload.file_preview_url,
44
- filename: payload.filename,
45
- matchSource: payload.match_source != null
46
- ? toMatchSource(payload.match_source)
47
- : undefined,
48
- matchedTransactionId: payload.matched_transaction?.transaction_id,
49
- status: toBatchFileStatus(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((file) => toBatchFile(file, filesEndPoint)),
100
- status: toBatchStatusValue(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((batch) => isBatchListStatusCompleted(batch.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((batch) => batch.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
- /**
164
- * Amount shown in the Unmatched tab manual-search list: **first line only** when `lines` exist.
165
- * Falls back to transaction-level totals via {@link getTransactionPayloadAmount} when there is
166
- * no line or no line amount (same currency fields as the rest of the transaction payload).
167
- */
168
- function getManualSearchListAmountFromPayload(payload) {
169
- const lineAmount = payload.lines?.[0]?.amount;
170
- if (lineAmount != null) {
171
- return toAmount(lineAmount, payload.currency_code, payload.currency_symbol);
172
- }
173
- return getTransactionPayloadAmount(payload);
174
- }
175
- /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
176
- export function supportedTransactionPayloadToManualSearchResult(payload) {
177
- const amountPayload = getManualSearchListAmountFromPayload(payload);
178
- return {
179
- amount: amountPayload.amount,
180
- currencyCode: amountPayload.currencyCode,
181
- entityId: payload.vendor_id ?? payload.customer_id ?? '',
182
- memo: payload.transaction_memo ?? '',
183
- transactionDate: payload.transaction_date,
184
- transactionId: payload.transaction_id,
185
- transactionType: payload.transaction_type,
186
- vendorName: payload.vendor_name ?? '',
187
- vendorLogo: toURL(payload.logo)?.href,
188
- };
189
- }
1
+ export {};
@@ -2,8 +2,10 @@ import { createSlice } from '@reduxjs/toolkit';
2
2
  import { geNestedAccountIDHierarchyForReport } from '../../../commonStateTypes/accountView/getNestedAccountIDHierarchyForReport';
3
3
  import { toMonthYearPeriodId, } from '../../../commonStateTypes/timePeriod';
4
4
  import { mapAccountBasePayloadToAccountBase, mapAccountMetadataPayloadToAccountMetadata, } from '../../../entity/account/accountPayload';
5
- import { getJEScheduleTransactionDetailKeyPayload, } from '../../../entity/jeSchedules/jeSchedulesPayload';
5
+ import { getTransactionDetailKeyPayload, } from '../../../entity/jeSchedules/jeSchedulesPayload';
6
+ import { toTransactionID } from '../../../entity/transaction/payloadTypes/transactionIDPayload';
6
7
  import { mapAccountTypeRecommendationPayloadToAccountRecommendationByType, } from '../../accountMappingView/accountTypeRecommendation/accountTypeRecommendationPayload';
8
+ import { getZeniTransactionDetailKey } from '../../transactionDetail/transactionDetailState';
7
9
  export const accountSettingsInitialState = {
8
10
  localData: {
9
11
  selectedPrepaidExpensesAccountIds: [],
@@ -97,8 +99,14 @@ const expenseAutomationJESchedulesView = createSlice({
97
99
  },
98
100
  fetchJeSchedulesSuccess(draft, action) {
99
101
  const { jeSchedules, selectedPeriod, failedJeSchedules, refreshViewInBackground, } = action.payload;
100
- const jeScheduleTransactionKeys = jeSchedules.map((schedules) => getJEScheduleTransactionDetailKeyPayload(schedules.base_transaction));
101
- const failedJeScheduleTransactionKeys = failedJeSchedules.map((schedules) => getJEScheduleTransactionDetailKeyPayload(schedules.base_transaction));
102
+ const jeScheduleTransactionKeys = jeSchedules.map((schedules) => {
103
+ const transactionID = toTransactionID(schedules.base_transaction);
104
+ return getZeniTransactionDetailKey(transactionID);
105
+ });
106
+ const failedJeScheduleTransactionKeys = failedJeSchedules.map((schedules) => {
107
+ const transactionID = toTransactionID(schedules.base_transaction);
108
+ return getZeniTransactionDetailKey(transactionID);
109
+ });
102
110
  if (refreshViewInBackground === true &&
103
111
  draft.refreshStatus.fetchState === 'In-Progress') {
104
112
  draft.refreshStatus = { fetchState: 'Completed', error: undefined };
@@ -264,7 +272,7 @@ const expenseAutomationJESchedulesView = createSlice({
264
272
  return {
265
273
  payload: {
266
274
  jeScheduleTransactionKeys: [
267
- ...jeSchedules.map((jeSchedule) => getJEScheduleTransactionDetailKeyPayload(jeSchedule.base_transaction)),
275
+ ...jeSchedules.map((jeSchedule) => getTransactionDetailKeyPayload(jeSchedule.base_transaction)),
268
276
  ],
269
277
  },
270
278
  };
@@ -1,38 +1,6 @@
1
- import { createAction, createSlice } from '@reduxjs/toolkit';
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',
@@ -51,8 +19,6 @@ export const initialState = {
51
19
  return this.fetchState == 'Completed';
52
20
  },
53
21
  };
54
- /** Epic trigger only; batch-details fetch is handled in epics. */
55
- export const fetchBulkUploadBatchDetails = createAction('expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetails');
56
22
  const expenseAutomationMissingReceiptsView = createSlice({
57
23
  name: 'expenseAutomationMissingReceiptsView',
58
24
  initialState,
@@ -154,404 +120,7 @@ const expenseAutomationMissingReceiptsView = createSlice({
154
120
  clearExpenseAutomationMissingReceiptsView(draft) {
155
121
  Object.assign(draft, initialState);
156
122
  },
157
- // -- Bulk Upload Actions --
158
- bulkUploadReceipts: {
159
- reducer(draft) {
160
- draft.bulkUpload.phase = 'uploading';
161
- draft.bulkUpload.uploadProgress = 0;
162
- draft.bulkUpload.uploadStatus = {
163
- fetchState: 'In-Progress',
164
- error: undefined,
165
- };
166
- },
167
- prepare(files) {
168
- return { payload: { files } };
169
- },
170
- },
171
- updateBulkUploadProgress(draft, action) {
172
- draft.bulkUpload.uploadProgress = action.payload;
173
- },
174
- bulkUploadReceiptsSuccess(draft, action) {
175
- draft.bulkUpload.currentBatchId = action.payload.batchId;
176
- draft.bulkUpload.uploadProgress = 100;
177
- draft.bulkUpload.uploadStatus = {
178
- fetchState: 'Completed',
179
- error: undefined,
180
- };
181
- draft.bulkUpload.phase = 'matching';
182
- },
183
- bulkUploadReceiptsFailure(draft, action) {
184
- draft.bulkUpload.uploadStatus = {
185
- fetchState: 'Error',
186
- error: action.payload.error,
187
- };
188
- draft.bulkUpload.phase = 'idle';
189
- },
190
- bulkUploadAutomatchingTimedOut: {
191
- reducer(draft, action) {
192
- if (draft.bulkUpload.phase !== 'matching' ||
193
- draft.bulkUpload.currentBatchId !== action.payload.batchId) {
194
- return;
195
- }
196
- draft.bulkUpload.phase = 'completed';
197
- },
198
- prepare(batchId) {
199
- return { payload: { batchId } };
200
- },
201
- },
202
- pusherBatchStatusUpdate(draft, action) {
203
- const batchStatus = action.payload;
204
- draft.bulkUpload.batchStatusById[batchStatus.batchId] = batchStatus;
205
- /**
206
- * Auto-matching banner (`phase === 'matching'`) must clear when the server reports this
207
- * upload batch is done — otherwise the Missing tab keeps MatchingProgressBanner until
208
- * batch-details APIs run; EmailUploadBanner should show again for the next upload.
209
- */
210
- if (batchStatus.status === 'completed' &&
211
- draft.bulkUpload.phase === 'matching' &&
212
- draft.bulkUpload.currentBatchId === batchStatus.batchId) {
213
- draft.bulkUpload.phase = 'completed';
214
- }
215
- },
216
- requestMissingReceiptsTabNavigation(draft, action) {
217
- draft.pendingMissingReceiptsTabNavigation = action.payload.tab;
218
- },
219
- clearMissingReceiptsTabNavigation(draft) {
220
- draft.pendingMissingReceiptsTabNavigation = null;
221
- },
222
- fetchBulkUploadBatchDetailsSuccess(draft, action) {
223
- const details = action.payload;
224
- draft.bulkUpload.batchDetailsById[details.batchId] = details;
225
- draft.bulkUpload.phase = 'completed';
226
- },
227
- fetchBulkUploadBatchDetailsFailure: {
228
- reducer(draft) {
229
- draft.bulkUpload.phase = 'completed';
230
- },
231
- prepare(payload) {
232
- return { payload };
233
- },
234
- },
235
- storeBatchDetails(draft, action) {
236
- const details = action.payload;
237
- draft.bulkUpload.batchDetailsById[details.batchId] = details;
238
- /**
239
- * Multi-batch fetch paths use `storeBatchDetails` (not `fetchBulkUploadBatchDetailsSuccess`).
240
- * Without this, `phase` stays `matching` after upload forever and the Unmatched tab keeps
241
- * showing the skeleton (`bulkUploadPhase === 'matching'` in web-components).
242
- */
243
- if (draft.bulkUpload.phase === 'matching' &&
244
- draft.bulkUpload.currentBatchId === details.batchId) {
245
- draft.bulkUpload.phase = 'completed';
246
- }
247
- },
248
- batchDetailFetchFailed(draft, action) {
249
- const { batchId } = action.payload;
250
- if (!draft.bulkUpload.failedBatchDetailIds.includes(batchId)) {
251
- draft.bulkUpload.failedBatchDetailIds.push(batchId);
252
- }
253
- if (draft.bulkUpload.phase === 'matching' &&
254
- draft.bulkUpload.currentBatchId === batchId) {
255
- draft.bulkUpload.phase = 'completed';
256
- }
257
- },
258
- setInitialBatchDetailsLoading(draft) {
259
- draft.bulkUpload.batchDetailsPaginationState = {
260
- fetchState: 'In-Progress',
261
- error: undefined,
262
- };
263
- },
264
- fetchMoreBatchDetails(draft) {
265
- draft.bulkUpload.batchDetailsPaginationState = {
266
- fetchState: 'In-Progress',
267
- error: undefined,
268
- };
269
- },
270
- fetchMoreBatchDetailsComplete(draft) {
271
- draft.bulkUpload.batchDetailsPaginationState = {
272
- fetchState: 'Completed',
273
- error: undefined,
274
- };
275
- const currentId = draft.bulkUpload.currentBatchId;
276
- const currentDetails = currentId != null
277
- ? draft.bulkUpload.batchDetailsById[currentId]
278
- : undefined;
279
- if (draft.bulkUpload.phase === 'matching' &&
280
- currentId != null &&
281
- currentDetails?.status === 'completed') {
282
- draft.bulkUpload.phase = 'completed';
283
- }
284
- },
285
- fetchMoreBatchDetailsFailure(draft, action) {
286
- draft.bulkUpload.batchDetailsPaginationState = {
287
- fetchState: 'Error',
288
- error: action.payload.error,
289
- };
290
- },
291
- fetchBulkUploadBatches: {
292
- reducer(draft, action) {
293
- if (action.payload.invalidateBatchDetailsCache === true) {
294
- draft.bulkUpload.batchDetailsById = {};
295
- draft.bulkUpload.failedBatchDetailIds = [];
296
- }
297
- draft.bulkUpload.batchListFetchState = {
298
- fetchState: 'In-Progress',
299
- error: undefined,
300
- };
301
- },
302
- prepare(input) {
303
- const fetchOptions = input ?? {};
304
- return {
305
- payload: {
306
- cacheOverride: fetchOptions.cacheOverride === true,
307
- invalidateBatchDetailsCache: fetchOptions.invalidateBatchDetailsCache === true,
308
- },
309
- };
310
- },
311
- },
312
- fetchBulkUploadBatchesSuccess(draft, action) {
313
- const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
314
- draft.bulkUpload.batchListByPeriod[periodId] = action.payload.batchList;
315
- draft.bulkUpload.batchListFetchState = {
316
- fetchState: 'Completed',
317
- error: undefined,
318
- };
319
- /**
320
- * When the multi-batch-details epic has nothing to fetch (e.g. list rows not `completed`
321
- * yet, or details already present), `phase` can stay `matching` even though we already
322
- * have completed details for `currentBatchId` (from polling / Pusher). Sync so the UI can
323
- * dismiss the Unmatched skeleton.
324
- */
325
- const currentId = draft.bulkUpload.currentBatchId;
326
- if (draft.bulkUpload.phase === 'matching' && currentId != null) {
327
- const existing = draft.bulkUpload.batchDetailsById[currentId];
328
- if (existing?.status === 'completed') {
329
- draft.bulkUpload.phase = 'completed';
330
- }
331
- }
332
- },
333
- fetchBulkUploadBatchesFailure(draft, action) {
334
- draft.bulkUpload.batchListFetchState = {
335
- fetchState: 'Error',
336
- error: action.payload.error,
337
- };
338
- },
339
- confirmBulkUploadMatch: {
340
- reducer(draft) {
341
- draft.bulkUpload.confirmMatchStatus = {
342
- fetchState: 'In-Progress',
343
- error: undefined,
344
- };
345
- },
346
- prepare(batchId, attachmentId, transactionId, transactionType, fileName) {
347
- return {
348
- payload: {
349
- batchId,
350
- attachmentId,
351
- transactionId,
352
- transactionType,
353
- fileName,
354
- },
355
- };
356
- },
357
- },
358
- confirmBulkUploadMatchSuccess(draft, action) {
359
- const { batchId, attachmentId, transactionId } = action.payload;
360
- draft.bulkUpload.confirmMatchStatus = {
361
- fetchState: 'Completed',
362
- error: undefined,
363
- };
364
- const details = draft.bulkUpload.batchDetailsById[batchId];
365
- if (details != null) {
366
- const file = details.files.find((batchFile) => batchFile.attachmentId === attachmentId);
367
- if (file != null) {
368
- const originalStatus = file.status;
369
- file.status = 'exact_match';
370
- file.matchedTransactionId = transactionId;
371
- file.candidates = undefined;
372
- details.summary.matched += 1;
373
- if (originalStatus === 'no_match') {
374
- details.summary.noMatch = Math.max(0, details.summary.noMatch - 1);
375
- }
376
- else if (originalStatus === 'possible_matches') {
377
- details.summary.possibleMatches = Math.max(0, details.summary.possibleMatches - 1);
378
- }
379
- }
380
- }
381
- draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
382
- draft.bulkUpload.manualSearchUiResetKey += 1;
383
- },
384
- confirmBulkUploadMatchFailure(draft, action) {
385
- draft.bulkUpload.confirmMatchStatus = {
386
- fetchState: 'Error',
387
- error: action.payload.error,
388
- };
389
- },
390
- setBulkUploadResultsTab(draft, action) {
391
- draft.bulkUpload.currentResultsTab = action.payload;
392
- },
393
- setBulkUploadCompletedSubTab(draft, action) {
394
- draft.bulkUpload.completedSubTab = action.payload;
395
- },
396
- setBulkUploadSortConfig(draft, action) {
397
- draft.bulkUpload.sortKey = action.payload.sortKey;
398
- draft.bulkUpload.sortOrder = action.payload.sortOrder;
399
- },
400
- clearBulkUpload(draft) {
401
- Object.assign(draft.bulkUpload, initialBulkUploadState);
402
- draft.pendingMissingReceiptsTabNavigation = null;
403
- },
404
- searchTransactionsForManualMatch: {
405
- reducer(draft, action) {
406
- const { query, pageToken } = action.payload;
407
- const isLoadMore = pageToken != null;
408
- const trimmed = query.trim();
409
- /**
410
- * Cleared or too-short query: no API (see epic). Reset fully (no In-Progress).
411
- * Only bump `manualSearchUiResetKey` when clearing a real search — not when the UI
412
- * dispatches `""` on every keystroke while length is below MIN (web-components always sends
413
- * `onSearch("")` in that case), or ReceiptCard remounts and the input loses focus.
414
- */
415
- if (!isLoadMore &&
416
- trimmed.length < MIN_MANUAL_TRANSACTION_SEARCH_LENGTH) {
417
- const hadActiveSearch = draft.bulkUpload.manualSearch.searchQuery.trim().length >=
418
- MIN_MANUAL_TRANSACTION_SEARCH_LENGTH ||
419
- draft.bulkUpload.manualSearch.results.length > 0;
420
- draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
421
- if (hadActiveSearch) {
422
- draft.bulkUpload.manualSearchUiResetKey += 1;
423
- }
424
- return;
425
- }
426
- draft.bulkUpload.manualSearch.searchQuery = query;
427
- if (isLoadMore) {
428
- draft.bulkUpload.manualSearch.isLoadingMore = true;
429
- }
430
- else {
431
- draft.bulkUpload.manualSearch.isLoadingMore = false;
432
- draft.bulkUpload.manualSearch.results = [];
433
- draft.bulkUpload.manualSearch.nextPageToken = null;
434
- draft.bulkUpload.manualSearch.totalCount = 0;
435
- draft.bulkUpload.manualSearch.fetchState = {
436
- fetchState: 'In-Progress',
437
- error: undefined,
438
- };
439
- }
440
- },
441
- prepare(query, pageToken) {
442
- return { payload: { query, pageToken: pageToken ?? undefined } };
443
- },
444
- },
445
- searchTransactionsForManualMatchSuccess(draft, action) {
446
- const { append, nextPageToken, results, totalCount } = action.payload;
447
- if (append) {
448
- const merged = [...draft.bulkUpload.manualSearch.results, ...results];
449
- const byId = new Map(merged.map((result) => [result.transactionId, result]));
450
- draft.bulkUpload.manualSearch.results = Array.from(byId.values());
451
- }
452
- else {
453
- draft.bulkUpload.manualSearch.results = results;
454
- }
455
- draft.bulkUpload.manualSearch.nextPageToken = nextPageToken;
456
- draft.bulkUpload.manualSearch.totalCount = totalCount;
457
- draft.bulkUpload.manualSearch.isLoadingMore = false;
458
- draft.bulkUpload.manualSearch.fetchState = {
459
- fetchState: 'Completed',
460
- error: undefined,
461
- };
462
- },
463
- searchTransactionsForManualMatchFailure(draft, action) {
464
- draft.bulkUpload.manualSearch.isLoadingMore = false;
465
- draft.bulkUpload.manualSearch.fetchState = {
466
- fetchState: 'Error',
467
- error: action.payload.error,
468
- };
469
- },
470
- clearManualSearchResults(draft) {
471
- draft.bulkUpload.manualSearch = initialBulkUploadState.manualSearch;
472
- draft.bulkUpload.manualSearchUiResetKey += 1;
473
- },
474
- acknowledgeBulkUploadConfirmMatchComplete(draft) {
475
- draft.bulkUpload.confirmMatchStatus = {
476
- fetchState: 'Not-Started',
477
- error: undefined,
478
- };
479
- },
480
- // -- Completed Transactions Actions --
481
- fetchCompletedTransactions: {
482
- reducer(draft, action) {
483
- const { pageToken } = action.payload;
484
- if (pageToken != null) {
485
- const periods = draft.bulkUpload.completedTransactionsByPeriod;
486
- for (const entry of Object.values(periods)) {
487
- if (entry.nextPageToken === pageToken) {
488
- entry.fetchState = {
489
- fetchState: 'In-Progress',
490
- error: undefined,
491
- };
492
- break;
493
- }
494
- }
495
- }
496
- },
497
- prepare(pageToken, cacheOverride) {
498
- return { payload: { pageToken, cacheOverride } };
499
- },
500
- },
501
- fetchCompletedTransactionsSuccess(draft, action) {
502
- const { transactionIds, nextPageToken, totalCount, selectedPeriod, isInitialLoad, } = action.payload;
503
- const periodId = toMonthYearPeriodId(selectedPeriod);
504
- const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
505
- if (isInitialLoad) {
506
- draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
507
- transactionIds,
508
- nextPageToken,
509
- totalCount,
510
- fetchState: { fetchState: 'Completed', error: undefined },
511
- };
512
- }
513
- else {
514
- const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
515
- if (existing != null) {
516
- existing.transactionIds.push(...transactionIds);
517
- existing.nextPageToken = nextPageToken;
518
- existing.totalCount = totalCount;
519
- existing.fetchState = { fetchState: 'Completed', error: undefined };
520
- }
521
- else {
522
- draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
523
- transactionIds,
524
- nextPageToken,
525
- totalCount,
526
- fetchState: { fetchState: 'Completed', error: undefined },
527
- };
528
- }
529
- }
530
- },
531
- fetchCompletedTransactionsFailure(draft, action) {
532
- const periodId = toMonthYearPeriodId(action.payload.selectedPeriod);
533
- const cacheKey = getCompletedTransactionsCacheKey(periodId, draft.bulkUpload.sortKey, draft.bulkUpload.sortOrder, draft.bulkUpload.completedSubTab);
534
- const existing = draft.bulkUpload.completedTransactionsByPeriod[cacheKey];
535
- if (existing != null) {
536
- existing.fetchState = {
537
- fetchState: 'Error',
538
- error: action.payload.error,
539
- };
540
- }
541
- else {
542
- draft.bulkUpload.completedTransactionsByPeriod[cacheKey] = {
543
- fetchState: { fetchState: 'Error', error: action.payload.error },
544
- nextPageToken: null,
545
- totalCount: 0,
546
- transactionIds: [],
547
- };
548
- }
549
- },
550
123
  },
551
124
  });
552
- export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView,
553
- // Bulk Upload
554
- bulkUploadReceipts, updateBulkUploadProgress, bulkUploadReceiptsSuccess, bulkUploadReceiptsFailure, 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,
555
- // Completed Transactions
556
- fetchCompletedTransactions, fetchCompletedTransactionsSuccess, fetchCompletedTransactionsFailure, } = expenseAutomationMissingReceiptsView.actions;
125
+ export const { fetchMissingReceipts, fetchMissingReceiptsSuccess, fetchMissingReceiptsFailure, uploadMissingReceiptSuccess, updateMissingReceiptUploadState, updateMissingReceiptsUIState, markMissingReceiptAsDone, clearExpenseAutomationMissingReceiptsView, } = expenseAutomationMissingReceiptsView.actions;
557
126
  export default expenseAutomationMissingReceiptsView.reducer;