@zeniai/client-epic-state 5.0.90-betaAR5 → 5.0.90-betaAR6

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 (73) hide show
  1. package/lib/entity/approvalRule/approvalRulePayload.d.ts +5 -34
  2. package/lib/entity/approvalRule/approvalRulePayload.js +10 -145
  3. package/lib/entity/approvalRule/approvalRuleSelector.d.ts +1 -25
  4. package/lib/entity/approvalRule/approvalRuleSelector.js +0 -40
  5. package/lib/entity/approvalRule/approvalRuleState.d.ts +7 -59
  6. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  7. package/lib/entity/snackbar/snackbarTypes.js +0 -2
  8. package/lib/epic.d.ts +1 -3
  9. package/lib/epic.js +1 -3
  10. package/lib/esm/entity/approvalRule/approvalRulePayload.js +10 -145
  11. package/lib/esm/entity/approvalRule/approvalRuleSelector.js +0 -35
  12. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -2
  13. package/lib/esm/epic.js +1 -3
  14. package/lib/esm/index.js +5 -7
  15. package/lib/esm/view/expenseAutomationView/transactionFilterHelpers.js +163 -66
  16. package/lib/esm/view/spendManagement/billPay/billPayReview/billPayReviewSelector.js +0 -14
  17. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +12 -109
  18. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +2 -10
  19. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +4 -8
  20. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +7 -11
  21. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +4 -13
  22. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +16 -140
  23. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -60
  24. package/lib/esm/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.js +2 -8
  25. package/lib/esm/view/spendManagement/reimbursement/editRemiView/epics/fetchEditRemiDetailPageEpic.js +1 -5
  26. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +2 -10
  27. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +2 -8
  28. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +7 -11
  29. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +4 -13
  30. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +11 -80
  31. package/lib/index.d.ts +6 -8
  32. package/lib/index.js +16 -27
  33. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  34. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  35. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  36. package/lib/view/expenseAutomationView/transactionFilterHelpers.js +163 -66
  37. package/lib/view/people/peopleTypes.d.ts +1 -1
  38. package/lib/view/spendManagement/billPay/billPayReview/billPayReviewSelector.d.ts +0 -7
  39. package/lib/view/spendManagement/billPay/billPayReview/billPayReviewSelector.js +0 -14
  40. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.d.ts +3 -14
  41. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +13 -110
  42. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewState.d.ts +0 -16
  43. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +2 -10
  44. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +4 -8
  45. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +6 -10
  46. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +3 -12
  47. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +1 -59
  48. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +17 -142
  49. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +5 -31
  50. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -8
  51. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +4 -60
  52. package/lib/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.js +2 -8
  53. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  54. package/lib/view/spendManagement/reimbursement/editRemiView/epics/fetchEditRemiDetailPageEpic.js +1 -5
  55. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +2 -10
  56. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +2 -8
  57. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +6 -10
  58. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +3 -12
  59. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.d.ts +3 -14
  60. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +12 -81
  61. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewState.d.ts +0 -12
  62. package/lib/view/taskManager/taskListView/taskList.d.ts +3 -3
  63. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +1 -1
  64. package/package.json +1 -1
  65. package/lib/entity/approvalRule/approvalRuleConflict.d.ts +0 -56
  66. package/lib/entity/approvalRule/approvalRuleConflict.js +0 -77
  67. package/lib/esm/entity/approvalRule/approvalRuleConflict.js +0 -74
  68. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +0 -54
  69. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +0 -61
  70. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.d.ts +0 -23
  71. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +0 -58
  72. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.d.ts +0 -14
  73. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +0 -65
@@ -7,19 +7,6 @@
7
7
  * being implicitly coerced to falsy.
8
8
  */
9
9
  const isNonEmptyString = (s) => s != null && s !== '';
10
- /**
11
- * First line item in UI order. `lineItemById` is a Record whose iteration
12
- * order is not guaranteed to match what the user sees; `sortedLineItems`
13
- * is the canonical ordering used by the categorization list/detail views.
14
- */
15
- const getFirstLineItemFromReviewLocalData = (localData) => {
16
- const { sortedLineItems, lineItemById } = localData;
17
- if (sortedLineItems.length > 0) {
18
- return lineItemById[sortedLineItems[0]];
19
- }
20
- const lineItems = Object.values(lineItemById);
21
- return lineItems.length > 0 ? lineItems[0] : undefined;
22
- };
23
10
  export const TRANSACTION_FILTER_CATEGORIES = [
24
11
  { value: 'payment_account_name', type: 'dropdown' },
25
12
  { value: 'payment_account_type', type: 'dropdown' },
@@ -93,15 +80,141 @@ const getLineAmountsForTransaction = (transaction) => {
93
80
  * instead).
94
81
  */
95
82
  const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
83
+ /**
84
+ * Per-line category (account) identifiers for a transaction. Source
85
+ * precedence mirrors `getLineAmountsForTransaction`:
86
+ *
87
+ * 1. `transactionLocalData.transactionReviewLocalData.lineItemById` —
88
+ * every locally-edited line item participates (not just the first
89
+ * sorted one, the way the old single-scalar `category` resolver did).
90
+ * 2. `transaction.transaction.lines` with the same type narrowing the
91
+ * old code used: only the three line types that carry an `account`
92
+ * (`transaction_with_account_and_class_line`,
93
+ * `transaction_with_product_or_service_line`,
94
+ * `journal_entry_transaction_line`) contribute. Payment-only / tax /
95
+ * discount lines are skipped rather than coerced to a sentinel.
96
+ *
97
+ * Each contributing line resolves to a single identifier via the same
98
+ * `accountId → qboId → accountName` fallback the old code used. Lines
99
+ * whose account is absent or blank everywhere drop out so the empty-array
100
+ * case bubbles up to `transactionMatchesCategory`'s absent-value contract
101
+ * (only `not_equal` matches a fully-missing identifier, every other
102
+ * operator excludes the row).
103
+ */
104
+ const getLineCategoryIdentifiersForTransaction = (transaction) => {
105
+ const localData = transaction?.transactionLocalData?.transactionReviewLocalData;
106
+ if (localData?.lineItemById != null) {
107
+ const lineItems = Object.values(localData.lineItemById);
108
+ if (lineItems.length > 0) {
109
+ return lineItems
110
+ .map((lineItem) => resolveAccountIdentifier(lineItem?.account))
111
+ .filter(isNonEmptyString);
112
+ }
113
+ }
114
+ if (transaction?.transaction?.lines != null &&
115
+ transaction.transaction.lines.length > 0) {
116
+ return transaction.transaction.lines
117
+ .map((line) => {
118
+ if (!isAccountAndClassLine(line)) {
119
+ return undefined;
120
+ }
121
+ return resolveAccountIdentifier(line.account);
122
+ })
123
+ .filter(isNonEmptyString);
124
+ }
125
+ return [];
126
+ };
127
+ /**
128
+ * Per-line class identifiers for a transaction. Same shape and precedence
129
+ * as `getLineCategoryIdentifiersForTransaction` but reads the `class`
130
+ * field on each line and uses the `classId → qboId → className` fallback.
131
+ */
132
+ const getLineClassIdentifiersForTransaction = (transaction) => {
133
+ const localData = transaction?.transactionLocalData?.transactionReviewLocalData;
134
+ if (localData?.lineItemById != null) {
135
+ const lineItems = Object.values(localData.lineItemById);
136
+ if (lineItems.length > 0) {
137
+ return lineItems
138
+ .map((lineItem) => resolveClassIdentifier(lineItem?.class))
139
+ .filter(isNonEmptyString);
140
+ }
141
+ }
142
+ if (transaction?.transaction?.lines != null &&
143
+ transaction.transaction.lines.length > 0) {
144
+ return transaction.transaction.lines
145
+ .map((line) => {
146
+ if (!isAccountAndClassLine(line)) {
147
+ return undefined;
148
+ }
149
+ return resolveClassIdentifier(line.class);
150
+ })
151
+ .filter(isNonEmptyString);
152
+ }
153
+ return [];
154
+ };
155
+ /**
156
+ * Type-narrowing guard for the three persisted line shapes that carry an
157
+ * `account` + `class`. Kept as a single helper so the type list stays in
158
+ * one place if a new categorizable line variant is added.
159
+ *
160
+ * Typed against the union element produced by indexing `lines[number]` on
161
+ * the broader transaction type — the parameter is permitted to be
162
+ * `undefined` so callers can pass a possibly-sparse `lines` element
163
+ * without an extra null check.
164
+ */
165
+ const isAccountAndClassLine = (line) => line?.type === 'transaction_with_account_and_class_line' ||
166
+ line?.type === 'transaction_with_product_or_service_line' ||
167
+ line?.type === 'journal_entry_transaction_line';
168
+ /**
169
+ * Resolve an `account` substructure to the comparable identifier the
170
+ * filter values are keyed by — same precedence the old single-scalar
171
+ * resolver used. `isNonEmptyString` rather than `??` so an empty-string
172
+ * placeholder doesn't shadow a meaningful later candidate.
173
+ */
174
+ const resolveAccountIdentifier = (account) => {
175
+ if (account == null) {
176
+ return undefined;
177
+ }
178
+ if (isNonEmptyString(account.accountId)) {
179
+ return account.accountId;
180
+ }
181
+ if (isNonEmptyString(account.qboId)) {
182
+ return account.qboId;
183
+ }
184
+ if (isNonEmptyString(account.accountName)) {
185
+ return account.accountName;
186
+ }
187
+ return undefined;
188
+ };
189
+ /**
190
+ * Mirror of `resolveAccountIdentifier` for the `class` substructure.
191
+ */
192
+ const resolveClassIdentifier = (classData) => {
193
+ if (classData == null) {
194
+ return undefined;
195
+ }
196
+ if (isNonEmptyString(classData.classId)) {
197
+ return classData.classId;
198
+ }
199
+ if (isNonEmptyString(classData.qboId)) {
200
+ return classData.qboId;
201
+ }
202
+ if (isNonEmptyString(classData.className)) {
203
+ return classData.className;
204
+ }
205
+ return undefined;
206
+ };
96
207
  /**
97
208
  * Resolve the comparable value for a transaction against a given filter field.
98
209
  * Returns undefined when the transaction doesn't carry the field — callers
99
210
  * decide whether absence counts as a match (for 'not_equal' it does).
100
211
  *
101
- * NOTE: the `'amount'` field is NOT handled here. Amount matching is
102
- * per-line (see `getLineAmountsForTransaction` + the early-return in
103
- * `transactionMatchesCategory`) and would otherwise need to return a
104
- * non-scalar value that doesn't fit this helper's contract.
212
+ * NOTE: the `'amount'`, `'category'`, and `'class'` fields are NOT handled
213
+ * here. All three use per-line matching via the corresponding
214
+ * `getLine*ForTransaction` helper and an early-return in
215
+ * `transactionMatchesCategory` they would otherwise need to return a
216
+ * non-scalar value that doesn't fit this helper's contract. Cases are
217
+ * preserved so the switch stays exhaustive over `TransactionFilterCategoryField`.
105
218
  */
106
219
  const getCategoryValueForTransaction = (key, transaction) => {
107
220
  switch (key) {
@@ -139,58 +252,13 @@ const getCategoryValueForTransaction = (key, transaction) => {
139
252
  return transaction.transaction.paymentType;
140
253
  }
141
254
  case 'category': {
142
- const localDataForCategory = transaction.transactionLocalData?.transactionReviewLocalData;
143
- if (localDataForCategory != null) {
144
- const firstLineItem = getFirstLineItemFromReviewLocalData(localDataForCategory);
145
- const accountId = firstLineItem?.account?.accountId;
146
- if (isNonEmptyString(accountId)) {
147
- return accountId;
148
- }
149
- const qboId = firstLineItem?.account?.qboId;
150
- if (isNonEmptyString(qboId)) {
151
- return qboId;
152
- }
153
- const accountName = firstLineItem?.account?.accountName;
154
- if (isNonEmptyString(accountName)) {
155
- return accountName;
156
- }
157
- }
158
- const firstLineForCategory = transaction.transaction.lines?.[0];
159
- if (firstLineForCategory?.type ===
160
- 'transaction_with_account_and_class_line' ||
161
- firstLineForCategory?.type ===
162
- 'transaction_with_product_or_service_line' ||
163
- firstLineForCategory?.type === 'journal_entry_transaction_line') {
164
- const account = firstLineForCategory.account;
165
- return account?.accountId ?? account?.qboId ?? account?.accountName;
166
- }
255
+ // Handled per-line in `transactionMatchesCategory` — see
256
+ // `getLineCategoryIdentifiersForTransaction`.
167
257
  return undefined;
168
258
  }
169
259
  case 'class': {
170
- const localDataForClass = transaction.transactionLocalData?.transactionReviewLocalData;
171
- if (localDataForClass != null) {
172
- const firstLineItemForClass = getFirstLineItemFromReviewLocalData(localDataForClass);
173
- const classId = firstLineItemForClass?.class?.classId;
174
- if (isNonEmptyString(classId)) {
175
- return classId;
176
- }
177
- const qboId = firstLineItemForClass?.class?.qboId;
178
- if (isNonEmptyString(qboId)) {
179
- return qboId;
180
- }
181
- const className = firstLineItemForClass?.class?.className;
182
- if (isNonEmptyString(className)) {
183
- return className;
184
- }
185
- }
186
- const firstLineForClass = transaction.transaction.lines?.[0];
187
- if (firstLineForClass?.type === 'transaction_with_account_and_class_line' ||
188
- firstLineForClass?.type ===
189
- 'transaction_with_product_or_service_line' ||
190
- firstLineForClass?.type === 'journal_entry_transaction_line') {
191
- const classData = firstLineForClass.class;
192
- return classData?.classId ?? classData?.qboId ?? classData?.className;
193
- }
260
+ // Handled per-line in `transactionMatchesCategory` — see
261
+ // `getLineClassIdentifiersForTransaction`.
194
262
  return undefined;
195
263
  }
196
264
  default:
@@ -246,6 +314,35 @@ const matchAmount = (amount, category) => {
246
314
  return op === 'not_equal' ? !matched : matched;
247
315
  };
248
316
  const transactionMatchesCategory = (transaction, category) => {
317
+ if (category.field === 'category' || category.field === 'class') {
318
+ // Per-line matching for category / class — mirrors the amount
319
+ // pattern below. A multi-line transaction surfaces when ANY of its
320
+ // lines has the selected account / class, instead of the old
321
+ // first-line-only behavior (which silently excluded transactions
322
+ // whose first sorted line wasn't categorized as the filter target,
323
+ // even if later lines were). The full row, with non-matching lines
324
+ // included, renders downstream. The matcher only decides row
325
+ // inclusion; it does NOT filter which lines are rendered inside the
326
+ // row.
327
+ //
328
+ // `not_equal` reads as "at least one line is NOT one of the filter
329
+ // values" — same `.some()` interpretation we adopted for amount.
330
+ // A row with lines [Software, Travel] matches `category != Software`
331
+ // (the Travel line satisfies the negation); a row with lines
332
+ // [Software, Software] does not (no line satisfies).
333
+ const lineIdentifiers = category.field === 'category'
334
+ ? getLineCategoryIdentifiersForTransaction(transaction)
335
+ : getLineClassIdentifiersForTransaction(transaction);
336
+ if (lineIdentifiers.length === 0) {
337
+ // Absent-value contract — same as amount's empty-array branch.
338
+ return category.matchingOperator === 'not_equal';
339
+ }
340
+ const filterValuesAsStrings = new Set(category.values.map((v) => v.toString()));
341
+ return lineIdentifiers.some((id) => {
342
+ const inList = filterValuesAsStrings.has(id);
343
+ return category.matchingOperator === 'not_equal' ? !inList : inList;
344
+ });
345
+ }
249
346
  if (category.field === 'amount') {
250
347
  // Per-line matching: the transaction is included if ANY of its lines
251
348
  // satisfies the operator. This is what the user expects when a
@@ -52,12 +52,6 @@ export const getReviewPageBillDetail = (state, billId) => {
52
52
  let recurringConfig;
53
53
  let billPayInfo;
54
54
  let isBillMarkedForRetry = false;
55
- // Bill-level accounting class id. Approval Rules 3.0 'department'
56
- // criteria match against this. Sourced from BillTransaction so
57
- // any selector that needs it (e.g. creator-as-approver lookup)
58
- // can read it off the view rather than reaching into
59
- // 'state.billTransactionState' itself.
60
- let classId;
61
55
  const zeniAssistRetryStatus = billId != null
62
56
  ? billDetailViewState.billDetailById[key].zeniAssist.retryStatus
63
57
  : undefined;
@@ -68,13 +62,6 @@ export const getReviewPageBillDetail = (state, billId) => {
68
62
  transaction?.billPayInfo.isCollectToAccountInfoFromVendorContact ?? false;
69
63
  isRecurring = transaction?.isRecurring ?? false;
70
64
  billPayInfo = transaction?.billPayInfo;
71
- // Normalise empty-string to undefined so downstream readers
72
- // treat "no class" uniformly regardless of whether the wire
73
- // used '' or omitted the field.
74
- classId =
75
- transaction?.classId != null && transaction.classId !== ''
76
- ? transaction.classId
77
- : undefined;
78
65
  if (isRecurring &&
79
66
  transaction?.recurringBillConfigId != null &&
80
67
  transaction.recurringBillInstance != null) {
@@ -191,6 +178,5 @@ export const getReviewPageBillDetail = (state, billId) => {
191
178
  zeniAssistRetryStatus,
192
179
  billPayInfo,
193
180
  outsideZeniPaymentInfo,
194
- classId,
195
181
  };
196
182
  };
@@ -13,7 +13,6 @@ export const initialState = {
13
13
  newApprovalRuleId: undefined,
14
14
  approvalRulesDeleteStatusById: {},
15
15
  billPaySetupApproverViewUpdateData: undefined,
16
- reorderStatus: { fetchState: 'Not-Started', error: undefined },
17
16
  hasValidState() {
18
17
  return this.fetchState === 'Completed';
19
18
  },
@@ -27,13 +26,8 @@ const billPaySetupApproverView = createSlice({
27
26
  draft.fetchState = 'In-Progress';
28
27
  draft.error = undefined;
29
28
  },
30
- // Approval Rules 3.0 `useV3` arrives from the screen connector
31
- // ('approval_rule_v3_config' dynamic config) and picks the v1
32
- // vs v2 endpoint in the fetch epic. Required (no default) so a
33
- // missing screen-connector wire surfaces at compile time rather
34
- // than silently falling back to v1 on a v3 tenant.
35
- prepare(cacheOverride = false, includeUserRoles = true, useV3) {
36
- return { payload: { cacheOverride, includeUserRoles, useV3 } };
29
+ prepare(cacheOverride = false, includeUserRoles = true) {
30
+ return { payload: { cacheOverride, includeUserRoles } };
37
31
  },
38
32
  },
39
33
  fetchBillPaySetupApproverViewSuccess: {
@@ -118,12 +112,8 @@ const billPaySetupApproverView = createSlice({
118
112
  error: undefined,
119
113
  };
120
114
  },
121
- // Approval Rules 3.0 — `useV3` flows from the screen connector
122
- // ('approval_rule_v3_config' dynamic config) so the delete epic
123
- // can pick the v1 vs v2 endpoint. Required (no default) so a
124
- // missing connector wire surfaces at compile time.
125
- prepare(approvalRuleId, useV3) {
126
- return { payload: { approvalRuleId, useV3 } };
115
+ prepare(approvalRuleId) {
116
+ return { payload: { approvalRuleId } };
127
117
  },
128
118
  },
129
119
  deleteBillPayApprovalRuleSuccess: {
@@ -155,100 +145,13 @@ const billPaySetupApproverView = createSlice({
155
145
  };
156
146
  },
157
147
  },
158
- /**
159
- * Approval Rules 3.0 list-page drag-and-drop reorder.
160
- *
161
- * The trigger action carries the desired ordering as an ID list.
162
- * The reducer optimistically replaces 'approvalRuleIds' so the
163
- * list page renders the new order immediately; the epic then
164
- * fires the PUT and either confirms (success — pulls updated
165
- * priorities from the response) or recovers (failure — refetches
166
- * the view so we don't strand a stale local order).
167
- */
168
- reorderBillPayApprovalRules: {
169
- reducer(draft, action) {
170
- const { approvalRuleIds } = action.payload;
171
- const wasReorderInFlight = draft.reorderStatus.fetchState === 'In-Progress';
172
- draft.reorderStatus = { fetchState: 'In-Progress', error: undefined };
173
- // Stash the pre-reorder order so 'Failure' can restore it
174
- // synchronously. The epic's refetch on failure remains as a
175
- // safety net (covers cases where the server's truth has
176
- // drifted from the local snapshot), but the snappy UX path
177
- // is the in-memory rollback.
178
- //
179
- // Only capture a fresh snapshot when no reorder is already in
180
- // flight. If a second drag fires before the first PUT lands,
181
- // the existing snapshot already holds the last server-backed
182
- // order; overwriting it with the first reorder's optimistic
183
- // result would mean a Failure rolls back to an uncommitted
184
- // intermediate order instead of the last good list.
185
- if (!wasReorderInFlight) {
186
- draft.reorderRollbackIds = draft.approvalRuleIds;
187
- }
188
- // Optimistic: render new order immediately. On failure, the
189
- // reducer restores 'reorderRollbackIds' and the epic refetch
190
- // reconciles any drift.
191
- draft.approvalRuleIds = approvalRuleIds;
192
- },
193
- // Approval Rules 3.0 — `useV3` required so a missing wire
194
- // surfaces at compile time. The reorder epic always hits the
195
- // v2 endpoint (v1 has no reorder route), but the payload still
196
- // carries the flag for the failure-path refetch which needs it.
197
- prepare(approvalRuleIds, useV3) {
198
- return { payload: { approvalRuleIds, useV3 } };
199
- },
200
- },
201
- reorderBillPayApprovalRulesSuccess: {
202
- reducer(draft, action) {
203
- const { approvalRuleIds } = action.payload;
204
- draft.reorderStatus = { fetchState: 'Completed', error: undefined };
205
- // The API response is authoritative — overwrite with the
206
- // server's reported order in case it normalised anything.
207
- draft.approvalRuleIds = approvalRuleIds;
208
- // Reorder succeeded — discard the snapshot so the next
209
- // reorder starts from this committed order.
210
- draft.reorderRollbackIds = undefined;
211
- },
212
- prepare(approvalRuleIds) {
213
- return { payload: { approvalRuleIds } };
214
- },
215
- },
216
- reorderBillPayApprovalRulesFailure: {
217
- reducer(draft, action) {
218
- const { status } = action.payload;
219
- draft.reorderStatus = { fetchState: 'Error', error: status };
220
- // Restore the snapshot taken on the trigger reducer before
221
- // the optimistic mutation. The epic still fires a refetch
222
- // alongside the failure action for cross-tab drift recovery,
223
- // but locally the user sees their last good order instantly.
224
- if (draft.reorderRollbackIds != null) {
225
- draft.approvalRuleIds = draft.reorderRollbackIds;
226
- draft.reorderRollbackIds = undefined;
227
- }
228
- },
229
- prepare(status) {
230
- return { payload: { status } };
231
- },
232
- },
233
- saveBillPaySetupApproverViewUpdates: {
234
- // Approval Rules 3.0 — `useV3` is sourced from the
235
- // `approval_rule_v3_config` dynamic config in the screen
236
- // connector. The reducer doesn't read it (the field only
237
- // matters in the save epic), but it must be declared so the
238
- // action's payload type is correctly inferred for downstream
239
- // consumers.
240
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
241
- reducer(draft, _action) {
242
- if (draft.billPaySetupApproverViewUpdateData != null) {
243
- draft.billPaySetupApproverViewUpdateData.updateStatus = {
244
- fetchState: 'In-Progress',
245
- error: undefined,
246
- };
247
- }
248
- },
249
- prepare(useV3) {
250
- return { payload: { useV3 } };
251
- },
148
+ saveBillPaySetupApproverViewUpdates(draft) {
149
+ if (draft.billPaySetupApproverViewUpdateData != null) {
150
+ draft.billPaySetupApproverViewUpdateData.updateStatus = {
151
+ fetchState: 'In-Progress',
152
+ error: undefined,
153
+ };
154
+ }
252
155
  },
253
156
  saveBillPaySetupApproverViewUpdatesSuccess: {
254
157
  reducer(draft, action) {
@@ -337,5 +240,5 @@ const billPaySetupApproverView = createSlice({
337
240
  },
338
241
  },
339
242
  });
340
- export const { fetchBillPaySetupApproverView, fetchBillPaySetupApproverViewSuccess, fetchBillPaySetupApproverViewFailure, fetchBillPayApproversDetails, fetchBillPayApproversList, fetchBillPayApproversListSuccess, fetchBillPayApproversListFailure, deleteBillPayApprovalRule, deleteBillPayApprovalRuleSuccess, deleteBillPayApprovalRuleFailure, reorderBillPayApprovalRules, reorderBillPayApprovalRulesSuccess, reorderBillPayApprovalRulesFailure, saveBillPaySetupApproverViewUpdates, saveBillPaySetupApproverViewUpdatesSuccess, saveBillPaySetupApproverViewUpdatesFailure, initializeBillPaySetupApproverViewUpdateData, saveBillPaySetupApproverViewUpdateData, clearBillPaySetupApproverViewUpdateData, setListeningToPusherEvent, clearBillPaySetupApproverView, } = billPaySetupApproverView.actions;
243
+ export const { fetchBillPaySetupApproverView, fetchBillPaySetupApproverViewSuccess, fetchBillPaySetupApproverViewFailure, fetchBillPayApproversDetails, fetchBillPayApproversList, fetchBillPayApproversListSuccess, fetchBillPayApproversListFailure, deleteBillPayApprovalRule, deleteBillPayApprovalRuleSuccess, deleteBillPayApprovalRuleFailure, saveBillPaySetupApproverViewUpdates, saveBillPaySetupApproverViewUpdatesSuccess, saveBillPaySetupApproverViewUpdatesFailure, initializeBillPaySetupApproverViewUpdateData, saveBillPaySetupApproverViewUpdateData, clearBillPaySetupApproverViewUpdateData, setListeningToPusherEvent, clearBillPaySetupApproverView, } = billPaySetupApproverView.actions;
341
244
  export default billPaySetupApproverView.reducer;
@@ -6,17 +6,9 @@ import { updateAllUsers } from '../../../../../entity/user/userReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
7
  import { deleteBillPayApprovalRule, deleteBillPayApprovalRuleFailure, deleteBillPayApprovalRuleSuccess, } from '../billPaySetupApproverViewReducer';
8
8
  export const deleteBillPayApprovalRuleEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(deleteBillPayApprovalRule.match), switchMap((action) => {
9
- const { approvalRuleId, useV3 } = action.payload;
10
- // Approval Rules 3.0 — flag-gated endpoint selection.
11
- // Explicit `=== true` keeps `strict-boolean-expressions` happy
12
- // when RTK's payload type widens to `any` in some configs.
13
- const endpoint = useV3 === true
14
- ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
15
- : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
9
+ const { approvalRuleId } = action.payload;
16
10
  return zeniAPI
17
- .deleteAndGetJSON(endpoint, {
18
- approval_rule_id: approvalRuleId,
19
- })
11
+ .deleteAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`, { approval_rule_id: approvalRuleId })
20
12
  .pipe(mergeMap((response) => {
21
13
  if (isSuccessResponse(response) && response.data != null) {
22
14
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
@@ -6,7 +6,7 @@ import { updateAllUsers } from '../../../../../entity/user/userReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
7
  import { fetchBillPaySetupApproverView, fetchBillPaySetupApproverViewFailure, fetchBillPaySetupApproverViewSuccess, } from '../billPaySetupApproverViewReducer';
8
8
  export const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBillPaySetupApproverView.match), switchMap((action) => {
9
- const { cacheOverride, useV3 } = action.payload;
9
+ const { cacheOverride } = action.payload;
10
10
  const { billPaySetupApproverViewState, approvalRuleState } = state$.value;
11
11
  const approvalRules = getApprovalRulesByIds(approvalRuleState, billPaySetupApproverViewState.approvalRuleIds);
12
12
  if (cacheOverride === true ||
@@ -14,13 +14,9 @@ export const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) =>
14
14
  billPaySetupApproverViewState.approvalRuleIds.length ||
15
15
  (billPaySetupApproverViewState.hasValidState() === false &&
16
16
  billPaySetupApproverViewState.fetchState !== 'In-Progress')) {
17
- // Approval Rules 3.0 — flag-gated endpoint selection.
18
- // Explicit `=== true` keeps `strict-boolean-expressions` happy
19
- // when RTK's payload type widens to `any` in some configs.
20
- const endpoint = useV3 === true
21
- ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
22
- : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
23
- return zeniAPI.getJSON(endpoint).pipe(mergeMap((response) => {
17
+ return zeniAPI
18
+ .getJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`)
19
+ .pipe(mergeMap((response) => {
24
20
  if (isSuccessResponse(response) && response.data != null) {
25
21
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
26
22
  const actions = [
@@ -1,6 +1,6 @@
1
1
  import { from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
- import { getAmountCriteria, getApprovalRuleById, getDepartmentCriteria, getVendorCriteria, } from '../../../../../entity/approvalRule/approvalRuleSelector';
3
+ import { getApprovalRuleById } from '../../../../../entity/approvalRule/approvalRuleSelector';
4
4
  import { clearBillPaySetupApproverViewUpdateData, initializeBillPaySetupApproverViewUpdateData, saveBillPaySetupApproverViewUpdateData, } from '../billPaySetupApproverViewReducer';
5
5
  export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state$) => actions$.pipe(filter(initializeBillPaySetupApproverViewUpdateData.match), mergeMap((action) => {
6
6
  const { approvalRuleId } = action.payload;
@@ -8,20 +8,16 @@ export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state
8
8
  if (approvalRuleId != null) {
9
9
  const approvalRule = getApprovalRuleById(state$.value.approvalRuleState, approvalRuleId);
10
10
  if (approvalRule != null) {
11
+ const criteria = approvalRule.criteria[0];
12
+ const range = criteria?.range;
11
13
  const billPaySetupApproverViewUpdateData = {
12
14
  approvalRuleId,
13
15
  steps: approvalRule.steps,
14
16
  criteria: {
15
- amount: getAmountCriteria(approvalRule.criteria),
16
- vendor: getVendorCriteria(approvalRule.criteria),
17
- department: getDepartmentCriteria(approvalRule.criteria),
17
+ rangeType: criteria?.rangeType,
18
+ rangeEntity: criteria?.rangeEntity,
19
+ range,
18
20
  },
19
- // Approval Rules 3.0 — seed rule-level fields so the form can
20
- // round-trip them on edit. Each may be undefined on legacy rules.
21
- name: approvalRule.name,
22
- description: approvalRule.description,
23
- separationOfDuties: approvalRule.separationOfDuties,
24
- isFallback: approvalRule.isFallback,
25
21
  };
26
22
  fetchActions.push(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewUpdateData));
27
23
  }
@@ -29,7 +25,7 @@ export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state
29
25
  else {
30
26
  const billPaySetupApproverViewCreateData = {
31
27
  steps: [],
32
- criteria: {},
28
+ criteria: undefined,
33
29
  };
34
30
  fetchActions.push(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewCreateData));
35
31
  }
@@ -5,24 +5,15 @@ import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
5
5
  import { updateAllUsers } from '../../../../../entity/user/userReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
7
  import { saveBillPaySetupApproverViewUpdates, saveBillPaySetupApproverViewUpdatesFailure, saveBillPaySetupApproverViewUpdatesSuccess, } from '../billPaySetupApproverViewReducer';
8
- import { toApprovalChangableInfoPayload, toApprovalChangableInfoPayloadV1, } from '../types/commonPayload';
9
- export const saveBillPaySetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveBillPaySetupApproverViewUpdates.match), switchMap((action) => {
8
+ import { toApprovalChangableInfoPayload } from '../types/commonPayload';
9
+ export const saveBillPaySetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveBillPaySetupApproverViewUpdates.match), switchMap(() => {
10
10
  const { billPaySetupApproverViewState } = state$.value;
11
11
  const billPaySetupApproverViewUpdateData = billPaySetupApproverViewState.billPaySetupApproverViewUpdateData;
12
12
  if (billPaySetupApproverViewUpdateData != null &&
13
13
  billPaySetupApproverViewUpdateData.data != null) {
14
- // Approval Rules 3.0 — gate URL + write-side payload mapper on
15
- // the `approval_rule_v3_config` dynamic config. `useV3` arrives
16
- // on the action payload from the screen connector.
17
- const { useV3 } = action.payload;
18
- const payload = useV3
19
- ? toApprovalChangableInfoPayload(billPaySetupApproverViewUpdateData.data)
20
- : toApprovalChangableInfoPayloadV1(billPaySetupApproverViewUpdateData.data);
21
- const endpoint = useV3
22
- ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
23
- : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
14
+ const payload = toApprovalChangableInfoPayload(billPaySetupApproverViewUpdateData.data);
24
15
  return zeniAPI
25
- .postAndGetJSON(endpoint, payload)
16
+ .postAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`, payload)
26
17
  .pipe(mergeMap((response) => {
27
18
  if (isSuccessResponse(response) && response.data != null) {
28
19
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);