@zeniai/client-epic-state 5.2.52-betaRD1 → 5.2.53-beta0ND

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 (116) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +1 -4
  2. package/lib/entity/jeSchedules/jeSchedulesReducer.js +5 -47
  3. package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +2 -1
  4. package/lib/entity/notificationRegistry/notificationRegistryReducer.js +20 -9
  5. package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +2 -1
  6. package/lib/entity/notificationRegistry/notificationRegistrySelector.js +7 -1
  7. package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +5 -0
  8. package/lib/entity/notificationRegistry/notificationRegistryState.js +7 -1
  9. package/lib/entity/sectionProjectView/sectionProjectViewReducer.js +3 -1
  10. package/lib/epic.d.ts +1 -2
  11. package/lib/epic.js +0 -2
  12. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +4 -46
  13. package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +20 -9
  14. package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +5 -0
  15. package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +5 -0
  16. package/lib/esm/entity/sectionProjectView/sectionProjectViewReducer.js +3 -1
  17. package/lib/esm/epic.js +0 -2
  18. package/lib/esm/index.js +7 -7
  19. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +4 -2
  20. package/lib/esm/view/aiCfoView/epics/fetchRoutineRunsEpic.js +3 -1
  21. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -9
  22. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +13 -10
  23. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
  24. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
  25. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  26. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +1 -60
  27. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  28. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
  29. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +28 -11
  30. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +45 -21
  31. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +4 -1
  32. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +19 -3
  33. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +16 -3
  34. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
  35. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +4 -1
  36. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +21 -21
  37. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
  38. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
  39. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
  40. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +43 -17
  41. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
  42. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
  43. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
  44. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +44 -18
  45. package/lib/esm/view/invoicing/invoicingFormDraft.js +13 -0
  46. package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +57 -9
  47. package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +20 -7
  48. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +43 -17
  49. package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +24 -4
  50. package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +12 -2
  51. package/lib/index.d.ts +7 -7
  52. package/lib/index.js +56 -50
  53. package/lib/view/aiCfoView/aiCfoViewReducer.js +4 -2
  54. package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +1 -1
  55. package/lib/view/aiCfoView/epics/fetchRoutineRunsEpic.js +3 -1
  56. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
  57. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +0 -8
  58. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +11 -8
  59. package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
  60. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
  61. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
  62. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  63. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +0 -18
  64. package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +18 -7
  65. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -8
  66. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +3 -62
  67. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  68. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +0 -2
  69. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +8 -4
  70. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
  71. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +27 -10
  72. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +0 -15
  73. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +8 -5
  74. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +22 -6
  75. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +47 -22
  76. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +3 -0
  77. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +7 -0
  78. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +18 -2
  79. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +14 -1
  80. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
  81. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +3 -0
  82. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +3 -2
  83. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +19 -19
  84. package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
  85. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +3 -1
  86. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
  87. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +7 -7
  88. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
  89. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +6 -0
  90. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.d.ts +15 -10
  91. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +42 -16
  92. package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
  93. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +3 -1
  94. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
  95. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +7 -0
  96. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
  97. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +6 -0
  98. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.d.ts +15 -11
  99. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +42 -16
  100. package/lib/view/invoicing/invoicingFormDraft.d.ts +10 -1
  101. package/lib/view/invoicing/invoicingFormDraft.js +14 -0
  102. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +49 -0
  103. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +59 -10
  104. package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +19 -6
  105. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +8 -5
  106. package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +43 -17
  107. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +4 -0
  108. package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +30 -5
  109. package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +4 -3
  110. package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +12 -2
  111. package/lib/view/settingsView/settingsViewPayload.d.ts +2 -0
  112. package/package.json +1 -1
  113. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -40
  114. package/lib/tsconfig.mocks.tsbuildinfo +0 -1
  115. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +0 -20
  116. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -44
@@ -182,18 +182,35 @@ function getExpenseAutomationTransactionView(state) {
182
182
  review: monthYearPeriodId != null ? totalCountByReview[monthYearPeriodId] : 0,
183
183
  autoCategorized: monthYearPeriodId != null ? totalCountByAutoCat[monthYearPeriodId] : 0,
184
184
  };
185
- // Parent-tab badge counts. Sourced from `parent_tab_total_count` in the
186
- // listing response and used exclusively by the navbar / tab strip badges.
187
- // Independent of which Completed sub-tab is active so the badge stays
188
- // stable across sub-tab switches.
185
+ // Tab badge counts, used exclusively by the navbar / tab strip badges. Both
186
+ // tabs are counted under the filters applied to the list, so a badge always
187
+ // equals the number of rows that tab shows.
188
+ //
189
+ // The ACTIVE tab prefers its own list count: the two are the same number (the
190
+ // backend's parent_tab_total_count mirrors total_count), but `uiState.totalCount`
191
+ // is restored by every cache path that skips a fetch -- switching back to an
192
+ // already-loaded period, or to a cached Completed sub-tab -- whereas the stored
193
+ // badge is only written when a response lands, so on those paths it would keep
194
+ // showing whatever was fetched last.
195
+ //
196
+ // The `in` check is load-bearing, not defensive: `totalCount` is a per-period
197
+ // map typed as `Record<MonthYearPeriodId, number>`, so indexing it is typed
198
+ // `number` but is `undefined` for any period the active (sub-)tab has not
199
+ // loaded -- the window between switching to a fresh sub-tab and its response
200
+ // landing. Falling back to the stored badge there keeps a real number in the
201
+ // label instead of blanking it.
189
202
  const parentTotalCountByTab = expenseAutomationTransactionsViewState.parentTotalCountByTab;
203
+ const storedBadgeByTab = (tab) => monthYearPeriodId != null
204
+ ? (parentTotalCountByTab[tab][monthYearPeriodId] ?? 0)
205
+ : 0;
206
+ const badgeForTab = (tab, listCountByPeriod) => selectedTransactionCategorizationTab === tab &&
207
+ monthYearPeriodId != null &&
208
+ monthYearPeriodId in listCountByPeriod
209
+ ? listCountByPeriod[monthYearPeriodId]
210
+ : storedBadgeByTab(tab);
190
211
  const parentTabTotalCountByTab = {
191
- review: monthYearPeriodId != null
192
- ? (parentTotalCountByTab.review[monthYearPeriodId] ?? 0)
193
- : 0,
194
- autoCategorized: monthYearPeriodId != null
195
- ? (parentTotalCountByTab.autoCategorized[monthYearPeriodId] ?? 0)
196
- : 0,
212
+ review: badgeForTab('review', totalCountByReview),
213
+ autoCategorized: badgeForTab('autoCategorized', totalCountByAutoCat),
197
214
  };
198
215
  const fetchStateByTab = {
199
216
  review: {
@@ -19,7 +19,6 @@ export type JESchedulePeriodTabKey = `${JEPageTab}_${MonthYearPeriodId}`;
19
19
  export declare const getJESchedulePeriodTabKey: (selectedPageTab: JEPageTab, monthYearPeriodId: MonthYearPeriodId) => JESchedulePeriodTabKey;
20
20
  export interface JESchedulesViewUIState {
21
21
  createdGroupCollapsed: boolean;
22
- failedGroupCollapsed: boolean;
23
22
  pendingGroupCollapsed: boolean;
24
23
  scrollPosition: {
25
24
  scrollTop: number;
@@ -42,22 +41,8 @@ export interface JEScheduleLocalData {
42
41
  updatedClassId?: ID;
43
42
  updatedVendor?: VendorBase;
44
43
  }
45
- /**
46
- * The Failed Postings bucket, and the only list on this page that is not scoped to a period.
47
- *
48
- * A failed posting is broken until someone resolves it, whatever month it belongs to, so windowing
49
- * it the way the schedule lists are windowed is what hid a March failure from the September close.
50
- * It therefore has no period-tab key, and its own fetch state rather than the slice's: the list is
51
- * fetched separately from `/1.0/expenses_automation/failed_je_postings`, so a slow or failing
52
- * lookup here must not blank the schedules table, or vice versa.
53
- */
54
- export interface FailedJePostingsState {
55
- fetchState: FetchStateAndError;
56
- jeScheduleTransactionKeys: JEScheduleTransactionKey[];
57
- }
58
44
  export interface JESchedulesViewState extends FetchedState {
59
45
  accountSettings: AccountSettingsState;
60
- failedJePostings: FailedJePostingsState;
61
46
  failedJeScheduleTransactionKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleTransactionKey[]>;
62
47
  ignoreStatusById: Record<JEScheduleTransactionKey, FetchStateAndError>;
63
48
  jeScheduleAccruedKeysByPeriodAndTab: Record<JESchedulePeriodTabKey, JEScheduleKey[]>;
@@ -139,11 +139,14 @@ export type TransactionsViewState = {
139
139
  */
140
140
  autoCategorizedSubTabCache: Partial<Record<CompletedSubTab, AutoCategorizedSubTabSnapshot>>;
141
141
  /**
142
- * Period-keyed parent tab counts, scoped per {@link TransactionsTab}.
143
- * Sourced from the listing response's `parent_tab_total_count` and used
144
- * exclusively to drive the parent tab badges on the UI — every other
145
- * count consumer (pagination, sub-tab chips, in-tab "showing X of Y")
146
- * keeps reading from {@link TransactionsViewUIState.totalCount}.
142
+ * Period-keyed tab badge counts, scoped per {@link TransactionsTab}. Every
143
+ * count here is taken under the filters currently applied to the list
144
+ * (`transaction_group` + Completed `sub_tab` + search), so a badge always
145
+ * matches the rows that tab renders. The active tab is filled from the
146
+ * listing response's `parent_tab_total_count` and the inactive one from its
147
+ * `other_tab_total_count`. Used exclusively to drive the tab badges — every
148
+ * other count consumer (pagination, in-tab "showing X of Y") keeps reading
149
+ * from {@link TransactionsViewUIState.totalCount}.
147
150
  */
148
151
  parentTotalCountByTab: Record<TransactionsTab, Record<MonthYearPeriodId, number>>;
149
152
  selectedTransactionCategorizationCompletedSubTab: CompletedSubTab;
@@ -7,10 +7,8 @@ import { InvoicingCatalogItemFormLocalData } from './editInvoicingCatalogItemDet
7
7
  export type SaveInvoicingCatalogItemResponse = ZeniAPIResponse<InvoicingPlanPayload>;
8
8
  /**
9
9
  * The price-point half of a save body. `InvoicingProductPayload` is the shape
10
- * the service returns; a save differs in two ways: a field is cleared by
11
- * sending an explicit `null` (an absent key reads as "leave it alone"), and a
12
- * price point the form has only just added carries a blank `id`, which the
13
- * update endpoint reads as "create this one".
10
+ * the service returns; a save differs in that a field is cleared by sending an
11
+ * explicit `null`, since an absent key reads as "leave it alone".
14
12
  */
15
13
  export type InvoicingCatalogSubFamilySavePayload = Omit<Partial<InvoicingProductPayload>, 'accounting_detail' | 'description' | 'invoice_notes'> & {
16
14
  accounting_detail?: InvoicingAccountingDetailPayload | null;
@@ -19,8 +17,13 @@ export type InvoicingCatalogSubFamilySavePayload = Omit<Partial<InvoicingProduct
19
17
  };
20
18
  /**
21
19
  * The catalog-item save body: the item the service returns, minus the fields it
22
- * assigns itself. Price points keep the `sub_families` name they are read back
23
- * under, and differ only in allowing the cleared and blank-id forms above.
20
+ * assigns itself.
21
+ *
22
+ * Price points travel under `sub_families`, the name they are read back under,
23
+ * and differ only in allowing the cleared forms above. An update addresses them
24
+ * by id, so a price point added on the form — which has none yet — is created
25
+ * by its own request instead; see
26
+ * `localDataToCreateInvoicingCatalogProductPayloads`.
24
27
  */
25
28
  export type InvoicingCatalogItemSavePayload = Omit<Partial<InvoicingPlanPayload>, 'sub_families'> & {
26
29
  sub_families?: InvoicingCatalogSubFamilySavePayload[];
@@ -51,6 +54,19 @@ export declare const buildAccountingDetail: (subFamily: InvoicingCatalogAccounti
51
54
  * edit cannot overwrite them with a value nobody chose.
52
55
  */
53
56
  export declare const localDataToSaveInvoicingCatalogItemPayload: (localData: InvoicingCatalogItemFormLocalData, isCreate: boolean, lookup: InvoicingCatalogAccountingLookup) => InvoicingCatalogItemSavePayload;
57
+ /**
58
+ * The bodies that create the price points added on an edit form, one per
59
+ * request to `/catalog/products`.
60
+ *
61
+ * An update cannot carry them: it addresses price points by id, and these have
62
+ * none until the service assigns one. They are bound to their item by
63
+ * `item_id`, so this needs the saved item's id and runs after the item itself
64
+ * is saved.
65
+ *
66
+ * Empty values are left off rather than sent as `null`: there is nothing on a
67
+ * price point that does not exist yet to clear.
68
+ */
69
+ export declare const localDataToCreateInvoicingCatalogProductPayloads: (localData: InvoicingCatalogItemFormLocalData, itemId: string, lookup: InvoicingCatalogAccountingLookup) => InvoicingCatalogSubFamilySavePayload[];
54
70
  export type RunInvoicingCatalogPlanActionResponse = ZeniAPIResponse<InvoicingPlanPayload>;
55
71
  export type RunInvoicingCatalogProductActionResponse = ZeniAPIResponse<InvoicingProductPayload>;
56
72
  export type InvoicingCatalogItemDetailResponse = ZeniAPIResponse<InvoicingPlanPayload>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.localDataToSaveInvoicingCatalogItemPayload = exports.buildAccountingDetail = void 0;
3
+ exports.localDataToCreateInvoicingCatalogProductPayloads = exports.localDataToSaveInvoicingCatalogItemPayload = exports.buildAccountingDetail = void 0;
4
4
  const accountPayload_1 = require("../../../entity/account/accountPayload");
5
5
  const classPayload_1 = require("../../../entity/class/classPayload");
6
6
  const invoicingCatalogItemFormHelper_1 = require("./invoicingCatalogItemFormHelper");
@@ -134,27 +134,52 @@ const localDataToSaveInvoicingCatalogItemPayload = (localData, isCreate, lookup)
134
134
  const subFamilies = localData.subFamilies.length > 0
135
135
  ? localData.subFamilies
136
136
  : [(0, invoicingCatalogItemFormHelper_1.blankInvoicingCatalogSubFamily)()];
137
- itemPayload.sub_families = isCreate
138
- ? subFamilies.map((subFamily) => buildSubFamilyPayload(localData, subFamily, false, lookup))
139
- : subFamilies.map((subFamily) => {
140
- // Edits send the same body a create does. The narrower hand-built one
141
- // this replaces had to be kept in step by hand and was not: it dropped
142
- // `accounting_detail` once, and `billing_cycles`, `price`,
143
- // `pricing_model`, `period`, the trial fields, `proration_type`,
144
- // `free_quantity`, `is_taxable` and `tiers` were never added at all, so
145
- // editing any of them looked saved and changed nothing.
146
- const detail = buildSubFamilyPayload(localData, subFamily, true, lookup);
147
- // `null` rather than omitted when empty: an absent key on an update
148
- // reads as "leave it alone", which would make a cleared mapping
149
- // impossible to save — the same reason `description` and
150
- // `invoice_notes` are cleared rather than dropped above.
151
- detail.accounting_detail = detail.accounting_detail ?? null;
152
- // A price point added on this form has no id yet, and travels with a
153
- // blank one. The update endpoint reads that as "create this one", so it
154
- // lands in the same request as the edits around it rather than a second
155
- // call that could fail on its own.
156
- return { ...detail, id: subFamily.id.trim() };
157
- });
137
+ if (isCreate) {
138
+ itemPayload.sub_families = subFamilies.map((subFamily) => buildSubFamilyPayload(localData, subFamily, false, lookup));
139
+ return itemPayload;
140
+ }
141
+ // Only price points the service has already stored travel in an update: it
142
+ // addresses them by id, and a blank one has nothing to address. A price point
143
+ // added on the form is created by its own request once the item is saved,
144
+ // rather than riding along as a row the update cannot place.
145
+ itemPayload.sub_families = subFamilies
146
+ .filter((subFamily) => subFamily.id !== '')
147
+ .map((subFamily) => {
148
+ // Edits send the same body a create does. The narrower hand-built one
149
+ // this replaces had to be kept in step by hand and was not: it dropped
150
+ // `accounting_detail` once, and `billing_cycles`, `price`,
151
+ // `pricing_model`, `period`, the trial fields, `proration_type`,
152
+ // `free_quantity`, `is_taxable` and `tiers` were never added at all, so
153
+ // editing any of them looked saved and changed nothing.
154
+ const detail = buildSubFamilyPayload(localData, subFamily, true, lookup);
155
+ // `null` rather than omitted when empty: an absent key on an update
156
+ // reads as "leave it alone", which would make a cleared mapping
157
+ // impossible to save — the same reason `description` and
158
+ // `invoice_notes` are cleared rather than dropped above.
159
+ detail.accounting_detail = detail.accounting_detail ?? null;
160
+ // Never blank: the filter above leaves only price points the service has
161
+ // already stored, which is the only kind an update can address.
162
+ return { ...detail, id: subFamily.id };
163
+ });
158
164
  return itemPayload;
159
165
  };
160
166
  exports.localDataToSaveInvoicingCatalogItemPayload = localDataToSaveInvoicingCatalogItemPayload;
167
+ /**
168
+ * The bodies that create the price points added on an edit form, one per
169
+ * request to `/catalog/products`.
170
+ *
171
+ * An update cannot carry them: it addresses price points by id, and these have
172
+ * none until the service assigns one. They are bound to their item by
173
+ * `item_id`, so this needs the saved item's id and runs after the item itself
174
+ * is saved.
175
+ *
176
+ * Empty values are left off rather than sent as `null`: there is nothing on a
177
+ * price point that does not exist yet to clear.
178
+ */
179
+ const localDataToCreateInvoicingCatalogProductPayloads = (localData, itemId, lookup) => localData.subFamilies
180
+ .filter((subFamily) => subFamily.id === '')
181
+ .map((subFamily) => ({
182
+ ...buildSubFamilyPayload(localData, subFamily, false, lookup),
183
+ item_id: itemId,
184
+ }));
185
+ exports.localDataToCreateInvoicingCatalogProductPayloads = localDataToCreateInvoicingCatalogProductPayloads;
@@ -47,6 +47,9 @@ const editInvoicingCatalogItemDetailView = (0, toolkit_1.createSlice)({
47
47
  draft.error = undefined;
48
48
  draft.savedItemId = action.payload.itemId;
49
49
  draft.savedKind = action.payload.kind;
50
+ // An edit is refetched on success; keep the saved values on screen until
51
+ // that lands, and let it replace them.
52
+ (0, invoicingFormDraft_1.applyInvoicingFormDraftSaved)(draft.editDraftById, action.payload.itemId);
50
53
  },
51
54
  submitInvoicingCatalogItemFormFailure(draft, action) {
52
55
  draft.fetchState = 'Error';
@@ -79,6 +79,13 @@ export interface InvoicingCatalogItemFormView extends SelectorView {
79
79
  */
80
80
  qboAccountHierarchy: NestedAccountHierarchyForReport[];
81
81
  qboClassHierarchy: NestedClassHierarchyForReport[];
82
+ /**
83
+ * The ids within the account tree an income account may be picked from.
84
+ * QuickBooks only accepts an income account on a product, so a price point
85
+ * mapped to anything else — A/R, deferred revenue, a bank account — fails to
86
+ * sync once an invoice carrying it is pushed.
87
+ */
88
+ qboIncomeAccountIds: string[];
82
89
  /**
83
90
  * Loading the item, as distinct from this view's own `fetchState`, which
84
91
  * tracks the save.
@@ -50,6 +50,21 @@ const NOT_STARTED = {
50
50
  error: undefined,
51
51
  fetchState: 'Not-Started',
52
52
  };
53
+ /**
54
+ * The QuickBooks ids a price point's income account may be picked from.
55
+ *
56
+ * Memoized, and collapsing to one shared empty array while QBO is disconnected:
57
+ * the pages turn this into their picker options and re-seed their form defaults
58
+ * when those change, so a fresh array on every store change would reset the form
59
+ * under the user — including mid-save.
60
+ */
61
+ const getInvoicingCatalogIncomeAccountIds = (0, toolkit_1.createSelector)([
62
+ invoicingQboViewSelector_1.getInvoicingQboAccountOptions,
63
+ (state) => (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state).qboAccountMappingKindOptions,
64
+ invoicingQboViewSelector_1.isInvoicingQboConnected,
65
+ ], (accounts, qboAccountMappingKindOptions, isQboConnected) => isQboConnected
66
+ ? (0, invoicingQboViewSelector_1.invoicingQboAccountIdsForMappingSlot)(accounts, qboAccountMappingKindOptions, invoicingQboViewSelector_1.INVOICING_INCOME_ACCOUNT_MAPPING_SLOT, invoicingQboViewSelector_1.INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES)
67
+ : invoicingQboViewSelector_1.NO_INVOICING_ACCOUNT_IDS);
53
68
  const getInvoicingCatalogItemFormView = (state, id) => {
54
69
  const { editDraftById, error, fetchState, newItemDraft, savedItemId, savedKind, } = state.editInvoicingCatalogItemDetailViewState;
55
70
  const plan = id != null ? (0, planSelector_1.getInvoicingPlanById)(state.invoicingPlanState, id) : undefined;
@@ -100,8 +115,9 @@ const getInvoicingCatalogItemFormView = (state, id) => {
100
115
  isFormLoading: (0, invoicingQboViewSelector_1.isInvoicingAccountingPickerDataLoading)(state) ||
101
116
  (0, invoicingFormDraft_1.isInvoicingFormDraftPending)(editDraftById, id),
102
117
  isQboPickerDataLoading: (0, invoicingQboViewSelector_1.isInvoicingAccountingPickerDataLoading)(state),
103
- qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? [],
104
- qboClassHierarchy: qboView?.nestedClassHierarchy ?? [],
118
+ qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? invoicingQboViewSelector_1.NO_INVOICING_ACCOUNT_HIERARCHY,
119
+ qboClassHierarchy: qboView?.nestedClassHierarchy ?? invoicingQboViewSelector_1.NO_INVOICING_CLASS_HIERARCHY,
120
+ qboIncomeAccountIds: getInvoicingCatalogIncomeAccountIds(state),
105
121
  applicabilityValues: invoicingCatalogItemFormHelper_1.INVOICING_CATALOG_APPLICABILITY_VALUES,
106
122
  applicableItemOptions,
107
123
  localData,
@@ -84,7 +84,20 @@ const saveInvoicingCatalogItemEpic = (actions$, state$, zeniAPI) => actions$.pip
84
84
  }));
85
85
  return resultActions;
86
86
  };
87
- return completeSave([]);
87
+ // Price points added on an edit form cannot ride in the update:
88
+ // it addresses them by id and they have none yet. They are created
89
+ // against the item that was just saved, and their responses join
90
+ // the same success — one of them failing is the whole save
91
+ // failing, since the item on screen would otherwise claim price
92
+ // points the service never stored. A create needs none of this:
93
+ // its price points are nested in the item body.
94
+ const newProductPayloads = id != null
95
+ ? (0, editInvoicingCatalogItemDetailViewPayload_1.localDataToCreateInvoicingCatalogProductPayloads)(localData, savedItem.id, accountingLookup)
96
+ : [];
97
+ if (newProductPayloads.length === 0) {
98
+ return completeSave([]);
99
+ }
100
+ return (0, rxjs_1.forkJoin)(newProductPayloads.map((productPayload) => zeniAPI.postAndGetJSON(`${baseUrl}/catalog/products`, productPayload))).pipe((0, operators_1.mergeMap)((productResponses) => completeSave(productResponses)));
88
101
  }
89
102
  return (0, rxjs_1.from)([
90
103
  (0, editInvoicingCatalogItemDetailViewReducer_1.submitInvoicingCatalogItemFormFailure)(response.status),
@@ -26,9 +26,13 @@ const seedInvoicingCatalogItemFormDraftEpic = (actions$, state$) => actions$.pip
26
26
  // endpoints merge their own list-shaped rows into the same store. Only a
27
27
  // completed detail load does, which is also exactly when the page's
28
28
  // cache-guarded fetch issues no request and this is the sole seed.
29
+ // A forced refetch is the caller asking for fresh data: the response will
30
+ // seed, and seeding first from the entity as it stands would mark the
31
+ // draft loaded and lock that response out.
29
32
  if (editInvoicingCatalogItemDetailViewReducer_1.fetchInvoicingCatalogItemDetailPage.match(action) &&
30
- state.editInvoicingCatalogItemDetailViewState.recordStateById[id]
31
- ?.fetchState !== 'Completed') {
33
+ (action.payload.cacheOverride === true ||
34
+ state.editInvoicingCatalogItemDetailViewState.recordStateById[id]
35
+ ?.fetchState !== 'Completed')) {
32
36
  return rxjs_1.EMPTY;
33
37
  }
34
38
  // Nothing to seed from on a cold open; the detail response triggers this
@@ -55,6 +55,9 @@ const editInvoicingCouponDetailView = (0, toolkit_1.createSlice)({
55
55
  draft.fetchState = 'Completed';
56
56
  draft.error = undefined;
57
57
  draft.savedCouponId = action.payload.couponId;
58
+ // An edit is refetched on success; keep the saved values on screen until
59
+ // that lands, and let it replace them.
60
+ (0, invoicingFormDraft_1.applyInvoicingFormDraftSaved)(draft.editDraftById, action.payload.couponId);
58
61
  },
59
62
  submitInvoicingCouponFormFailure(draft, action) {
60
63
  draft.fetchState = 'Error';
@@ -82,8 +82,9 @@ export interface InvoicingCouponFormView extends EditInvoicingCouponDetailView {
82
82
  /**
83
83
  * The account tree the discounts-account picker renders, and the QuickBooks
84
84
  * ids within it the discounts slot accepts. Two values rather than a filtered
85
- * tree: the picker groups by parent, and dropping a parent that is not itself
86
- * an income account would take its income children with it.
85
+ * tree: the picker flattens the tree into options by walking each node's
86
+ * children, so dropping a parent that is not itself an income account would
87
+ * drop its income descendants with it.
87
88
  *
88
89
  * Empty until QBO is connected — the form must not offer a mapping that
89
90
  * cannot be pushed.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInvoicingCouponFormView = exports.getEditInvoicingCouponDetailViewState = void 0;
4
+ const toolkit_1 = require("@reduxjs/toolkit");
4
5
  const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
5
6
  const couponSelector_1 = require("../../../entity/invoicing/coupon/couponSelector");
6
7
  const invoicingCommonPayload_1 = require("../../../entity/invoicing/invoicingCommonPayload");
@@ -14,6 +15,21 @@ const editInvoicingCouponDetailViewState_1 = require("./editInvoicingCouponDetai
14
15
  * the id of the coupon last saved, and — when a `couponId` is passed (edit
15
16
  * mode) — the existing coupon entity to prefill the form.
16
17
  */
18
+ /**
19
+ * The QuickBooks ids the discounts account may be picked from.
20
+ *
21
+ * Memoized, and collapsing to one shared empty array while QBO is disconnected:
22
+ * the form turns this into its picker options and re-seeds its defaults when
23
+ * those change, so a fresh array on every store change would reset the form
24
+ * under the user until their first edit.
25
+ */
26
+ const getInvoicingCouponDiscountsAccountIds = (0, toolkit_1.createSelector)([
27
+ invoicingQboViewSelector_1.getInvoicingQboAccountOptions,
28
+ (state) => (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state).qboAccountMappingKindOptions,
29
+ invoicingQboViewSelector_1.isInvoicingQboConnected,
30
+ ], (accounts, qboAccountMappingKindOptions, isQboConnected) => isQboConnected
31
+ ? (0, invoicingQboViewSelector_1.invoicingQboAccountIdsForMappingSlot)(accounts, qboAccountMappingKindOptions, invoicingQboViewSelector_1.INVOICING_DISCOUNTS_ACCOUNT_MAPPING_SLOT, invoicingQboViewSelector_1.INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES)
32
+ : invoicingQboViewSelector_1.NO_INVOICING_ACCOUNT_IDS);
17
33
  const NOT_STARTED = {
18
34
  error: undefined,
19
35
  fetchState: 'Not-Started',
@@ -55,14 +71,6 @@ const getEditInvoicingCouponDetailViewState = (state, couponId) => {
55
71
  };
56
72
  };
57
73
  exports.getEditInvoicingCouponDetailViewState = getEditInvoicingCouponDetailViewState;
58
- /**
59
- * The account types the discounts slot falls back to when the config has no
60
- * `discounts_account` kind. A QuickBooks discount line posts to an income
61
- * account; offering every account instead would let a save be rejected.
62
- */
63
- const DEFAULT_DISCOUNTS_ACCOUNT_TYPES = 'Income';
64
- /** The account-mapping slot a coupon's discounts account shares with settings. */
65
- const DISCOUNTS_ACCOUNT_MAPPING_SLOT = 'discounts_account';
66
74
  /**
67
75
  * Bundled view for the discount form screen: the edit view (save state + the
68
76
  * coupon to prefill in edit mode), the draft `localData` (seeded from the
@@ -78,7 +86,7 @@ const getInvoicingCouponFormView = (state, couponId) => {
78
86
  const localData = couponId != null
79
87
  ? (0, invoicingFormDraft_1.getInvoicingFormDraftLocalData)(editDraftById, couponId, editInvoicingCouponDetailViewState_1.initialInvoicingCouponFormLocalData)
80
88
  : newCouponDraft;
81
- const { billingPeriodUnitOptions, discountApplyOnOptions, discountDurationTypeOptions, discountTypeOptions, qboAccountMappingKindOptions, } = (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state);
89
+ const { billingPeriodUnitOptions, discountApplyOnOptions, discountDurationTypeOptions, discountTypeOptions, } = (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state);
82
90
  const isQboConnected = (0, invoicingQboViewSelector_1.isInvoicingQboConnected)(state);
83
91
  const qboView = isQboConnected ? (0, invoicingQboViewSelector_1.getInvoicingQboView)(state) : undefined;
84
92
  const isQboPickerDataLoading = (0, invoicingQboViewSelector_1.isInvoicingAccountingPickerDataLoading)(state);
@@ -88,14 +96,6 @@ const getInvoicingCouponFormView = (state, couponId) => {
88
96
  const isCreateSeedPending = couponId == null &&
89
97
  (settingsFetchState === 'Not-Started' ||
90
98
  settingsFetchState === 'In-Progress');
91
- // The account types the discounts slot accepts come from the same config the
92
- // QBO settings page reads, so the two pickers offer the same accounts and
93
- // widening the slot stays a config change. Matched on the slot rather than
94
- // the code as written: a config that names the kind `discounts_account_id`
95
- // is the same slot, and missing it here would quietly fall back to the
96
- // default and offer a different set than the settings page does.
97
- const discountsAccountTypes = qboAccountMappingKindOptions.find((kindOption) => (0, invoicingCommonPayload_1.toInvoicingQboAccountMappingSlot)(kindOption.code) ===
98
- DISCOUNTS_ACCOUNT_MAPPING_SLOT)?.accountTypes ?? DEFAULT_DISCOUNTS_ACCOUNT_TYPES;
99
99
  return {
100
100
  ...base,
101
101
  applyOnOptions: discountApplyOnOptions.map(invoicingCommonPayload_1.toInvoicingFormOption),
@@ -134,8 +134,8 @@ const getInvoicingCouponFormView = (state, couponId) => {
134
134
  },
135
135
  mode: couponId != null ? 'edit' : 'create',
136
136
  periodUnitOptions: billingPeriodUnitOptions.map(invoicingCommonPayload_1.toInvoicingFormOption),
137
- qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? [],
138
- qboIncomeAccountIds: (0, invoicingQboViewSelector_1.invoicingAccountsForQboAccountTypes)(qboView?.accounts ?? [], discountsAccountTypes).map((account) => account.id),
137
+ qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? invoicingQboViewSelector_1.NO_INVOICING_ACCOUNT_HIERARCHY,
138
+ qboIncomeAccountIds: getInvoicingCouponDiscountsAccountIds(state),
139
139
  };
140
140
  };
141
141
  exports.getInvoicingCouponFormView = getInvoicingCouponFormView;
@@ -26,9 +26,13 @@ const seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.pipe((0,
26
26
  // endpoints merge their own list-shaped rows into the same store. Only a
27
27
  // completed detail load does, which is also exactly when the page's
28
28
  // cache-guarded fetch issues no request and this is the sole seed.
29
+ // A forced refetch is the caller asking for fresh data: the response will
30
+ // seed, and seeding first from the entity as it stands would mark the
31
+ // draft loaded and lock that response out.
29
32
  if (editInvoicingCouponDetailViewReducer_1.fetchInvoicingCouponDetailPage.match(action) &&
30
- state.editInvoicingCouponDetailViewState.recordStateById[id]
31
- ?.fetchState !== 'Completed') {
33
+ (action.payload.cacheOverride === true ||
34
+ state.editInvoicingCouponDetailViewState.recordStateById[id]
35
+ ?.fetchState !== 'Completed')) {
32
36
  return rxjs_1.EMPTY;
33
37
  }
34
38
  // Nothing to seed from on a cold open; the detail response triggers this
@@ -56,6 +56,8 @@ export declare const fetchInvoicingPaymentLinkEmailPreview: import("@reduxjs/too
56
56
  customerId: ID;
57
57
  }, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormSuccess">, submitInvoicingCustomerFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormFailure">, resetEditInvoicingCustomerDetailView: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<{
58
58
  id?: ID;
59
- } | undefined, "editInvoicingCustomerDetailView/resetEditInvoicingCustomerDetailView">, initializeInvoicingCustomerAddress: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: InitializeInvoicingCustomerAddressPayload], InitializeInvoicingCustomerAddressPayload, "editInvoicingCustomerDetailView/initializeInvoicingCustomerAddress", never, never>;
59
+ } | undefined, "editInvoicingCustomerDetailView/resetEditInvoicingCustomerDetailView">, initializeInvoicingCustomerAddress: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: InitializeInvoicingCustomerAddressPayload], InitializeInvoicingCustomerAddressPayload, "editInvoicingCustomerDetailView/initializeInvoicingCustomerAddress", never, never>, claimInvoicingCustomerBillingAddress: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
60
+ id: ID;
61
+ }, "editInvoicingCustomerDetailView/claimInvoicingCustomerBillingAddress">;
60
62
  declare const _default: import("redux").Reducer<EditInvoicingCustomerDetailViewState>;
61
63
  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.initializeInvoicingCustomerAddress = exports.resetEditInvoicingCustomerDetailView = exports.submitInvoicingCustomerFormFailure = exports.submitInvoicingCustomerFormSuccess = exports.submitInvoicingCustomerForm = exports.updateInvoicingCustomerFormDraft = exports.updateInvoicingCustomerDetailFailure = exports.submitAddPromotionalCredits = exports.resetPromotionalCreditAction = exports.updateInvoicingCustomerDetail = exports.seedInvoicingCustomerFormDraft = exports.fetchInvoicingCustomerDetailPage = exports.fetchInvoicingCustomerDetail = exports.addPromotionalCreditsSuccess = exports.addPromotionalCreditsFailure = exports.updateInvoicingPaymentLinkEmailPreviewFailure = exports.updateInvoicingPaymentLinkEmailPreview = exports.fetchInvoicingPaymentLinkEmailPreviewPage = exports.fetchInvoicingPaymentLinkEmailPreview = exports.initialState = void 0;
4
+ exports.claimInvoicingCustomerBillingAddress = exports.initializeInvoicingCustomerAddress = exports.resetEditInvoicingCustomerDetailView = exports.submitInvoicingCustomerFormFailure = exports.submitInvoicingCustomerFormSuccess = exports.submitInvoicingCustomerForm = exports.updateInvoicingCustomerFormDraft = exports.updateInvoicingCustomerDetailFailure = exports.submitAddPromotionalCredits = exports.resetPromotionalCreditAction = exports.updateInvoicingCustomerDetail = exports.seedInvoicingCustomerFormDraft = exports.fetchInvoicingCustomerDetailPage = exports.fetchInvoicingCustomerDetail = exports.addPromotionalCreditsSuccess = exports.addPromotionalCreditsFailure = exports.updateInvoicingPaymentLinkEmailPreviewFailure = exports.updateInvoicingPaymentLinkEmailPreview = exports.fetchInvoicingPaymentLinkEmailPreviewPage = exports.fetchInvoicingPaymentLinkEmailPreview = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const rootActions_1 = require("../../../rootActions");
7
7
  const invoicingFormDraft_1 = require("../invoicingFormDraft");
@@ -12,6 +12,7 @@ exports.initialState = {
12
12
  emailPreviewCustomerId: undefined,
13
13
  promotionalCreditSubmitState: { fetchState: 'Not-Started', error: undefined },
14
14
  recordStateById: {},
15
+ billingAddressOwnerId: undefined,
15
16
  fetchState: 'Not-Started',
16
17
  error: undefined,
17
18
  editDraftById: {},
@@ -158,6 +159,9 @@ const editInvoicingCustomerDetailView = (0, toolkit_1.createSlice)({
158
159
  draft.fetchState = 'Completed';
159
160
  draft.error = undefined;
160
161
  draft.savedCustomerId = action.payload.customerId;
162
+ // An edit is refetched on success; keep the saved values on screen until
163
+ // that lands, and let it replace them.
164
+ (0, invoicingFormDraft_1.applyInvoicingFormDraftSaved)(draft.editDraftById, action.payload.customerId);
161
165
  },
162
166
  submitInvoicingCustomerFormFailure(draft, action) {
163
167
  draft.fetchState = 'Error';
@@ -187,6 +191,10 @@ const editInvoicingCustomerDetailView = (0, toolkit_1.createSlice)({
187
191
  return { payload };
188
192
  },
189
193
  },
194
+ /** Record which customer the shared billing-address slot now belongs to. */
195
+ claimInvoicingCustomerBillingAddress(draft, action) {
196
+ draft.billingAddressOwnerId = action.payload.id;
197
+ },
190
198
  },
191
199
  extraReducers: (builder) => {
192
200
  builder.addCase(rootActions_1.clearAll, (draft) => {
@@ -194,5 +202,5 @@ const editInvoicingCustomerDetailView = (0, toolkit_1.createSlice)({
194
202
  });
195
203
  },
196
204
  });
197
- _a = editInvoicingCustomerDetailView.actions, exports.fetchInvoicingPaymentLinkEmailPreview = _a.fetchInvoicingPaymentLinkEmailPreview, exports.fetchInvoicingPaymentLinkEmailPreviewPage = _a.fetchInvoicingPaymentLinkEmailPreviewPage, exports.updateInvoicingPaymentLinkEmailPreview = _a.updateInvoicingPaymentLinkEmailPreview, exports.updateInvoicingPaymentLinkEmailPreviewFailure = _a.updateInvoicingPaymentLinkEmailPreviewFailure, exports.addPromotionalCreditsFailure = _a.addPromotionalCreditsFailure, exports.addPromotionalCreditsSuccess = _a.addPromotionalCreditsSuccess, exports.fetchInvoicingCustomerDetail = _a.fetchInvoicingCustomerDetail, exports.fetchInvoicingCustomerDetailPage = _a.fetchInvoicingCustomerDetailPage, exports.seedInvoicingCustomerFormDraft = _a.seedInvoicingCustomerFormDraft, exports.updateInvoicingCustomerDetail = _a.updateInvoicingCustomerDetail, exports.resetPromotionalCreditAction = _a.resetPromotionalCreditAction, exports.submitAddPromotionalCredits = _a.submitAddPromotionalCredits, exports.updateInvoicingCustomerDetailFailure = _a.updateInvoicingCustomerDetailFailure, exports.updateInvoicingCustomerFormDraft = _a.updateInvoicingCustomerFormDraft, exports.submitInvoicingCustomerForm = _a.submitInvoicingCustomerForm, exports.submitInvoicingCustomerFormSuccess = _a.submitInvoicingCustomerFormSuccess, exports.submitInvoicingCustomerFormFailure = _a.submitInvoicingCustomerFormFailure, exports.resetEditInvoicingCustomerDetailView = _a.resetEditInvoicingCustomerDetailView, exports.initializeInvoicingCustomerAddress = _a.initializeInvoicingCustomerAddress;
205
+ _a = editInvoicingCustomerDetailView.actions, exports.fetchInvoicingPaymentLinkEmailPreview = _a.fetchInvoicingPaymentLinkEmailPreview, exports.fetchInvoicingPaymentLinkEmailPreviewPage = _a.fetchInvoicingPaymentLinkEmailPreviewPage, exports.updateInvoicingPaymentLinkEmailPreview = _a.updateInvoicingPaymentLinkEmailPreview, exports.updateInvoicingPaymentLinkEmailPreviewFailure = _a.updateInvoicingPaymentLinkEmailPreviewFailure, exports.addPromotionalCreditsFailure = _a.addPromotionalCreditsFailure, exports.addPromotionalCreditsSuccess = _a.addPromotionalCreditsSuccess, exports.fetchInvoicingCustomerDetail = _a.fetchInvoicingCustomerDetail, exports.fetchInvoicingCustomerDetailPage = _a.fetchInvoicingCustomerDetailPage, exports.seedInvoicingCustomerFormDraft = _a.seedInvoicingCustomerFormDraft, exports.updateInvoicingCustomerDetail = _a.updateInvoicingCustomerDetail, exports.resetPromotionalCreditAction = _a.resetPromotionalCreditAction, exports.submitAddPromotionalCredits = _a.submitAddPromotionalCredits, exports.updateInvoicingCustomerDetailFailure = _a.updateInvoicingCustomerDetailFailure, exports.updateInvoicingCustomerFormDraft = _a.updateInvoicingCustomerFormDraft, exports.submitInvoicingCustomerForm = _a.submitInvoicingCustomerForm, exports.submitInvoicingCustomerFormSuccess = _a.submitInvoicingCustomerFormSuccess, exports.submitInvoicingCustomerFormFailure = _a.submitInvoicingCustomerFormFailure, exports.resetEditInvoicingCustomerDetailView = _a.resetEditInvoicingCustomerDetailView, exports.initializeInvoicingCustomerAddress = _a.initializeInvoicingCustomerAddress, exports.claimInvoicingCustomerBillingAddress = _a.claimInvoicingCustomerBillingAddress;
198
206
  exports.default = editInvoicingCustomerDetailView.reducer;
@@ -86,13 +86,13 @@ export interface InvoicingCustomerFormView extends SelectorView {
86
86
  billingAddressId?: ID;
87
87
  billingAddressLabel?: string;
88
88
  emailPreview?: InvoicingPaymentLinkEmailPreviewData;
89
+ /**
90
+ * A billing address entered on the Address screen that the customer has not
91
+ * saved yet. The inline-edit form cannot see it — the address lives in the
92
+ * shared address store, not in a field — so the detail page reads this to
93
+ * offer Save, or the address could never be linked.
94
+ */
95
+ hasUnsavedBillingAddress?: boolean;
89
96
  savedCustomerId?: ID;
90
97
  }
91
- /**
92
- * Bundled view for the customer create/edit form. Exposes the draft `localData`
93
- * (seeded from the existing customer entity in edit mode until the user edits),
94
- * the canonical option value sets (labels resolved in web-components), the save
95
- * fetch state/error, and the id of the customer last saved — so the form screen
96
- * depends on this single selector.
97
- */
98
98
  export declare const getInvoicingCustomerFormView: (state: RootState, invoicingCustomerID?: ID) => InvoicingCustomerFormView;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInvoicingCustomerFormView = exports.getInvoicingCustomerRecord = void 0;
4
4
  const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
5
+ const addressSelector_1 = require("../../../entity/address/addressSelector");
5
6
  const invoiceSelector_1 = require("../../../entity/invoicing/invoice/invoiceSelector");
6
7
  const invoicingCustomerSelector_1 = require("../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector");
7
8
  const invoicingCustomerSelector_2 = require("../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector");
@@ -54,6 +55,37 @@ exports.getInvoicingCustomerRecord = getInvoicingCustomerRecord;
54
55
  * fetch state/error, and the id of the customer last saved — so the form screen
55
56
  * depends on this single selector.
56
57
  */
58
+ /**
59
+ * Whether the billing address entered on the Address screen is a change the
60
+ * customer has not saved. Presence alone cannot say so: the detail page seeds
61
+ * the address store with the saved address on load so the Address screen opens
62
+ * prefilled. Only a pending address that differs from the saved one — or one
63
+ * where nothing is saved yet — is an unsaved change. Compared on what the user
64
+ * enters; a saved address's coordinates and timestamps are left out.
65
+ */
66
+ const isBillingAddressUnsaved = (state, id, savedBillingAddressId) => {
67
+ // The slot is keyed by address type alone; only a draft this customer owns counts.
68
+ if (id == null ||
69
+ state.editInvoicingCustomerDetailViewState.billingAddressOwnerId !== id) {
70
+ return false;
71
+ }
72
+ const pending = state.addressViewState.newAddressState?.[invoicingCustomerFormConfig_1.INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE]?.addressToCreate;
73
+ if (pending == null) {
74
+ return false;
75
+ }
76
+ const saved = savedBillingAddressId != null
77
+ ? (0, addressSelector_1.getAddressByAddressId)(state.addressState, savedBillingAddressId)
78
+ : undefined;
79
+ if (saved == null) {
80
+ return true;
81
+ }
82
+ return !(pending.street.join('\u0000') === saved.street.join('\u0000') &&
83
+ pending.city === saved.city &&
84
+ pending.state === saved.state &&
85
+ pending.postalCode === saved.postalCode &&
86
+ pending.country === saved.country &&
87
+ (pending.countryCode ?? '') === (saved.countryCode ?? ''));
88
+ };
57
89
  const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
58
90
  const { editDraftById, error, fetchState, newCustomerDraft, savedCustomerId } = state.editInvoicingCustomerDetailViewState;
59
91
  const mode = invoicingCustomerID != null ? 'edit' : 'create';
@@ -105,6 +137,7 @@ const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
105
137
  taxabilityOptions,
106
138
  billingAddressId,
107
139
  billingAddressLabel,
140
+ hasUnsavedBillingAddress: isBillingAddressUnsaved(state, invoicingCustomerID, customer?.billingAddressId),
108
141
  savedCustomerId,
109
142
  fetchState,
110
143
  error,
@@ -53,6 +53,12 @@ export interface EditInvoicingCustomerDetailViewState extends FetchedState {
53
53
  promotionalCreditSubmitState: FetchStateAndError;
54
54
  /** Detail-load state per customer id. */
55
55
  recordStateById: Record<ID, FetchStateAndError>;
56
+ /**
57
+ * The customer whose billing address currently occupies the shared address
58
+ * store slot. That slot is keyed by address type alone, so without this a
59
+ * draft seeded or edited for one customer would pass for the next one's.
60
+ */
61
+ billingAddressOwnerId?: ID;
56
62
  emailPreview?: InvoicingPaymentLinkEmailPreviewData;
57
63
  emailPreviewCustomerId?: ID;
58
64
  savedCustomerId?: ID;