@zeniai/client-epic-state 5.2.73 → 5.2.74-betaAK0

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 (131) hide show
  1. package/lib/entity/aiCfo/aiCfoState.d.ts +2 -2
  2. package/lib/entity/billPay/billTransaction/billTransactionState.d.ts +2 -2
  3. package/lib/entity/chargeCardTransaction/chargeCardTransaction.d.ts +1 -1
  4. package/lib/entity/depositAccountTransaction/depositAccountTransaction.d.ts +1 -1
  5. package/lib/entity/invoicing/coupon/couponSelector.d.ts +1 -0
  6. package/lib/entity/invoicing/coupon/couponSelector.js +5 -0
  7. package/lib/entity/invoicing/{product/productPayload.d.ts → invoicingCatalog/invoicingCatalogPayload.d.ts} +44 -6
  8. package/lib/entity/invoicing/{product/productPayload.js → invoicingCatalog/invoicingCatalogPayload.js} +50 -6
  9. package/lib/entity/invoicing/invoicingCatalog/invoicingCatalogReducer.d.ts +12 -0
  10. package/lib/entity/invoicing/{plan/planReducer.js → invoicingCatalog/invoicingCatalogReducer.js} +20 -21
  11. package/lib/entity/invoicing/{plan/planSelector.d.ts → invoicingCatalog/invoicingCatalogSelector.d.ts} +5 -6
  12. package/lib/entity/invoicing/{plan/planSelector.js → invoicingCatalog/invoicingCatalogSelector.js} +12 -12
  13. package/lib/entity/invoicing/{product/productState.d.ts → invoicingCatalog/invoicingCatalogState.d.ts} +42 -6
  14. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +4 -4
  15. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  16. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  17. package/lib/epic.d.ts +4 -2
  18. package/lib/epic.js +5 -1
  19. package/lib/esm/entity/invoicing/coupon/couponSelector.js +4 -0
  20. package/lib/esm/entity/invoicing/{product/productPayload.js → invoicingCatalog/invoicingCatalogPayload.js} +46 -3
  21. package/lib/esm/entity/invoicing/{plan/planReducer.js → invoicingCatalog/invoicingCatalogReducer.js} +19 -20
  22. package/lib/esm/entity/invoicing/{plan/planSelector.js → invoicingCatalog/invoicingCatalogSelector.js} +8 -8
  23. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  24. package/lib/esm/epic.js +5 -1
  25. package/lib/esm/index.js +7 -10
  26. package/lib/esm/reducer.js +4 -7
  27. package/lib/esm/view/invoicing/createInvoice/createInvoiceEpic.js +9 -1
  28. package/lib/esm/view/invoicing/createInvoice/createInvoiceSelector.js +1 -1
  29. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +5 -3
  30. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/fetchInvoicingCatalogItemDetailEpic.js +2 -2
  31. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogPlanActionEpic.js +2 -2
  32. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogProductActionEpic.js +4 -4
  33. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +3 -7
  34. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +2 -2
  35. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +5 -1
  36. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewPayload.js +55 -0
  37. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +35 -1
  38. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +80 -2
  39. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionEstimateEpic.js +49 -0
  40. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +23 -14
  41. package/lib/esm/view/invoicing/invoiceList/invoiceListReducer.js +8 -1
  42. package/lib/esm/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogPlanListEpic.js +2 -2
  43. package/lib/esm/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogProductListEpic.js +2 -2
  44. package/lib/esm/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +55 -22
  45. package/lib/esm/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewState.js +1 -20
  46. package/lib/esm/view/spendManagement/commonSetup/epic/setup/resetKycKybEpic.js +37 -0
  47. package/lib/esm/view/spendManagement/commonSetup/setupViewReducer.js +21 -1
  48. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +2 -1
  49. package/lib/index.d.ts +12 -16
  50. package/lib/index.js +41 -45
  51. package/lib/reducer.d.ts +1 -2
  52. package/lib/reducer.js +4 -7
  53. package/lib/rootStateTypes.d.ts +3 -5
  54. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  55. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -2
  56. package/lib/view/invoicing/createInvoice/createInvoiceEpic.d.ts +3 -2
  57. package/lib/view/invoicing/createInvoice/createInvoiceEpic.js +8 -0
  58. package/lib/view/invoicing/createInvoice/createInvoiceSelector.d.ts +2 -2
  59. package/lib/view/invoicing/createInvoice/createInvoiceSelector.js +2 -2
  60. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +8 -9
  61. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +2 -2
  62. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +5 -3
  63. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/fetchInvoicingCatalogItemDetailEpic.d.ts +2 -2
  64. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/fetchInvoicingCatalogItemDetailEpic.js +2 -2
  65. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.d.ts +3 -4
  66. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogPlanActionEpic.d.ts +2 -2
  67. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogPlanActionEpic.js +2 -2
  68. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogProductActionEpic.d.ts +2 -3
  69. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/runInvoicingCatalogProductActionEpic.js +4 -4
  70. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.d.ts +2 -3
  71. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +3 -7
  72. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +2 -2
  73. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +3 -1
  74. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +6 -2
  75. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewPayload.d.ts +46 -1
  76. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewPayload.js +57 -1
  77. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +10 -2
  78. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +36 -2
  79. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +23 -3
  80. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +83 -3
  81. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +58 -0
  82. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionEstimateEpic.d.ts +7 -0
  83. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionEstimateEpic.js +53 -0
  84. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.d.ts +11 -1
  85. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +26 -15
  86. package/lib/view/invoicing/invoiceList/invoiceListReducer.d.ts +3 -1
  87. package/lib/view/invoicing/invoiceList/invoiceListReducer.js +9 -2
  88. package/lib/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogListPageEpic.d.ts +2 -2
  89. package/lib/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogPlanListEpic.d.ts +2 -2
  90. package/lib/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogPlanListEpic.js +2 -2
  91. package/lib/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogProductListEpic.d.ts +2 -2
  92. package/lib/view/invoicing/invoicingCatalogListView/epics/fetchInvoicingCatalogProductListEpic.js +2 -2
  93. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewPayload.d.ts +3 -3
  94. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.d.ts +33 -15
  95. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +57 -23
  96. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewState.d.ts +0 -15
  97. package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewState.js +0 -22
  98. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.d.ts +1 -1
  99. package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.d.ts +1 -1
  100. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.d.ts +1 -1
  101. package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewState.d.ts +1 -1
  102. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  103. package/lib/view/spendManagement/billPay/billList/billListReducer.d.ts +5 -5
  104. package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
  105. package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.d.ts +2 -2
  106. package/lib/view/spendManagement/commonSetup/epic/setup/resetKycKybEpic.d.ts +8 -0
  107. package/lib/view/spendManagement/commonSetup/epic/setup/resetKycKybEpic.js +41 -0
  108. package/lib/view/spendManagement/commonSetup/setupViewReducer.d.ts +1 -1
  109. package/lib/view/spendManagement/commonSetup/setupViewReducer.js +22 -2
  110. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +1 -0
  111. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +2 -1
  112. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +1 -0
  113. package/lib/view/spendManagement/reimbursement/editRemiView/editRemiViewReducer.d.ts +2 -2
  114. package/lib/view/spendManagement/reimbursement/remiListView/remiListReducer.d.ts +5 -5
  115. package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +2 -2
  116. package/package.json +1 -26
  117. package/lib/entity/invoicing/plan/planPayload.d.ts +0 -40
  118. package/lib/entity/invoicing/plan/planPayload.js +0 -51
  119. package/lib/entity/invoicing/plan/planReducer.d.ts +0 -14
  120. package/lib/entity/invoicing/plan/planState.d.ts +0 -43
  121. package/lib/entity/invoicing/product/productReducer.d.ts +0 -9
  122. package/lib/entity/invoicing/product/productReducer.js +0 -50
  123. package/lib/entity/invoicing/product/productSelector.d.ts +0 -4
  124. package/lib/entity/invoicing/product/productSelector.js +0 -17
  125. package/lib/entity/invoicing/product/productState.js +0 -2
  126. package/lib/esm/entity/invoicing/plan/planPayload.js +0 -47
  127. package/lib/esm/entity/invoicing/product/productReducer.js +0 -43
  128. package/lib/esm/entity/invoicing/product/productSelector.js +0 -10
  129. package/lib/esm/entity/invoicing/product/productState.js +0 -1
  130. /package/lib/entity/invoicing/{plan/planState.js → invoicingCatalog/invoicingCatalogState.js} +0 -0
  131. /package/lib/esm/entity/invoicing/{plan/planState.js → invoicingCatalog/invoicingCatalogState.js} +0 -0
@@ -1,11 +1,12 @@
1
1
  import { Amount } from '../../../commonStateTypes/amount';
2
2
  import { FetchStateAndError, ID } from '../../../commonStateTypes/common';
3
3
  import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
4
+ import { InvoicingCatalogPricePoint } from '../../../entity/invoicing/invoicingCatalog/invoicingCatalogState';
4
5
  import { InvoicingFieldHelpByCode, InvoicingNamedOption, InvoicingSubscriptionLifecycleActionOption } from '../../../entity/invoicing/invoicingCommonPayload';
5
6
  import { InvoicingSubscription } from '../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionState';
6
- import { InvoicingProduct } from '../../../entity/invoicing/product/productState';
7
7
  import { RootState } from '../../../rootStateTypes';
8
- import { InvoicingSubscriptionFormLocalData } from './editInvoicingSubscriptionDetailViewState';
8
+ import { ZeniDate } from '../../../zeniDayJS';
9
+ import { InvoicingSubscriptionEstimateState, InvoicingSubscriptionFormLocalData, InvoicingSubscriptionInvoiceEstimate } from './editInvoicingSubscriptionDetailViewState';
9
10
  /**
10
11
  * Bundled view for the subscription create/edit form's save concern: the save
11
12
  * fetch state/error, the id of the subscription last saved, and — when an
@@ -29,6 +30,22 @@ export interface EditInvoicingSubscriptionDetailView extends SelectorView {
29
30
  * `{label, value}` records, so this stays free of any web-components
30
31
  * dependency while leaving the screen nothing to derive.
31
32
  */
33
+ export type InvoicingSubscriptionEstimateKind = 'invoice_now' | 'later_invoice' | 'proration_credit' | 'proration_invoice' | 'reason_only';
34
+ export interface InvoicingSubscriptionEstimateView {
35
+ /** A later invoice quotes today's credit balances, which can change by then. */
36
+ creditsMayChange: boolean;
37
+ fetchState: FetchStateAndError;
38
+ nonRenewing: boolean;
39
+ /** The one invoice to show, whichever estimate it came from. */
40
+ invoice?: InvoicingSubscriptionInvoiceEstimate;
41
+ kind?: InvoicingSubscriptionEstimateKind;
42
+ nextBillingAt?: ZeniDate;
43
+ reason?: string;
44
+ storeCredit?: Amount;
45
+ termEnd?: ZeniDate;
46
+ termStart?: ZeniDate;
47
+ }
48
+ export declare const toInvoicingSubscriptionEstimateView: ({ estimate, fetchState, subscriptionId }: InvoicingSubscriptionEstimateState, invoicingSubscriptionID?: ID) => InvoicingSubscriptionEstimateView;
32
49
  export interface InvoicingSubscriptionFormView extends SelectorView {
33
50
  /** Lifecycle action in flight, folded in from the record view. */
34
51
  actionState: FetchStateAndError;
@@ -43,6 +60,8 @@ export interface InvoicingSubscriptionFormView extends SelectorView {
43
60
  charges: InvoicingSubscriptionOption[];
44
61
  coupons: InvoicingSubscriptionOption[];
45
62
  customers: InvoicingSubscriptionOption[];
63
+ /** The review dialog's cost estimate for saving this draft. */
64
+ estimate: InvoicingSubscriptionEstimateView;
46
65
  fieldHelp: InvoicingFieldHelpByCode;
47
66
  /**
48
67
  * True while the subscription being edited is still on its way to the form.
@@ -107,7 +126,8 @@ export declare const getEditInvoicingSubscriptionDetailViewState: (state: RootSt
107
126
  * Lives here rather than in a screen so the create/edit form and the detail
108
127
  * page's inline edit narrow their pickers by the same rule.
109
128
  */
110
- export declare const getInvoicingItemsAllowedForPlan: (products: InvoicingProduct[], plan: InvoicingProduct | undefined) => InvoicingProduct[];
129
+ export declare const getInvoicingItemsAllowedForPlan: (products: InvoicingCatalogPricePoint[], plan: InvoicingCatalogPricePoint | undefined) => InvoicingCatalogPricePoint[];
130
+ export declare const isInvoicingAddonPeriodCompatible: (addon: InvoicingCatalogPricePoint, plan: InvoicingCatalogPricePoint | undefined) => boolean;
111
131
  /**
112
132
  * One entry in a subscription-form picker, ready for the screen to render.
113
133
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInvoicingSubscriptionFormView = exports.getInvoicingItemsAllowedForPlan = exports.getEditInvoicingSubscriptionDetailViewState = void 0;
3
+ exports.getInvoicingSubscriptionFormView = exports.isInvoicingAddonPeriodCompatible = exports.getInvoicingItemsAllowedForPlan = exports.getEditInvoicingSubscriptionDetailViewState = exports.toInvoicingSubscriptionEstimateView = void 0;
4
4
  const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
5
5
  const addressSelector_1 = require("../../../entity/address/addressSelector");
6
6
  const invoicingSubscriptionSelector_1 = require("../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionSelector");
@@ -12,6 +12,58 @@ const invoicingCustomerListViewSelector_1 = require("../invoicingCustomerListVie
12
12
  const invoicingFormDraft_1 = require("../invoicingFormDraft");
13
13
  const invoicingSubscriptionFormConfig_1 = require("./invoicingSubscriptionFormConfig");
14
14
  const invoicingSubscriptionFormConfig_2 = require("./invoicingSubscriptionFormConfig");
15
+ const notStartedEstimateView = {
16
+ creditsMayChange: false,
17
+ fetchState: { fetchState: 'Not-Started', error: undefined },
18
+ nonRenewing: false,
19
+ };
20
+ const toInvoicingSubscriptionEstimateView = ({ estimate, fetchState, subscriptionId }, invoicingSubscriptionID) => {
21
+ // A slot asked for another subscription is not this form's estimate.
22
+ if (subscriptionId !== invoicingSubscriptionID) {
23
+ return notStartedEstimateView;
24
+ }
25
+ if (estimate == null) {
26
+ return { ...notStartedEstimateView, fetchState };
27
+ }
28
+ const { invoice, nextInvoice, proration, reason, term } = estimate;
29
+ const base = {
30
+ fetchState,
31
+ nonRenewing: term?.becomesNonRenewing === true,
32
+ nextBillingAt: term?.nextBillingAt,
33
+ reason: reason !== '' ? reason : undefined,
34
+ termEnd: term?.currentTermEnd,
35
+ termStart: term?.currentTermStart,
36
+ };
37
+ if (proration?.documentType === 'invoice' && proration.invoice != null) {
38
+ return {
39
+ ...base,
40
+ creditsMayChange: false,
41
+ invoice: proration.invoice,
42
+ kind: 'proration_invoice',
43
+ };
44
+ }
45
+ if (proration?.documentType === 'credit_note') {
46
+ return {
47
+ ...base,
48
+ creditsMayChange: false,
49
+ kind: 'proration_credit',
50
+ storeCredit: { ...proration.net, amount: Math.abs(proration.net.amount) },
51
+ };
52
+ }
53
+ if (estimate.willBeInvoiced && invoice != null) {
54
+ return { ...base, creditsMayChange: false, invoice, kind: 'invoice_now' };
55
+ }
56
+ if (nextInvoice != null) {
57
+ return {
58
+ ...base,
59
+ creditsMayChange: true,
60
+ invoice: nextInvoice,
61
+ kind: 'later_invoice',
62
+ };
63
+ }
64
+ return { ...base, creditsMayChange: false, kind: 'reason_only' };
65
+ };
66
+ exports.toInvoicingSubscriptionEstimateView = toInvoicingSubscriptionEstimateView;
15
67
  const getEditInvoicingSubscriptionDetailViewState = (state, invoicingSubscriptionID) => {
16
68
  const { error, fetchState, savedSubscriptionId } = state.editInvoicingSubscriptionDetailViewState;
17
69
  const { subscriptionCommercialEditAllowedFromStatuses, subscriptionLifecycleActionOptions, subscriptionMetadataEditAllowedFromStatuses, } = (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state);
@@ -91,6 +143,28 @@ const getInvoicingItemsAllowedForPlan = (products, plan) => {
91
143
  return products.filter((product) => product.itemID != null && allowedItemIDs.includes(product.itemID));
92
144
  };
93
145
  exports.getInvoicingItemsAllowedForPlan = getInvoicingItemsAllowedForPlan;
146
+ // Years count as months so they compare; any other unit only meets itself.
147
+ const billingPeriodInCommonUnit = (pricePoint) => {
148
+ const { period, periodUnit } = pricePoint;
149
+ if (period == null || periodUnit == null || periodUnit === '') {
150
+ return undefined;
151
+ }
152
+ return periodUnit === 'year'
153
+ ? { count: period * 12, unit: 'month' }
154
+ : { count: period, unit: periodUnit };
155
+ };
156
+ // The add-on's period must divide the plan's (create 422s otherwise); fails open when they cannot be compared.
157
+ const isInvoicingAddonPeriodCompatible = (addon, plan) => {
158
+ const addonPeriod = billingPeriodInCommonUnit(addon);
159
+ const planPeriod = plan != null ? billingPeriodInCommonUnit(plan) : undefined;
160
+ if (addonPeriod == null ||
161
+ planPeriod == null ||
162
+ addonPeriod.unit !== planPeriod.unit) {
163
+ return true;
164
+ }
165
+ return addonPeriod.count > 0 && planPeriod.count % addonPeriod.count === 0;
166
+ };
167
+ exports.isInvoicingAddonPeriodCompatible = isInvoicingAddonPeriodCompatible;
94
168
  /**
95
169
  * A price row can only be subscribed by its price code, so one without a code
96
170
  * is not an option the form can offer.
@@ -154,7 +228,7 @@ const toInvoicingCustomerOption = (customer) => ({
154
228
  value: customer.id,
155
229
  });
156
230
  const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
157
- const { editDraftById, error, fetchState, newSubscriptionDraft, savedSubscriptionId, } = state.editInvoicingSubscriptionDetailViewState;
231
+ const { editDraftById, error, estimateState, fetchState, newSubscriptionDraft, savedSubscriptionId, } = state.editInvoicingSubscriptionDetailViewState;
158
232
  const mode = invoicingSubscriptionID != null ? 'edit' : 'create';
159
233
  const subscription = invoicingSubscriptionID != null
160
234
  ? (0, invoicingSubscriptionSelector_1.getInvoicingSubscriptionById)(state.invoicingSubscriptionState, invoicingSubscriptionID)
@@ -179,7 +253,12 @@ const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
179
253
  // pickers offer only those: subscription create rejects the rest with a 422,
180
254
  // and an option that can only fail is not a choice. The applicability rides
181
255
  // on the price rows already in the store, so this is a join, not a refetch.
182
- const allowedCatalogPrices = (0, exports.getInvoicingItemsAllowedForPlan)((0, invoicingCatalogListViewSelector_1.getInvoicingCatalogPrices)(catalogListView.products), planPrices.find((plan) => plan.priceCode === localData.planPriceCode)).filter(hasInvoicingPriceCode);
256
+ const selectedPlanPrice = planPrices.find((plan) => plan.priceCode === localData.planPriceCode);
257
+ // Add-ons also have to bill on the plan's cadence; charges are one-time.
258
+ const allowedCatalogPrices = (0, exports.getInvoicingItemsAllowedForPlan)((0, invoicingCatalogListViewSelector_1.getInvoicingCatalogPrices)(catalogListView.products), selectedPlanPrice)
259
+ .filter(hasInvoicingPriceCode)
260
+ .filter((product) => product.itemType !== 'addon' ||
261
+ (0, exports.isInvoicingAddonPeriodCompatible)(product, selectedPlanPrice));
183
262
  const catalogItemOptionsOfType = (itemType) => allowedCatalogPrices
184
263
  .filter((product) => product.itemType === itemType)
185
264
  .map(toInvoicingCatalogItemOption);
@@ -203,6 +282,7 @@ const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
203
282
  subscriptionMetadataEditAllowedFromStatuses: configState.subscriptionMetadataEditAllowedFromStatuses,
204
283
  recordState,
205
284
  isFormLoading: (0, invoicingFormDraft_1.isInvoicingFormDraftPending)(editDraftById, invoicingSubscriptionID),
285
+ estimate: (0, exports.toInvoicingSubscriptionEstimateView)(estimateState, invoicingSubscriptionID),
206
286
  fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'subscription'),
207
287
  addons: catalogItemOptionsOfType('addon'),
208
288
  charges: catalogItemOptionsOfType('charge'),
@@ -1,5 +1,6 @@
1
1
  import { Amount } from '../../../commonStateTypes/amount';
2
2
  import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
3
+ import { ZeniDate } from '../../../zeniDayJS';
3
4
  import { InvoicingFormDraftById } from '../invoicingFormDraft';
4
5
  /**
5
6
  * Draft form state for the create/edit subscription form. Held in CES so the
@@ -39,10 +40,67 @@ export interface InvoicingSubscriptionFormLocalData {
39
40
  /** Unset until the user enters one, so an explicit 0 stays distinguishable. */
40
41
  setupFee?: Amount;
41
42
  }
43
+ export interface InvoicingSubscriptionEstimateLineItem {
44
+ amount: Amount;
45
+ description: string;
46
+ discountAmount: Amount;
47
+ quantity: number;
48
+ unitAmount: Amount;
49
+ dateFrom?: ZeniDate;
50
+ dateTo?: ZeniDate;
51
+ taxAmount?: Amount;
52
+ }
53
+ /** An invoice the save would raise now, or the next one it would raise later. */
54
+ export interface InvoicingSubscriptionInvoiceEstimate {
55
+ amountDue: Amount;
56
+ couponDiscountTotal: Amount;
57
+ /** Refundable credits plus excess payments; promotional credits are separate. */
58
+ creditsApplied: Amount;
59
+ grossSubTotal: Amount;
60
+ lineItems: InvoicingSubscriptionEstimateLineItem[];
61
+ promotionalCreditsApplied: Amount;
62
+ /** After coupons and promotional credits. */
63
+ subTotal: Amount;
64
+ total: Amount;
65
+ dueDate?: ZeniDate;
66
+ invoiceDate?: ZeniDate;
67
+ /** Absent when the tax quote failed on a later invoice; Save still succeeds. */
68
+ tax?: Amount;
69
+ }
70
+ export interface InvoicingSubscriptionProrationEstimate {
71
+ /** `invoice`, `credit_note`, or `none` when the change nets to zero. */
72
+ documentType: string;
73
+ net: Amount;
74
+ invoice?: InvoicingSubscriptionInvoiceEstimate;
75
+ }
76
+ export interface InvoicingSubscriptionTermEstimate {
77
+ becomesNonRenewing: boolean;
78
+ currentTermEnd?: ZeniDate;
79
+ currentTermStart?: ZeniDate;
80
+ nextBillingAt?: ZeniDate;
81
+ }
82
+ /** What a save would bill, from `POST /subscriptions[/{id}]/estimate`. */
83
+ export interface InvoicingSubscriptionEstimate {
84
+ /** The service's sentence for why nothing is invoiced now; empty otherwise. */
85
+ reason: string;
86
+ willBeInvoiced: boolean;
87
+ invoice?: InvoicingSubscriptionInvoiceEstimate;
88
+ nextInvoice?: InvoicingSubscriptionInvoiceEstimate;
89
+ proration?: InvoicingSubscriptionProrationEstimate;
90
+ term?: InvoicingSubscriptionTermEstimate;
91
+ }
92
+ export interface InvoicingSubscriptionEstimateState {
93
+ fetchState: FetchStateAndError;
94
+ estimate?: InvoicingSubscriptionEstimate;
95
+ /** The subscription the estimate was asked for; absent for a new one. */
96
+ subscriptionId?: ID;
97
+ }
42
98
  export interface EditInvoicingSubscriptionDetailViewState extends FetchedState {
43
99
  /** Lifecycle action fetch state per subscription id. */
44
100
  actionStateById: Record<ID, FetchStateAndError>;
45
101
  editDraftById: InvoicingFormDraftById<InvoicingSubscriptionFormLocalData>;
102
+ /** The cost estimate shown before a save; nothing is saved by asking. */
103
+ estimateState: InvoicingSubscriptionEstimateState;
46
104
  newSubscriptionDraft: InvoicingSubscriptionFormLocalData;
47
105
  /** Detail-load state per subscription id. */
48
106
  recordStateById: Record<ID, FetchStateAndError>;
@@ -0,0 +1,7 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { RootState } from '../../../rootStateTypes';
4
+ import { ZeniAPI } from '../../../zeniAPI';
5
+ import { fetchInvoicingSubscriptionEstimate, updateInvoicingSubscriptionEstimate, updateInvoicingSubscriptionEstimateFailure } from './editInvoicingSubscriptionDetailViewReducer';
6
+ export type ActionType = ReturnType<typeof fetchInvoicingSubscriptionEstimate> | ReturnType<typeof updateInvoicingSubscriptionEstimate> | ReturnType<typeof updateInvoicingSubscriptionEstimateFailure>;
7
+ export declare const fetchInvoicingSubscriptionEstimateEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchInvoicingSubscriptionEstimateEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const couponSelector_1 = require("../../../entity/invoicing/coupon/couponSelector");
7
+ const responsePayload_1 = require("../../../responsePayload");
8
+ const editInvoicingSubscriptionDetailViewPayload_1 = require("./editInvoicingSubscriptionDetailViewPayload");
9
+ const editInvoicingSubscriptionDetailViewReducer_1 = require("./editInvoicingSubscriptionDetailViewReducer");
10
+ const saveInvoicingSubscriptionEpic_1 = require("./saveInvoicingSubscriptionEpic");
11
+ // Posts Save's exact body; a changed coupon rides along as `coupons` (Save syncs it after the PUT).
12
+ const fetchInvoicingSubscriptionEstimateEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(editInvoicingSubscriptionDetailViewReducer_1.fetchInvoicingSubscriptionEstimate.match), (0, operators_1.switchMap)((action) => {
13
+ const { id } = action.payload;
14
+ const { data, localData, previousCouponCode } = (0, saveInvoicingSubscriptionEpic_1.invoicingSubscriptionSaveRequest)(state$.value, id);
15
+ const couponCode = localData.couponId;
16
+ const coupon = (0, couponSelector_1.getInvoicingCouponByCode)(state$.value.invoicingCouponState, couponCode);
17
+ const body = id != null &&
18
+ (0, saveInvoicingSubscriptionEpic_1.isInvoicingSubscriptionCouponChanged)(previousCouponCode, couponCode)
19
+ ? {
20
+ ...data,
21
+ coupons: couponCode !== ''
22
+ ? [
23
+ {
24
+ applied_count: 0,
25
+ apply_till: null,
26
+ coupon_code: couponCode,
27
+ coupon_id: coupon?.id ?? couponCode,
28
+ },
29
+ ]
30
+ : [],
31
+ }
32
+ : data;
33
+ const baseUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/subscriptions`;
34
+ const url = id != null
35
+ ? `${baseUrl}/${encodeURIComponent(id)}/estimate`
36
+ : `${baseUrl}/estimate`;
37
+ return zeniAPI
38
+ .postAndGetJSON(url, body)
39
+ .pipe((0, operators_1.map)((response) => (0, responsePayload_1.isSuccessResponse)(response) && response.data != null
40
+ ? (0, editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionEstimate)({
41
+ estimate: (0, editInvoicingSubscriptionDetailViewPayload_1.mapInvoicingSubscriptionEstimatePayloadToState)(response.data),
42
+ id,
43
+ })
44
+ : (0, editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionEstimateFailure)({
45
+ id,
46
+ status: response.status,
47
+ })), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionEstimateFailure)({
48
+ id,
49
+ status: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Subscription estimate REST API call errored out ' +
50
+ JSON.stringify(error)),
51
+ }))));
52
+ }));
53
+ exports.fetchInvoicingSubscriptionEstimateEpic = fetchInvoicingSubscriptionEstimateEpic;
@@ -1,12 +1,22 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
+ import { ID } from '../../../commonStateTypes/common';
3
4
  import { updateAddresses } from '../../../entity/address/addressReducer';
4
5
  import { updateInvoicingSubscriptions } from '../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionReducer';
5
6
  import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
6
7
  import { RootState } from '../../../rootStateTypes';
7
8
  import { ZeniAPI } from '../../../zeniAPI';
8
9
  import { resetNewAddressDataInLocalStore } from '../../addressView/addressViewReducer';
10
+ import { invalidateInvoicingCustomerDetail } from '../editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer';
11
+ import { invalidateInvoiceListForCustomer } from '../invoiceList/invoiceListReducer';
9
12
  import { addInvoicingSubscriptionToList } from '../invoicingSubscriptionListView/invoicingSubscriptionListViewReducer';
10
13
  import { submitInvoicingSubscriptionForm, submitInvoicingSubscriptionFormFailure, submitInvoicingSubscriptionFormSuccess, syncInvoicingSubscriptionCoupons } from './editInvoicingSubscriptionDetailViewReducer';
11
- export type ActionType = ReturnType<typeof submitInvoicingSubscriptionForm> | ReturnType<typeof submitInvoicingSubscriptionFormSuccess> | ReturnType<typeof submitInvoicingSubscriptionFormFailure> | ReturnType<typeof syncInvoicingSubscriptionCoupons> | ReturnType<typeof resetNewAddressDataInLocalStore> | ReturnType<typeof updateAddresses> | ReturnType<typeof updateInvoicingSubscriptions> | ReturnType<typeof addInvoicingSubscriptionToList> | ReturnType<typeof openSnackbar>;
14
+ import { InvoicingSubscriptionFormLocalData } from './editInvoicingSubscriptionDetailViewState';
15
+ export type ActionType = ReturnType<typeof submitInvoicingSubscriptionForm> | ReturnType<typeof submitInvoicingSubscriptionFormSuccess> | ReturnType<typeof submitInvoicingSubscriptionFormFailure> | ReturnType<typeof syncInvoicingSubscriptionCoupons> | ReturnType<typeof resetNewAddressDataInLocalStore> | ReturnType<typeof updateAddresses> | ReturnType<typeof updateInvoicingSubscriptions> | ReturnType<typeof addInvoicingSubscriptionToList> | ReturnType<typeof invalidateInvoicingCustomerDetail> | ReturnType<typeof invalidateInvoiceListForCustomer> | ReturnType<typeof openSnackbar>;
16
+ export declare const isInvoicingSubscriptionCouponChanged: (previousCouponCode: string, nextCouponCode: string) => boolean;
17
+ export declare const invoicingSubscriptionSaveRequest: (rootState: RootState, id?: ID) => {
18
+ data: Record<string, unknown>;
19
+ localData: InvoicingSubscriptionFormLocalData;
20
+ previousCouponCode: string;
21
+ };
12
22
  export declare const saveInvoicingSubscriptionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.saveInvoicingSubscriptionEpic = void 0;
3
+ exports.saveInvoicingSubscriptionEpic = exports.invoicingSubscriptionSaveRequest = exports.isInvoicingSubscriptionCouponChanged = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
6
  const addressReducer_1 = require("../../../entity/address/addressReducer");
@@ -10,14 +10,18 @@ const snackbarApiError_1 = require("../../../entity/snackbar/snackbarApiError");
10
10
  const snackbarReducer_1 = require("../../../entity/snackbar/snackbarReducer");
11
11
  const responsePayload_1 = require("../../../responsePayload");
12
12
  const addressViewReducer_1 = require("../../addressView/addressViewReducer");
13
+ const editInvoicingCustomerDetailViewReducer_1 = require("../editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer");
14
+ const invoiceListReducer_1 = require("../invoiceList/invoiceListReducer");
13
15
  const invoicingSubscriptionListViewReducer_1 = require("../invoicingSubscriptionListView/invoicingSubscriptionListViewReducer");
14
16
  const editInvoicingSubscriptionDetailViewPayload_1 = require("./editInvoicingSubscriptionDetailViewPayload");
15
17
  const editInvoicingSubscriptionDetailViewReducer_1 = require("./editInvoicingSubscriptionDetailViewReducer");
16
18
  const invoicingSubscriptionFormConfig_1 = require("./invoicingSubscriptionFormConfig");
17
19
  const normalizeCouponCode = (value) => (value ?? '').trim().toUpperCase();
18
- const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(editInvoicingSubscriptionDetailViewReducer_1.submitInvoicingSubscriptionForm.match), (0, operators_1.mergeMap)((action) => {
19
- const { id } = action.payload;
20
- const rootState = state$.value;
20
+ const isInvoicingSubscriptionCouponChanged = (previousCouponCode, nextCouponCode) => normalizeCouponCode(previousCouponCode) !==
21
+ normalizeCouponCode(nextCouponCode);
22
+ exports.isInvoicingSubscriptionCouponChanged = isInvoicingSubscriptionCouponChanged;
23
+ // The draft a save reads and the body it sends; the estimate previews the same body.
24
+ const invoicingSubscriptionSaveRequest = (rootState, id) => {
21
25
  const viewState = rootState.editInvoicingSubscriptionDetailViewState;
22
26
  const localData = (id != null
23
27
  ? viewState.editDraftById[id]?.localData
@@ -26,18 +30,24 @@ const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pi
26
30
  // object in the payload (same pattern as the customer save flow).
27
31
  const shippingAddress = rootState.addressViewState.newAddressState?.[invoicingSubscriptionFormConfig_1.INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE]?.addressToCreate;
28
32
  const data = (0, editInvoicingSubscriptionDetailViewPayload_1.localDataToSaveInvoicingSubscriptionPayload)(localData, shippingAddress);
29
- // Coupons are synced via apply/remove-coupon after PUT (not via coupon_ids).
30
33
  if (id != null) {
31
34
  delete data.coupon_ids;
32
35
  }
36
+ const savedCoupon = id != null
37
+ ? rootState.invoicingSubscriptionState.invoicingSubscriptionByID[id]
38
+ ?.coupons?.[0]
39
+ : undefined;
40
+ return {
41
+ data,
42
+ localData,
43
+ previousCouponCode: savedCoupon?.couponCode ?? savedCoupon?.couponID ?? '',
44
+ };
45
+ };
46
+ exports.invoicingSubscriptionSaveRequest = invoicingSubscriptionSaveRequest;
47
+ const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(editInvoicingSubscriptionDetailViewReducer_1.submitInvoicingSubscriptionForm.match), (0, operators_1.mergeMap)((action) => {
48
+ const { id } = action.payload;
49
+ const { data, localData, previousCouponCode } = (0, exports.invoicingSubscriptionSaveRequest)(state$.value, id);
33
50
  const baseUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0`;
34
- const previousCouponCode = id != null
35
- ? (rootState.invoicingSubscriptionState.invoicingSubscriptionByID[id]
36
- ?.coupons?.[0]?.couponCode ??
37
- rootState.invoicingSubscriptionState.invoicingSubscriptionByID[id]
38
- ?.coupons?.[0]?.couponID ??
39
- '')
40
- : '';
41
51
  const request$ = id != null
42
52
  ? zeniAPI.putAndGetJSON(`${baseUrl}/subscriptions/${encodeURIComponent(id)}`, { ...data })
43
53
  : zeniAPI.postAndGetJSON(`${baseUrl}/subscriptions`, { ...data });
@@ -55,8 +65,7 @@ const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pi
55
65
  }
56
66
  const saved = response.data;
57
67
  const couponChanged = id != null &&
58
- normalizeCouponCode(previousCouponCode) !==
59
- normalizeCouponCode(localData.couponId);
68
+ (0, exports.isInvoicingSubscriptionCouponChanged)(previousCouponCode, localData.couponId);
60
69
  // Edit + coupon change: merge the saved subscription, then hand the
61
70
  // coupon attach/detach to syncInvoicingSubscriptionCouponsEpic, which
62
71
  // finishes the flow (form success on both calls ok, form failure
@@ -89,7 +98,9 @@ const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pi
89
98
  resultActions.push((0, invoicingSubscriptionListViewReducer_1.addInvoicingSubscriptionToList)({
90
99
  id: saved.id,
91
100
  status: saved.status,
92
- }));
101
+ }),
102
+ // The service may bill the first invoice on create.
103
+ (0, editInvoicingCustomerDetailViewReducer_1.invalidateInvoicingCustomerDetail)({ id: saved.customer_id }), (0, invoiceListReducer_1.invalidateInvoiceListForCustomer)({ customerId: saved.customer_id }));
93
104
  }
94
105
  resultActions.push((0, snackbarReducer_1.openSnackbar)({
95
106
  messageSection: 'invoicing_subscription_saved',
@@ -45,6 +45,8 @@ export declare const fetchInvoiceList: import("@reduxjs/toolkit").ActionCreatorW
45
45
  }, "invoicingInvoiceList/updateInvoiceList">, updateInvoiceListFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingInvoiceList/updateInvoiceListFailure">, fetchInvoiceCounts: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"invoicingInvoiceList/fetchInvoiceCounts">, updateInvoiceCounts: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingListCounts, "invoicingInvoiceList/updateInvoiceCounts">, updateInvoiceCountsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingInvoiceList/updateInvoiceCountsFailure">, fetchInvoiceKPIs: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"invoicingInvoiceList/fetchInvoiceKPIs">, updateInvoiceKPIs: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoicingInvoiceKPIs, "invoicingInvoiceList/updateInvoiceKPIs">, updateInvoiceKPIsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "invoicingInvoiceList/updateInvoiceKPIsFailure">, updateInvoiceListFilters: import("@reduxjs/toolkit").ActionCreatorWithPayload<InvoiceListFilters, "invoicingInvoiceList/updateInvoiceListFilters">, setInvoiceActiveTab: import("@reduxjs/toolkit").ActionCreatorWithPayload<"paid" | "voided" | "partially_paid" | "payment_due" | "not_paid" | "all", "invoicingInvoiceList/setInvoiceActiveTab">, addInvoiceToList: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
46
46
  id: ID;
47
47
  status: InvoicingInvoiceStatus;
48
- }, "invoicingInvoiceList/addInvoiceToList">;
48
+ }, "invoicingInvoiceList/addInvoiceToList">, invalidateInvoiceListForCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
49
+ customerId: ID;
50
+ }, "invoicingInvoiceList/invalidateInvoiceListForCustomer">;
49
51
  declare const _default: import("redux").Reducer<InvoiceListState>;
50
52
  export default _default;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.addInvoiceToList = exports.setInvoiceActiveTab = exports.updateInvoiceListFilters = exports.updateInvoiceKPIsFailure = exports.updateInvoiceKPIs = exports.fetchInvoiceKPIs = exports.updateInvoiceCountsFailure = exports.updateInvoiceCounts = exports.fetchInvoiceCounts = exports.updateInvoiceListFailure = exports.updateInvoiceList = exports.fetchInvoiceListPage = exports.fetchInvoiceList = exports.initialState = exports.sameInvoiceListQuery = void 0;
4
+ exports.invalidateInvoiceListForCustomer = exports.addInvoiceToList = exports.setInvoiceActiveTab = exports.updateInvoiceListFilters = exports.updateInvoiceKPIsFailure = exports.updateInvoiceKPIs = exports.fetchInvoiceKPIs = exports.updateInvoiceCountsFailure = exports.updateInvoiceCounts = exports.fetchInvoiceCounts = exports.updateInvoiceListFailure = exports.updateInvoiceList = exports.fetchInvoiceListPage = exports.fetchInvoiceList = exports.initialState = exports.sameInvoiceListQuery = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const rootActions_1 = require("../../../rootActions");
7
7
  const invoiceListState_1 = require("./invoiceListState");
@@ -129,6 +129,13 @@ const invoiceList = (0, toolkit_1.createSlice)({
129
129
  draft.kpisFetchState.fetchState = 'Error';
130
130
  draft.kpisFetchState.error = action.payload;
131
131
  },
132
+ // Counts are fetched under the same customer filter, so they go stale with the tabs.
133
+ invalidateInvoiceListForCustomer(draft, action) {
134
+ if (draft.filters.customerId === action.payload.customerId) {
135
+ draft.invoiceByTab = (0, invoiceListState_1.makeInvoiceByTab)();
136
+ draft.countsFetchState = { fetchState: 'Not-Started', error: undefined };
137
+ }
138
+ },
132
139
  updateInvoiceListFilters(draft, action) {
133
140
  draft.filters = action.payload;
134
141
  },
@@ -171,5 +178,5 @@ const invoiceList = (0, toolkit_1.createSlice)({
171
178
  });
172
179
  },
173
180
  });
174
- _a = invoiceList.actions, exports.fetchInvoiceList = _a.fetchInvoiceList, exports.fetchInvoiceListPage = _a.fetchInvoiceListPage, exports.updateInvoiceList = _a.updateInvoiceList, exports.updateInvoiceListFailure = _a.updateInvoiceListFailure, exports.fetchInvoiceCounts = _a.fetchInvoiceCounts, exports.updateInvoiceCounts = _a.updateInvoiceCounts, exports.updateInvoiceCountsFailure = _a.updateInvoiceCountsFailure, exports.fetchInvoiceKPIs = _a.fetchInvoiceKPIs, exports.updateInvoiceKPIs = _a.updateInvoiceKPIs, exports.updateInvoiceKPIsFailure = _a.updateInvoiceKPIsFailure, exports.updateInvoiceListFilters = _a.updateInvoiceListFilters, exports.setInvoiceActiveTab = _a.setInvoiceActiveTab, exports.addInvoiceToList = _a.addInvoiceToList;
181
+ _a = invoiceList.actions, exports.fetchInvoiceList = _a.fetchInvoiceList, exports.fetchInvoiceListPage = _a.fetchInvoiceListPage, exports.updateInvoiceList = _a.updateInvoiceList, exports.updateInvoiceListFailure = _a.updateInvoiceListFailure, exports.fetchInvoiceCounts = _a.fetchInvoiceCounts, exports.updateInvoiceCounts = _a.updateInvoiceCounts, exports.updateInvoiceCountsFailure = _a.updateInvoiceCountsFailure, exports.fetchInvoiceKPIs = _a.fetchInvoiceKPIs, exports.updateInvoiceKPIs = _a.updateInvoiceKPIs, exports.updateInvoiceKPIsFailure = _a.updateInvoiceKPIsFailure, exports.updateInvoiceListFilters = _a.updateInvoiceListFilters, exports.setInvoiceActiveTab = _a.setInvoiceActiveTab, exports.addInvoiceToList = _a.addInvoiceToList, exports.invalidateInvoiceListForCustomer = _a.invalidateInvoiceListForCustomer;
175
182
  exports.default = invoiceList.reducer;
@@ -1,13 +1,13 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
- import { updateInvoicingPlans } from '../../../../entity/invoicing/plan/planReducer';
3
+ import { updateInvoicingCatalogItems } from '../../../../entity/invoicing/invoicingCatalog/invoicingCatalogReducer';
4
4
  import { RootState } from '../../../../rootStateTypes';
5
5
  import { fetchInvoicingCatalogCounts, fetchInvoicingCatalogListPage, fetchInvoicingCatalogPlanList, fetchInvoicingCatalogProductList, updateInvoicingCatalogCounts, updateInvoicingCatalogCountsFailure, updateInvoicingCatalogPlanList, updateInvoicingCatalogPlanListFailure, updateInvoicingCatalogProductList, updateInvoicingCatalogProductListFailure } from '../invoicingCatalogListViewReducer';
6
6
  /**
7
7
  * Aggregate of every action emitted across the catalog list view epics. Wired
8
8
  * into the root action union for this view.
9
9
  */
10
- export type ActionType = ReturnType<typeof fetchInvoicingCatalogPlanList> | ReturnType<typeof fetchInvoicingCatalogProductList> | ReturnType<typeof fetchInvoicingCatalogListPage> | ReturnType<typeof fetchInvoicingCatalogCounts> | ReturnType<typeof updateInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanListFailure> | ReturnType<typeof updateInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductListFailure> | ReturnType<typeof updateInvoicingCatalogCounts> | ReturnType<typeof updateInvoicingCatalogCountsFailure> | ReturnType<typeof updateInvoicingPlans>;
10
+ export type ActionType = ReturnType<typeof fetchInvoicingCatalogPlanList> | ReturnType<typeof fetchInvoicingCatalogProductList> | ReturnType<typeof fetchInvoicingCatalogListPage> | ReturnType<typeof fetchInvoicingCatalogCounts> | ReturnType<typeof updateInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanListFailure> | ReturnType<typeof updateInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductListFailure> | ReturnType<typeof updateInvoicingCatalogCounts> | ReturnType<typeof updateInvoicingCatalogCountsFailure> | ReturnType<typeof updateInvoicingCatalogItems>;
11
11
  /**
12
12
  * Orchestrates the catalog page: on `fetchInvoicingCatalogListPage`, fans out to
13
13
  * the plan-list, product-list and counts fetches, skipping any whose data is
@@ -1,8 +1,8 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
- import { updateInvoicingPlans } from '../../../../entity/invoicing/plan/planReducer';
3
+ import { updateInvoicingCatalogItems } from '../../../../entity/invoicing/invoicingCatalog/invoicingCatalogReducer';
4
4
  import { RootState } from '../../../../rootStateTypes';
5
5
  import { ZeniAPI } from '../../../../zeniAPI';
6
6
  import { fetchInvoicingCatalogPlanList, updateInvoicingCatalogPlanList, updateInvoicingCatalogPlanListFailure } from '../invoicingCatalogListViewReducer';
7
- export type ActionType = ReturnType<typeof fetchInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanListFailure> | ReturnType<typeof updateInvoicingPlans>;
7
+ export type ActionType = ReturnType<typeof fetchInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanList> | ReturnType<typeof updateInvoicingCatalogPlanListFailure> | ReturnType<typeof updateInvoicingCatalogItems>;
8
8
  export declare const fetchInvoicingCatalogPlanListEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchInvoicingCatalogPlanListEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
- const planReducer_1 = require("../../../../entity/invoicing/plan/planReducer");
6
+ const invoicingCatalogReducer_1 = require("../../../../entity/invoicing/invoicingCatalog/invoicingCatalogReducer");
7
7
  const responsePayload_1 = require("../../../../responsePayload");
8
8
  const invoicingApiHelper_1 = require("../../invoicingApiHelper");
9
9
  const invoicingCatalogListViewReducer_1 = require("../invoicingCatalogListViewReducer");
@@ -32,7 +32,7 @@ const fetchInvoicingCatalogPlanListEpic = (actions$, _state$, zeniAPI) => action
32
32
  if ((0, responsePayload_1.isSuccessResponse)(response)) {
33
33
  const items = response.data?.items ?? [];
34
34
  return [
35
- (0, planReducer_1.updateInvoicingPlans)(items, 'merge'),
35
+ (0, invoicingCatalogReducer_1.updateInvoicingCatalogItems)(items, 'merge'),
36
36
  (0, invoicingCatalogListViewReducer_1.updateInvoicingCatalogPlanList)({
37
37
  ids: items.map((item) => item.id),
38
38
  nextCursor: response.data?.next_cursor ?? null,
@@ -1,8 +1,8 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
- import { updateInvoicingPlans } from '../../../../entity/invoicing/plan/planReducer';
3
+ import { updateInvoicingCatalogItems } from '../../../../entity/invoicing/invoicingCatalog/invoicingCatalogReducer';
4
4
  import { RootState } from '../../../../rootStateTypes';
5
5
  import { ZeniAPI } from '../../../../zeniAPI';
6
6
  import { fetchInvoicingCatalogProductList, updateInvoicingCatalogProductList, updateInvoicingCatalogProductListFailure } from '../invoicingCatalogListViewReducer';
7
- export type ActionType = ReturnType<typeof fetchInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductListFailure> | ReturnType<typeof updateInvoicingPlans>;
7
+ export type ActionType = ReturnType<typeof fetchInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductList> | ReturnType<typeof updateInvoicingCatalogProductListFailure> | ReturnType<typeof updateInvoicingCatalogItems>;
8
8
  export declare const fetchInvoicingCatalogProductListEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchInvoicingCatalogProductListEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
- const planReducer_1 = require("../../../../entity/invoicing/plan/planReducer");
6
+ const invoicingCatalogReducer_1 = require("../../../../entity/invoicing/invoicingCatalog/invoicingCatalogReducer");
7
7
  const responsePayload_1 = require("../../../../responsePayload");
8
8
  const invoicingApiHelper_1 = require("../../invoicingApiHelper");
9
9
  const invoicingCatalogListViewReducer_1 = require("../invoicingCatalogListViewReducer");
@@ -32,7 +32,7 @@ const fetchInvoicingCatalogProductListEpic = (actions$, _state$, zeniAPI) => act
32
32
  if ((0, responsePayload_1.isSuccessResponse)(response)) {
33
33
  const items = response.data?.items ?? [];
34
34
  return [
35
- (0, planReducer_1.updateInvoicingPlans)(items, 'merge'),
35
+ (0, invoicingCatalogReducer_1.updateInvoicingCatalogItems)(items, 'merge'),
36
36
  (0, invoicingCatalogListViewReducer_1.updateInvoicingCatalogProductList)({
37
37
  ids: items.map((item) => item.id),
38
38
  nextCursor: response.data?.next_cursor ?? null,
@@ -1,6 +1,6 @@
1
+ import { InvoicingCatalogItemPayload } from '../../../entity/invoicing/invoicingCatalog/invoicingCatalogPayload';
1
2
  import { InvoicingListCounts, InvoicingPaginatedList } from '../../../entity/invoicing/invoicingCommonPayload';
2
- import { InvoicingPlanPayload } from '../../../entity/invoicing/plan/planPayload';
3
3
  import { ZeniAPIResponse } from '../../../responsePayload';
4
- export type InvoicingCatalogPlanListResponse = ZeniAPIResponse<InvoicingPaginatedList<InvoicingPlanPayload>>;
5
- export type InvoicingCatalogProductListResponse = ZeniAPIResponse<InvoicingPaginatedList<InvoicingPlanPayload>>;
4
+ export type InvoicingCatalogPlanListResponse = ZeniAPIResponse<InvoicingPaginatedList<InvoicingCatalogItemPayload>>;
5
+ export type InvoicingCatalogProductListResponse = ZeniAPIResponse<InvoicingPaginatedList<InvoicingCatalogItemPayload>>;
6
6
  export type InvoicingCatalogCountsResponse = ZeniAPIResponse<InvoicingListCounts>;