@zeniai/client-epic-state 5.0.97 → 5.0.98-betaJK1

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 (91) hide show
  1. package/lib/entity/approvalRule/approvalRuleConflict.d.ts +56 -0
  2. package/lib/entity/approvalRule/approvalRuleConflict.js +77 -0
  3. package/lib/entity/approvalRule/approvalRulePayload.d.ts +34 -5
  4. package/lib/entity/approvalRule/approvalRulePayload.js +145 -10
  5. package/lib/entity/approvalRule/approvalRuleSelector.d.ts +25 -1
  6. package/lib/entity/approvalRule/approvalRuleSelector.js +40 -0
  7. package/lib/entity/approvalRule/approvalRuleState.d.ts +59 -7
  8. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  9. package/lib/entity/snackbar/snackbarTypes.js +3 -0
  10. package/lib/entity/task/taskPayload.d.ts +1 -0
  11. package/lib/entity/task/taskPayload.js +1 -0
  12. package/lib/entity/task/taskReducer.d.ts +5 -1
  13. package/lib/entity/task/taskReducer.js +8 -2
  14. package/lib/entity/task/taskState.d.ts +1 -0
  15. package/lib/epic.d.ts +5 -1
  16. package/lib/epic.js +5 -1
  17. package/lib/esm/entity/approvalRule/approvalRuleConflict.js +74 -0
  18. package/lib/esm/entity/approvalRule/approvalRulePayload.js +145 -10
  19. package/lib/esm/entity/approvalRule/approvalRuleSelector.js +35 -0
  20. package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
  21. package/lib/esm/entity/task/taskPayload.js +1 -0
  22. package/lib/esm/entity/task/taskReducer.js +7 -1
  23. package/lib/esm/epic.js +5 -1
  24. package/lib/esm/index.js +9 -7
  25. package/lib/esm/view/spendManagement/billPay/billPayReview/billPayReviewSelector.js +14 -0
  26. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +109 -12
  27. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  28. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  29. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +11 -7
  30. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +54 -0
  31. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +13 -4
  32. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +140 -16
  33. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +60 -4
  34. package/lib/esm/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.js +8 -2
  35. package/lib/esm/view/spendManagement/reimbursement/editRemiView/epics/fetchEditRemiDetailPageEpic.js +5 -1
  36. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  37. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  38. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +11 -7
  39. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +61 -0
  40. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +13 -4
  41. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +80 -11
  42. package/lib/esm/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +80 -0
  43. package/lib/esm/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +36 -0
  44. package/lib/esm/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +13 -0
  45. package/lib/esm/view/taskManager/taskDetailView/taskDetailReducer.js +51 -2
  46. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +19 -8
  47. package/lib/index.d.ts +11 -9
  48. package/lib/index.js +32 -19
  49. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  50. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  51. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  52. package/lib/view/spendManagement/billPay/billPayReview/billPayReviewSelector.d.ts +7 -0
  53. package/lib/view/spendManagement/billPay/billPayReview/billPayReviewSelector.js +14 -0
  54. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.d.ts +14 -3
  55. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +110 -13
  56. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewState.d.ts +16 -0
  57. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  58. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  59. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +10 -6
  60. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.d.ts +23 -0
  61. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +58 -0
  62. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +12 -3
  63. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +59 -1
  64. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +142 -17
  65. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +31 -5
  66. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +8 -1
  67. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +60 -4
  68. package/lib/view/spendManagement/billPay/editBillView/epics/fetchEditBillDetailPageEpic.js +8 -2
  69. package/lib/view/spendManagement/reimbursement/editRemiView/epics/fetchEditRemiDetailPageEpic.js +5 -1
  70. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  71. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  72. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +10 -6
  73. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.d.ts +14 -0
  74. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +65 -0
  75. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +12 -3
  76. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.d.ts +14 -3
  77. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +81 -12
  78. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewState.d.ts +12 -0
  79. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.d.ts +9 -0
  80. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +84 -0
  81. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.d.ts +8 -0
  82. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +40 -0
  83. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.d.ts +2 -1
  84. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +13 -0
  85. package/lib/view/taskManager/taskDetailView/taskDetail.d.ts +13 -0
  86. package/lib/view/taskManager/taskDetailView/taskDetailReducer.d.ts +14 -2
  87. package/lib/view/taskManager/taskDetailView/taskDetailReducer.js +52 -3
  88. package/lib/view/taskManager/taskDetailView/taskDetailSelector.d.ts +2 -1
  89. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +17 -6
  90. package/lib/view/taskManager/taskListView/taskList.d.ts +3 -3
  91. package/package.json +1 -1
@@ -1,20 +1,48 @@
1
1
  export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
2
- let criteriaPayload = [];
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;
3
6
  if (approverViewUpdateData.criteria != null) {
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
- ];
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
+ }
18
46
  }
19
47
  const steps = approverViewUpdateData.steps.map((step) => {
20
48
  return {
@@ -35,10 +63,106 @@ export const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
35
63
  });
36
64
  const isUpdate = approverViewUpdateData.approvalRuleId != null;
37
65
  const payload = {
38
- criteria: criteriaPayload,
39
66
  steps,
40
67
  is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
41
68
  };
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. Emits the legacy snake_case array shape that
96
+ * '/approval-rules' historically consumed (see the V1 fixture in
97
+ * 'entity/entityApprovalStatus/__mocks__/json/entityApprovalStatusPayload.json'):
98
+ * criteria: [{type: 'range', range_entity: 'currency', min, max,
99
+ * currency_code, currency_symbol}]
100
+ *
101
+ * Open-ended semantics are preserved on the wire: an absent 'min' or
102
+ * 'max' is sent as 'null' rather than synthesised to '0' or
103
+ * 'MAX_SAFE_INTEGER', so a 'greater_than' / 'less_than' rule stays
104
+ * one-sided after rollback rather than collapsing into a closed range.
105
+ *
106
+ * The V1 backend does not understand vendor / department criteria or
107
+ * the rule-level 3.0 fields, so those are dropped on the wire.
108
+ */
109
+ export const toApprovalChangableInfoPayloadV1 = (approverViewUpdateData) => {
110
+ const amount = approverViewUpdateData.criteria?.amount;
111
+ const minAmount = amount?.min;
112
+ const maxAmount = amount?.max;
113
+ const currencyCode = minAmount?.currencyCode ?? maxAmount?.currencyCode ?? 'USD';
114
+ const currencySymbol = minAmount?.currencySymbol ?? maxAmount?.currencySymbol ?? '$';
115
+ const steps = approverViewUpdateData.steps.map((step) => {
116
+ return {
117
+ action: step.action,
118
+ operator: step.operator,
119
+ actors: step.actors
120
+ .filter((actor) => actor.subType !== 'admin')
121
+ .map((actor) => {
122
+ return {
123
+ type: actor.type,
124
+ id: actor.userId ?? null,
125
+ sub_type: actor.subType ?? null,
126
+ id_type: actor.idType ?? null,
127
+ is_implicit_actor: actor.isImplicitActor ?? false,
128
+ };
129
+ }),
130
+ };
131
+ });
132
+ const isUpdate = approverViewUpdateData.approvalRuleId != null;
133
+ const minValue = minAmount?.amount ?? null;
134
+ const maxValue = maxAmount?.amount ?? null;
135
+ // Approval Rules 3.0 — guard against the both-null case. The form
136
+ // is expected to always set at least one bound, but if drift ever
137
+ // hands us a rule with no min and no max we'd otherwise emit
138
+ // '[{type: range, min: null, max: null, ...}]' — a payload that
139
+ // (a) the read-side 'legacyAmountRangeToCriteria' decodes back to
140
+ // '[]' (asymmetric round-trip), and (b) the V1 backend will
141
+ // reject anyway. Emit 'criteria: []' instead so the save fails
142
+ // cleanly on the server side and we leave a breadcrumb in the
143
+ // console for diagnosis rather than persisting mis-shaped data.
144
+ const criteria = [];
145
+ if (minValue == null && maxValue == null) {
146
+ console.warn('[approvalRules][V1] toApprovalChangableInfoPayloadV1: rule has ' +
147
+ 'no amount bounds; emitting empty criteria array. The V1 backend ' +
148
+ 'will reject this save — caller should ensure at least one bound ' +
149
+ 'is set on the form.');
150
+ }
151
+ else {
152
+ criteria.push({
153
+ type: 'range',
154
+ range_entity: 'currency',
155
+ min: minValue,
156
+ max: maxValue,
157
+ currency_code: currencyCode,
158
+ currency_symbol: currencySymbol,
159
+ });
160
+ }
161
+ const payload = {
162
+ steps,
163
+ is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
164
+ criteria,
165
+ };
42
166
  if (isUpdate) {
43
167
  payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
44
168
  }
@@ -1,5 +1,6 @@
1
1
  import recordGet from 'lodash/get';
2
2
  import has from 'lodash/has';
3
+ import { getAmountCriteria, getDepartmentCriteria, getVendorCriteria, } from '../../../../entity/approvalRule/approvalRuleSelector';
3
4
  import { reduceFetchState } from '../../../../commonStateTypes/reduceFetchState';
4
5
  import { getBankAccountByBankAccountId, getBankAccountsByBankAccountIds, } from '../../../../entity/bankAccount/bankAccountSelector';
5
6
  import { getContactById, getContactsByIds, } from '../../../../entity/billPay/contact/contactSelector';
@@ -356,6 +357,14 @@ export const getEditBillDetail = (state, isVendorRecommendationFeatureEnabled, i
356
357
  isDeleted,
357
358
  showAutofill,
358
359
  addBillAutoFields,
360
+ // Bill-level accounting class. Approval Rules 3.0 'department'
361
+ // criteria match against this. Lives on BillTransaction; not on
362
+ // any sub-section. Empty-string is normalised to 'undefined'
363
+ // so downstream readers treat "no class" uniformly regardless
364
+ // of whether the wire used '' or omitted the field.
365
+ classId: transaction?.classId != null && transaction.classId !== ''
366
+ ? transaction.classId
367
+ : undefined,
359
368
  billStage,
360
369
  deleteStatus,
361
370
  billActivities,
@@ -678,12 +687,59 @@ export const getDefaultWithdrawFromAccount = (state, depositAccounts, companyId,
678
687
  }
679
688
  return undefined;
680
689
  };
681
- export const checkIfCreatorIsApprover = (billAmount, approvalRules, signedInUser) => {
690
+ export const checkIfCreatorIsApprover = (billAmount, approvalRules, signedInUser, billVendorId, billDepartmentId) => {
682
691
  let isCreatorAlsoApprover = false;
692
+ // Approval Rules 3.0 — a rule applies to a bill only when all of
693
+ // its present criteria are satisfied. Criteria not declared on
694
+ // the rule are treated as "no narrowing on this axis".
695
+ //
696
+ // Strict-match semantics for vendor / department: if the rule
697
+ // narrows by an axis but the bill has no value on that axis, the
698
+ // rule does NOT apply (an absent bill-side value can't satisfy
699
+ // either 'is' or 'is_not'). Amount is always present on a rule
700
+ // (the form enforces this), but bounds may be one-sided.
683
701
  const approvalRule = approvalRules.find((rule) => {
684
- const { max, min } = rule.criteria[0].range;
685
- return (billAmount > min.amount &&
686
- (max?.amount != null ? billAmount <= max?.amount : true));
702
+ const vendorCriteria = getVendorCriteria(rule.criteria);
703
+ if (vendorCriteria != null) {
704
+ if (billVendorId == null) {
705
+ return false;
706
+ }
707
+ const includesVendor = vendorCriteria.vendorIds.includes(billVendorId);
708
+ if (vendorCriteria.operator === 'is' && !includesVendor) {
709
+ return false;
710
+ }
711
+ if (vendorCriteria.operator === 'is_not' && includesVendor) {
712
+ return false;
713
+ }
714
+ }
715
+ const departmentCriteria = getDepartmentCriteria(rule.criteria);
716
+ if (departmentCriteria != null) {
717
+ if (billDepartmentId == null) {
718
+ return false;
719
+ }
720
+ const includesDepartment = departmentCriteria.departmentIds.includes(billDepartmentId);
721
+ if (departmentCriteria.operator === 'is' && !includesDepartment) {
722
+ return false;
723
+ }
724
+ if (departmentCriteria.operator === 'is_not' && includesDepartment) {
725
+ return false;
726
+ }
727
+ }
728
+ const amountCriteria = getAmountCriteria(rule.criteria);
729
+ if (amountCriteria == null) {
730
+ // The form guarantees an amount criterion on every rule, so
731
+ // this branch is defensive against backend drift. Keep
732
+ // pre-3.0 behaviour: a rule that doesn't declare amount
733
+ // doesn't participate here.
734
+ return false;
735
+ }
736
+ // Bounds use the wire's inclusive 'gte' / 'lte' semantics, and
737
+ // either side may be absent for a one-sided 'greater_than' /
738
+ // 'less_than' rule.
739
+ const { min, max } = amountCriteria;
740
+ const matchesMin = min == null || billAmount >= min.amount;
741
+ const matchesMax = max == null || billAmount <= max.amount;
742
+ return matchesMin && matchesMax;
687
743
  });
688
744
  if (approvalRule != null) {
689
745
  const requireApprovalSteps = approvalRule.steps.filter((step) => step.action === 'require_approval');
@@ -38,7 +38,10 @@ export const fetchEditBillDetailPageEpic = (actions$, state$) => actions$.pipe(f
38
38
  else {
39
39
  billDetailActions.push(updateShowAutofill(true));
40
40
  }
41
- billDetailActions.push(fetchBillPaySetupApproverView(true));
41
+ // Side-fetch from the edit-bill page bootstrap. The triggering
42
+ // action doesn't carry the V3 flag, so we explicitly target v1
43
+ // here; tenants on v3 re-fetch through their own screen connector.
44
+ billDetailActions.push(fetchBillPaySetupApproverView(true, true, false));
42
45
  }
43
46
  else {
44
47
  if (state.ownerListState.fetchState !== 'In-Progress' &&
@@ -81,7 +84,10 @@ export const fetchEditBillDetailPageEpic = (actions$, state$) => actions$.pipe(f
81
84
  // While opening New Bill Refresh Approval Rules and Payment Accounts
82
85
  if (approvalViewFetchState !== 'In-Progress' &&
83
86
  approvalViewFetchState !== 'Completed') {
84
- billDetailActions.push(fetchBillPaySetupApproverView(true));
87
+ // Side-fetch from the edit-bill page bootstrap. The triggering
88
+ // action doesn't carry the V3 flag, so we explicitly target v1
89
+ // here; tenants on v3 re-fetch through their own screen connector.
90
+ billDetailActions.push(fetchBillPaySetupApproverView(true, true, false));
85
91
  }
86
92
  }
87
93
  return concat(from(billDetailActions));
@@ -63,7 +63,11 @@ export const fetchEditRemiDetailPageEpic = (actions$, state$) => actions$.pipe(f
63
63
  const approvalRules = state.remiSetupApproverViewState;
64
64
  if (approvalRules.fetchState !== 'Completed' &&
65
65
  approvalRules.fetchState !== 'In-Progress') {
66
- remiDetailActions.push(fetchRemiSetupApproverView(true));
66
+ // Side-fetch from the edit-reim page bootstrap. The
67
+ // triggering action doesn't carry the V3 flag, so we
68
+ // explicitly target v1; v3 tenants re-fetch via their
69
+ // own screen connector.
70
+ remiDetailActions.push(fetchRemiSetupApproverView(true, false, false, false));
67
71
  }
68
72
  }
69
73
  }
@@ -6,9 +6,17 @@ 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 } = action.payload;
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`;
10
16
  return zeniAPI
11
- .deleteAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules`, { approval_rule_id: approvalRuleId })
17
+ .deleteAndGetJSON(endpoint, {
18
+ approval_rule_id: approvalRuleId,
19
+ })
12
20
  .pipe(mergeMap((response) => {
13
21
  if (isSuccessResponse(response) && response.data != null) {
14
22
  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 } = action.payload;
9
+ const { cacheOverride, resolveAttributeToUser, includeImplicitActors, useV3, } = action.payload;
10
10
  const { remiSetupApproverViewState, approvalRuleState } = state$.value;
11
11
  const approvalRules = getApprovalRulesByIds(approvalRuleState, remiSetupApproverViewState.approvalRuleIds);
12
12
  if (cacheOverride === true ||
@@ -14,8 +14,14 @@ 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`;
17
23
  return zeniAPI
18
- .getJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules?query={"is_include_implicit_actors": ${includeImplicitActors}, "is_resolve_attribute_to_user":${resolveAttributeToUser}}`)
24
+ .getJSON(`${basePath}?query={"is_include_implicit_actors": ${includeImplicitActors}, "is_resolve_attribute_to_user":${resolveAttributeToUser}}`)
19
25
  .pipe(mergeMap((response) => {
20
26
  if (isSuccessResponse(response) && response.data != null) {
21
27
  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 { getApprovalRuleById } from '../../../../../entity/approvalRule/approvalRuleSelector';
3
+ import { getAmountCriteria, getApprovalRuleById, getDepartmentCriteria, getVendorCriteria, } 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,16 +8,20 @@ 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;
13
11
  const remiSetupApproverViewUpdateData = {
14
12
  approvalRuleId,
15
13
  steps: approvalRule.steps,
16
14
  criteria: {
17
- rangeType: criteria?.rangeType,
18
- rangeEntity: criteria?.rangeEntity,
19
- range,
15
+ amount: getAmountCriteria(approvalRule.criteria),
16
+ vendor: getVendorCriteria(approvalRule.criteria),
17
+ department: getDepartmentCriteria(approvalRule.criteria),
20
18
  },
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,
21
25
  };
22
26
  fetchActions.push(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewUpdateData));
23
27
  }
@@ -25,7 +29,7 @@ export const initializeRemiSetupApproverViewUpdateDataEpic = (actions$, state$)
25
29
  else {
26
30
  const remiSetupApproverViewCreateData = {
27
31
  steps: [],
28
- criteria: undefined,
32
+ criteria: {},
29
33
  };
30
34
  fetchActions.push(clearRemiSetupApproverViewUpdateData(), saveRemiSetupApproverViewUpdateData(remiSetupApproverViewCreateData));
31
35
  }
@@ -0,0 +1,61 @@
1
+ import { from } from 'rxjs';
2
+ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
+ import { updateApprovalRules } from '../../../../../entity/approvalRule/approvalRuleReducer';
4
+ import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
5
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
6
+ import { fetchRemiSetupApproverView, reorderRemiApprovalRules, reorderRemiApprovalRulesFailure, reorderRemiApprovalRulesSuccess, } from '../remiSetupApproverViewReducer';
7
+ export const reorderRemiApprovalRulesEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(reorderRemiApprovalRules.match), switchMap((action) => {
8
+ const { approvalRuleIds, useV3 } = action.payload;
9
+ const endpoint = `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules-v2/reorder`;
10
+ return zeniAPI
11
+ .putAndGetJSON(endpoint, {
12
+ rule_ids: approvalRuleIds,
13
+ })
14
+ .pipe(mergeMap((response) => {
15
+ if (isSuccessResponse(response) && response.data != null) {
16
+ const serverOrderedIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
17
+ const actions = [
18
+ updateApprovalRules(response.data.approval_rules),
19
+ reorderRemiApprovalRulesSuccess(serverOrderedIds),
20
+ openSnackbar({
21
+ messageSection: `reimbursement_approval_reorder`,
22
+ messageText: 'success',
23
+ type: 'success',
24
+ }),
25
+ ];
26
+ return from(actions);
27
+ }
28
+ else {
29
+ return from([
30
+ reorderRemiApprovalRulesFailure(response.status),
31
+ openSnackbar({
32
+ messageSection: `reimbursement_approval_reorder`,
33
+ messageText: 'failed',
34
+ type: 'error',
35
+ }),
36
+ // Failure-recovery refetch — match the screen connector
37
+ // convention '(cacheOverride, resolveAttributeToUser,
38
+ // includeImplicitActors, useV3)' rather than copying BillPay's
39
+ // 3-arg shape. With the previous useV3-as-default-false the
40
+ // V3 flag was being smuggled in as 'includeImplicitActors',
41
+ // which silently broke V3 recovery refetches.
42
+ fetchRemiSetupApproverView(true, false, false, useV3),
43
+ ]);
44
+ }
45
+ }), catchError((error) => from([
46
+ reorderRemiApprovalRulesFailure(createZeniAPIStatus('Unexpected Error', 'Reorder Reimbursement Approval Rules errored out' +
47
+ JSON.stringify(error))),
48
+ openSnackbar({
49
+ messageSection: `reimbursement_approval_reorder`,
50
+ messageText: 'failed',
51
+ type: 'error',
52
+ }),
53
+ // Failure-recovery refetch — match the screen connector
54
+ // convention '(cacheOverride, resolveAttributeToUser,
55
+ // includeImplicitActors, useV3)' rather than copying BillPay's
56
+ // 3-arg shape. With the previous useV3-as-default-false the
57
+ // V3 flag was being smuggled in as 'includeImplicitActors',
58
+ // which silently broke V3 recovery refetches.
59
+ fetchRemiSetupApproverView(true, false, false, useV3),
60
+ ])));
61
+ }));
@@ -4,16 +4,25 @@ import { updateApprovalRules } from '../../../../../entity/approvalRule/approval
4
4
  import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
5
5
  import { updateAllUsers } from '../../../../../entity/user/userReducer';
6
6
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
- import { toApprovalChangableInfoPayload } from '../../../billPay/billPaySetupApproverView/types/commonPayload';
7
+ import { toApprovalChangableInfoPayload, toApprovalChangableInfoPayloadV1, } from '../../../billPay/billPaySetupApproverView/types/commonPayload';
8
8
  import { saveRemiSetupApproverViewUpdates, saveRemiSetupApproverViewUpdatesFailure, saveRemiSetupApproverViewUpdatesSuccess, } from '../remiSetupApproverViewReducer';
9
- export const saveRemiSetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveRemiSetupApproverViewUpdates.match), switchMap(() => {
9
+ export const saveRemiSetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveRemiSetupApproverViewUpdates.match), switchMap((action) => {
10
10
  const { remiSetupApproverViewState } = state$.value;
11
11
  const remiSetupApproverViewUpdateData = remiSetupApproverViewState.remiSetupApproverViewUpdateData;
12
12
  if (remiSetupApproverViewUpdateData != null &&
13
13
  remiSetupApproverViewUpdateData.data != null) {
14
- const payload = toApprovalChangableInfoPayload(remiSetupApproverViewUpdateData.data);
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(remiSetupApproverViewUpdateData.data)
20
+ : toApprovalChangableInfoPayloadV1(remiSetupApproverViewUpdateData.data);
21
+ const endpoint = useV3
22
+ ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules-v2`
23
+ : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules`;
15
24
  return zeniAPI
16
- .postAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/reimbursements/approval-rules`, payload)
25
+ .postAndGetJSON(endpoint, payload)
17
26
  .pipe(mergeMap((response) => {
18
27
  if (isSuccessResponse(response) && response.data != null) {
19
28
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
@@ -13,6 +13,7 @@ export const initialState = {
13
13
  newApprovalRuleId: undefined,
14
14
  approvalRulesDeleteStatusById: {},
15
15
  remiSetupApproverViewUpdateData: undefined,
16
+ reorderStatus: { fetchState: 'Not-Started', error: undefined },
16
17
  hasValidState() {
17
18
  return this.fetchState === 'Completed';
18
19
  },
@@ -26,12 +27,17 @@ const remiSetupApproverView = createSlice({
26
27
  draft.fetchState = 'In-Progress';
27
28
  draft.error = undefined;
28
29
  },
29
- prepare(cacheOverride = false, resolveAttributeToUser = false, includeImplicitActors = false) {
30
+ // Approval Rules 3.0 `useV3` arrives from the screen connector
31
+ // ('approval_rule_v3_config' dynamic config) and picks v1 vs v2
32
+ // endpoint in the fetch epic. Required (no default) so a missing
33
+ // connector wire surfaces at compile time.
34
+ prepare(cacheOverride = false, resolveAttributeToUser = false, includeImplicitActors = false, useV3) {
30
35
  return {
31
36
  payload: {
32
37
  cacheOverride,
33
38
  resolveAttributeToUser,
34
39
  includeImplicitActors,
40
+ useV3,
35
41
  },
36
42
  };
37
43
  },
@@ -134,8 +140,12 @@ const remiSetupApproverView = createSlice({
134
140
  error: undefined,
135
141
  };
136
142
  },
137
- prepare(approvalRuleId) {
138
- return { payload: { approvalRuleId } };
143
+ // Approval Rules 3.0 — `useV3` flows from the screen connector
144
+ // ('approval_rule_v3_config' dynamic config) so the delete epic
145
+ // can pick the v1 vs v2 endpoint. Required (no default) so a
146
+ // missing connector wire surfaces at compile time.
147
+ prepare(approvalRuleId, useV3) {
148
+ return { payload: { approvalRuleId, useV3 } };
139
149
  },
140
150
  },
141
151
  deleteRemiApprovalRuleSuccess: {
@@ -167,13 +177,72 @@ const remiSetupApproverView = createSlice({
167
177
  };
168
178
  },
169
179
  },
170
- saveRemiSetupApproverViewUpdates(draft) {
171
- if (draft.remiSetupApproverViewUpdateData != null) {
172
- draft.remiSetupApproverViewUpdateData.updateStatus = {
173
- fetchState: 'In-Progress',
174
- error: undefined,
175
- };
176
- }
180
+ /**
181
+ * Approval Rules 3.0 list-page drag-and-drop reorder.
182
+ * See BillPay equivalent for the longer rationale.
183
+ */
184
+ reorderRemiApprovalRules: {
185
+ reducer(draft, action) {
186
+ const { approvalRuleIds } = action.payload;
187
+ const wasReorderInFlight = draft.reorderStatus.fetchState === 'In-Progress';
188
+ draft.reorderStatus = { fetchState: 'In-Progress', error: undefined };
189
+ // Stash the pre-reorder order for synchronous rollback on
190
+ // 'Failure'. See the BillPay reducer for the rationale,
191
+ // including the in-flight guard: a second drag before the
192
+ // first PUT lands must not overwrite the snapshot.
193
+ if (!wasReorderInFlight) {
194
+ draft.reorderRollbackIds = draft.approvalRuleIds;
195
+ }
196
+ draft.approvalRuleIds = approvalRuleIds;
197
+ },
198
+ // Approval Rules 3.0 — `useV3` required so a missing wire
199
+ // surfaces at compile time. Mirror of BillPay's reorder.prepare.
200
+ prepare(approvalRuleIds, useV3) {
201
+ return { payload: { approvalRuleIds, useV3 } };
202
+ },
203
+ },
204
+ reorderRemiApprovalRulesSuccess: {
205
+ reducer(draft, action) {
206
+ const { approvalRuleIds } = action.payload;
207
+ draft.reorderStatus = { fetchState: 'Completed', error: undefined };
208
+ draft.approvalRuleIds = approvalRuleIds;
209
+ draft.reorderRollbackIds = undefined;
210
+ },
211
+ prepare(approvalRuleIds) {
212
+ return { payload: { approvalRuleIds } };
213
+ },
214
+ },
215
+ reorderRemiApprovalRulesFailure: {
216
+ reducer(draft, action) {
217
+ const { status } = action.payload;
218
+ draft.reorderStatus = { fetchState: 'Error', error: status };
219
+ if (draft.reorderRollbackIds != null) {
220
+ draft.approvalRuleIds = draft.reorderRollbackIds;
221
+ draft.reorderRollbackIds = undefined;
222
+ }
223
+ },
224
+ prepare(status) {
225
+ return { payload: { status } };
226
+ },
227
+ },
228
+ saveRemiSetupApproverViewUpdates: {
229
+ // Approval Rules 3.0 — `useV3` sourced from
230
+ // `approval_rule_v3_config` dynamic config in the screen
231
+ // connector; epic uses it to pick v1 vs v2 URL + mapper. The
232
+ // reducer doesn't read the action but the parameter must be
233
+ // declared so the action payload type carries downstream.
234
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
235
+ reducer(draft, _action) {
236
+ if (draft.remiSetupApproverViewUpdateData != null) {
237
+ draft.remiSetupApproverViewUpdateData.updateStatus = {
238
+ fetchState: 'In-Progress',
239
+ error: undefined,
240
+ };
241
+ }
242
+ },
243
+ prepare(useV3) {
244
+ return { payload: { useV3 } };
245
+ },
177
246
  },
178
247
  saveRemiSetupApproverViewUpdatesSuccess: {
179
248
  reducer(draft, action) {
@@ -262,5 +331,5 @@ const remiSetupApproverView = createSlice({
262
331
  },
263
332
  },
264
333
  });
265
- export const { fetchRemiSetupApproverView, fetchRemiSetupApproverViewSuccess, fetchRemiSetupApproverViewFailure, fetchRemiApproversDetails, fetchRemiApproversList, fetchRemiApproversListSuccess, fetchRemiApproversListFailure, deleteRemiApprovalRule, deleteRemiApprovalRuleSuccess, deleteRemiApprovalRuleFailure, saveRemiSetupApproverViewUpdates, saveRemiSetupApproverViewUpdatesSuccess, saveRemiSetupApproverViewUpdatesFailure, initializeRemiSetupApproverViewUpdateData, saveRemiSetupApproverViewUpdateData, setListeningToPusherEvent, clearRemiSetupApproverViewUpdateData, clearRemiSetupApproverView, } = remiSetupApproverView.actions;
334
+ export const { fetchRemiSetupApproverView, fetchRemiSetupApproverViewSuccess, fetchRemiSetupApproverViewFailure, fetchRemiApproversDetails, fetchRemiApproversList, fetchRemiApproversListSuccess, fetchRemiApproversListFailure, deleteRemiApprovalRule, deleteRemiApprovalRuleSuccess, deleteRemiApprovalRuleFailure, reorderRemiApprovalRules, reorderRemiApprovalRulesSuccess, reorderRemiApprovalRulesFailure, saveRemiSetupApproverViewUpdates, saveRemiSetupApproverViewUpdatesSuccess, saveRemiSetupApproverViewUpdatesFailure, initializeRemiSetupApproverViewUpdateData, saveRemiSetupApproverViewUpdateData, setListeningToPusherEvent, clearRemiSetupApproverViewUpdateData, clearRemiSetupApproverView, } = remiSetupApproverView.actions;
266
335
  export default remiSetupApproverView.reducer;