@zeniai/client-epic-state 5.0.90-beta0ND → 5.0.90-betaAR2

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 (132) hide show
  1. package/lib/commonStateTypes/animations.d.ts +1 -1
  2. package/lib/commonStateTypes/animations.js +0 -1
  3. package/lib/entity/approvalRule/approvalRuleConflict.d.ts +56 -0
  4. package/lib/entity/approvalRule/approvalRuleConflict.js +77 -0
  5. package/lib/entity/approvalRule/approvalRulePayload.d.ts +34 -5
  6. package/lib/entity/approvalRule/approvalRulePayload.js +145 -10
  7. package/lib/entity/approvalRule/approvalRuleSelector.d.ts +25 -1
  8. package/lib/entity/approvalRule/approvalRuleSelector.js +40 -0
  9. package/lib/entity/approvalRule/approvalRuleState.d.ts +59 -7
  10. package/lib/entity/company/companyPayload.d.ts +0 -4
  11. package/lib/entity/company/companyPayload.js +0 -4
  12. package/lib/entity/company/companyStateTypes.d.ts +0 -4
  13. package/lib/entity/paymentAccount/paymentAccountSelector.d.ts +0 -1
  14. package/lib/entity/paymentAccount/paymentAccountSelector.js +0 -4
  15. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  16. package/lib/entity/snackbar/snackbarTypes.js +2 -0
  17. package/lib/entity/tenant/epic/deleteConnectionEpic.d.ts +1 -1
  18. package/lib/entity/tenant/epic/saveAPIKeyConnectionEpic.d.ts +1 -1
  19. package/lib/entity/tenant/epic/saveConnectorCredentialsEpic.d.ts +3 -3
  20. package/lib/entity/tenant/epic/saveOAuthConnectionEpic.d.ts +1 -1
  21. package/lib/entity/tenant/tenantPayload.d.ts +0 -1
  22. package/lib/entity/tenant/tenantReducer.d.ts +25 -38
  23. package/lib/entity/tenant/tenantReducer.js +5 -65
  24. package/lib/entity/tenant/tenantState.d.ts +0 -1
  25. package/lib/epic.d.ts +5 -8
  26. package/lib/epic.js +5 -9
  27. package/lib/esm/commonStateTypes/animations.js +0 -1
  28. package/lib/esm/entity/approvalRule/approvalRuleConflict.js +74 -0
  29. package/lib/esm/entity/approvalRule/approvalRulePayload.js +145 -10
  30. package/lib/esm/entity/approvalRule/approvalRuleSelector.js +35 -0
  31. package/lib/esm/entity/company/companyPayload.js +0 -4
  32. package/lib/esm/entity/paymentAccount/paymentAccountSelector.js +0 -3
  33. package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
  34. package/lib/esm/entity/tenant/tenantReducer.js +3 -63
  35. package/lib/esm/epic.js +5 -9
  36. package/lib/esm/index.js +13 -14
  37. package/lib/esm/view/fileView/epic/deleteFileEpic.js +2 -2
  38. package/lib/esm/view/fileView/epic/deleteFileListEpic.js +2 -2
  39. package/lib/esm/view/fileView/epic/updateFileNameEpic.js +2 -2
  40. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewReducer.js +50 -217
  41. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +1 -7
  42. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewState.js +0 -12
  43. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +92 -12
  44. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  45. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  46. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +11 -7
  47. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +54 -0
  48. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +13 -4
  49. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +122 -16
  50. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
  51. package/lib/esm/view/spendManagement/commonSetup/setupViewReducer.js +52 -105
  52. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +1 -6
  53. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  54. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  55. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +11 -7
  56. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +49 -0
  57. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +13 -4
  58. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +71 -11
  59. package/lib/index.d.ts +15 -17
  60. package/lib/index.js +42 -51
  61. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  62. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  63. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  64. package/lib/view/fileView/epic/deleteFileEpic.js +1 -1
  65. package/lib/view/fileView/epic/deleteFileListEpic.js +1 -1
  66. package/lib/view/fileView/epic/updateFileNameEpic.js +1 -1
  67. package/lib/view/onboardingView/customerView/onboardingCustomerViewPayload.d.ts +0 -3
  68. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.d.ts +4 -41
  69. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.js +51 -219
  70. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +1 -5
  71. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +2 -11
  72. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.d.ts +0 -40
  73. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.js +1 -13
  74. package/lib/view/people/peopleTypes.d.ts +1 -1
  75. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.d.ts +14 -3
  76. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +93 -13
  77. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewState.d.ts +16 -0
  78. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  79. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  80. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +10 -6
  81. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.d.ts +23 -0
  82. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +58 -0
  83. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +12 -3
  84. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +50 -1
  85. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +124 -17
  86. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +31 -5
  87. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
  88. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  89. package/lib/view/spendManagement/commonSetup/setupViewReducer.d.ts +2 -28
  90. package/lib/view/spendManagement/commonSetup/setupViewReducer.js +53 -106
  91. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +2 -7
  92. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +1 -6
  93. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +0 -19
  94. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  95. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  96. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +10 -6
  97. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.d.ts +14 -0
  98. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +53 -0
  99. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +12 -3
  100. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.d.ts +14 -3
  101. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +72 -12
  102. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewState.d.ts +12 -0
  103. package/lib/view/taskManager/taskListView/taskList.d.ts +3 -3
  104. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +1 -1
  105. package/package.json +1 -1
  106. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.d.ts +0 -21
  107. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.js +0 -54
  108. package/lib/esm/entity/tenant/epic/initEmailConnectOAuthEpic.js +0 -50
  109. package/lib/esm/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +0 -42
  110. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +0 -29
  111. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +0 -40
  112. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +0 -52
  113. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +0 -59
  114. package/lib/esm/view/spendManagement/commonSetup/kycKybAutofillActions.js +0 -14
  115. package/lib/esm/view/spendManagement/commonSetup/kycKybParseMapper.js +0 -205
  116. package/lib/esm/view/spendManagement/commonSetup/types/kycKybAutofill.js +0 -28
  117. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.d.ts +0 -7
  118. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +0 -46
  119. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.d.ts +0 -8
  120. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +0 -33
  121. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.d.ts +0 -9
  122. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +0 -44
  123. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.d.ts +0 -28
  124. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +0 -56
  125. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.d.ts +0 -30
  126. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +0 -63
  127. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.d.ts +0 -33
  128. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.js +0 -17
  129. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.d.ts +0 -24
  130. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.js +0 -213
  131. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.d.ts +0 -125
  132. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.js +0 -32
@@ -1,7 +1,5 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { date } from '../../../zeniDayJS';
3
- import { parseUploadedKybDocument, parseUploadedKybDocumentFailure, parseUploadedKycDocument, parseUploadedKycDocumentFailure, } from '../../spendManagement/commonSetup/kycKybAutofillActions';
4
- import { emptyAiAgentsActivationSubview, } from './onboardingCustomerViewState';
5
3
  const initialStatus = {
6
4
  fetchState: 'Not-Started',
7
5
  error: undefined,
@@ -11,31 +9,61 @@ export const initialState = {
11
9
  saveStatus: initialStatus,
12
10
  dashboardLoadedStatus: initialStatus,
13
11
  currentStep: 'link_payment_account',
14
- parsingDocumentFileIds: [],
15
12
  companyDetails: {
16
- autoFilledFields: [],
17
13
  localData: undefined,
18
14
  },
19
- companyOfficerUpdateStatus: (() => {
20
- const emptyOfficerSlot = {
21
- autoFilledFields: [],
15
+ companyOfficerUpdateStatus: {
16
+ Officer_1: {
22
17
  localData: undefined,
23
18
  sendOtpStatus: initialStatus,
24
19
  otpverificationStatus: initialStatus,
25
- };
26
- return {
27
- Officer_1: { ...emptyOfficerSlot },
28
- Officer_2: { ...emptyOfficerSlot },
29
- Officer_3: { ...emptyOfficerSlot },
30
- Officer_4: { ...emptyOfficerSlot },
31
- Officer_5: { ...emptyOfficerSlot },
32
- Officer_6: { ...emptyOfficerSlot },
33
- Officer_7: { ...emptyOfficerSlot },
34
- Officer_8: { ...emptyOfficerSlot },
35
- Officer_9: { ...emptyOfficerSlot },
36
- Officer_10: { ...emptyOfficerSlot },
37
- };
38
- })(),
20
+ },
21
+ Officer_2: {
22
+ localData: undefined,
23
+ sendOtpStatus: initialStatus,
24
+ otpverificationStatus: initialStatus,
25
+ },
26
+ Officer_3: {
27
+ localData: undefined,
28
+ sendOtpStatus: initialStatus,
29
+ otpverificationStatus: initialStatus,
30
+ },
31
+ Officer_4: {
32
+ localData: undefined,
33
+ sendOtpStatus: initialStatus,
34
+ otpverificationStatus: initialStatus,
35
+ },
36
+ Officer_5: {
37
+ localData: undefined,
38
+ sendOtpStatus: initialStatus,
39
+ otpverificationStatus: initialStatus,
40
+ },
41
+ Officer_6: {
42
+ localData: undefined,
43
+ sendOtpStatus: initialStatus,
44
+ otpverificationStatus: initialStatus,
45
+ },
46
+ Officer_7: {
47
+ localData: undefined,
48
+ sendOtpStatus: initialStatus,
49
+ otpverificationStatus: initialStatus,
50
+ },
51
+ Officer_8: {
52
+ localData: undefined,
53
+ sendOtpStatus: initialStatus,
54
+ otpverificationStatus: initialStatus,
55
+ },
56
+ Officer_9: {
57
+ localData: undefined,
58
+ sendOtpStatus: initialStatus,
59
+ otpverificationStatus: initialStatus,
60
+ },
61
+ Officer_10: {
62
+ localData: undefined,
63
+ sendOtpStatus: initialStatus,
64
+ otpverificationStatus: initialStatus,
65
+ },
66
+ },
39
67
  primaryContactDetails: {},
40
68
  paymentAccountDetails: {
41
69
  fetchStatus: initialStatus,
@@ -63,7 +91,6 @@ export const initialState = {
63
91
  },
64
92
  fetchState: 'Not-Started',
65
93
  error: undefined,
66
- aiAgentsActivation: { ...emptyAiAgentsActivationSubview },
67
94
  uiState: {
68
95
  isQBOPopupOpen: false,
69
96
  isCardPaymentPopupOpen: false,
@@ -153,126 +180,6 @@ const onboardingCustomerView = createSlice({
153
180
  };
154
181
  },
155
182
  },
156
- acknowledgeOnboardingAiFinanceTeam: {
157
- reducer(draft) {
158
- draft.aiFinanceTeamAcknowledgementStatus = {
159
- fetchState: 'In-Progress',
160
- error: undefined,
161
- };
162
- },
163
- prepare(companyId) {
164
- return {
165
- payload: { companyId },
166
- };
167
- },
168
- },
169
- acknowledgeOnboardingAiFinanceTeamSuccess(draft) {
170
- draft.aiFinanceTeamAcknowledgementStatus = {
171
- fetchState: 'Completed',
172
- error: undefined,
173
- };
174
- },
175
- acknowledgeOnboardingAiFinanceTeamFailure: {
176
- reducer(draft, action) {
177
- draft.aiFinanceTeamAcknowledgementStatus = {
178
- fetchState: 'Error',
179
- error: action.payload,
180
- };
181
- },
182
- prepare(error) {
183
- return {
184
- payload: error,
185
- };
186
- },
187
- },
188
- acknowledgeOnboardingAiActivationViewed: {
189
- reducer(draft) {
190
- draft.aiActivationViewedAcknowledgementStatus = {
191
- fetchState: 'In-Progress',
192
- error: undefined,
193
- };
194
- },
195
- prepare(companyId) {
196
- return {
197
- payload: { companyId },
198
- };
199
- },
200
- },
201
- acknowledgeOnboardingAiActivationViewedSuccess(draft) {
202
- draft.aiActivationViewedAcknowledgementStatus = {
203
- fetchState: 'Completed',
204
- error: undefined,
205
- };
206
- },
207
- acknowledgeOnboardingAiActivationViewedFailure: {
208
- reducer(draft, action) {
209
- draft.aiActivationViewedAcknowledgementStatus = {
210
- fetchState: 'Error',
211
- error: action.payload,
212
- };
213
- },
214
- prepare(error) {
215
- return {
216
- payload: error,
217
- };
218
- },
219
- },
220
- fetchAiAgentsActivationStatus(draft) {
221
- draft.aiAgentsActivation.fetchStatus = {
222
- fetchState: 'In-Progress',
223
- error: undefined,
224
- };
225
- },
226
- fetchAiAgentsActivationStatusSuccess: {
227
- reducer(draft, action) {
228
- draft.aiAgentsActivation.fetchStatus = {
229
- fetchState: 'Completed',
230
- error: undefined,
231
- };
232
- draft.aiAgentsActivation.phases = action.payload.phases;
233
- draft.aiAgentsActivation.counts = action.payload.counts;
234
- },
235
- prepare(payload) {
236
- return { payload };
237
- },
238
- },
239
- fetchAiAgentsActivationStatusFailure: {
240
- reducer(draft, action) {
241
- draft.aiAgentsActivation.fetchStatus = {
242
- fetchState: 'Error',
243
- error: action.payload,
244
- };
245
- },
246
- prepare(error) {
247
- return { payload: error };
248
- },
249
- },
250
- aiAgentsActivationCountsUpdated: {
251
- reducer(draft, action) {
252
- draft.aiAgentsActivation.counts = {
253
- ...draft.aiAgentsActivation.counts,
254
- ...action.payload,
255
- };
256
- },
257
- prepare(payload) {
258
- return { payload };
259
- },
260
- },
261
- aiAgentsActivationPhaseChanged: {
262
- reducer(draft, action) {
263
- const target = draft.aiAgentsActivation.phases;
264
- const index = target.findIndex((phase) => phase.key === action.payload.key);
265
- if (index === -1) {
266
- target.push(action.payload);
267
- }
268
- else {
269
- target[index] = { ...target[index], ...action.payload };
270
- }
271
- },
272
- prepare(payload) {
273
- return { payload };
274
- },
275
- },
276
183
  updateOnboardingCustomerViewDashboardLoaded: {
277
184
  reducer(draft) {
278
185
  draft.dashboardLoadedStatus = {
@@ -685,81 +592,7 @@ const onboardingCustomerView = createSlice({
685
592
  clearOnboardingCustomerView(draft) {
686
593
  Object.assign(draft, initialState);
687
594
  },
688
- /** Merge AI-parsed officer fields into the officer's onboarding localData. */
689
- applyKycDocumentAutofillForOnboarding: {
690
- reducer(draft, action) {
691
- const { officerType, values, autoFilledFieldNames, fileId } = action.payload;
692
- const slot = draft.companyOfficerUpdateStatus[officerType];
693
- slot.localData = Object.assign({}, slot.localData, values);
694
- slot.autoFilledFields = Array.from(new Set([...slot.autoFilledFields, ...autoFilledFieldNames]));
695
- draft.parsingDocumentFileIds = draft.parsingDocumentFileIds.filter((id) => id !== fileId);
696
- },
697
- prepare(payload) {
698
- return { payload };
699
- },
700
- },
701
- /** Merge AI-parsed company fields into companyDetails onboarding localData. */
702
- applyKybDocumentAutofillForOnboarding: {
703
- reducer(draft, action) {
704
- const { values, autoFilledFieldNames, fileId } = action.payload;
705
- draft.companyDetails.localData = Object.assign({}, draft.companyDetails.localData, values);
706
- const prev = draft.companyDetails.autoFilledFields ?? [];
707
- draft.companyDetails.autoFilledFields = Array.from(new Set([...prev, ...autoFilledFieldNames]));
708
- draft.parsingDocumentFileIds = draft.parsingDocumentFileIds.filter((id) => id !== fileId);
709
- },
710
- prepare(payload) {
711
- return { payload };
712
- },
713
- },
714
- /** Wipe AI-autofill badges during onboarding. */
715
- clearKycKybAutofillForOnboarding: {
716
- reducer(draft, action) {
717
- const { officerType } = action.payload;
718
- if (officerType != null) {
719
- draft.companyOfficerUpdateStatus[officerType].autoFilledFields = [];
720
- }
721
- else {
722
- draft.companyDetails.autoFilledFields = [];
723
- Object.keys(draft.companyOfficerUpdateStatus).forEach((key) => {
724
- draft.companyOfficerUpdateStatus[key].autoFilledFields = [];
725
- });
726
- }
727
- },
728
- prepare(payload = {}) {
729
- return { payload };
730
- },
731
- },
732
- },
733
- extraReducers: (builder) => {
734
- const addParsingFileId = (draft, fileId) => {
735
- if (!draft.parsingDocumentFileIds.includes(fileId)) {
736
- draft.parsingDocumentFileIds.push(fileId);
737
- }
738
- };
739
- const removeParsingFileId = (draft, fileId) => {
740
- draft.parsingDocumentFileIds = draft.parsingDocumentFileIds.filter((id) => id !== fileId);
741
- };
742
- builder.addCase(parseUploadedKycDocument, (draft, action) => {
743
- if (action.payload.target === 'onboarding') {
744
- addParsingFileId(draft, action.payload.fileId);
745
- }
746
- });
747
- builder.addCase(parseUploadedKybDocument, (draft, action) => {
748
- if (action.payload.target === 'onboarding') {
749
- addParsingFileId(draft, action.payload.fileId);
750
- }
751
- });
752
- builder.addCase(parseUploadedKycDocumentFailure, (draft, action) => {
753
- if (action.payload.target === 'onboarding') {
754
- removeParsingFileId(draft, action.payload.fileId);
755
- }
756
- });
757
- builder.addCase(parseUploadedKybDocumentFailure, (draft, action) => {
758
- if (action.payload.target === 'onboarding') {
759
- removeParsingFileId(draft, action.payload.fileId);
760
- }
761
- });
762
595
  },
763
596
  });
764
- export const { fetchOnboardingCustomerView, fetchOnboardingCustomerSetupView, fetchOnboardingCustomerSetupViewSuccess, fetchOnboardingCustomerSetupViewFailure, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewCompleteStatusSuccess, updateOnboardingCustomerViewCompleteStatusFailure, acknowledgeOnboardingAiFinanceTeam, acknowledgeOnboardingAiFinanceTeamSuccess, acknowledgeOnboardingAiFinanceTeamFailure, acknowledgeOnboardingAiActivationViewed, acknowledgeOnboardingAiActivationViewedSuccess, acknowledgeOnboardingAiActivationViewedFailure, fetchAiAgentsActivationStatus, fetchAiAgentsActivationStatusSuccess, fetchAiAgentsActivationStatusFailure, aiAgentsActivationCountsUpdated, aiAgentsActivationPhaseChanged, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingCustomerViewDashboardLoadedSuccess, updateOnboardingCustomerViewDashboardLoadedFailure, updateOnboardingCustomerView, updateOnboardingCustomerViewSuccess, updateOnboardingCustomerViewFailure, updateOnboardingPaymentAccountStatus, updateOnboardingPaymentAccountStatusSuccess, updateOnboardingPaymentAccountStatusFailure, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountLoginStatusSuccess, updateOnboardingPaymentAccountLoginStatusFailure, establishOnboardingPlaidConnection, establishOnboardingPlaidConnectionSuccess, establishOnboardingPlaidConnectionFailure, getOnboardingPlaidLinkToken, getOnboardingPlaidLinkTokenSuccess, getOnboardingPlaidLinkTokenFailure, updateCurrentStep, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewLocalStoreData, saveOnboardingCustomerViewDataInLocalStore, saveOnboardingCompnayOfficerPhoneInLocalStore, updateOnboardingCustomerViewUIState, sendOnboardingOfficerOtp, sendOnboardingOfficerOtpSuccess, sendOnboardingOfficerOtpFailure, resendOnboardingOfficerOtp, verifyOnboardingOfficerOtp, verifyOnboardingOfficerOtpSuccess, verifyOnboardingOfficerOtpFailure, clearOnboardingCustomerViewDataInLocalStore, clearOnboardingCustomerView, applyKycDocumentAutofillForOnboarding, applyKybDocumentAutofillForOnboarding, clearKycKybAutofillForOnboarding, } = onboardingCustomerView.actions;
597
+ export const { fetchOnboardingCustomerView, fetchOnboardingCustomerSetupView, fetchOnboardingCustomerSetupViewSuccess, fetchOnboardingCustomerSetupViewFailure, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewCompleteStatusSuccess, updateOnboardingCustomerViewCompleteStatusFailure, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingCustomerViewDashboardLoadedSuccess, updateOnboardingCustomerViewDashboardLoadedFailure, updateOnboardingCustomerView, updateOnboardingCustomerViewSuccess, updateOnboardingCustomerViewFailure, updateOnboardingPaymentAccountStatus, updateOnboardingPaymentAccountStatusSuccess, updateOnboardingPaymentAccountStatusFailure, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountLoginStatusSuccess, updateOnboardingPaymentAccountLoginStatusFailure, establishOnboardingPlaidConnection, establishOnboardingPlaidConnectionSuccess, establishOnboardingPlaidConnectionFailure, getOnboardingPlaidLinkToken, getOnboardingPlaidLinkTokenSuccess, getOnboardingPlaidLinkTokenFailure, updateCurrentStep, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewLocalStoreData, saveOnboardingCustomerViewDataInLocalStore, saveOnboardingCompnayOfficerPhoneInLocalStore, updateOnboardingCustomerViewUIState, sendOnboardingOfficerOtp, sendOnboardingOfficerOtpSuccess, sendOnboardingOfficerOtpFailure, resendOnboardingOfficerOtp, verifyOnboardingOfficerOtp, verifyOnboardingOfficerOtpSuccess, verifyOnboardingOfficerOtpFailure, clearOnboardingCustomerViewDataInLocalStore, clearOnboardingCustomerView, } = onboardingCustomerView.actions;
765
598
  export default onboardingCustomerView.reducer;
@@ -11,7 +11,7 @@ import { getCompanyAndIdentityDetails, } from '../../spendManagement/commonSetup
11
11
  import { ALL_ONBOARDING_STEPS, ALL_ZENI_USER_ONBOARDING_STEPS, REQUIRED_ONBOARDING_STEPS, ZENI_USER_REQUIRED_ONBOARDING_STEPS, toOnboardingStepType, } from './onboardingCustomerViewState';
12
12
  export function getOnboardingCustomerView(state, companyId) {
13
13
  const { fileState, paymentAccountState, onboardingCustomerViewState, userState, userRoleState, subscriptionPaymentAccountState, companyConfigState, cardPaymentViewState, countryListState, addressViewState, } = state;
14
- const { companyDetails, companyOfficerUpdateStatus, primaryContactDetails, subscriptionPaymentAccountIds, paymentAccountDetails, plaidConnectionDetails, parsingDocumentFileIds, updateStatus, saveStatus, currentStep, uiState, fetchState, error, } = onboardingCustomerViewState;
14
+ const { companyDetails, companyOfficerUpdateStatus, primaryContactDetails, subscriptionPaymentAccountIds, paymentAccountDetails, plaidConnectionDetails, updateStatus, saveStatus, currentStep, uiState, fetchState, error, } = onboardingCustomerViewState;
15
15
  const { paymentAccountIds } = paymentAccountDetails;
16
16
  let subscriptionPaymentAccount;
17
17
  let paymentAccount;
@@ -54,7 +54,6 @@ export function getOnboardingCustomerView(state, companyId) {
54
54
  companyDetails,
55
55
  companyOfficerUpdateStatus,
56
56
  primaryContactDetails,
57
- parsingDocumentFileIds,
58
57
  });
59
58
  const companyAddress = addressViewState.newAddressState?.company_address;
60
59
  if (companyAddress == null &&
@@ -120,7 +119,6 @@ export function getOnboardingCustomerView(state, companyId) {
120
119
  return {
121
120
  companyDetailsLocalData,
122
121
  companyOfficerLocalData,
123
- parsingDocumentFileIds,
124
122
  subscriptionBillingAddress: subscriptionBillingAddress?.addressToCreate,
125
123
  companyView,
126
124
  allNationalityCountries,
@@ -325,7 +323,3 @@ export const getProductSettingsString = (productSettings) => {
325
323
  .map((key) => productKeyMap[key])
326
324
  .join(',');
327
325
  };
328
- const fromActivationView = (state) => state.onboardingCustomerViewState.aiAgentsActivation;
329
- export const getAiAgentsActivationSubview = (state) => fromActivationView(state);
330
- export const getAiAgentsActivationPhases = (state) => fromActivationView(state).phases;
331
- export const getAiAgentsActivationCounts = (state) => fromActivationView(state).counts;
@@ -26,15 +26,3 @@ export const ALL_ONBOARDING_STEPS = [
26
26
  ...ALL_ZENI_USER_ONBOARDING_STEPS_WITHOUT_ACCOUNT,
27
27
  ];
28
28
  export const toOnboardingStepType = (v) => stringToUnion(v, ALL_ONBOARDING_STEPS);
29
- export const emptyAiAgentsActivationCounts = {
30
- customerCount: 0,
31
- glAccountCount: 0,
32
- targetTransactionCount: 0,
33
- transactionCount: 0,
34
- vendorCount: 0,
35
- };
36
- export const emptyAiAgentsActivationSubview = {
37
- counts: emptyAiAgentsActivationCounts,
38
- fetchStatus: { fetchState: 'Not-Started', error: undefined },
39
- phases: [],
40
- };
@@ -13,6 +13,7 @@ export const initialState = {
13
13
  newApprovalRuleId: undefined,
14
14
  approvalRulesDeleteStatusById: {},
15
15
  billPaySetupApproverViewUpdateData: undefined,
16
+ reorderStatus: { fetchState: 'Not-Started', error: undefined },
16
17
  hasValidState() {
17
18
  return this.fetchState === 'Completed';
18
19
  },
@@ -26,8 +27,11 @@ const billPaySetupApproverView = createSlice({
26
27
  draft.fetchState = 'In-Progress';
27
28
  draft.error = undefined;
28
29
  },
29
- prepare(cacheOverride = false, includeUserRoles = true) {
30
- return { payload: { cacheOverride, includeUserRoles } };
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 } };
31
35
  },
32
36
  },
33
37
  fetchBillPaySetupApproverViewSuccess: {
@@ -112,8 +116,11 @@ const billPaySetupApproverView = createSlice({
112
116
  error: undefined,
113
117
  };
114
118
  },
115
- prepare(approvalRuleId) {
116
- return { payload: { approvalRuleId } };
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 } };
117
124
  },
118
125
  },
119
126
  deleteBillPayApprovalRuleSuccess: {
@@ -145,13 +152,86 @@ const billPaySetupApproverView = createSlice({
145
152
  };
146
153
  },
147
154
  },
148
- saveBillPaySetupApproverViewUpdates(draft) {
149
- if (draft.billPaySetupApproverViewUpdateData != null) {
150
- draft.billPaySetupApproverViewUpdateData.updateStatus = {
151
- fetchState: 'In-Progress',
152
- error: undefined,
153
- };
154
- }
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
+ // Stash the pre-reorder order so 'Failure' can restore it
170
+ // synchronously. The epic's refetch on failure remains as a
171
+ // safety net (covers cases where the server's truth has
172
+ // drifted from the local snapshot), but the snappy UX path
173
+ // is the in-memory rollback.
174
+ draft.reorderRollbackIds = draft.approvalRuleIds;
175
+ // Optimistic: render new order immediately. On failure, the
176
+ // reducer restores 'reorderRollbackIds' and the epic refetch
177
+ // reconciles any drift.
178
+ draft.approvalRuleIds = approvalRuleIds;
179
+ },
180
+ prepare(approvalRuleIds, useV3 = false) {
181
+ return { payload: { approvalRuleIds, useV3 } };
182
+ },
183
+ },
184
+ reorderBillPayApprovalRulesSuccess: {
185
+ reducer(draft, action) {
186
+ const { approvalRuleIds } = action.payload;
187
+ draft.reorderStatus = { fetchState: 'Completed', error: undefined };
188
+ // The API response is authoritative — overwrite with the
189
+ // server's reported order in case it normalised anything.
190
+ draft.approvalRuleIds = approvalRuleIds;
191
+ // Reorder succeeded — discard the snapshot so the next
192
+ // reorder starts from this committed order.
193
+ draft.reorderRollbackIds = undefined;
194
+ },
195
+ prepare(approvalRuleIds) {
196
+ return { payload: { approvalRuleIds } };
197
+ },
198
+ },
199
+ reorderBillPayApprovalRulesFailure: {
200
+ reducer(draft, action) {
201
+ const { status } = action.payload;
202
+ draft.reorderStatus = { fetchState: 'Error', error: status };
203
+ // Restore the snapshot taken on the trigger reducer before
204
+ // the optimistic mutation. The epic still fires a refetch
205
+ // alongside the failure action for cross-tab drift recovery,
206
+ // but locally the user sees their last good order instantly.
207
+ if (draft.reorderRollbackIds != null) {
208
+ draft.approvalRuleIds = draft.reorderRollbackIds;
209
+ draft.reorderRollbackIds = undefined;
210
+ }
211
+ },
212
+ prepare(status) {
213
+ return { payload: { status } };
214
+ },
215
+ },
216
+ saveBillPaySetupApproverViewUpdates: {
217
+ // Approval Rules 3.0 — `useV3` is sourced from the
218
+ // `approval_rule_v3_config` dynamic config in the screen
219
+ // connector. The reducer doesn't read it (the field only
220
+ // matters in the save epic), but it must be declared so the
221
+ // action's payload type is correctly inferred for downstream
222
+ // consumers.
223
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
224
+ reducer(draft, _action) {
225
+ if (draft.billPaySetupApproverViewUpdateData != null) {
226
+ draft.billPaySetupApproverViewUpdateData.updateStatus = {
227
+ fetchState: 'In-Progress',
228
+ error: undefined,
229
+ };
230
+ }
231
+ },
232
+ prepare(useV3) {
233
+ return { payload: { useV3 } };
234
+ },
155
235
  },
156
236
  saveBillPaySetupApproverViewUpdatesSuccess: {
157
237
  reducer(draft, action) {
@@ -240,5 +320,5 @@ const billPaySetupApproverView = createSlice({
240
320
  },
241
321
  },
242
322
  });
243
- export const { fetchBillPaySetupApproverView, fetchBillPaySetupApproverViewSuccess, fetchBillPaySetupApproverViewFailure, fetchBillPayApproversDetails, fetchBillPayApproversList, fetchBillPayApproversListSuccess, fetchBillPayApproversListFailure, deleteBillPayApprovalRule, deleteBillPayApprovalRuleSuccess, deleteBillPayApprovalRuleFailure, saveBillPaySetupApproverViewUpdates, saveBillPaySetupApproverViewUpdatesSuccess, saveBillPaySetupApproverViewUpdatesFailure, initializeBillPaySetupApproverViewUpdateData, saveBillPaySetupApproverViewUpdateData, clearBillPaySetupApproverViewUpdateData, setListeningToPusherEvent, clearBillPaySetupApproverView, } = billPaySetupApproverView.actions;
323
+ 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;
244
324
  export default billPaySetupApproverView.reducer;
@@ -6,9 +6,17 @@ 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 } = 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/bill-pay/approval-rules-v2`
15
+ : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
10
16
  return zeniAPI
11
- .deleteAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/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 { fetchBillPaySetupApproverView, fetchBillPaySetupApproverViewFailure, fetchBillPaySetupApproverViewSuccess, } from '../billPaySetupApproverViewReducer';
8
8
  export const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBillPaySetupApproverView.match), switchMap((action) => {
9
- const { cacheOverride } = action.payload;
9
+ const { cacheOverride, useV3 } = action.payload;
10
10
  const { billPaySetupApproverViewState, approvalRuleState } = state$.value;
11
11
  const approvalRules = getApprovalRulesByIds(approvalRuleState, billPaySetupApproverViewState.approvalRuleIds);
12
12
  if (cacheOverride === true ||
@@ -14,9 +14,13 @@ export const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) =>
14
14
  billPaySetupApproverViewState.approvalRuleIds.length ||
15
15
  (billPaySetupApproverViewState.hasValidState() === false &&
16
16
  billPaySetupApproverViewState.fetchState !== 'In-Progress')) {
17
- return zeniAPI
18
- .getJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`)
19
- .pipe(mergeMap((response) => {
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) => {
20
24
  if (isSuccessResponse(response) && response.data != null) {
21
25
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
22
26
  const actions = [
@@ -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 { 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,16 +8,20 @@ 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;
13
11
  const billPaySetupApproverViewUpdateData = {
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(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewUpdateData));
23
27
  }
@@ -25,7 +29,7 @@ export const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state
25
29
  else {
26
30
  const billPaySetupApproverViewCreateData = {
27
31
  steps: [],
28
- criteria: undefined,
32
+ criteria: {},
29
33
  };
30
34
  fetchActions.push(clearBillPaySetupApproverViewUpdateData(), saveBillPaySetupApproverViewUpdateData(billPaySetupApproverViewCreateData));
31
35
  }
@@ -0,0 +1,54 @@
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 { fetchBillPaySetupApproverView, reorderBillPayApprovalRules, reorderBillPayApprovalRulesFailure, reorderBillPayApprovalRulesSuccess, } from '../billPaySetupApproverViewReducer';
7
+ export const reorderBillPayApprovalRulesEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(reorderBillPayApprovalRules.match), switchMap((action) => {
8
+ const { approvalRuleIds, useV3 } = action.payload;
9
+ // Approval Rules 3.0 — flag-gated endpoint selection. Mirrors
10
+ // the pattern used by delete + fetch epics: the v3 dev host
11
+ // until the production base URL ships the v2 reorder route.
12
+ const endpoint = `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2/reorder`;
13
+ return zeniAPI
14
+ .putAndGetJSON(endpoint, {
15
+ rule_ids: approvalRuleIds,
16
+ })
17
+ .pipe(mergeMap((response) => {
18
+ if (isSuccessResponse(response) && response.data != null) {
19
+ const serverOrderedIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
20
+ const actions = [
21
+ updateApprovalRules(response.data.approval_rules),
22
+ reorderBillPayApprovalRulesSuccess(serverOrderedIds),
23
+ openSnackbar({
24
+ messageSection: `bill_pay_approval_reorder`,
25
+ messageText: 'success',
26
+ type: 'success',
27
+ }),
28
+ ];
29
+ return from(actions);
30
+ }
31
+ else {
32
+ const recovery = [
33
+ reorderBillPayApprovalRulesFailure(response.status),
34
+ openSnackbar({
35
+ messageSection: `bill_pay_approval_reorder`,
36
+ messageText: 'failed',
37
+ type: 'error',
38
+ }),
39
+ // Refetch to revert the optimistic order to server truth.
40
+ fetchBillPaySetupApproverView(true, true, useV3),
41
+ ];
42
+ return from(recovery);
43
+ }
44
+ }), catchError((error) => from([
45
+ reorderBillPayApprovalRulesFailure(createZeniAPIStatus('Unexpected Error', 'Reorder Bill Pay Approval Rules errored out' +
46
+ JSON.stringify(error))),
47
+ openSnackbar({
48
+ messageSection: `bill_pay_approval_reorder`,
49
+ messageText: 'failed',
50
+ type: 'error',
51
+ }),
52
+ fetchBillPaySetupApproverView(true, true, useV3),
53
+ ])));
54
+ }));