@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.
- package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +1 -4
- package/lib/entity/jeSchedules/jeSchedulesReducer.js +5 -47
- package/lib/entity/notificationRegistry/notificationRegistryReducer.d.ts +2 -1
- package/lib/entity/notificationRegistry/notificationRegistryReducer.js +20 -9
- package/lib/entity/notificationRegistry/notificationRegistrySelector.d.ts +2 -1
- package/lib/entity/notificationRegistry/notificationRegistrySelector.js +7 -1
- package/lib/entity/notificationRegistry/notificationRegistryState.d.ts +5 -0
- package/lib/entity/notificationRegistry/notificationRegistryState.js +7 -1
- package/lib/entity/sectionProjectView/sectionProjectViewReducer.js +3 -1
- package/lib/epic.d.ts +1 -2
- package/lib/epic.js +0 -2
- package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +4 -46
- package/lib/esm/entity/notificationRegistry/notificationRegistryReducer.js +20 -9
- package/lib/esm/entity/notificationRegistry/notificationRegistrySelector.js +5 -0
- package/lib/esm/entity/notificationRegistry/notificationRegistryState.js +5 -0
- package/lib/esm/entity/sectionProjectView/sectionProjectViewReducer.js +3 -1
- package/lib/esm/epic.js +0 -2
- package/lib/esm/index.js +7 -7
- package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +4 -2
- package/lib/esm/view/aiCfoView/epics/fetchRoutineRunsEpic.js +3 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -9
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +13 -10
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +1 -60
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +28 -11
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +45 -21
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +4 -1
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +19 -3
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +16 -3
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +4 -1
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +21 -21
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +43 -17
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +44 -18
- package/lib/esm/view/invoicing/invoicingFormDraft.js +13 -0
- package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +57 -9
- package/lib/esm/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +20 -7
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewReducer.js +43 -17
- package/lib/esm/view/notificationPreferencesView/notificationPreferencesViewSelector.js +24 -4
- package/lib/esm/view/settingsView/epic/fetchNotificationSettingsEpic.js +12 -2
- package/lib/index.d.ts +7 -7
- package/lib/index.js +56 -50
- package/lib/view/aiCfoView/aiCfoViewReducer.js +4 -2
- package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +1 -1
- package/lib/view/aiCfoView/epics/fetchRoutineRunsEpic.js +3 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +0 -8
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +11 -8
- package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +15 -34
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -12
- package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +0 -18
- package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +18 -7
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +2 -8
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +3 -62
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +0 -2
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +8 -4
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +12 -20
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +27 -10
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +0 -15
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +8 -5
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +22 -6
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +47 -22
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +3 -0
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +7 -0
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +18 -2
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +14 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +6 -2
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +3 -0
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +3 -2
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +19 -19
- package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +6 -2
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +10 -2
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +7 -7
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +33 -0
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +6 -0
- package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.d.ts +15 -10
- package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +42 -16
- package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +6 -2
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +10 -2
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +7 -0
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +34 -0
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +6 -0
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.d.ts +15 -11
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +42 -16
- package/lib/view/invoicing/invoicingFormDraft.d.ts +10 -1
- package/lib/view/invoicing/invoicingFormDraft.js +14 -0
- package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +49 -0
- package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +59 -10
- package/lib/view/notificationPreferencesView/epics/saveNotificationPreferencesEpic.js +19 -6
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.d.ts +8 -5
- package/lib/view/notificationPreferencesView/notificationPreferencesViewReducer.js +43 -17
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.d.ts +4 -0
- package/lib/view/notificationPreferencesView/notificationPreferencesViewSelector.js +30 -5
- package/lib/view/notificationPreferencesView/notificationPreferencesViewState.d.ts +4 -3
- package/lib/view/settingsView/epic/fetchNotificationSettingsEpic.js +12 -2
- package/lib/view/settingsView/settingsViewPayload.d.ts +2 -0
- package/package.json +1 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -40
- package/lib/tsconfig.mocks.tsbuildinfo +0 -1
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +0 -20
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -44
|
@@ -130,26 +130,50 @@ export const localDataToSaveInvoicingCatalogItemPayload = (localData, isCreate,
|
|
|
130
130
|
const subFamilies = localData.subFamilies.length > 0
|
|
131
131
|
? localData.subFamilies
|
|
132
132
|
: [blankInvoicingCatalogSubFamily()];
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
133
|
+
if (isCreate) {
|
|
134
|
+
itemPayload.sub_families = subFamilies.map((subFamily) => buildSubFamilyPayload(localData, subFamily, false, lookup));
|
|
135
|
+
return itemPayload;
|
|
136
|
+
}
|
|
137
|
+
// Only price points the service has already stored travel in an update: it
|
|
138
|
+
// addresses them by id, and a blank one has nothing to address. A price point
|
|
139
|
+
// added on the form is created by its own request once the item is saved,
|
|
140
|
+
// rather than riding along as a row the update cannot place.
|
|
141
|
+
itemPayload.sub_families = subFamilies
|
|
142
|
+
.filter((subFamily) => subFamily.id !== '')
|
|
143
|
+
.map((subFamily) => {
|
|
144
|
+
// Edits send the same body a create does. The narrower hand-built one
|
|
145
|
+
// this replaces had to be kept in step by hand and was not: it dropped
|
|
146
|
+
// `accounting_detail` once, and `billing_cycles`, `price`,
|
|
147
|
+
// `pricing_model`, `period`, the trial fields, `proration_type`,
|
|
148
|
+
// `free_quantity`, `is_taxable` and `tiers` were never added at all, so
|
|
149
|
+
// editing any of them looked saved and changed nothing.
|
|
150
|
+
const detail = buildSubFamilyPayload(localData, subFamily, true, lookup);
|
|
151
|
+
// `null` rather than omitted when empty: an absent key on an update
|
|
152
|
+
// reads as "leave it alone", which would make a cleared mapping
|
|
153
|
+
// impossible to save — the same reason `description` and
|
|
154
|
+
// `invoice_notes` are cleared rather than dropped above.
|
|
155
|
+
detail.accounting_detail = detail.accounting_detail ?? null;
|
|
156
|
+
// Never blank: the filter above leaves only price points the service has
|
|
157
|
+
// already stored, which is the only kind an update can address.
|
|
158
|
+
return { ...detail, id: subFamily.id };
|
|
159
|
+
});
|
|
154
160
|
return itemPayload;
|
|
155
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* The bodies that create the price points added on an edit form, one per
|
|
164
|
+
* request to `/catalog/products`.
|
|
165
|
+
*
|
|
166
|
+
* An update cannot carry them: it addresses price points by id, and these have
|
|
167
|
+
* none until the service assigns one. They are bound to their item by
|
|
168
|
+
* `item_id`, so this needs the saved item's id and runs after the item itself
|
|
169
|
+
* is saved.
|
|
170
|
+
*
|
|
171
|
+
* Empty values are left off rather than sent as `null`: there is nothing on a
|
|
172
|
+
* price point that does not exist yet to clear.
|
|
173
|
+
*/
|
|
174
|
+
export const localDataToCreateInvoicingCatalogProductPayloads = (localData, itemId, lookup) => localData.subFamilies
|
|
175
|
+
.filter((subFamily) => subFamily.id === '')
|
|
176
|
+
.map((subFamily) => ({
|
|
177
|
+
...buildSubFamilyPayload(localData, subFamily, false, lookup),
|
|
178
|
+
item_id: itemId,
|
|
179
|
+
}));
|
|
@@ -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 { initialInvoicingCatalogItemFormLocalData } from './invoicingCatalogItemFormHelper';
|
|
5
5
|
export const initialState = {
|
|
6
6
|
fetchState: 'Not-Started',
|
|
@@ -43,6 +43,9 @@ const editInvoicingCatalogItemDetailView = createSlice({
|
|
|
43
43
|
draft.error = undefined;
|
|
44
44
|
draft.savedItemId = action.payload.itemId;
|
|
45
45
|
draft.savedKind = action.payload.kind;
|
|
46
|
+
// An edit is refetched on success; keep the saved values on screen until
|
|
47
|
+
// that lands, and let it replace them.
|
|
48
|
+
applyInvoicingFormDraftSaved(draft.editDraftById, action.payload.itemId);
|
|
46
49
|
},
|
|
47
50
|
submitInvoicingCatalogItemFormFailure(draft, action) {
|
|
48
51
|
draft.fetchState = 'Error';
|
|
@@ -3,7 +3,7 @@ import { reduceAllFetchState } from '../../../commonStateTypes/reduceFetchState'
|
|
|
3
3
|
import { getInvoicingPlanById, getInvoicingPlansByIds, } from '../../../entity/invoicing/plan/planSelector';
|
|
4
4
|
import { getInvoicingConfigView, invoicingFieldHelpForGroup, } from '../invoicingConfigView/invoicingConfigViewSelector';
|
|
5
5
|
import { getInvoicingFormDraftLocalData, isInvoicingFormDraftPending, } from '../invoicingFormDraft';
|
|
6
|
-
import { getInvoicingQboView, isInvoicingAccountingPickerDataLoading, isInvoicingQboConnected, } from '../invoicingQboView/invoicingQboViewSelector';
|
|
6
|
+
import { INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES, INVOICING_INCOME_ACCOUNT_MAPPING_SLOT, NO_INVOICING_ACCOUNT_HIERARCHY, NO_INVOICING_ACCOUNT_IDS, NO_INVOICING_CLASS_HIERARCHY, getInvoicingQboAccountOptions, getInvoicingQboView, invoicingQboAccountIdsForMappingSlot, isInvoicingAccountingPickerDataLoading, isInvoicingQboConnected, } from '../invoicingQboView/invoicingQboViewSelector';
|
|
7
7
|
import { INVOICING_CATALOG_APPLICABILITY_VALUES, INVOICING_CATALOG_PRICING_MODEL_VALUES, INVOICING_CATALOG_PRORATION_VALUES, INVOICING_CATALOG_TIER_TYPE_VALUES, initialInvoicingCatalogItemFormLocalData, } from './invoicingCatalogItemFormHelper';
|
|
8
8
|
export const getEditInvoicingCatalogItemDetailViewState = (state) => ({
|
|
9
9
|
fetchState: state.editInvoicingCatalogItemDetailViewState.fetchState,
|
|
@@ -44,6 +44,21 @@ const NOT_STARTED = {
|
|
|
44
44
|
error: undefined,
|
|
45
45
|
fetchState: 'Not-Started',
|
|
46
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* The QuickBooks ids a price point's income account may be picked from.
|
|
49
|
+
*
|
|
50
|
+
* Memoized, and collapsing to one shared empty array while QBO is disconnected:
|
|
51
|
+
* the pages turn this into their picker options and re-seed their form defaults
|
|
52
|
+
* when those change, so a fresh array on every store change would reset the form
|
|
53
|
+
* under the user — including mid-save.
|
|
54
|
+
*/
|
|
55
|
+
const getInvoicingCatalogIncomeAccountIds = createSelector([
|
|
56
|
+
getInvoicingQboAccountOptions,
|
|
57
|
+
(state) => getInvoicingConfigView(state).qboAccountMappingKindOptions,
|
|
58
|
+
isInvoicingQboConnected,
|
|
59
|
+
], (accounts, qboAccountMappingKindOptions, isQboConnected) => isQboConnected
|
|
60
|
+
? invoicingQboAccountIdsForMappingSlot(accounts, qboAccountMappingKindOptions, INVOICING_INCOME_ACCOUNT_MAPPING_SLOT, INVOICING_DEFAULT_INCOME_ACCOUNT_TYPES)
|
|
61
|
+
: NO_INVOICING_ACCOUNT_IDS);
|
|
47
62
|
export const getInvoicingCatalogItemFormView = (state, id) => {
|
|
48
63
|
const { editDraftById, error, fetchState, newItemDraft, savedItemId, savedKind, } = state.editInvoicingCatalogItemDetailViewState;
|
|
49
64
|
const plan = id != null ? getInvoicingPlanById(state.invoicingPlanState, id) : undefined;
|
|
@@ -94,8 +109,9 @@ export const getInvoicingCatalogItemFormView = (state, id) => {
|
|
|
94
109
|
isFormLoading: isInvoicingAccountingPickerDataLoading(state) ||
|
|
95
110
|
isInvoicingFormDraftPending(editDraftById, id),
|
|
96
111
|
isQboPickerDataLoading: isInvoicingAccountingPickerDataLoading(state),
|
|
97
|
-
qboAccountHierarchy: qboView?.nestedAccountHierarchy ??
|
|
98
|
-
qboClassHierarchy: qboView?.nestedClassHierarchy ??
|
|
112
|
+
qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? NO_INVOICING_ACCOUNT_HIERARCHY,
|
|
113
|
+
qboClassHierarchy: qboView?.nestedClassHierarchy ?? NO_INVOICING_CLASS_HIERARCHY,
|
|
114
|
+
qboIncomeAccountIds: getInvoicingCatalogIncomeAccountIds(state),
|
|
99
115
|
applicabilityValues: INVOICING_CATALOG_APPLICABILITY_VALUES,
|
|
100
116
|
applicableItemOptions,
|
|
101
117
|
localData,
|
package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { from } from 'rxjs';
|
|
1
|
+
import { forkJoin, from } from 'rxjs';
|
|
2
2
|
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
3
|
import { mergeInvoicingPlanSubFamily, updateInvoicingPlans, } from '../../../entity/invoicing/plan/planReducer';
|
|
4
4
|
import { updateInvoicingProducts } from '../../../entity/invoicing/product/productReducer';
|
|
@@ -7,7 +7,7 @@ import { openSnackbar } from '../../../entity/snackbar/snackbarReducer';
|
|
|
7
7
|
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
8
8
|
import { addInvoicingCatalogItem } from '../invoicingCatalogListView/invoicingCatalogListViewReducer';
|
|
9
9
|
import { getInvoicingCatalogAccountingLookup } from '../invoicingQboView/invoicingQboViewSelector';
|
|
10
|
-
import { localDataToSaveInvoicingCatalogItemPayload, } from './editInvoicingCatalogItemDetailViewPayload';
|
|
10
|
+
import { localDataToCreateInvoicingCatalogProductPayloads, localDataToSaveInvoicingCatalogItemPayload, } from './editInvoicingCatalogItemDetailViewPayload';
|
|
11
11
|
import { submitInvoicingCatalogItemForm, submitInvoicingCatalogItemFormFailure, submitInvoicingCatalogItemFormSuccess, } from './editInvoicingCatalogItemDetailViewReducer';
|
|
12
12
|
export const saveInvoicingCatalogItemEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter((action) => submitInvoicingCatalogItemForm.match(action)), mergeMap((action) => {
|
|
13
13
|
const { id } = action.payload;
|
|
@@ -81,7 +81,20 @@ export const saveInvoicingCatalogItemEpic = (actions$, state$, zeniAPI) => actio
|
|
|
81
81
|
}));
|
|
82
82
|
return resultActions;
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
// Price points added on an edit form cannot ride in the update:
|
|
85
|
+
// it addresses them by id and they have none yet. They are created
|
|
86
|
+
// against the item that was just saved, and their responses join
|
|
87
|
+
// the same success — one of them failing is the whole save
|
|
88
|
+
// failing, since the item on screen would otherwise claim price
|
|
89
|
+
// points the service never stored. A create needs none of this:
|
|
90
|
+
// its price points are nested in the item body.
|
|
91
|
+
const newProductPayloads = id != null
|
|
92
|
+
? localDataToCreateInvoicingCatalogProductPayloads(localData, savedItem.id, accountingLookup)
|
|
93
|
+
: [];
|
|
94
|
+
if (newProductPayloads.length === 0) {
|
|
95
|
+
return completeSave([]);
|
|
96
|
+
}
|
|
97
|
+
return forkJoin(newProductPayloads.map((productPayload) => zeniAPI.postAndGetJSON(`${baseUrl}/catalog/products`, productPayload))).pipe(mergeMap((productResponses) => completeSave(productResponses)));
|
|
85
98
|
}
|
|
86
99
|
return from([
|
|
87
100
|
submitInvoicingCatalogItemFormFailure(response.status),
|
|
@@ -23,9 +23,13 @@ export const seedInvoicingCatalogItemFormDraftEpic = (actions$, state$) => actio
|
|
|
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 (fetchInvoicingCatalogItemDetailPage.match(action) &&
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
(action.payload.cacheOverride === true ||
|
|
31
|
+
state.editInvoicingCatalogItemDetailViewState.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
|
package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js
CHANGED
|
@@ -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 { initialInvoicingCouponFormLocalData, } from './editInvoicingCouponDetailViewState';
|
|
5
5
|
export const initialState = {
|
|
6
6
|
fetchState: 'Not-Started',
|
|
@@ -51,6 +51,9 @@ const editInvoicingCouponDetailView = createSlice({
|
|
|
51
51
|
draft.fetchState = 'Completed';
|
|
52
52
|
draft.error = undefined;
|
|
53
53
|
draft.savedCouponId = action.payload.couponId;
|
|
54
|
+
// An edit is refetched on success; keep the saved values on screen until
|
|
55
|
+
// that lands, and let it replace them.
|
|
56
|
+
applyInvoicingFormDraftSaved(draft.editDraftById, action.payload.couponId);
|
|
54
57
|
},
|
|
55
58
|
submitInvoicingCouponFormFailure(draft, action) {
|
|
56
59
|
draft.fetchState = 'Error';
|
|
@@ -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,
|
|
4
|
+
import { toInvoicingFormOption, } from '../../../entity/invoicing/invoicingCommonPayload';
|
|
4
5
|
import { getInvoicingConfigView, invoicingFieldHelpForGroup, } from '../invoicingConfigView/invoicingConfigViewSelector';
|
|
5
6
|
import { getInvoicingFormDraftLocalData, isInvoicingFormDraftPending, } from '../invoicingFormDraft';
|
|
6
|
-
import {
|
|
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,
|
|
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:
|
|
133
|
+
qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? NO_INVOICING_ACCOUNT_HIERARCHY,
|
|
134
|
+
qboIncomeAccountIds: getInvoicingCouponDiscountsAccountIds(state),
|
|
135
135
|
};
|
|
136
136
|
};
|
package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
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,
|
|
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 '
|
|
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
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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)
|
|
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
|
|
22
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
}));
|
package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
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,
|