@zeniai/client-epic-state 5.2.41-beta6MM → 5.2.41-beta8MM

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 (195) hide show
  1. package/lib/entity/billPay/billTransaction/billTransactionReducer.d.ts +5 -1
  2. package/lib/entity/billPay/billTransaction/billTransactionReducer.js +17 -2
  3. package/lib/entity/invoicing/coupon/couponPayload.d.ts +8 -0
  4. package/lib/entity/invoicing/coupon/couponPayload.js +8 -0
  5. package/lib/entity/invoicing/coupon/couponState.d.ts +6 -0
  6. package/lib/entity/invoicing/dunningCase/dunningCaseTypes.d.ts +1 -1
  7. package/lib/entity/invoicing/plan/planSelector.d.ts +20 -0
  8. package/lib/entity/invoicing/plan/planSelector.js +42 -0
  9. package/lib/entity/invoicing/product/productPayload.d.ts +8 -1
  10. package/lib/entity/invoicing/product/productPayload.js +4 -1
  11. package/lib/entity/invoicing/product/productState.d.ts +16 -0
  12. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +4 -1
  13. package/lib/entity/jeSchedules/jeSchedulesReducer.js +79 -5
  14. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  15. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  16. package/lib/entity/task/taskState.d.ts +1 -1
  17. package/lib/epic.d.ts +4 -1
  18. package/lib/epic.js +10 -4
  19. package/lib/esm/entity/billPay/billTransaction/billTransactionReducer.js +16 -1
  20. package/lib/esm/entity/invoicing/coupon/couponPayload.js +8 -0
  21. package/lib/esm/entity/invoicing/plan/planSelector.js +39 -0
  22. package/lib/esm/entity/invoicing/product/productPayload.js +4 -1
  23. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +78 -4
  24. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  25. package/lib/esm/epic.js +10 -4
  26. package/lib/esm/index.js +8 -7
  27. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +3 -2
  28. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +39 -0
  29. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +14 -1
  30. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +10 -13
  31. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
  32. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
  33. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  34. package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +6 -0
  35. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +74 -1
  36. package/lib/esm/view/expenseAutomationView/reducers/reconciliationViewReducer.js +80 -53
  37. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  38. package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +6 -2
  39. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
  40. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +28 -11
  41. package/lib/esm/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
  42. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +67 -35
  43. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +22 -11
  44. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +23 -4
  45. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
  46. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +19 -5
  47. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +30 -7
  48. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.js +16 -1
  49. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +22 -11
  50. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +69 -6
  51. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.js +22 -0
  52. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.js +22 -4
  53. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +18 -4
  54. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +29 -6
  55. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +28 -12
  56. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +37 -2
  57. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +43 -17
  58. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/saveInvoicingCustomerEpic.js +1 -1
  59. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +29 -6
  60. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +30 -14
  61. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +143 -8
  62. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
  63. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +44 -18
  64. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +1 -1
  65. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.js +29 -8
  66. package/lib/esm/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +12 -0
  67. package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.js +6 -6
  68. package/lib/esm/view/invoicing/invoicingFormDraft.js +78 -0
  69. package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +57 -9
  70. package/lib/esm/view/recommendation/recommendationPayload.js +3 -1
  71. package/lib/esm/view/recommendation/recommendationReducer.js +27 -7
  72. package/lib/esm/view/recommendation/recommendationSelector.js +1 -0
  73. package/lib/esm/view/recommendation/submitRecommendationFeedbackEpic.js +20 -8
  74. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +87 -1
  75. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
  76. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
  77. package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +97 -0
  78. package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +85 -0
  79. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewReducer.js +18 -1
  80. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
  81. package/lib/esm/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +95 -0
  82. package/lib/index.d.ts +9 -8
  83. package/lib/index.js +54 -48
  84. package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +3 -2
  85. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +20 -0
  86. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +43 -0
  87. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
  88. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +13 -0
  89. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +8 -11
  90. package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
  91. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
  92. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
  93. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  94. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  95. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +18 -0
  96. package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +18 -7
  97. package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +6 -0
  98. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +10 -3
  99. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +76 -3
  100. package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.js +80 -53
  101. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  102. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +3 -0
  103. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +8 -4
  104. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +1 -0
  105. package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +7 -2
  106. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
  107. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +27 -10
  108. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +16 -0
  109. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +8 -5
  110. package/lib/view/invoicing/createInvoice/createInvoiceSelector.d.ts +7 -2
  111. package/lib/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
  112. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +46 -5
  113. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +69 -36
  114. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.d.ts +3 -1
  115. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +22 -11
  116. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +17 -0
  117. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +22 -3
  118. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewState.d.ts +2 -1
  119. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.d.ts +2 -2
  120. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
  121. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +17 -3
  122. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.d.ts +10 -6
  123. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +29 -6
  124. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.d.ts +5 -1
  125. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.js +16 -1
  126. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.d.ts +3 -1
  127. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +22 -11
  128. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +46 -0
  129. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +68 -5
  130. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.d.ts +21 -1
  131. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.js +24 -1
  132. package/lib/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.d.ts +9 -5
  133. package/lib/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.js +22 -4
  134. package/lib/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +18 -4
  135. package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.d.ts +10 -6
  136. package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +28 -5
  137. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +5 -1
  138. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +29 -13
  139. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +16 -7
  140. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +37 -2
  141. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +8 -1
  142. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.d.ts +15 -10
  143. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +42 -16
  144. package/lib/view/invoicing/editInvoicingCustomerDetailView/saveInvoicingCustomerEpic.js +1 -1
  145. package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.d.ts +10 -6
  146. package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +28 -5
  147. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +5 -1
  148. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +31 -15
  149. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +79 -12
  150. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +145 -9
  151. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +8 -1
  152. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
  153. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.d.ts +15 -11
  154. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +42 -16
  155. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +1 -1
  156. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.d.ts +10 -6
  157. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.js +28 -7
  158. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.d.ts +10 -0
  159. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +12 -0
  160. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.d.ts +1 -1
  161. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.d.ts +2 -2
  162. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.js +6 -6
  163. package/lib/view/invoicing/invoicingFormDraft.d.ts +63 -0
  164. package/lib/view/invoicing/invoicingFormDraft.js +86 -0
  165. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +49 -0
  166. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +59 -10
  167. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.d.ts +1 -1
  168. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewState.d.ts +1 -1
  169. package/lib/view/recommendation/recommendationPayload.d.ts +1 -0
  170. package/lib/view/recommendation/recommendationPayload.js +5 -0
  171. package/lib/view/recommendation/recommendationReducer.d.ts +7 -1
  172. package/lib/view/recommendation/recommendationReducer.js +28 -8
  173. package/lib/view/recommendation/recommendationSelector.d.ts +2 -0
  174. package/lib/view/recommendation/recommendationSelector.js +3 -1
  175. package/lib/view/recommendation/recommendationState.d.ts +2 -1
  176. package/lib/view/recommendation/submitRecommendationFeedbackEpic.d.ts +2 -2
  177. package/lib/view/recommendation/submitRecommendationFeedbackEpic.js +18 -6
  178. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewPayload.d.ts +19 -0
  179. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.d.ts +10 -1
  180. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +88 -2
  181. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.d.ts +1 -0
  182. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
  183. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.d.ts +7 -0
  184. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
  185. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.d.ts +37 -0
  186. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +104 -0
  187. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.d.ts +24 -0
  188. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +92 -0
  189. package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.d.ts +4 -1
  190. package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.js +19 -2
  191. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -0
  192. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
  193. package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.d.ts +18 -0
  194. package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +102 -0
  195. package/package.json +2 -2
@@ -1,7 +1,8 @@
1
- import { EMPTY } from 'rxjs';
1
+ import { EMPTY, of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { isSuccessStatus } from '../../responsePayload';
4
- import { submitRecommendationFeedback } from './recommendationReducer';
4
+ import { isPromptedRecommendationFeedback, } from './recommendationPayload';
5
+ import { submitRecommendationFeedback, submitRecommendationFeedbackCompleted, } from './recommendationReducer';
5
6
  const toRequestBody = (payload) => ({
6
7
  line_id: payload.lineId ?? null,
7
8
  dimension: payload.dimension,
@@ -33,20 +34,31 @@ const toRequestBody = (payload) => ({
33
34
  retracts_feedback_id: payload.retractsFeedbackId ?? null,
34
35
  features: payload.features ?? null,
35
36
  });
36
- // Fire-and-forget: the epic never re-emits an action. Feedback delivery is a
37
- // side-effect that must not disrupt the categorization UX, so both the
38
- // success and error paths complete silently (errors are logged for debugging).
37
+ // Always reports completion so the feedback popup can show a loader and tell the
38
+ // user what happened. The categorization itself still never waits on this: a
39
+ // failure is surfaced in a toast rather than blocking or reverting the change.
39
40
  export const submitRecommendationFeedbackEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(submitRecommendationFeedback.match), mergeMap((action) => {
40
41
  const { transactionId } = action.payload;
42
+ // Only the override that opened the popup reports completion; accepts and
43
+ // retractions stay fire-and-forget so they cannot settle the popup.
44
+ const isPrompted = isPromptedRecommendationFeedback(action.payload.outcome);
41
45
  return zeniAPI
42
46
  .postAndGetJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/transactions/${transactionId}/recommendation-feedback`, toRequestBody(action.payload))
43
47
  .pipe(mergeMap((response) => {
44
- if (!isSuccessStatus(response)) {
48
+ const succeeded = isSuccessStatus(response);
49
+ if (!succeeded) {
45
50
  console.error('submitRecommendationFeedbackEpic: recommendation feedback was not recorded', response.status);
46
51
  }
47
- return EMPTY;
52
+ return isPrompted
53
+ ? of(submitRecommendationFeedbackCompleted({
54
+ succeeded,
55
+ error: succeeded ? undefined : response.status,
56
+ }))
57
+ : EMPTY;
48
58
  }), catchError((error) => {
49
59
  console.error('submitRecommendationFeedbackEpic: failed to submit recommendation feedback', error);
50
- return EMPTY;
60
+ return isPrompted
61
+ ? of(submitRecommendationFeedbackCompleted({ succeeded: false }))
62
+ : EMPTY;
51
63
  }));
52
64
  }));
@@ -18,6 +18,12 @@ const billDetailView = createSlice({
18
18
  detail.fetchState !== 'In-Progress') {
19
19
  draft.billDetailById[key] = {
20
20
  ...initialBillDetailView,
21
+ // Deliberately independent of the detail fetch: recommendations
22
+ // are requested separately and must not be reset by a detail
23
+ // refresh, which on the edit route lands right after the
24
+ // recommendations request has already started.
25
+ recommendationsFetchStatus: detail?.recommendationsFetchStatus ??
26
+ initialBillDetailView.recommendationsFetchStatus,
21
27
  };
22
28
  }
23
29
  },
@@ -69,6 +75,86 @@ const billDetailView = createSlice({
69
75
  };
70
76
  },
71
77
  },
78
+ fetchBillRecommendations: {
79
+ reducer(draft, action) {
80
+ const key = getBillTransactionDetailKey(action.payload.billId);
81
+ // The edit route can mount before the bill detail entry exists — its
82
+ // screen dispatches this before the parent requests the detail. Seed
83
+ // the entry rather than bailing, or the status would sit at
84
+ // `Not-Started` for the whole wait and round trip.
85
+ const detail = recordGet(draft.billDetailById, key, undefined) ?? {
86
+ ...initialBillDetailView,
87
+ billId: action.payload.billId,
88
+ };
89
+ const { fetchState } = detail.recommendationsFetchStatus;
90
+ // Both screens dispatch once per bill — on mount, keyed by bill id,
91
+ // not on every render — so this guard is not what prevents a render
92
+ // loop; the epic's per-bill `exhaustMap` is what collapses the two
93
+ // sites' dispatches into one request.
94
+ //
95
+ // `Error` is deliberately allowed through: a bill whose fetch failed
96
+ // must be able to try again when the screen is next opened.
97
+ if (action.payload.cacheOverride === true ||
98
+ (fetchState !== 'In-Progress' && fetchState !== 'Completed')) {
99
+ draft.billDetailById[key] = {
100
+ ...detail,
101
+ recommendationsFetchStatus: {
102
+ fetchState: 'In-Progress',
103
+ error: undefined,
104
+ },
105
+ };
106
+ }
107
+ },
108
+ prepare(billId, cacheOverride = false) {
109
+ return {
110
+ payload: { billId, cacheOverride },
111
+ };
112
+ },
113
+ },
114
+ fetchBillRecommendationsSuccess: {
115
+ reducer(draft, action) {
116
+ const key = getBillTransactionDetailKey(action.payload.billId);
117
+ const detail = recordGet(draft.billDetailById, key, undefined);
118
+ if (detail != null) {
119
+ draft.billDetailById[key] = {
120
+ ...detail,
121
+ recommendationsFetchStatus: {
122
+ fetchState: 'Completed',
123
+ error: undefined,
124
+ },
125
+ };
126
+ }
127
+ },
128
+ // `didWriteRecommendations` is false on the skip paths, which resolve
129
+ // the status without fetching anything. Consumers that react by
130
+ // recomputing local state must not run then — there is nothing new to
131
+ // apply, and recomputing would reset the line's "update to" selections.
132
+ prepare(billId, didWriteRecommendations = false) {
133
+ return {
134
+ payload: { billId, didWriteRecommendations },
135
+ };
136
+ },
137
+ },
138
+ fetchBillRecommendationsFailure: {
139
+ reducer(draft, action) {
140
+ const key = getBillTransactionDetailKey(action.payload.billId);
141
+ const detail = recordGet(draft.billDetailById, key, undefined);
142
+ if (detail != null) {
143
+ draft.billDetailById[key] = {
144
+ ...detail,
145
+ recommendationsFetchStatus: {
146
+ fetchState: 'Error',
147
+ error: action.payload.error,
148
+ },
149
+ };
150
+ }
151
+ },
152
+ prepare(billId, error) {
153
+ return {
154
+ payload: { billId, error },
155
+ };
156
+ },
157
+ },
72
158
  deleteBill: {
73
159
  reducer(draft, action) {
74
160
  const key = getBillTransactionDetailKey(action.payload.billId);
@@ -462,5 +548,5 @@ const billDetailView = createSlice({
462
548
  });
463
549
  },
464
550
  });
465
- export const { fetchBillDetail, updateBillDetail, updateBillDetailFetchState, removeBillDetail, deleteBill, deleteBillSuccessOrFailure, approveOrRejectBill, approveOrRejectBillSuccess, approveOrRejectBillFailure, updateApprovalStatusOnSuccess, cancelAndDeleteBill, cancelAndDeleteBillSuccessOrFailure, waitForVendorByNameThenUpdateBillDetail, fetchEligibleActionsForBill, updateEligibleActionsForBill, updateFetchEligibleActionsFailureState, retryOrRefundBill, retryOrRefundBillSuccess, retryOrRefundBillFailure, } = billDetailView.actions;
551
+ export const { fetchBillDetail, fetchBillRecommendations, fetchBillRecommendationsSuccess, fetchBillRecommendationsFailure, updateBillDetail, updateBillDetailFetchState, removeBillDetail, deleteBill, deleteBillSuccessOrFailure, approveOrRejectBill, approveOrRejectBillSuccess, approveOrRejectBillFailure, updateApprovalStatusOnSuccess, cancelAndDeleteBill, cancelAndDeleteBillSuccessOrFailure, waitForVendorByNameThenUpdateBillDetail, fetchEligibleActionsForBill, updateEligibleActionsForBill, updateFetchEligibleActionsFailureState, retryOrRefundBill, retryOrRefundBillSuccess, retryOrRefundBillFailure, } = billDetailView.actions;
466
552
  export default billDetailView.reducer;
@@ -219,6 +219,7 @@ export const getBillDetailView = (state, billId) => {
219
219
  fetchState: fetchState.fetchState,
220
220
  error: fetchState.error,
221
221
  version: 0,
222
+ recommendationsFetchStatus: billTransactionDetails?.recommendationsFetchStatus,
222
223
  transactionDetails: transaction,
223
224
  createdBy,
224
225
  bankAccount,
@@ -30,6 +30,10 @@ export const initialBillDetailView = {
30
30
  fetchState: 'Not-Started',
31
31
  error: undefined,
32
32
  },
33
+ recommendationsFetchStatus: {
34
+ fetchState: 'Not-Started',
35
+ error: undefined,
36
+ },
33
37
  billId: undefined,
34
38
  eventIds: [],
35
39
  entityApprovalIds: [],
@@ -0,0 +1,97 @@
1
+ import recordGet from 'lodash/get';
2
+ import { of } from 'rxjs';
3
+ import { exhaustMap, filter, groupBy, mergeMap, take } from 'rxjs/operators';
4
+ import { createZeniAPIStatus } from '../../../../../responsePayload';
5
+ import { fetchBillRecommendations, fetchBillRecommendationsFailure, updateBillDetail, updateBillDetailFetchState, } from '../billDetailViewReducer';
6
+ import { getBillTransactionDetailKey } from '../billDetailViewState';
7
+ import { fetchRecommendationsForBill, getBillTransaction, } from './fetchRecommendationsForBill';
8
+ /**
9
+ * Standalone recommendations fetch for a bill, so neither the bill detail nor
10
+ * the bill edit screen waits on recommendation composition.
11
+ *
12
+ * Which bills need it is decided from the bill's stage: an approval-stage bill
13
+ * gets them from the dedicated endpoint
14
+ * (`GET /1.0/bills/transactions/{transaction_id}/recommendations`), while a
15
+ * draft gets them on the bill detail response itself. The platform makes that
16
+ * split from the bill's status, so neither request carries a flag asking for
17
+ * one behaviour or the other.
18
+ *
19
+ * Only `recommendations` is read — per line, and what drives the "Update to X"
20
+ * checkbox and the Recommended group in the category/class dropdowns. The
21
+ * endpoint returns no entity-level recommendation and the edit form does not
22
+ * render one.
23
+ *
24
+ * Failure is confined to `recommendationsFetchStatus` — no bill-detail action
25
+ * is emitted, so a failed or slow recommendations fetch can neither block nor
26
+ * error out either screen.
27
+ *
28
+ * @precondition Every site dispatching `fetchBillRecommendations` must also
29
+ * cause the bill detail to be requested for that bill. This epic waits for the
30
+ * detail when it is not already in the store, and that wait settles only on a
31
+ * detail write or a detail error. A caller that dispatches without one would
32
+ * leave the wait open, and the per-bill `exhaustMap` would then drop later
33
+ * retries for that bill. Both current callers satisfy this: the bill detail
34
+ * route dispatches `fetchBillDetail` alongside, and the edit route reaches it
35
+ * through `fetchEditBillDetailPage`.
36
+ */
37
+ export const fetchBillRecommendationsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBillRecommendations.match),
38
+ // The bill detail route requests these and the edit screen asks again on
39
+ // every mount, so repeats are normal. Drop the ones whose bill is already
40
+ // done before they reach the request.
41
+ filter((action) => action.payload.cacheOverride === true ||
42
+ areRecommendationsAlreadyFetched(state$.value, action.payload.billId) === false),
43
+ // Per bill, then `exhaustMap` rather than `switchMap`: a repeat that
44
+ // arrives while the request (or the wait for the bill detail) is still
45
+ // running is ignored, where `switchMap` would cancel the in-flight one and
46
+ // re-issue it. `groupBy` keeps that per bill, so navigating to another
47
+ // bill mid-flight still fetches for the new one.
48
+ groupBy((action) => action.payload.billId), mergeMap((actionsForBill$) => actionsForBill$.pipe(exhaustMap((action) => {
49
+ const { billId, cacheOverride } = action.payload;
50
+ if (isBillReadyForRecommendations(state$.value, billId)) {
51
+ return fetchRecommendationsForBill(state$.value, billId, zeniAPI, cacheOverride);
52
+ }
53
+ // The edit route can mount before the bill detail response lands,
54
+ // and the request needs the vendor / line ids / amount from it. Wait
55
+ // for the detail write for this bill rather than dropping the fetch,
56
+ // and settle on a detail error too.
57
+ //
58
+ // A leftover `Error` on the bill detail is deliberately NOT treated
59
+ // as terminal here. On the edit route this action is dispatched
60
+ // before the parent screen re-requests the detail — React runs the
61
+ // child's effect first — so failing on the stale error would leave
62
+ // recommendations failed even though the detail is about to succeed.
63
+ //
64
+ // The invariant this relies on: every dispatch site also causes the
65
+ // bill detail to be requested. Both do today. A future site that
66
+ // does not would leave this waiting, and `exhaustMap` would drop
67
+ // later retries for that bill.
68
+ const billDetailSettled$ = actions$.pipe(filter((waited) => {
69
+ if (updateBillDetail.match(waited)) {
70
+ return waited.payload.billId === billId;
71
+ }
72
+ return (updateBillDetailFetchState.match(waited) &&
73
+ waited.payload.fetchState === 'Error' &&
74
+ waited.payload.billId === billId);
75
+ }), take(1) // don't listen forever! IMPORTANT!
76
+ );
77
+ return billDetailSettled$.pipe(mergeMap((waited) => {
78
+ if (updateBillDetail.match(waited)) {
79
+ return fetchRecommendationsForBill(state$.value, billId, zeniAPI, cacheOverride);
80
+ }
81
+ // Bill detail failed; there is nothing to recommend against.
82
+ return of(fetchBillRecommendationsFailure(billId, waited.payload.error ??
83
+ createZeniAPIStatus('Unexpected Error', 'Bill detail fetch failed before recommendations could be requested')));
84
+ }));
85
+ }))));
86
+ /**
87
+ * Helper functions
88
+ */
89
+ function areRecommendationsAlreadyFetched(state, billId) {
90
+ const billDetail = recordGet(state.billDetailViewState.billDetailById, getBillTransactionDetailKey(billId), undefined);
91
+ return billDetail?.recommendationsFetchStatus.fetchState === 'Completed';
92
+ }
93
+ function isBillReadyForRecommendations(state, billId) {
94
+ const billDetail = recordGet(state.billDetailViewState.billDetailById, getBillTransactionDetailKey(billId), undefined);
95
+ return (billDetail?.fetchState === 'Completed' &&
96
+ getBillTransaction(state, billId) != null);
97
+ }
@@ -0,0 +1,85 @@
1
+ import recordGet from 'lodash/get';
2
+ import { from, of } from 'rxjs';
3
+ import { catchError, mergeMap } from 'rxjs/operators';
4
+ import { transformRecommendation } from '../../../../../commonPayloadTypes/recommendationPayload';
5
+ import { updateBillTransactionRecommendations } from '../../../../../entity/billPay/billTransaction/billTransactionReducer';
6
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
7
+ import { fetchBillRecommendationsFailure, fetchBillRecommendationsSuccess, } from '../billDetailViewReducer';
8
+ /**
9
+ * Requests the recommendations for one bill and maps them onto the transaction
10
+ * entity, or resolves without a request for a bill that does not need them.
11
+ *
12
+ * Only `recommendations` is read from the response — per line, and what drives
13
+ * the "Update to X" checkbox and the Recommended group in the category/class
14
+ * dropdowns. The endpoint returns no entity-level recommendation and the edit
15
+ * form does not render one.
16
+ */
17
+ export function fetchRecommendationsForBill(state, billId, zeniAPI, cacheOverride = false) {
18
+ const transaction = getBillTransaction(state, billId);
19
+ const lineIds = transaction?.lines?.map((line) => line.id) ?? [];
20
+ if (transaction == null ||
21
+ shouldSkipRecommendations(transaction, cacheOverride)) {
22
+ return of(fetchBillRecommendationsSuccess(billId));
23
+ }
24
+ // The bill is scoped by the path, so this endpoint takes no query — there is
25
+ // no `is_include_*` flag to turn off the way the bill detail request has.
26
+ return zeniAPI
27
+ .getJSON(`${zeniAPI.apiEndPoints.spendManagementMicroServiceBaseUrl}/1.0/bills/transactions/${billId}/recommendations`)
28
+ .pipe(mergeMap((response) => {
29
+ if (!isSuccessResponse(response) || response.data == null) {
30
+ return of(fetchBillRecommendationsFailure(billId, response.status));
31
+ }
32
+ const actions = [];
33
+ // Positional line <-> recommendation mapping, matching
34
+ // `getRecommendationsPerLine` — the mapping the recommendations went
35
+ // through while the bill detail response still carried them. This
36
+ // endpoint returns them flat, not nested under `transaction`.
37
+ const recommendationPayloads = response.data.recommendations ?? [];
38
+ // The pairing is a convention shared with the platform, not
39
+ // something the payload enforces, so a mismatch would otherwise
40
+ // mis-assign or silently drop recommendations. Degrade safely —
41
+ // extra entries are ignored and unmatched lines get none — but say
42
+ // so, because it means the two sides have diverged.
43
+ if (recommendationPayloads.length !== lineIds.length) {
44
+ console.warn(`Bill ${billId}: ${recommendationPayloads.length} recommendation entries for ${lineIds.length} lines. ` +
45
+ 'They are paired by position, so this bill may be scored incorrectly.');
46
+ }
47
+ const recommendationByLineId = {};
48
+ lineIds.forEach((lineId, index) => {
49
+ const recommendationPayload = recommendationPayloads[index];
50
+ if (recommendationPayload != null) {
51
+ recommendationByLineId[lineId] = transformRecommendation(recommendationPayload);
52
+ }
53
+ });
54
+ actions.push(updateBillTransactionRecommendations(billId, recommendationByLineId));
55
+ // Entity writes first, then the view status, so consumers reading on
56
+ // the status flip already see the recommendations.
57
+ actions.push(fetchBillRecommendationsSuccess(billId, true));
58
+ return from(actions);
59
+ }), catchError((error) => of(fetchBillRecommendationsFailure(billId, createZeniAPIStatus('Unexpected Error', `Fetch bill recommendations REST API call errored out ${error}`)))));
60
+ }
61
+ export function getBillTransaction(state, billId) {
62
+ return recordGet(state.billTransactionState.transactionById, billId, undefined);
63
+ }
64
+ /**
65
+ * Helper functions
66
+ */
67
+ // Awaiting-approval bills are the only ones this request exists for. A draft
68
+ // opens the edit form directly, so its recommendations ride along on the bill
69
+ // detail response; `paid` bills cannot reach the form at all. The platform
70
+ // decides which of those two it is from the bill's status, which is why the
71
+ // request carries no flag asking for either.
72
+ function shouldSkipRecommendations(transaction, cacheOverride) {
73
+ return (transaction.billPayInfo.stage.code !== 'pending_approval' ||
74
+ transaction.isDeleted === true ||
75
+ // No vendor (a draft carrying only a candidate vendor name) means no
76
+ // entity to recommend against — the vendor-selection flow covers that.
77
+ Boolean(transaction.vendor?.id) === false ||
78
+ // The bill detail response already carried them. `toVendorTransaction`
79
+ // maps them straight onto the entity, so requesting again would only
80
+ // re-fetch what is here — this is what lets the platform move the line
81
+ // between embedded and on-demand without a client change. A forced
82
+ // refresh is the one case that still goes to the endpoint.
83
+ (cacheOverride === false &&
84
+ Object.keys(transaction.recommendations ?? {}).length > 0));
85
+ }
@@ -149,6 +149,23 @@ const editBillView = createSlice({
149
149
  }
150
150
  }
151
151
  },
152
+ // Applied when the standalone recommendations fetch resolves after the
153
+ // edit local store was already initialized. `initializeBillToLocalStore`
154
+ // is guarded to run once, so without this the late recommendations would
155
+ // never reach the category/class autofill or the "update to" checkbox.
156
+ updateBillLineRecommendationsInLocalStore: {
157
+ reducer(draft, action) {
158
+ const { billId, updatesByLineId } = action.payload;
159
+ const key = getBillTransactionDetailKey(billId);
160
+ const editBill = draft.editBillStateById[key];
161
+ if (editBill != null) {
162
+ editBill.billDetailLocalData.updatesByLineId = Object.assign({}, editBill.billDetailLocalData.updatesByLineId, updatesByLineId);
163
+ }
164
+ },
165
+ prepare(billId, updatesByLineId) {
166
+ return { payload: { billId, updatesByLineId } };
167
+ },
168
+ },
152
169
  discardBillUpdatesInLocalStore(draft, action) {
153
170
  if (action.payload.billId != null) {
154
171
  const { billId } = action.payload;
@@ -494,7 +511,7 @@ const editBillView = createSlice({
494
511
  });
495
512
  },
496
513
  });
497
- export const { fetchEditBillDetailPage, fetchBillAndInitializeLocalStore, fetchVendorByNameAndParseInvoice, initializeBillToLocalStore, saveBillUpdatesToLocalStore, discardBillUpdatesInLocalStore, saveBillDetail, saveBillSuccessOrFailure, updateEditBillFetchStateCompleted, parseInvoiceToBill, waitForBillDetailThenInitializeLocalStore, waitForVendorByNameThenParsetoLocalStore, updateInternationalTransferFeeBearerPaymentMethodInLocalData, updateShowAutofill, updateAddBillAutoFields, updateBillUploadFetchState, updateRecommendedVendorId, updateSuggestedVendorIdFromParsedInvoice, updateVendorContact, updateVendorContactSuccessOrFailure, convertAmountToHomeCurrency, currencyConversionValueSuccessOrFailure, updateHomeCurrencyConversion, fetchVendorAndUpdateBillLocalData, waitForVendorByIdThenSaveBillUpdatetoLocalStore, markBillForRetry, updateOutsideZeniPaymentLocalData, discardOutsideZeniPaymentLocalData, updateNewAddedBillPaymentAccount, updateWithdrawFromAccountId, removeBillFileFromLocalStore, replaceBillFileInLocalStore, updateShouldReplaceBillData, } = editBillView.actions;
514
+ export const { fetchEditBillDetailPage, fetchBillAndInitializeLocalStore, fetchVendorByNameAndParseInvoice, initializeBillToLocalStore, saveBillUpdatesToLocalStore, updateBillLineRecommendationsInLocalStore, discardBillUpdatesInLocalStore, saveBillDetail, saveBillSuccessOrFailure, updateEditBillFetchStateCompleted, parseInvoiceToBill, waitForBillDetailThenInitializeLocalStore, waitForVendorByNameThenParsetoLocalStore, updateInternationalTransferFeeBearerPaymentMethodInLocalData, updateShowAutofill, updateAddBillAutoFields, updateBillUploadFetchState, updateRecommendedVendorId, updateSuggestedVendorIdFromParsedInvoice, updateVendorContact, updateVendorContactSuccessOrFailure, convertAmountToHomeCurrency, currencyConversionValueSuccessOrFailure, updateHomeCurrencyConversion, fetchVendorAndUpdateBillLocalData, waitForVendorByIdThenSaveBillUpdatetoLocalStore, markBillForRetry, updateOutsideZeniPaymentLocalData, discardOutsideZeniPaymentLocalData, updateNewAddedBillPaymentAccount, updateWithdrawFromAccountId, removeBillFileFromLocalStore, replaceBillFileInLocalStore, updateShouldReplaceBillData, } = editBillView.actions;
498
515
  export default editBillView.reducer;
499
516
  function doUpdateRecurringBillLocalData(billDetail, currentConfig, prevConfig) {
500
517
  const recurringBillDetail = updateRecurringBillDetails(currentConfig, prevConfig, billDetail.recurringBillInstances, billDetail.recipientTotalAmount?.amount);
@@ -380,6 +380,9 @@ export const getEditBillDetail = (state, isVendorRecommendationFeatureEnabled, i
380
380
  classHierarchyList,
381
381
  latestApprovedDate: getLatestApprovalDate(billActivities),
382
382
  recommendationByLineID: recommendations,
383
+ recommendationsFetchStatus: billId != null
384
+ ? billDetailViewState.billDetailById[getBillTransactionDetailKey(billId)]?.recommendationsFetchStatus
385
+ : undefined,
383
386
  isRecurring,
384
387
  recurringBillInstances,
385
388
  recurringConfig,
@@ -0,0 +1,95 @@
1
+ import recordGet from 'lodash/get';
2
+ import { EMPTY, of } from 'rxjs';
3
+ import { filter, mergeMap } from 'rxjs/operators';
4
+ import { getAccountList, } from '../../../../accountList/accountListSelector';
5
+ import { getClassList, } from '../../../../classList/classListSelector';
6
+ import { fetchBillRecommendationsSuccess } from '../../billDetailView/billDetailViewReducer';
7
+ import { getBillTransactionDetailKey } from '../../billDetailView/billDetailViewState';
8
+ import { updateBillLineRecommendationsInLocalStore } from '../editBillViewReducer';
9
+ import { getLineRecommendationsLocalData } from './initializeBillToLocalStoreEpic';
10
+ /**
11
+ * Back-fills the edit local store once the standalone recommendations fetch
12
+ * resolves. `initializeBillToLocalStore` reads `transaction.recommendations`
13
+ * exactly once and is guarded against re-running, so the recommendation-derived
14
+ * line data (category/class autofill, `recommendedCategory` / `recommendedClass`
15
+ * behind the "update to" checkbox) has to be recomputed here instead.
16
+ *
17
+ * Recomputes from the entity lines with the same helper the initializer uses, so
18
+ * an untouched line ends up exactly as it would have had the recommendations
19
+ * been present at init time.
20
+ */
21
+ export const applyBillRecommendationsToLocalStoreEpic = (actions$, state$) => actions$.pipe(filter(fetchBillRecommendationsSuccess.match),
22
+ // The skip paths resolve the status without fetching — a draft whose
23
+ // recommendations came on the bill detail response, or a stage that is not
24
+ // served any. `initializeBillToLocalStore` has already read those, so
25
+ // recomputing here would only reset the line's "update to" selections.
26
+ filter((action) => action.payload.didWriteRecommendations), mergeMap((action) => {
27
+ const { billId } = action.payload;
28
+ const state = state$.value;
29
+ const key = getBillTransactionDetailKey(billId);
30
+ const editBillState = recordGet(state.editBillDetailViewState.editBillStateById, key, undefined);
31
+ const transaction = recordGet(state.billTransactionState.transactionById, billId, undefined);
32
+ const recommendations = transaction?.recommendations;
33
+ if (editBillState == null ||
34
+ transaction == null ||
35
+ transaction.lines == null ||
36
+ recommendations == null ||
37
+ Object.keys(recommendations).length === 0) {
38
+ return EMPTY;
39
+ }
40
+ const localData = editBillState.billDetailLocalData;
41
+ // The recommendations were requested for the vendor on the bill. If the
42
+ // user has since switched vendors, `fetchVendorAndUpdateBillLocalData`
43
+ // owns the line data and these are stale — leave it alone.
44
+ //
45
+ // Both sides are QBO ids despite the field names suggesting otherwise.
46
+ // `transaction.vendor` is built by `mapVendorBasePayloadToVendorBase`,
47
+ // whose id is `getVendorPayloadIdentifier` = `vendor_id ?? qbo_id`, and
48
+ // on a bill transaction payload `vendor_id` IS the QBO id — the Zeni id
49
+ // rides separately as `zeni_vendor_id`. Verified against live DEV and QA
50
+ // responses, both of which have `vendor_id === qbo_vendor_id`.
51
+ if (localData.vendor?.qboId !== transaction.vendor?.id) {
52
+ return EMPTY;
53
+ }
54
+ const accountList = getAccountList(state.accountState, state.accountListState, 'billPayAccountList');
55
+ const classList = getClassList(state.classState, state.classListState);
56
+ const updatesByLineId = {};
57
+ transaction.lines.forEach((line) => {
58
+ // A line whose category/class the user already set keeps their input.
59
+ const localLine = localData.updatesByLineId[line.id];
60
+ if (localLine?.isCategoryOrClassUpdated) {
61
+ return;
62
+ }
63
+ // The helper spreads whatever line it is given into its result, and
64
+ // the reducer replaces the entry wholesale, so the local line has to
65
+ // go in or edits that leave `isCategoryOrClassUpdated` untouched — an
66
+ // amount or description changed while this fetch was in flight — get
67
+ // reverted.
68
+ //
69
+ // Category and class are the exception and come from the ENTITY line,
70
+ // exactly as at init. By now the local line may hold a category the
71
+ // vendor default autofilled when no recommendation was available yet,
72
+ // and the helper reads whatever it is given as the line's original
73
+ // value and will not replace one. Passing that back would leave an
74
+ // untouched line on the vendor default instead of the per-line
75
+ // recommendation, so the back-fill would not match what init would
76
+ // have produced had the recommendations been there all along.
77
+ const localLineWithEntityCategory = localLine == null || hasAccountAndClass(line) === false
78
+ ? line
79
+ : {
80
+ ...localLine,
81
+ account: line.account,
82
+ class: line.class,
83
+ };
84
+ updatesByLineId[line.id] = getLineRecommendationsLocalData(line.id, localLineWithEntityCategory, recommendations, accountList, classList, localData.vendor);
85
+ });
86
+ if (Object.keys(updatesByLineId).length === 0) {
87
+ return EMPTY;
88
+ }
89
+ return of(updateBillLineRecommendationsInLocalStore(billId, updatesByLineId));
90
+ }));
91
+ // Only some `Line` members carry a category and class. A guard rather than a
92
+ // cast so a shape change is a compile error, not a silent `undefined`.
93
+ function hasAccountAndClass(line) {
94
+ return 'account' in line;
95
+ }