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

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 (88) hide show
  1. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +1 -4
  2. package/lib/entity/jeSchedules/jeSchedulesReducer.js +5 -47
  3. package/lib/epic.d.ts +1 -2
  4. package/lib/epic.js +4 -6
  5. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +4 -46
  6. package/lib/esm/epic.js +4 -6
  7. package/lib/esm/index.js +3 -3
  8. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -9
  9. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +13 -10
  10. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
  11. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
  12. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  13. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +1 -60
  14. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  15. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
  16. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +28 -11
  17. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +45 -21
  18. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +4 -1
  19. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +19 -3
  20. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +16 -3
  21. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
  22. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +4 -1
  23. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +21 -21
  24. package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
  25. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
  26. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
  27. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +43 -17
  28. package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
  29. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
  30. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
  31. package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +44 -18
  32. package/lib/esm/view/invoicing/invoicingFormDraft.js +13 -0
  33. package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +57 -9
  34. package/lib/index.d.ts +3 -3
  35. package/lib/index.js +49 -50
  36. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
  37. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +0 -8
  38. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +11 -8
  39. package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
  42. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
  43. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +0 -18
  44. package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +18 -7
  45. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -8
  46. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +3 -62
  47. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
  48. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +0 -2
  49. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +8 -4
  50. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
  51. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +27 -10
  52. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +0 -15
  53. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +8 -5
  54. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +22 -6
  55. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +47 -22
  56. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +3 -0
  57. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +7 -0
  58. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +18 -2
  59. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +14 -1
  60. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
  61. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +3 -0
  62. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +3 -2
  63. package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +19 -19
  64. package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
  65. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +3 -1
  66. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
  67. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +7 -7
  68. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
  69. package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +6 -0
  70. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.d.ts +15 -10
  71. package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +42 -16
  72. package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
  73. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +3 -1
  74. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
  75. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +7 -0
  76. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
  77. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +6 -0
  78. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.d.ts +15 -11
  79. package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +42 -16
  80. package/lib/view/invoicing/invoicingFormDraft.d.ts +10 -1
  81. package/lib/view/invoicing/invoicingFormDraft.js +14 -0
  82. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +49 -0
  83. package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +59 -10
  84. package/package.json +1 -1
  85. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -40
  86. package/lib/tsconfig.mocks.tsbuildinfo +0 -1
  87. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +0 -20
  88. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -44
@@ -1,9 +1,10 @@
1
+ import { createSelector } from '@reduxjs/toolkit';
1
2
  import { reduceAllFetchState } from '../../../commonStateTypes/reduceFetchState';
2
3
  import { getInvoicingCouponById } from '../../../entity/invoicing/coupon/couponSelector';
3
- import { toInvoicingFormOption, toInvoicingQboAccountMappingSlot, } from '../../../entity/invoicing/invoicingCommonPayload';
4
+ import { toInvoicingFormOption, } from '../../../entity/invoicing/invoicingCommonPayload';
4
5
  import { getInvoicingConfigView, invoicingFieldHelpForGroup, } from '../invoicingConfigView/invoicingConfigViewSelector';
5
6
  import { getInvoicingFormDraftLocalData, isInvoicingFormDraftPending, } from '../invoicingFormDraft';
6
- import { getInvoicingQboView, invoicingAccountsForQboAccountTypes, invoicingQboAccountByQboId, isInvoicingAccountingPickerDataLoading, isInvoicingQboConnected, } from '../invoicingQboView/invoicingQboViewSelector';
7
+ import { INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES, INVOICING_DISCOUNTS_ACCOUNT_MAPPING_SLOT, NO_INVOICING_ACCOUNT_HIERARCHY, NO_INVOICING_ACCOUNT_IDS, getInvoicingQboAccountOptions, getInvoicingQboView, invoicingQboAccountByQboId, invoicingQboAccountIdsForMappingSlot, isInvoicingAccountingPickerDataLoading, isInvoicingQboConnected, } from '../invoicingQboView/invoicingQboViewSelector';
7
8
  import { getInvoicingSettings, getInvoicingSettingsFetchState, } from '../settingsView/settingsViewSelector';
8
9
  import { initialInvoicingCouponFormLocalData, invoicingCouponDiscountsAccountIdForCreate, } from './editInvoicingCouponDetailViewState';
9
10
  /**
@@ -11,6 +12,21 @@ import { initialInvoicingCouponFormLocalData, invoicingCouponDiscountsAccountIdF
11
12
  * the id of the coupon last saved, and — when a `couponId` is passed (edit
12
13
  * mode) — the existing coupon entity to prefill the form.
13
14
  */
15
+ /**
16
+ * The QuickBooks ids the discounts account may be picked from.
17
+ *
18
+ * Memoized, and collapsing to one shared empty array while QBO is disconnected:
19
+ * the form turns this into its picker options and re-seeds its defaults when
20
+ * those change, so a fresh array on every store change would reset the form
21
+ * under the user until their first edit.
22
+ */
23
+ const getInvoicingCouponDiscountsAccountIds = createSelector([
24
+ getInvoicingQboAccountOptions,
25
+ (state) => getInvoicingConfigView(state).qboAccountMappingKindOptions,
26
+ isInvoicingQboConnected,
27
+ ], (accounts, qboAccountMappingKindOptions, isQboConnected) => isQboConnected
28
+ ? invoicingQboAccountIdsForMappingSlot(accounts, qboAccountMappingKindOptions, INVOICING_DISCOUNTS_ACCOUNT_MAPPING_SLOT, INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES)
29
+ : NO_INVOICING_ACCOUNT_IDS);
14
30
  const NOT_STARTED = {
15
31
  error: undefined,
16
32
  fetchState: 'Not-Started',
@@ -51,14 +67,6 @@ export const getEditInvoicingCouponDetailViewState = (state, couponId) => {
51
67
  version: 1.0,
52
68
  };
53
69
  };
54
- /**
55
- * The account types the discounts slot falls back to when the config has no
56
- * `discounts_account` kind. A QuickBooks discount line posts to an income
57
- * account; offering every account instead would let a save be rejected.
58
- */
59
- const DEFAULT_DISCOUNTS_ACCOUNT_TYPES = 'Income';
60
- /** The account-mapping slot a coupon's discounts account shares with settings. */
61
- const DISCOUNTS_ACCOUNT_MAPPING_SLOT = 'discounts_account';
62
70
  /**
63
71
  * Bundled view for the discount form screen: the edit view (save state + the
64
72
  * coupon to prefill in edit mode), the draft `localData` (seeded from the
@@ -74,7 +82,7 @@ export const getInvoicingCouponFormView = (state, couponId) => {
74
82
  const localData = couponId != null
75
83
  ? getInvoicingFormDraftLocalData(editDraftById, couponId, initialInvoicingCouponFormLocalData)
76
84
  : newCouponDraft;
77
- const { billingPeriodUnitOptions, discountApplyOnOptions, discountDurationTypeOptions, discountTypeOptions, qboAccountMappingKindOptions, } = getInvoicingConfigView(state);
85
+ const { billingPeriodUnitOptions, discountApplyOnOptions, discountDurationTypeOptions, discountTypeOptions, } = getInvoicingConfigView(state);
78
86
  const isQboConnected = isInvoicingQboConnected(state);
79
87
  const qboView = isQboConnected ? getInvoicingQboView(state) : undefined;
80
88
  const isQboPickerDataLoading = isInvoicingAccountingPickerDataLoading(state);
@@ -84,14 +92,6 @@ export const getInvoicingCouponFormView = (state, couponId) => {
84
92
  const isCreateSeedPending = couponId == null &&
85
93
  (settingsFetchState === 'Not-Started' ||
86
94
  settingsFetchState === 'In-Progress');
87
- // The account types the discounts slot accepts come from the same config the
88
- // QBO settings page reads, so the two pickers offer the same accounts and
89
- // widening the slot stays a config change. Matched on the slot rather than
90
- // the code as written: a config that names the kind `discounts_account_id`
91
- // is the same slot, and missing it here would quietly fall back to the
92
- // default and offer a different set than the settings page does.
93
- const discountsAccountTypes = qboAccountMappingKindOptions.find((kindOption) => toInvoicingQboAccountMappingSlot(kindOption.code) ===
94
- DISCOUNTS_ACCOUNT_MAPPING_SLOT)?.accountTypes ?? DEFAULT_DISCOUNTS_ACCOUNT_TYPES;
95
95
  return {
96
96
  ...base,
97
97
  applyOnOptions: discountApplyOnOptions.map(toInvoicingFormOption),
@@ -130,7 +130,7 @@ export const getInvoicingCouponFormView = (state, couponId) => {
130
130
  },
131
131
  mode: couponId != null ? 'edit' : 'create',
132
132
  periodUnitOptions: billingPeriodUnitOptions.map(toInvoicingFormOption),
133
- qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? [],
134
- qboIncomeAccountIds: invoicingAccountsForQboAccountTypes(qboView?.accounts ?? [], discountsAccountTypes).map((account) => account.id),
133
+ qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? NO_INVOICING_ACCOUNT_HIERARCHY,
134
+ qboIncomeAccountIds: getInvoicingCouponDiscountsAccountIds(state),
135
135
  };
136
136
  };
@@ -23,9 +23,13 @@ export const seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.p
23
23
  // endpoints merge their own list-shaped rows into the same store. Only a
24
24
  // completed detail load does, which is also exactly when the page's
25
25
  // cache-guarded fetch issues no request and this is the sole seed.
26
+ // A forced refetch is the caller asking for fresh data: the response will
27
+ // seed, and seeding first from the entity as it stands would mark the
28
+ // draft loaded and lock that response out.
26
29
  if (fetchInvoicingCouponDetailPage.match(action) &&
27
- state.editInvoicingCouponDetailViewState.recordStateById[id]
28
- ?.fetchState !== 'Completed') {
30
+ (action.payload.cacheOverride === true ||
31
+ state.editInvoicingCouponDetailViewState.recordStateById[id]
32
+ ?.fetchState !== 'Completed')) {
29
33
  return EMPTY;
30
34
  }
31
35
  // Nothing to seed from on a cold open; the detail response triggers this
@@ -1,6 +1,6 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { clearAll } from '../../../rootActions';
3
- import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
3
+ import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSaved, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
4
4
  import { initialInvoicingCustomerFormLocalData } from './invoicingCustomerFormConfig';
5
5
  export const initialState = {
6
6
  emailPreviewFetchState: { fetchState: 'Not-Started', error: undefined },
@@ -8,6 +8,7 @@ export const initialState = {
8
8
  emailPreviewCustomerId: undefined,
9
9
  promotionalCreditSubmitState: { fetchState: 'Not-Started', error: undefined },
10
10
  recordStateById: {},
11
+ billingAddressOwnerId: undefined,
11
12
  fetchState: 'Not-Started',
12
13
  error: undefined,
13
14
  editDraftById: {},
@@ -154,6 +155,9 @@ const editInvoicingCustomerDetailView = createSlice({
154
155
  draft.fetchState = 'Completed';
155
156
  draft.error = undefined;
156
157
  draft.savedCustomerId = action.payload.customerId;
158
+ // An edit is refetched on success; keep the saved values on screen until
159
+ // that lands, and let it replace them.
160
+ applyInvoicingFormDraftSaved(draft.editDraftById, action.payload.customerId);
157
161
  },
158
162
  submitInvoicingCustomerFormFailure(draft, action) {
159
163
  draft.fetchState = 'Error';
@@ -183,6 +187,10 @@ const editInvoicingCustomerDetailView = createSlice({
183
187
  return { payload };
184
188
  },
185
189
  },
190
+ /** Record which customer the shared billing-address slot now belongs to. */
191
+ claimInvoicingCustomerBillingAddress(draft, action) {
192
+ draft.billingAddressOwnerId = action.payload.id;
193
+ },
186
194
  },
187
195
  extraReducers: (builder) => {
188
196
  builder.addCase(clearAll, (draft) => {
@@ -190,5 +198,5 @@ const editInvoicingCustomerDetailView = createSlice({
190
198
  });
191
199
  },
192
200
  });
193
- export const { fetchInvoicingPaymentLinkEmailPreview, fetchInvoicingPaymentLinkEmailPreviewPage, updateInvoicingPaymentLinkEmailPreview, updateInvoicingPaymentLinkEmailPreviewFailure, addPromotionalCreditsFailure, addPromotionalCreditsSuccess, fetchInvoicingCustomerDetail, fetchInvoicingCustomerDetailPage, seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail, resetPromotionalCreditAction, submitAddPromotionalCredits, updateInvoicingCustomerDetailFailure, updateInvoicingCustomerFormDraft, submitInvoicingCustomerForm, submitInvoicingCustomerFormSuccess, submitInvoicingCustomerFormFailure, resetEditInvoicingCustomerDetailView, initializeInvoicingCustomerAddress, } = editInvoicingCustomerDetailView.actions;
201
+ export const { fetchInvoicingPaymentLinkEmailPreview, fetchInvoicingPaymentLinkEmailPreviewPage, updateInvoicingPaymentLinkEmailPreview, updateInvoicingPaymentLinkEmailPreviewFailure, addPromotionalCreditsFailure, addPromotionalCreditsSuccess, fetchInvoicingCustomerDetail, fetchInvoicingCustomerDetailPage, seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail, resetPromotionalCreditAction, submitAddPromotionalCredits, updateInvoicingCustomerDetailFailure, updateInvoicingCustomerFormDraft, submitInvoicingCustomerForm, submitInvoicingCustomerFormSuccess, submitInvoicingCustomerFormFailure, resetEditInvoicingCustomerDetailView, initializeInvoicingCustomerAddress, claimInvoicingCustomerBillingAddress, } = editInvoicingCustomerDetailView.actions;
194
202
  export default editInvoicingCustomerDetailView.reducer;
@@ -1,4 +1,5 @@
1
1
  import { reduceAllFetchState } from '../../../commonStateTypes/reduceFetchState';
2
+ import { getAddressByAddressId } from '../../../entity/address/addressSelector';
2
3
  import { getInvoicesByIds } from '../../../entity/invoicing/invoice/invoiceSelector';
3
4
  import { getInvoicingCustomerById } from '../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector';
4
5
  import { invoicingCustomerPaymentMethods } from '../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector';
@@ -50,6 +51,37 @@ export const getInvoicingCustomerRecord = (state, invoicingCustomerID) => {
50
51
  * fetch state/error, and the id of the customer last saved — so the form screen
51
52
  * depends on this single selector.
52
53
  */
54
+ /**
55
+ * Whether the billing address entered on the Address screen is a change the
56
+ * customer has not saved. Presence alone cannot say so: the detail page seeds
57
+ * the address store with the saved address on load so the Address screen opens
58
+ * prefilled. Only a pending address that differs from the saved one — or one
59
+ * where nothing is saved yet — is an unsaved change. Compared on what the user
60
+ * enters; a saved address's coordinates and timestamps are left out.
61
+ */
62
+ const isBillingAddressUnsaved = (state, id, savedBillingAddressId) => {
63
+ // The slot is keyed by address type alone; only a draft this customer owns counts.
64
+ if (id == null ||
65
+ state.editInvoicingCustomerDetailViewState.billingAddressOwnerId !== id) {
66
+ return false;
67
+ }
68
+ const pending = state.addressViewState.newAddressState?.[INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE]?.addressToCreate;
69
+ if (pending == null) {
70
+ return false;
71
+ }
72
+ const saved = savedBillingAddressId != null
73
+ ? getAddressByAddressId(state.addressState, savedBillingAddressId)
74
+ : undefined;
75
+ if (saved == null) {
76
+ return true;
77
+ }
78
+ return !(pending.street.join('\u0000') === saved.street.join('\u0000') &&
79
+ pending.city === saved.city &&
80
+ pending.state === saved.state &&
81
+ pending.postalCode === saved.postalCode &&
82
+ pending.country === saved.country &&
83
+ (pending.countryCode ?? '') === (saved.countryCode ?? ''));
84
+ };
53
85
  export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
54
86
  const { editDraftById, error, fetchState, newCustomerDraft, savedCustomerId } = state.editInvoicingCustomerDetailViewState;
55
87
  const mode = invoicingCustomerID != null ? 'edit' : 'create';
@@ -101,6 +133,7 @@ export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
101
133
  taxabilityOptions,
102
134
  billingAddressId,
103
135
  billingAddressLabel,
136
+ hasUnsavedBillingAddress: isBillingAddressUnsaved(state, invoicingCustomerID, customer?.billingAddressId),
104
137
  savedCustomerId,
105
138
  fetchState,
106
139
  error,
@@ -1,35 +1,61 @@
1
- import { EMPTY, of } from 'rxjs';
1
+ import { EMPTY, from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
3
  import { getAddressByAddressId } from '../../../entity/address/addressSelector';
4
4
  import { getInvoicingCustomerById } from '../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector';
5
- import { newAddressInLocalStore } from '../../addressView/addressViewReducer';
6
- import { updateInvoicingCustomerDetail } from '../editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer';
7
- import { initializeInvoicingCustomerAddress } from './editInvoicingCustomerDetailViewReducer';
5
+ import { newAddressInLocalStore, removeNewAddressDataInLocalStore, } from '../../addressView/addressViewReducer';
6
+ import { claimInvoicingCustomerBillingAddress, fetchInvoicingCustomerDetail, fetchInvoicingCustomerDetailPage, initializeInvoicingCustomerAddress, updateInvoicingCustomerDetail, } from './editInvoicingCustomerDetailViewReducer';
8
7
  import { INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE } from './invoicingCustomerFormConfig';
9
8
  /**
10
- * Seed the shared Address screen with an existing customer's saved billing
11
- * address (looked up in the address entity store by `billingAddressId`). Runs
12
- * both when the customer detail loads and on an explicit initialize trigger.
13
- * Skips when an in-progress draft already exists, so an address the user just
14
- * entered survives navigating between the form and the Address screen. Mirrors
15
- * `initializeVendorAddressEpic`.
9
+ * Seed the shared Address screen with the customer's saved billing address, and
10
+ * record that the slot is this customer's. Runs when a detail request is issued
11
+ * (every path that loads a record issues one — the detail page when not cached,
12
+ * the create/edit form always), when the page opens, when the detail load
13
+ * lands, and on an explicit initialize trigger.
14
+ *
15
+ * The address store slot is keyed by address type alone, so it can still hold
16
+ * another customer's draft. Only a draft this customer owns is left alone —
17
+ * that is what lets an address the user just entered survive a trip to the
18
+ * Address screen. Anything else is replaced by this customer's saved address,
19
+ * or cleared when it has none. Opening the page counts as a trigger because a
20
+ * record already loaded this session issues no detail request at all.
16
21
  */
17
22
  export const initializeInvoicingCustomerAddressEpic = (actions$, state$) => actions$.pipe(filter((action) => initializeInvoicingCustomerAddress.match(action) ||
18
- updateInvoicingCustomerDetail.match(action)), mergeMap((action) => {
23
+ updateInvoicingCustomerDetail.match(action) ||
24
+ fetchInvoicingCustomerDetailPage.match(action) ||
25
+ fetchInvoicingCustomerDetail.match(action)), mergeMap((action) => {
19
26
  const { id } = action.payload;
27
+ if (id == null) {
28
+ return EMPTY;
29
+ }
20
30
  const rootState = state$.value;
21
- const existingDraft = rootState.addressViewState.newAddressState?.[INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE]?.addressToCreate;
22
- if (existingDraft != null || id == null) {
31
+ const pending = rootState.addressViewState.newAddressState?.[INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE]?.addressToCreate;
32
+ const ownerId = rootState.editInvoicingCustomerDetailViewState.billingAddressOwnerId;
33
+ // A detail response speaks for the record it loaded, which may no longer
34
+ // be the one on screen: its request keeps running when the user moves on
35
+ // to a cached record, which issues no request of its own to cancel it.
36
+ // Only the page-open and explicit triggers define the current record.
37
+ if (updateInvoicingCustomerDetail.match(action) &&
38
+ ownerId != null &&
39
+ ownerId !== id) {
40
+ return EMPTY;
41
+ }
42
+ if (pending != null && ownerId === id) {
23
43
  return EMPTY;
24
44
  }
25
45
  const customer = getInvoicingCustomerById(rootState.invoicingCustomerState, id);
26
46
  const address = customer?.billingAddressId != null
27
47
  ? getAddressByAddressId(rootState.addressState, customer.billingAddressId)
28
48
  : undefined;
29
- return address != null
30
- ? of(newAddressInLocalStore({
49
+ const actions = [];
50
+ if (address != null) {
51
+ actions.push(newAddressInLocalStore({
31
52
  addressType: INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE,
32
53
  addressToCreate: address,
33
- }))
34
- : EMPTY;
54
+ }));
55
+ }
56
+ else if (pending != null) {
57
+ actions.push(removeNewAddressDataInLocalStore(INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE));
58
+ }
59
+ actions.push(claimInvoicingCustomerBillingAddress({ id }));
60
+ return from(actions);
35
61
  }));
@@ -23,9 +23,13 @@ export const seedInvoicingCustomerFormDraftEpic = (actions$, state$) => actions$
23
23
  // endpoints merge their own list-shaped rows into the same store. Only a
24
24
  // completed detail load does, which is also exactly when the page's
25
25
  // cache-guarded fetch issues no request and this is the sole seed.
26
+ // A forced refetch is the caller asking for fresh data: the response will
27
+ // seed, and seeding first from the entity as it stands would mark the
28
+ // draft loaded and lock that response out.
26
29
  if (fetchInvoicingCustomerDetailPage.match(action) &&
27
- state.editInvoicingCustomerDetailViewState.recordStateById[id]
28
- ?.fetchState !== 'Completed') {
30
+ (action.payload.cacheOverride === true ||
31
+ state.editInvoicingCustomerDetailViewState.recordStateById[id]
32
+ ?.fetchState !== 'Completed')) {
29
33
  return EMPTY;
30
34
  }
31
35
  // Nothing to seed from on a cold open; the detail response triggers this
@@ -1,6 +1,6 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
2
  import { clearAll } from '../../../rootActions';
3
- import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
3
+ import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSaved, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
4
4
  import { initialInvoicingSubscriptionFormLocalData } from './invoicingSubscriptionFormConfig';
5
5
  export const initialState = {
6
6
  fetchState: 'Not-Started',
@@ -8,6 +8,7 @@ export const initialState = {
8
8
  editDraftById: {},
9
9
  actionStateById: {},
10
10
  recordStateById: {},
11
+ shippingAddressOwnerId: undefined,
11
12
  newSubscriptionDraft: { ...initialInvoicingSubscriptionFormLocalData },
12
13
  savedSubscriptionId: undefined,
13
14
  hasValidState() {
@@ -105,6 +106,9 @@ const editInvoicingSubscriptionDetailView = createSlice({
105
106
  draft.fetchState = 'Completed';
106
107
  draft.error = undefined;
107
108
  draft.savedSubscriptionId = action.payload.subscriptionId;
109
+ // An edit is refetched on success; keep the saved values on screen until
110
+ // that lands, and let it replace them.
111
+ applyInvoicingFormDraftSaved(draft.editDraftById, action.payload.subscriptionId);
108
112
  },
109
113
  submitInvoicingSubscriptionFormFailure(draft, action) {
110
114
  draft.fetchState = 'Error';
@@ -136,6 +140,10 @@ const editInvoicingSubscriptionDetailView = createSlice({
136
140
  return { payload };
137
141
  },
138
142
  },
143
+ /** Record which subscription the shared shipping-address slot now belongs to. */
144
+ claimInvoicingSubscriptionShippingAddress(draft, action) {
145
+ draft.shippingAddressOwnerId = action.payload.id;
146
+ },
139
147
  // Trigger only — handled by syncInvoicingSubscriptionCouponsEpic.
140
148
  syncInvoicingSubscriptionCoupons: {
141
149
  reducer() { },
@@ -150,5 +158,5 @@ const editInvoicingSubscriptionDetailView = createSlice({
150
158
  });
151
159
  },
152
160
  });
153
- export const { runInvoicingSubscriptionAction, runInvoicingSubscriptionActionFailure, runInvoicingSubscriptionActionSuccess, fetchInvoicingSubscriptionDetail, fetchInvoicingSubscriptionDetailPage, fetchInvoicingSubscriptionFormPage, seedInvoicingSubscriptionFormDraft, updateInvoicingSubscriptionDetail, updateInvoicingSubscriptionDetailFailure, updateInvoicingSubscriptionFormDraft, submitInvoicingSubscriptionForm, submitInvoicingSubscriptionFormSuccess, submitInvoicingSubscriptionFormFailure, resetEditInvoicingSubscriptionDetailView, initializeInvoicingSubscriptionAddress, syncInvoicingSubscriptionCoupons, } = editInvoicingSubscriptionDetailView.actions;
161
+ export const { runInvoicingSubscriptionAction, runInvoicingSubscriptionActionFailure, runInvoicingSubscriptionActionSuccess, fetchInvoicingSubscriptionDetail, fetchInvoicingSubscriptionDetailPage, fetchInvoicingSubscriptionFormPage, seedInvoicingSubscriptionFormDraft, updateInvoicingSubscriptionDetail, updateInvoicingSubscriptionDetailFailure, updateInvoicingSubscriptionFormDraft, submitInvoicingSubscriptionForm, submitInvoicingSubscriptionFormSuccess, submitInvoicingSubscriptionFormFailure, resetEditInvoicingSubscriptionDetailView, initializeInvoicingSubscriptionAddress, claimInvoicingSubscriptionShippingAddress, syncInvoicingSubscriptionCoupons, } = editInvoicingSubscriptionDetailView.actions;
154
162
  export default editInvoicingSubscriptionDetailView.reducer;
@@ -1,4 +1,5 @@
1
1
  import { reduceAllFetchState } from '../../../commonStateTypes/reduceFetchState';
2
+ import { getAddressByAddressId } from '../../../entity/address/addressSelector';
2
3
  import { getInvoicingSubscriptionById } from '../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionSelector';
3
4
  import { getFormattedAddress } from '../../addressView/addressViewSelector';
4
5
  import { getInvoicingCouponListItems } from '../couponView/couponViewSelector';
@@ -24,6 +25,37 @@ export const getEditInvoicingSubscriptionDetailViewState = (state, invoicingSubs
24
25
  version: 1.0,
25
26
  };
26
27
  };
28
+ /**
29
+ * Whether the shipping address entered on the Address screen is a change the
30
+ * subscription has not saved. Presence alone cannot say so: the detail page seeds
31
+ * the address store with the saved address on load so the Address screen opens
32
+ * prefilled. Only a pending address that differs from the saved one — or one
33
+ * where nothing is saved yet — is an unsaved change. Compared on what the user
34
+ * enters; a saved address's coordinates and timestamps are left out.
35
+ */
36
+ const isShippingAddressUnsaved = (state, id, savedShippingAddressId) => {
37
+ // The slot is keyed by address type alone; only a draft this subscription owns counts.
38
+ if (id == null ||
39
+ state.editInvoicingSubscriptionDetailViewState.shippingAddressOwnerId !== id) {
40
+ return false;
41
+ }
42
+ const pending = state.addressViewState.newAddressState?.[INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE]?.addressToCreate;
43
+ if (pending == null) {
44
+ return false;
45
+ }
46
+ const saved = savedShippingAddressId != null
47
+ ? getAddressByAddressId(state.addressState, savedShippingAddressId)
48
+ : undefined;
49
+ if (saved == null) {
50
+ return true;
51
+ }
52
+ return !(pending.street.join('\u0000') === saved.street.join('\u0000') &&
53
+ pending.city === saved.city &&
54
+ pending.state === saved.state &&
55
+ pending.postalCode === saved.postalCode &&
56
+ pending.country === saved.country &&
57
+ (pending.countryCode ?? '') === (saved.countryCode ?? ''));
58
+ };
27
59
  export const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
28
60
  const { editDraftById, error, fetchState, newSubscriptionDraft, savedSubscriptionId, } = state.editInvoicingSubscriptionDetailViewState;
29
61
  const mode = invoicingSubscriptionID != null ? 'edit' : 'create';
@@ -43,6 +75,7 @@ export const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID)
43
75
  const shippingAddressLabel = newAddress?.addressToCreate != null
44
76
  ? getFormattedAddress(newAddress.addressToCreate)
45
77
  : undefined;
78
+ const hasUnsavedShippingAddress = isShippingAddressUnsaved(state, invoicingSubscriptionID, subscription?.shippingAddressId);
46
79
  const catalogListView = getInvoicingCatalogListView(state);
47
80
  const planPrices = getInvoicingCatalogPrices(catalogListView.plans);
48
81
  const addonAndChargePrices = getInvoicingCatalogPrices(catalogListView.products);
@@ -75,6 +108,7 @@ export const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID)
75
108
  products: addonAndChargePrices,
76
109
  savedSubscriptionId,
77
110
  shippingAddressLabel,
111
+ hasUnsavedShippingAddress,
78
112
  subscription,
79
113
  fetchState,
80
114
  error,
@@ -1,36 +1,62 @@
1
- import { EMPTY, of } from 'rxjs';
1
+ import { EMPTY, from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
3
  import { getAddressByAddressId } from '../../../entity/address/addressSelector';
4
4
  import { getInvoicingSubscriptionById } from '../../../entity/invoicing/invoicingSubscription/invoicingSubscriptionSelector';
5
- import { newAddressInLocalStore } from '../../addressView/addressViewReducer';
6
- import { updateInvoicingSubscriptionDetail } from './editInvoicingSubscriptionDetailViewReducer';
7
- import { initializeInvoicingSubscriptionAddress } from './editInvoicingSubscriptionDetailViewReducer';
5
+ import { newAddressInLocalStore, removeNewAddressDataInLocalStore, } from '../../addressView/addressViewReducer';
6
+ import { claimInvoicingSubscriptionShippingAddress, fetchInvoicingSubscriptionDetail, fetchInvoicingSubscriptionDetailPage, initializeInvoicingSubscriptionAddress, updateInvoicingSubscriptionDetail, } from './editInvoicingSubscriptionDetailViewReducer';
8
7
  import { INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE } from './invoicingSubscriptionFormConfig';
9
8
  /**
10
- * Seed the shared Address screen with an existing subscription's saved shipping
11
- * address (looked up in the shared address store by `shippingAddressId`, same as
12
- * the customer billing-address flow).
13
- * Runs both when the subscription detail loads and on an explicit initialize
14
- * trigger. Skips when an in-progress draft already exists, so an address the
15
- * user just entered survives navigating between the form and the Address screen.
16
- * Mirrors `initializeInvoicingCustomerAddressEpic`.
9
+ * Seed the shared Address screen with the subscription's saved shipping address, and
10
+ * record that the slot is this subscription's. Runs when a detail request is issued
11
+ * (every path that loads a record issues one — the detail page when not cached,
12
+ * the create/edit form always), when the page opens, when the detail load
13
+ * lands, and on an explicit initialize trigger.
14
+ *
15
+ * The address store slot is keyed by address type alone, so it can still hold
16
+ * another subscription's draft. Only a draft this subscription owns is left alone —
17
+ * that is what lets an address the user just entered survive a trip to the
18
+ * Address screen. Anything else is replaced by this subscription's saved address,
19
+ * or cleared when it has none. Opening the page counts as a trigger because a
20
+ * record already loaded this session issues no detail request at all.
17
21
  */
18
22
  export const initializeInvoicingSubscriptionAddressEpic = (actions$, state$) => actions$.pipe(filter((action) => initializeInvoicingSubscriptionAddress.match(action) ||
19
- updateInvoicingSubscriptionDetail.match(action)), mergeMap((action) => {
23
+ updateInvoicingSubscriptionDetail.match(action) ||
24
+ fetchInvoicingSubscriptionDetailPage.match(action) ||
25
+ fetchInvoicingSubscriptionDetail.match(action)), mergeMap((action) => {
20
26
  const { id } = action.payload;
27
+ if (id == null) {
28
+ return EMPTY;
29
+ }
21
30
  const rootState = state$.value;
22
- const existingDraft = rootState.addressViewState.newAddressState?.[INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE]?.addressToCreate;
23
- if (existingDraft != null || id == null) {
31
+ const pending = rootState.addressViewState.newAddressState?.[INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE]?.addressToCreate;
32
+ const ownerId = rootState.editInvoicingSubscriptionDetailViewState
33
+ .shippingAddressOwnerId;
34
+ // A detail response speaks for the record it loaded, which may no longer
35
+ // be the one on screen: its request keeps running when the user moves on
36
+ // to a cached record, which issues no request of its own to cancel it.
37
+ // Only the page-open and explicit triggers define the current record.
38
+ if (updateInvoicingSubscriptionDetail.match(action) &&
39
+ ownerId != null &&
40
+ ownerId !== id) {
41
+ return EMPTY;
42
+ }
43
+ if (pending != null && ownerId === id) {
24
44
  return EMPTY;
25
45
  }
26
46
  const subscription = getInvoicingSubscriptionById(rootState.invoicingSubscriptionState, id);
27
47
  const address = subscription?.shippingAddressId != null
28
48
  ? getAddressByAddressId(rootState.addressState, subscription.shippingAddressId)
29
49
  : undefined;
30
- return address != null
31
- ? of(newAddressInLocalStore({
50
+ const actions = [];
51
+ if (address != null) {
52
+ actions.push(newAddressInLocalStore({
32
53
  addressType: INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE,
33
54
  addressToCreate: address,
34
- }))
35
- : EMPTY;
55
+ }));
56
+ }
57
+ else if (pending != null) {
58
+ actions.push(removeNewAddressDataInLocalStore(INVOICING_SUBSCRIPTION_SHIPPING_ADDRESS_TYPE));
59
+ }
60
+ actions.push(claimInvoicingSubscriptionShippingAddress({ id }));
61
+ return from(actions);
36
62
  }));
@@ -41,6 +41,19 @@ export function applyInvoicingFormDraftFailure(draftById, id, blankLocalData) {
41
41
  }
42
42
  existing.fetchState = 'Error';
43
43
  }
44
+ /**
45
+ * The record behind this draft was just saved and is about to be refetched.
46
+ * Keep the values on screen — dropping them would blank the form for the round
47
+ * trip, and the form remounts on the response anyway — but stop counting them
48
+ * as the loaded record's, so that response is allowed to replace them.
49
+ */
50
+ export function applyInvoicingFormDraftSaved(draftById, id) {
51
+ const existing = draftById[id];
52
+ if (existing == null) {
53
+ return;
54
+ }
55
+ existing.fetchState = 'Not-Started';
56
+ }
44
57
  /** The draft's values, or the blank form when nothing is drafted yet. */
45
58
  export function getInvoicingFormDraftLocalData(draftById, id, blankLocalData) {
46
59
  if (id == null) {
@@ -1,3 +1,5 @@
1
+ import { createSelector } from '@reduxjs/toolkit';
2
+ import { toInvoicingQboAccountMappingSlot, } from '../../../entity/invoicing/invoicingCommonPayload';
1
3
  import { getAccountList, getNestedAccountListHierarchy, } from '../../accountList/accountListSelector';
2
4
  import { getClassList, getNestedClassListHierarchy, } from '../../classList/classListSelector';
3
5
  // The shared bucket, fetched with the same arguments as the other consumers so
@@ -82,14 +84,20 @@ export const getInvoicingCatalogAccountingLookup = (state) => ({
82
84
  classByQboId: (qboId) => invoicingQboClassByQboId(state, qboId),
83
85
  });
84
86
  /**
85
- * Accounts and classes as the invoicing pickers need them. Both come from the
86
- * shared accounting-service lists, so whatever another screen already loaded
87
- * is reused. `qboId` is the submitted value because that is what the invoicing
88
- * API stores; an account without one cannot be posted, so it is dropped rather
89
- * than offered.
87
+ * Accounts as the invoicing pickers need them, from the shared
88
+ * accounting-service list, so whatever another screen already loaded is reused.
89
+ * `qboId` is the submitted value because that is what the invoicing API stores;
90
+ * an account without one cannot be posted, so it is dropped rather than offered.
91
+ *
92
+ * Memoized on the two slices it reads: the pickers and the lists derived from
93
+ * them are handed straight to forms, and a fresh array on every store change
94
+ * re-seeds a form the user is editing.
90
95
  */
91
- const invoicingAccountingOptions = (state) => {
92
- const { accounts } = getAccountList(state.accountState, state.accountListState, INVOICING_ACCOUNT_LIST_KEY);
96
+ export const getInvoicingQboAccountOptions = createSelector([
97
+ (state) => state.accountState,
98
+ (state) => state.accountListState,
99
+ ], (accountState, accountListState) => {
100
+ const { accounts } = getAccountList(accountState, accountListState, INVOICING_ACCOUNT_LIST_KEY);
93
101
  return accounts.flatMap((account) => {
94
102
  if (account.qboId == null || account.isDeleted === true) {
95
103
  return [];
@@ -102,7 +110,7 @@ const invoicingAccountingOptions = (state) => {
102
110
  },
103
111
  ];
104
112
  });
105
- };
113
+ });
106
114
  /**
107
115
  * Normalises an account-type name for comparison. The config's mapping kinds
108
116
  * name QuickBooks types the way QuickBooks displays them ("Other Current
@@ -138,6 +146,46 @@ export const invoicingAccountsForQboAccountTypes = (accounts, accountTypes) => {
138
146
  return accounts.filter((account) => account.accountType != null &&
139
147
  wanted.has(normalizeAccountTypeName(account.accountType)));
140
148
  };
149
+ /**
150
+ * The account-mapping slot a catalog price point's income account shares with
151
+ * the settings page, and the one a discount's account shares with it.
152
+ */
153
+ export const INVOICING_INCOME_ACCOUNT_MAPPING_SLOT = 'default_income_account';
154
+ export const INVOICING_DISCOUNTS_ACCOUNT_MAPPING_SLOT = 'discounts_account';
155
+ /**
156
+ * The account types a slot falls back to when the config carries no kind for
157
+ * it. QuickBooks posts a product, a price and a discount line to an income
158
+ * account; offering every account instead would let a save be rejected.
159
+ */
160
+ export const INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES = 'Income';
161
+ /**
162
+ * The QuickBooks ids a mapping slot's picker may offer, from the account types
163
+ * the config gives that slot — so every picker filling the same slot offers the
164
+ * same accounts, and widening one stays a config change.
165
+ *
166
+ * Ids rather than a filtered tree: the pickers flatten the tree into options by
167
+ * walking each node's children, so dropping a parent that is not itself of the
168
+ * wanted type would drop its matching descendants with it.
169
+ *
170
+ * Matched on the slot rather than the code as written, since a config naming
171
+ * the kind `discounts_account_id` means the same slot. A slot the config does
172
+ * not carry falls back to `defaultAccountTypes` rather than to every account.
173
+ */
174
+ export const invoicingQboAccountIdsForMappingSlot = (accounts, accountMappingKindOptions, mappingSlot, defaultAccountTypes) => {
175
+ const accountTypes = accountMappingKindOptions.find((kindOption) => toInvoicingQboAccountMappingSlot(kindOption.code) === mappingSlot)?.accountTypes ?? defaultAccountTypes;
176
+ return invoicingAccountsForQboAccountTypes(accounts, accountTypes).map((account) => account.id);
177
+ };
178
+ /**
179
+ * Stable empties for a tenant with no QBO connection.
180
+ *
181
+ * `?? []` builds a fresh array per call, and the invoicing forms re-seed their
182
+ * fields whenever their option lists change identity — so a form open against a
183
+ * disconnected tenant would reset itself on every unrelated store change, until
184
+ * the first edit disarms the re-seed.
185
+ */
186
+ export const NO_INVOICING_ACCOUNT_HIERARCHY = [];
187
+ export const NO_INVOICING_CLASS_HIERARCHY = [];
188
+ export const NO_INVOICING_ACCOUNT_IDS = [];
141
189
  /** Classes as the invoicing pickers need them, from the shared class list. */
142
190
  const invoicingAccountingClassOptions = (state) => {
143
191
  const { classes } = getClassList(state.classState, state.classListState);
@@ -159,7 +207,7 @@ export const getInvoicingQboView = (state) => {
159
207
  const qboState = state.invoicingQboViewState;
160
208
  const accountList = state.accountListState.byReportId[INVOICING_ACCOUNT_LIST_KEY];
161
209
  return {
162
- accounts: invoicingAccountingOptions(state),
210
+ accounts: getInvoicingQboAccountOptions(state),
163
211
  accountsFetchState: {
164
212
  fetchState: accountList.fetchState,
165
213
  error: accountList.error,