@zeniai/client-epic-state 5.0.85-betaAR1 → 5.0.85-betaAR3

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 (64) hide show
  1. package/lib/entity/approvalRule/approvalRulePayload.d.ts +5 -34
  2. package/lib/entity/approvalRule/approvalRulePayload.js +10 -130
  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 -130
  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 +66 -18
  16. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +12 -74
  17. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +2 -10
  18. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +4 -8
  19. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +7 -11
  20. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +4 -13
  21. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +16 -122
  22. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +2 -7
  23. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +2 -10
  24. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +2 -8
  25. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +7 -11
  26. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +4 -13
  27. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +11 -63
  28. package/lib/index.d.ts +6 -8
  29. package/lib/index.js +16 -26
  30. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  31. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  32. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  33. package/lib/view/expenseAutomationView/transactionFilterHelpers.js +66 -18
  34. package/lib/view/people/peopleTypes.d.ts +1 -1
  35. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.d.ts +3 -14
  36. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +13 -75
  37. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewState.d.ts +0 -8
  38. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +2 -10
  39. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +4 -8
  40. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +6 -10
  41. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +3 -12
  42. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +1 -50
  43. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +17 -124
  44. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +5 -31
  45. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +2 -7
  46. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  47. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +2 -10
  48. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +2 -8
  49. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +6 -10
  50. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +3 -12
  51. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.d.ts +3 -14
  52. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +12 -64
  53. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewState.d.ts +0 -5
  54. package/lib/view/taskManager/taskListView/taskList.d.ts +3 -3
  55. package/package.json +1 -1
  56. package/lib/entity/approvalRule/approvalRuleConflict.d.ts +0 -56
  57. package/lib/entity/approvalRule/approvalRuleConflict.js +0 -77
  58. package/lib/esm/entity/approvalRule/approvalRuleConflict.js +0 -74
  59. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +0 -54
  60. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +0 -49
  61. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.d.ts +0 -23
  62. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +0 -58
  63. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.d.ts +0 -14
  64. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +0 -53
@@ -28,28 +28,57 @@ export const TRANSACTION_FILTER_CATEGORIES = [
28
28
  { value: 'class', type: 'dropdown' },
29
29
  { value: 'amount', type: 'numberRange' },
30
30
  ];
31
+ /**
32
+ * Per-line amounts for a transaction, preserving the canonical source
33
+ * precedence:
34
+ *
35
+ * 1. `transactionLocalData.transactionReviewLocalData.lineItemById` —
36
+ * the locally-edited line items the user sees in the grid. Reflects
37
+ * unsaved edits so the filter matches what the user actually has on
38
+ * screen, not the pre-edit server state.
39
+ * 2. `transaction.transaction.lines` — persisted lines from the
40
+ * transaction payload.
41
+ * 3. `[transaction.amount.amount]` — single-element fallback for
42
+ * transactions that don't have a `lines` array at all (treat the
43
+ * transaction-level amount as a one-line transaction).
44
+ *
45
+ * Returned as an array so the amount filter in `transactionMatchesCategory`
46
+ * can OR-combine per-line `matchAmount` results: a transaction is included
47
+ * if ANY of its lines satisfies the operator, and the full row (with all
48
+ * lines, matching or not) renders downstream. Before the per-line change
49
+ * this helper's predecessor in `getCategoryValueForTransaction` summed
50
+ * these values into a single aggregate and compared the sum.
51
+ */
52
+ const getLineAmountsForTransaction = (transaction) => {
53
+ const localData = transaction.transactionLocalData?.transactionReviewLocalData;
54
+ if (localData?.lineItemById != null) {
55
+ const lineItems = Object.values(localData.lineItemById);
56
+ if (lineItems.length > 0) {
57
+ return lineItems.map((lineItem) => lineItem.amount?.amount ?? 0);
58
+ }
59
+ }
60
+ if (transaction.transaction.lines != null &&
61
+ transaction.transaction.lines.length > 0) {
62
+ return transaction.transaction.lines.map((line) => line.amount?.amount ?? 0);
63
+ }
64
+ return [transaction.amount.amount];
65
+ };
31
66
  /**
32
67
  * Resolve the comparable value for a transaction against a given filter field.
33
68
  * Returns undefined when the transaction doesn't carry the field — callers
34
69
  * decide whether absence counts as a match (for 'not_equal' it does).
70
+ *
71
+ * NOTE: the `'amount'` field is NOT handled here. Amount matching is
72
+ * per-line (see `getLineAmountsForTransaction` + the early-return in
73
+ * `transactionMatchesCategory`) and would otherwise need to return a
74
+ * non-scalar value that doesn't fit this helper's contract.
35
75
  */
36
76
  const getCategoryValueForTransaction = (key, transaction) => {
37
77
  switch (key) {
38
78
  case 'amount': {
39
- // Prefer transactionLocalData line items (sum). Fall back to lines on
40
- // the transaction itself. Final fallback: transaction-level amount.
41
- const localDataForAmount = transaction.transactionLocalData?.transactionReviewLocalData;
42
- if (localDataForAmount?.lineItemById) {
43
- const lineItems = Object.values(localDataForAmount.lineItemById);
44
- if (lineItems.length > 0) {
45
- return lineItems.reduce((sum, lineItem) => sum + (lineItem.amount?.amount ?? 0), 0);
46
- }
47
- }
48
- if (transaction.transaction.lines &&
49
- transaction.transaction.lines.length > 0) {
50
- return transaction.transaction.lines.reduce((sum, line) => sum + (line.amount?.amount ?? 0), 0);
51
- }
52
- return transaction.amount.amount;
79
+ // Handled per-line in `transactionMatchesCategory` see the note on
80
+ // this function's JSDoc and `getLineAmountsForTransaction` above.
81
+ return undefined;
53
82
  }
54
83
  case 'payee': {
55
84
  if (isNonEmptyString(transaction.vendorName)) {
@@ -187,6 +216,27 @@ const matchAmount = (amount, category) => {
187
216
  return op === 'not_equal' ? !matched : matched;
188
217
  };
189
218
  const transactionMatchesCategory = (transaction, category) => {
219
+ if (category.field === 'amount') {
220
+ // Per-line matching: the transaction is included if ANY of its lines
221
+ // satisfies the operator. This is what the user expects when a
222
+ // multi-line transaction contains lines at different amounts — they
223
+ // want the row to surface if even one line falls in the filter's
224
+ // range. The full row (with non-matching lines too) renders
225
+ // downstream; this matcher only decides row inclusion. Same
226
+ // operator + sign semantics as the aggregate version, just applied
227
+ // per line.
228
+ //
229
+ // `not_equal` deserves a sanity-check: `matchAmount` already inverts
230
+ // internally for that operator, so for a line whose amount is NOT
231
+ // in the filter's `values`, matchAmount returns true; for a line
232
+ // whose amount IS in the values, it returns false. `.some()` over
233
+ // lines therefore means "the transaction has at least one line that
234
+ // is not equal to any of the filter values" — which is the right
235
+ // match-any-line interpretation of `not_equal` (a transaction
236
+ // matches if it has a line that satisfies the negation).
237
+ const lineAmounts = getLineAmountsForTransaction(transaction);
238
+ return lineAmounts.some((lineAmount) => matchAmount(lineAmount, category));
239
+ }
190
240
  const value = getCategoryValueForTransaction(category.field, transaction);
191
241
  if (value == null) {
192
242
  // Absent-value semantics — pinning these down explicitly so the
@@ -206,12 +256,10 @@ const transactionMatchesCategory = (transaction, category) => {
206
256
  // are filtered out.
207
257
  //
208
258
  // Only the `not_equal` branch returns `true` here; everything else
209
- // falls through to the `false` below.
259
+ // falls through to the `false` below. Note: 'amount' never lands here
260
+ // because it short-circuits to the per-line path above.
210
261
  return category.matchingOperator === 'not_equal';
211
262
  }
212
- if (category.field === 'amount') {
213
- return matchAmount(Number(value), category);
214
- }
215
263
  const valueStr = value.toString();
216
264
  const valueInList = category.values.some((v) => v.toString() === valueStr);
217
265
  return category.matchingOperator === 'not_equal' ? !valueInList : valueInList;
@@ -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,11 +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 vs
32
- // v2 endpoint in the fetch epic.
33
- prepare(cacheOverride = false, includeUserRoles = true, useV3 = false) {
34
- return { payload: { cacheOverride, includeUserRoles, useV3 } };
29
+ prepare(cacheOverride = false, includeUserRoles = true) {
30
+ return { payload: { cacheOverride, includeUserRoles } };
35
31
  },
36
32
  },
37
33
  fetchBillPaySetupApproverViewSuccess: {
@@ -116,11 +112,8 @@ const billPaySetupApproverView = createSlice({
116
112
  error: undefined,
117
113
  };
118
114
  },
119
- // Approval Rules 3.0 — `useV3` flows from the screen connector
120
- // (`approval_rule_v3_config` dynamic config) so the delete epic
121
- // can pick the v1 vs v2 endpoint.
122
- prepare(approvalRuleId, useV3 = false) {
123
- return { payload: { approvalRuleId, useV3 } };
115
+ prepare(approvalRuleId) {
116
+ return { payload: { approvalRuleId } };
124
117
  },
125
118
  },
126
119
  deleteBillPayApprovalRuleSuccess: {
@@ -152,68 +145,13 @@ const billPaySetupApproverView = createSlice({
152
145
  };
153
146
  },
154
147
  },
155
- /**
156
- * Approval Rules 3.0 list-page drag-and-drop reorder.
157
- *
158
- * The trigger action carries the desired ordering as an ID list.
159
- * The reducer optimistically replaces 'approvalRuleIds' so the
160
- * list page renders the new order immediately; the epic then
161
- * fires the PUT and either confirms (success — pulls updated
162
- * priorities from the response) or recovers (failure — refetches
163
- * the view so we don't strand a stale local order).
164
- */
165
- reorderBillPayApprovalRules: {
166
- reducer(draft, action) {
167
- const { approvalRuleIds } = action.payload;
168
- draft.reorderStatus = { fetchState: 'In-Progress', error: undefined };
169
- // Optimistic: render new order immediately. On failure, the
170
- // epic dispatches fetchBillPaySetupApproverView to restore.
171
- draft.approvalRuleIds = approvalRuleIds;
172
- },
173
- prepare(approvalRuleIds, useV3 = false) {
174
- return { payload: { approvalRuleIds, useV3 } };
175
- },
176
- },
177
- reorderBillPayApprovalRulesSuccess: {
178
- reducer(draft, action) {
179
- const { approvalRuleIds } = action.payload;
180
- draft.reorderStatus = { fetchState: 'Completed', error: undefined };
181
- // The API response is authoritative — overwrite with the
182
- // server's reported order in case it normalised anything.
183
- draft.approvalRuleIds = approvalRuleIds;
184
- },
185
- prepare(approvalRuleIds) {
186
- return { payload: { approvalRuleIds } };
187
- },
188
- },
189
- reorderBillPayApprovalRulesFailure: {
190
- reducer(draft, action) {
191
- const { status } = action.payload;
192
- draft.reorderStatus = { fetchState: 'Error', error: status };
193
- },
194
- prepare(status) {
195
- return { payload: { status } };
196
- },
197
- },
198
- saveBillPaySetupApproverViewUpdates: {
199
- // Approval Rules 3.0 — `useV3` is sourced from the
200
- // `approval_rule_v3_config` dynamic config in the screen
201
- // connector. The reducer doesn't read it (the field only
202
- // matters in the save epic), but it must be declared so the
203
- // action's payload type is correctly inferred for downstream
204
- // consumers.
205
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
206
- reducer(draft, _action) {
207
- if (draft.billPaySetupApproverViewUpdateData != null) {
208
- draft.billPaySetupApproverViewUpdateData.updateStatus = {
209
- fetchState: 'In-Progress',
210
- error: undefined,
211
- };
212
- }
213
- },
214
- prepare(useV3) {
215
- return { payload: { useV3 } };
216
- },
148
+ saveBillPaySetupApproverViewUpdates(draft) {
149
+ if (draft.billPaySetupApproverViewUpdateData != null) {
150
+ draft.billPaySetupApproverViewUpdateData.updateStatus = {
151
+ fetchState: 'In-Progress',
152
+ error: undefined,
153
+ };
154
+ }
217
155
  },
218
156
  saveBillPaySetupApproverViewUpdatesSuccess: {
219
157
  reducer(draft, action) {
@@ -302,5 +240,5 @@ const billPaySetupApproverView = createSlice({
302
240
  },
303
241
  },
304
242
  });
305
- 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;
306
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);
@@ -1,48 +1,20 @@
1
1
  export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
2
- // Form-side criteria is a structured object with optional slots for
3
- // amount / vendor / department; flatten it into the wire format's
4
- // `conditions[]` array.
5
- let criteriaPayload;
2
+ let criteriaPayload = [];
6
3
  if (approverViewUpdateData.criteria != null) {
7
- const { amount, vendor, department } = approverViewUpdateData.criteria;
8
- const conditions = [];
9
- if (amount?.min != null) {
10
- conditions.push({
11
- field: 'amount',
12
- type: 'gte',
13
- value: amount.min.amount,
14
- });
15
- }
16
- if (amount?.max != null) {
17
- conditions.push({
18
- field: 'amount',
19
- type: 'lte',
20
- value: amount.max.amount,
21
- });
22
- }
23
- if (vendor != null && vendor.vendorIds.length > 0) {
24
- conditions.push({
25
- field: 'vendor_id',
26
- type: vendor.operator === 'is_not' ? 'not_in' : 'in',
27
- value: vendor.vendorIds,
28
- });
29
- }
30
- if (department != null && department.departmentIds.length > 0) {
31
- conditions.push({
32
- field: 'department_id',
33
- type: department.operator === 'is_not' ? 'not_in' : 'in',
34
- value: department.departmentIds,
35
- });
36
- }
37
- if (conditions.length > 0) {
38
- const currency = amount?.min ?? amount?.max ?? null;
39
- criteriaPayload = {
40
- conditions,
41
- criteria_operator: 'and',
42
- currency_code: currency?.currencyCode ?? 'USD',
43
- currency_symbol: currency?.currencySymbol ?? '$',
44
- };
45
- }
4
+ const criteria = approverViewUpdateData.criteria;
5
+ const { rangeType, rangeEntity, range } = criteria;
6
+ const { min, max } = range;
7
+ const { currencyCode, currencySymbol } = min;
8
+ criteriaPayload = [
9
+ {
10
+ type: rangeType,
11
+ range_entity: rangeEntity,
12
+ min: min.amount,
13
+ max: max?.amount ?? null,
14
+ currency_code: currencyCode,
15
+ currency_symbol: currencySymbol,
16
+ },
17
+ ];
46
18
  }
47
19
  const steps = approverViewUpdateData.steps.map((step) => {
48
20
  return {
@@ -63,88 +35,10 @@ export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
63
35
  });
64
36
  const isUpdate = approverViewUpdateData.approvalRuleId != null;
65
37
  const payload = {
38
+ criteria: criteriaPayload,
66
39
  steps,
67
40
  is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
68
41
  };
69
- if (criteriaPayload != null) {
70
- payload.criteria = criteriaPayload;
71
- }
72
- // Approval Rules 3.0 — surface rule-level fields when the form set them.
73
- // Send only what the user actually entered: an undefined value means
74
- // "no opinion" and stays off the wire.
75
- if (approverViewUpdateData.name != null) {
76
- payload.name = approverViewUpdateData.name;
77
- }
78
- if (approverViewUpdateData.description != null) {
79
- payload.description = approverViewUpdateData.description;
80
- }
81
- if (approverViewUpdateData.separationOfDuties != null) {
82
- payload.is_separation_of_duty_enabled =
83
- approverViewUpdateData.separationOfDuties;
84
- }
85
- if (approverViewUpdateData.isFallback != null) {
86
- payload.is_fallback = approverViewUpdateData.isFallback;
87
- }
88
- if (isUpdate) {
89
- payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
90
- }
91
- return payload;
92
- };
93
- /**
94
- * V1 wire mapper — used when `approval_rule_v3_config` resolves to OFF
95
- * for the current tenant. Translates the form-side amount criteria into
96
- * the legacy `{rangeType, rangeEntity, range: {min, max}}` shape. The
97
- * V1 backend does not understand vendor / department criteria or the
98
- * rule-level 3.0 fields, so those are dropped on the wire.
99
- *
100
- * The form-side amount slot is always read as a `range`-style criteria
101
- * here: V1 schemas only supported ranges, so an absent `min` or `max`
102
- * falls back to `0` / `Number.MAX_SAFE_INTEGER`.
103
- */
104
- export const toApprovalChangableInfoPayloadV1 = (approverViewUpdateData) => {
105
- const amount = approverViewUpdateData.criteria?.amount;
106
- const minAmount = amount?.min;
107
- const maxAmount = amount?.max;
108
- const currencyCode = minAmount?.currencyCode ?? maxAmount?.currencyCode ?? 'USD';
109
- const currencySymbol = minAmount?.currencySymbol ?? maxAmount?.currencySymbol ?? '$';
110
- const steps = approverViewUpdateData.steps.map((step) => {
111
- return {
112
- action: step.action,
113
- operator: step.operator,
114
- actors: step.actors
115
- .filter((actor) => actor.subType !== 'admin')
116
- .map((actor) => {
117
- return {
118
- type: actor.type,
119
- id: actor.userId ?? null,
120
- sub_type: actor.subType ?? null,
121
- id_type: actor.idType ?? null,
122
- is_implicit_actor: actor.isImplicitActor ?? false,
123
- };
124
- }),
125
- };
126
- });
127
- const isUpdate = approverViewUpdateData.approvalRuleId != null;
128
- const payload = {
129
- steps,
130
- is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
131
- criteria: {
132
- rangeType: 'range',
133
- rangeEntity: 'currency',
134
- range: {
135
- min: {
136
- amount: minAmount?.amount ?? 0,
137
- currencyCode,
138
- currencySymbol,
139
- },
140
- max: {
141
- amount: maxAmount?.amount ?? Number.MAX_SAFE_INTEGER,
142
- currencyCode,
143
- currencySymbol,
144
- },
145
- },
146
- },
147
- };
148
42
  if (isUpdate) {
149
43
  payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
150
44
  }
@@ -1,6 +1,5 @@
1
1
  import recordGet from 'lodash/get';
2
2
  import has from 'lodash/has';
3
- import { getAmountCriteria } from '../../../../entity/approvalRule/approvalRuleSelector';
4
3
  import { reduceFetchState } from '../../../../commonStateTypes/reduceFetchState';
5
4
  import { getBankAccountByBankAccountId, getBankAccountsByBankAccountIds, } from '../../../../entity/bankAccount/bankAccountSelector';
6
5
  import { getContactById, getContactsByIds, } from '../../../../entity/billPay/contact/contactSelector';
@@ -682,13 +681,9 @@ export const getDefaultWithdrawFromAccount = (state, depositAccounts, companyId,
682
681
  export const checkIfCreatorIsApprover = (billAmount, approvalRules, signedInUser) => {
683
682
  let isCreatorAlsoApprover = false;
684
683
  const approvalRule = approvalRules.find((rule) => {
685
- const amountCriteria = getAmountCriteria(rule.criteria);
686
- if (amountCriteria?.min == null) {
687
- return false;
688
- }
689
- const { min, max } = amountCriteria;
684
+ const { max, min } = rule.criteria[0].range;
690
685
  return (billAmount > min.amount &&
691
- (max?.amount != null ? billAmount <= max.amount : true));
686
+ (max?.amount != null ? billAmount <= max?.amount : true));
692
687
  });
693
688
  if (approvalRule != null) {
694
689
  const requireApprovalSteps = approvalRule.steps.filter((step) => step.action === 'require_approval');
@@ -6,17 +6,9 @@ import { updateAllUsers } from '../../../../../entity/user/userReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
7
  import { deleteRemiApprovalRule, deleteRemiApprovalRuleFailure, deleteRemiApprovalRuleSuccess, } from '../remiSetupApproverViewReducer';
8
8
  export const deleteRemiApprovalRuleEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(deleteRemiApprovalRule.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/reimbursements/approval-rules-v2`
15
- : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/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/reimbursements/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 { fetchRemiSetupApproverView, fetchRemiSetupApproverViewFailure, fetchRemiSetupApproverViewSuccess, } from '../remiSetupApproverViewReducer';
8
8
  export const fetchRemiSetupApproverViewEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchRemiSetupApproverView.match), switchMap((action) => {
9
- const { cacheOverride, resolveAttributeToUser, includeImplicitActors, useV3, } = action.payload;
9
+ const { cacheOverride, resolveAttributeToUser, includeImplicitActors } = action.payload;
10
10
  const { remiSetupApproverViewState, approvalRuleState } = state$.value;
11
11
  const approvalRules = getApprovalRulesByIds(approvalRuleState, remiSetupApproverViewState.approvalRuleIds);
12
12
  if (cacheOverride === true ||
@@ -14,14 +14,8 @@ export const fetchRemiSetupApproverViewEpic = (actions$, state$, zeniAPI) => act
14
14
  remiSetupApproverViewState.approvalRuleIds.length ||
15
15
  (remiSetupApproverViewState.hasValidState() === false &&
16
16
  remiSetupApproverViewState.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 basePath = useV3 === true
21
- ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules-v2`
22
- : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules`;
23
17
  return zeniAPI
24
- .getJSON(`${basePath}?query={"is_include_implicit_actors": ${includeImplicitActors}, "is_resolve_attribute_to_user":${resolveAttributeToUser}}`)
18
+ .getJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules?query={"is_include_implicit_actors": ${includeImplicitActors}, "is_resolve_attribute_to_user":${resolveAttributeToUser}}`)
25
19
  .pipe(mergeMap((response) => {
26
20
  if (isSuccessResponse(response) && response.data != null) {
27
21
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
@@ -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 { clearRemiSetupApproverViewUpdateData, initializeRemiSetupApproverViewUpdateData, saveRemiSetupApproverViewUpdateData, } from '../remiSetupApproverViewReducer';
5
5
  export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$) => actions$.pipe(filter(initializeRemiSetupApproverViewUpdateData.match), mergeMap((action) => {
6
6
  const { approvalRuleId } = action.payload;
@@ -8,20 +8,16 @@ export const initializeRemiSetupApproverViewUpdateDataEpic = (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 remiSetupApproverViewUpdateData = {
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(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewUpdateData));
27
23
  }
@@ -29,7 +25,7 @@ export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$)
29
25
  else {
30
26
  const remiSetupApproverViewCreateData = {
31
27
  steps: [],
32
- criteria: {},
28
+ criteria: undefined,
33
29
  };
34
30
  fetchActions.push(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewCreateData));
35
31
  }