@zeniai/client-epic-state 5.2.41-beta6MM → 5.2.41-beta7MM
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/billPay/billTransaction/billTransactionReducer.d.ts +5 -1
- package/lib/entity/billPay/billTransaction/billTransactionReducer.js +17 -2
- package/lib/entity/invoicing/coupon/couponPayload.d.ts +8 -0
- package/lib/entity/invoicing/coupon/couponPayload.js +8 -0
- package/lib/entity/invoicing/coupon/couponState.d.ts +6 -0
- package/lib/entity/invoicing/dunningCase/dunningCaseTypes.d.ts +1 -1
- package/lib/entity/invoicing/plan/planSelector.d.ts +20 -0
- package/lib/entity/invoicing/plan/planSelector.js +42 -0
- package/lib/entity/invoicing/product/productPayload.d.ts +8 -1
- package/lib/entity/invoicing/product/productPayload.js +4 -1
- package/lib/entity/invoicing/product/productState.d.ts +16 -0
- package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +4 -1
- package/lib/entity/jeSchedules/jeSchedulesReducer.js +79 -5
- package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
- package/lib/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/entity/task/taskState.d.ts +1 -1
- package/lib/epic.d.ts +4 -1
- package/lib/epic.js +10 -4
- package/lib/esm/entity/billPay/billTransaction/billTransactionReducer.js +16 -1
- package/lib/esm/entity/invoicing/coupon/couponPayload.js +8 -0
- package/lib/esm/entity/invoicing/plan/planSelector.js +39 -0
- package/lib/esm/entity/invoicing/product/productPayload.js +4 -1
- package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +78 -4
- package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
- package/lib/esm/epic.js +10 -4
- package/lib/esm/index.js +8 -7
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +3 -2
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +39 -0
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +14 -1
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +10 -13
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
- package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
- package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
- package/lib/esm/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +6 -0
- package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +74 -1
- package/lib/esm/view/expenseAutomationView/reducers/reconciliationViewReducer.js +80 -53
- package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
- package/lib/esm/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +6 -2
- package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
- package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +28 -11
- package/lib/esm/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +67 -35
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +22 -11
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +23 -4
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +19 -5
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +30 -7
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.js +16 -1
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +22 -11
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +69 -6
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.js +22 -0
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.js +22 -4
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +18 -4
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +29 -6
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +28 -12
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +37 -2
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +43 -17
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/saveInvoicingCustomerEpic.js +1 -1
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +29 -6
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +30 -14
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +143 -8
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +44 -18
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +1 -1
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.js +29 -8
- package/lib/esm/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +12 -0
- package/lib/esm/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.js +6 -6
- package/lib/esm/view/invoicing/invoicingFormDraft.js +78 -0
- package/lib/esm/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +57 -9
- package/lib/esm/view/recommendation/recommendationPayload.js +3 -1
- package/lib/esm/view/recommendation/recommendationReducer.js +27 -7
- package/lib/esm/view/recommendation/recommendationSelector.js +1 -0
- package/lib/esm/view/recommendation/submitRecommendationFeedbackEpic.js +20 -8
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +87 -1
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +97 -0
- package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +85 -0
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewReducer.js +18 -1
- package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
- package/lib/esm/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +95 -0
- package/lib/index.d.ts +9 -8
- package/lib/index.js +54 -48
- package/lib/view/expenseAutomationView/epics/jeSchedule/actualMatching/ignoreActualMatchingSuggestionEpic.js +3 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +20 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +43 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +13 -0
- package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +8 -11
- package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +38 -17
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
- package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +17 -1
- package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationEpic.js +15 -4
- package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
- package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +18 -0
- package/lib/view/expenseAutomationView/payload/transactionCategorizationPayload.d.ts +18 -7
- package/lib/view/expenseAutomationView/reducers/actualMatchingViewReducer.js +6 -0
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +10 -3
- package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +76 -3
- package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.js +80 -53
- package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +10 -0
- package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +3 -0
- package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +8 -4
- package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.d.ts +1 -0
- package/lib/view/expenseAutomationView/selectors/actualMatchingViewSelector.js +7 -2
- package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +49 -14
- package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +27 -10
- package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +16 -0
- package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +8 -5
- package/lib/view/invoicing/createInvoice/createInvoiceSelector.d.ts +7 -2
- package/lib/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.d.ts +46 -5
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewPayload.js +69 -36
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +22 -11
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +17 -0
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +22 -3
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewState.d.ts +2 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.d.ts +2 -2
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +17 -3
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +29 -6
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.d.ts +5 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewPayload.js +16 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +22 -11
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +46 -0
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +68 -5
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.d.ts +21 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.js +24 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.d.ts +9 -5
- package/lib/view/invoicing/editInvoicingCouponDetailView/fetchInvoicingCouponDetailPageEpic.js +22 -4
- package/lib/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +18 -4
- package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +28 -5
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +5 -1
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +29 -13
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +16 -7
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +37 -2
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +8 -1
- package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.d.ts +15 -10
- package/lib/view/invoicing/editInvoicingCustomerDetailView/initializeInvoicingCustomerAddressEpic.js +42 -16
- package/lib/view/invoicing/editInvoicingCustomerDetailView/saveInvoicingCustomerEpic.js +1 -1
- package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +28 -5
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +5 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +31 -15
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +79 -12
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +145 -9
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +8 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.d.ts +15 -11
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddressEpic.js +42 -16
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js +1 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/seedInvoicingSubscriptionFormDraftEpic.js +28 -7
- package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.d.ts +10 -0
- package/lib/view/invoicing/invoicingCatalogListView/invoicingCatalogListViewSelector.js +12 -0
- package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewReducer.d.ts +1 -1
- package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.d.ts +2 -2
- package/lib/view/invoicing/invoicingDunningCaseListView/invoicingDunningCaseListViewState.js +6 -6
- package/lib/view/invoicing/invoicingFormDraft.d.ts +63 -0
- package/lib/view/invoicing/invoicingFormDraft.js +86 -0
- package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.d.ts +49 -0
- package/lib/view/invoicing/invoicingQboView/invoicingQboViewSelector.js +59 -10
- package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewReducer.d.ts +1 -1
- package/lib/view/invoicing/invoicingSubscriptionListView/invoicingSubscriptionListViewState.d.ts +1 -1
- package/lib/view/recommendation/recommendationPayload.d.ts +1 -0
- package/lib/view/recommendation/recommendationPayload.js +5 -0
- package/lib/view/recommendation/recommendationReducer.d.ts +7 -1
- package/lib/view/recommendation/recommendationReducer.js +28 -8
- package/lib/view/recommendation/recommendationSelector.d.ts +2 -0
- package/lib/view/recommendation/recommendationSelector.js +3 -1
- package/lib/view/recommendation/recommendationState.d.ts +2 -1
- package/lib/view/recommendation/submitRecommendationFeedbackEpic.d.ts +2 -2
- package/lib/view/recommendation/submitRecommendationFeedbackEpic.js +18 -6
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewPayload.d.ts +19 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.d.ts +10 -1
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +88 -2
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.d.ts +1 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.d.ts +7 -0
- package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.d.ts +37 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +104 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.d.ts +24 -0
- package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +92 -0
- package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.d.ts +4 -1
- package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.js +19 -2
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -0
- package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
- package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.d.ts +18 -0
- package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +102 -0
- package/package.json +2 -2
package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { EMPTY, of } from 'rxjs';
|
|
2
2
|
import { filter, mergeMap, withLatestFrom } from 'rxjs/operators';
|
|
3
3
|
import { getInvoicingCouponById } from '../../../entity/invoicing/coupon/couponSelector';
|
|
4
|
-
import { seedInvoicingCouponFormDraft, updateInvoicingCouponDetail, } from './editInvoicingCouponDetailViewReducer';
|
|
4
|
+
import { fetchInvoicingCouponDetailPage, seedInvoicingCouponFormDraft, updateInvoicingCouponDetail, } from './editInvoicingCouponDetailViewReducer';
|
|
5
5
|
import { entityToInvoicingCouponFormLocalData } from './editInvoicingCouponDetailViewState';
|
|
6
6
|
/**
|
|
7
|
-
* Seeds the edit draft from the record the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Seeds the edit draft from the record, so the form has its values before it
|
|
8
|
+
* mounts. The reducer ignores a seed once the draft holds the record, which is
|
|
9
|
+
* what stops a background refetch from overwriting edits in progress.
|
|
10
|
+
*
|
|
11
|
+
* Opening the page counts as a trigger, not just the detail response: the page
|
|
12
|
+
* fetch is cache-guarded, so re-opening a form for a record already loaded this
|
|
13
|
+
* session issues no request at all — and a draft cleared in between (by a save
|
|
14
|
+
* or a cancel) would have nothing left to seed it.
|
|
11
15
|
*/
|
|
12
|
-
export const seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.pipe(filter(updateInvoicingCouponDetail.match
|
|
16
|
+
export const seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.pipe(filter((action) => updateInvoicingCouponDetail.match(action) ||
|
|
17
|
+
fetchInvoicingCouponDetailPage.match(action)), withLatestFrom(state$), mergeMap(([action, state]) => {
|
|
13
18
|
const { id } = action.payload;
|
|
19
|
+
if (id == null) {
|
|
20
|
+
return EMPTY;
|
|
21
|
+
}
|
|
22
|
+
// The entity alone does not say the whole record is loaded — the list
|
|
23
|
+
// endpoints merge their own list-shaped rows into the same store. Only a
|
|
24
|
+
// completed detail load does, which is also exactly when the page's
|
|
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.
|
|
29
|
+
if (fetchInvoicingCouponDetailPage.match(action) &&
|
|
30
|
+
(action.payload.cacheOverride === true ||
|
|
31
|
+
state.editInvoicingCouponDetailViewState.recordStateById[id]
|
|
32
|
+
?.fetchState !== 'Completed')) {
|
|
33
|
+
return EMPTY;
|
|
34
|
+
}
|
|
35
|
+
// Nothing to seed from on a cold open; the detail response triggers this
|
|
36
|
+
// again once it lands.
|
|
14
37
|
const coupon = getInvoicingCouponById(state.invoicingCouponState, id);
|
|
15
38
|
if (coupon == null) {
|
|
16
39
|
return EMPTY;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { clearAll } from '../../../rootActions';
|
|
3
|
+
import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSaved, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
|
|
3
4
|
import { initialInvoicingCustomerFormLocalData } from './invoicingCustomerFormConfig';
|
|
4
5
|
export const initialState = {
|
|
5
6
|
emailPreviewFetchState: { fetchState: 'Not-Started', error: undefined },
|
|
@@ -7,6 +8,7 @@ export const initialState = {
|
|
|
7
8
|
emailPreviewCustomerId: undefined,
|
|
8
9
|
promotionalCreditSubmitState: { fetchState: 'Not-Started', error: undefined },
|
|
9
10
|
recordStateById: {},
|
|
11
|
+
billingAddressOwnerId: undefined,
|
|
10
12
|
fetchState: 'Not-Started',
|
|
11
13
|
error: undefined,
|
|
12
14
|
editDraftById: {},
|
|
@@ -123,20 +125,17 @@ const editInvoicingCustomerDetailView = createSlice({
|
|
|
123
125
|
fetchState: 'Error',
|
|
124
126
|
error: action.payload.status,
|
|
125
127
|
};
|
|
128
|
+
applyInvoicingFormDraftFailure(draft.editDraftById, action.payload.id, initialInvoicingCustomerFormLocalData);
|
|
126
129
|
},
|
|
127
|
-
/**
|
|
128
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
129
|
-
* exists so a late refetch cannot overwrite in-progress edits.
|
|
130
|
-
*/
|
|
130
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
131
131
|
seedInvoicingCustomerFormDraft(draft, action) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
132
|
+
const { id, localData } = action.payload;
|
|
133
|
+
applyInvoicingFormDraftSeed(draft.editDraftById, id, localData);
|
|
135
134
|
},
|
|
136
135
|
updateInvoicingCustomerFormDraft(draft, action) {
|
|
137
136
|
const { id, localData } = action.payload;
|
|
138
137
|
if (id != null) {
|
|
139
|
-
draft.editDraftById
|
|
138
|
+
applyInvoicingFormDraftEdit(draft.editDraftById, id, localData);
|
|
140
139
|
}
|
|
141
140
|
else {
|
|
142
141
|
draft.newCustomerDraft = localData;
|
|
@@ -156,17 +155,30 @@ const editInvoicingCustomerDetailView = createSlice({
|
|
|
156
155
|
draft.fetchState = 'Completed';
|
|
157
156
|
draft.error = undefined;
|
|
158
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);
|
|
159
161
|
},
|
|
160
162
|
submitInvoicingCustomerFormFailure(draft, action) {
|
|
161
163
|
draft.fetchState = 'Error';
|
|
162
164
|
draft.error = action.payload;
|
|
163
165
|
},
|
|
164
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Discard a form's draft — the customer's own when `id` is given,
|
|
168
|
+
* the create draft otherwise. Scoped to the one form on purpose: another
|
|
169
|
+
* customer's half-finished edit is not this form's to throw away.
|
|
170
|
+
* Clearing every draft at once is what `clearAll` is for.
|
|
171
|
+
*/
|
|
172
|
+
resetEditInvoicingCustomerDetailView(draft, action) {
|
|
165
173
|
draft.fetchState = 'Not-Started';
|
|
166
174
|
draft.error = undefined;
|
|
167
175
|
draft.savedCustomerId = undefined;
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
const id = action.payload?.id;
|
|
177
|
+
if (id == null) {
|
|
178
|
+
draft.newCustomerDraft = { ...initialInvoicingCustomerFormLocalData };
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
delete draft.editDraftById[id];
|
|
170
182
|
},
|
|
171
183
|
// Trigger only — handled by initializeInvoicingCustomerAddressEpic.
|
|
172
184
|
initializeInvoicingCustomerAddress: {
|
|
@@ -175,6 +187,10 @@ const editInvoicingCustomerDetailView = createSlice({
|
|
|
175
187
|
return { payload };
|
|
176
188
|
},
|
|
177
189
|
},
|
|
190
|
+
/** Record which customer the shared billing-address slot now belongs to. */
|
|
191
|
+
claimInvoicingCustomerBillingAddress(draft, action) {
|
|
192
|
+
draft.billingAddressOwnerId = action.payload.id;
|
|
193
|
+
},
|
|
178
194
|
},
|
|
179
195
|
extraReducers: (builder) => {
|
|
180
196
|
builder.addCase(clearAll, (draft) => {
|
|
@@ -182,5 +198,5 @@ const editInvoicingCustomerDetailView = createSlice({
|
|
|
182
198
|
});
|
|
183
199
|
},
|
|
184
200
|
});
|
|
185
|
-
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;
|
|
186
202
|
export default editInvoicingCustomerDetailView.reducer;
|
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
5
6
|
import { getFormattedAddress } from '../../addressView/addressViewSelector';
|
|
6
7
|
import { getInvoicingPaymentLinkSendState, getInvoicingPaymentMethodSaveState, getInvoicingPlaidLinkToken, getInvoicingPlaidLinkTokenFetchState, getInvoicingSentPaymentLinkEmail, getInvoicingSentPaymentLinkMagicUrl, getInvoicingSetupIntent, getInvoicingSetupIntentFetchState, } from '../customerPaymentMethod/customerPaymentMethodSelector';
|
|
7
8
|
import { getInvoicingConfigView, invoicingFieldHelpForGroup, } from '../invoicingConfigView/invoicingConfigViewSelector';
|
|
9
|
+
import { getInvoicingFormDraftLocalData, isInvoicingFormDraftPending, } from '../invoicingFormDraft';
|
|
8
10
|
import { isStripeConnectedFromSettings } from '../settingsView/invoicingSettingsHelpers';
|
|
9
11
|
import { getInvoicingSettings } from '../settingsView/settingsViewSelector';
|
|
10
12
|
import { INVOICING_CUSTOMER_BILLING_ADDRESS_TYPE, initialInvoicingCustomerFormLocalData, } from './invoicingCustomerFormConfig';
|
|
@@ -49,6 +51,37 @@ export const getInvoicingCustomerRecord = (state, invoicingCustomerID) => {
|
|
|
49
51
|
* fetch state/error, and the id of the customer last saved — so the form screen
|
|
50
52
|
* depends on this single selector.
|
|
51
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
|
+
};
|
|
52
85
|
export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
53
86
|
const { editDraftById, error, fetchState, newCustomerDraft, savedCustomerId } = state.editInvoicingCustomerDetailViewState;
|
|
54
87
|
const mode = invoicingCustomerID != null ? 'edit' : 'create';
|
|
@@ -59,8 +92,7 @@ export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
59
92
|
// `seedInvoicingCustomerFormDraftEpic` when the detail load lands. Until then
|
|
60
93
|
// the page is showing its skeleton.
|
|
61
94
|
const localData = invoicingCustomerID != null
|
|
62
|
-
? (editDraftById
|
|
63
|
-
initialInvoicingCustomerFormLocalData)
|
|
95
|
+
? getInvoicingFormDraftLocalData(editDraftById, invoicingCustomerID, initialInvoicingCustomerFormLocalData)
|
|
64
96
|
: newCustomerDraft;
|
|
65
97
|
// Billing address is captured via the shared Address screen and seeded there
|
|
66
98
|
// (from the address entity) on detail load, so the formatted label comes from
|
|
@@ -78,6 +110,7 @@ export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
78
110
|
? { error: undefined, fetchState: 'Completed' }
|
|
79
111
|
: (state.editInvoicingCustomerDetailViewState.recordStateById[invoicingCustomerID] ?? { error: undefined, fetchState: 'Not-Started' });
|
|
80
112
|
const { emailPreview, emailPreviewCustomerId, emailPreviewFetchState } = state.editInvoicingCustomerDetailViewState;
|
|
113
|
+
const isFormLoading = isInvoicingFormDraftPending(editDraftById, invoicingCustomerID);
|
|
81
114
|
return {
|
|
82
115
|
// A preview cached for another customer is not this screen's.
|
|
83
116
|
emailPreview: emailPreviewCustomerId === invoicingCustomerID ? emailPreview : undefined,
|
|
@@ -92,6 +125,7 @@ export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
92
125
|
promotionalCreditSubmitState: state.editInvoicingCustomerDetailViewState.promotionalCreditSubmitState,
|
|
93
126
|
record: getInvoicingCustomerRecord(state, invoicingCustomerID),
|
|
94
127
|
fieldHelp: invoicingFieldHelpForGroup(state, 'customer'),
|
|
128
|
+
isFormLoading,
|
|
95
129
|
customerTypeOptions,
|
|
96
130
|
localData,
|
|
97
131
|
mode,
|
|
@@ -99,6 +133,7 @@ export const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
99
133
|
taxabilityOptions,
|
|
100
134
|
billingAddressId,
|
|
101
135
|
billingAddressLabel,
|
|
136
|
+
hasUnsavedBillingAddress: isBillingAddressUnsaved(state, invoicingCustomerID, customer?.billingAddressId),
|
|
102
137
|
savedCustomerId,
|
|
103
138
|
fetchState,
|
|
104
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
|
}));
|
|
@@ -16,7 +16,7 @@ export const saveInvoicingCustomerEpic = (actions$, state$, zeniAPI) => actions$
|
|
|
16
16
|
const rootState = state$.value;
|
|
17
17
|
const viewState = rootState.editInvoicingCustomerDetailViewState;
|
|
18
18
|
const localData = (id != null
|
|
19
|
-
? viewState.editDraftById[id]
|
|
19
|
+
? viewState.editDraftById[id]?.localData
|
|
20
20
|
: viewState.newCustomerDraft) ?? viewState.newCustomerDraft;
|
|
21
21
|
// Billing address captured via the shared Address screen is sent as an
|
|
22
22
|
// object in the payload; the backend creates it and returns its id
|
package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { EMPTY, of } from 'rxjs';
|
|
2
2
|
import { filter, mergeMap, withLatestFrom } from 'rxjs/operators';
|
|
3
3
|
import { getInvoicingCustomerById } from '../../../entity/invoicing/invoicingCustomer/invoicingCustomerSelector';
|
|
4
|
-
import { seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail, } from './editInvoicingCustomerDetailViewReducer';
|
|
4
|
+
import { fetchInvoicingCustomerDetailPage, seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail, } from './editInvoicingCustomerDetailViewReducer';
|
|
5
5
|
import { entityToInvoicingCustomerFormLocalData } from './invoicingCustomerFormConfig';
|
|
6
6
|
/**
|
|
7
|
-
* Seeds the edit draft from the record the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Seeds the edit draft from the record, so the form has its values before it
|
|
8
|
+
* mounts. The reducer ignores a seed once the draft holds the record, which is
|
|
9
|
+
* what stops a background refetch from overwriting edits in progress.
|
|
10
|
+
*
|
|
11
|
+
* Opening the page counts as a trigger, not just the detail response: the page
|
|
12
|
+
* fetch is cache-guarded, so re-opening for a record already loaded this
|
|
13
|
+
* session issues no request at all — and a draft cleared in between (by a save
|
|
14
|
+
* or a cancel) would have nothing left to seed it.
|
|
11
15
|
*/
|
|
12
|
-
export const seedInvoicingCustomerFormDraftEpic = (actions$, state$) => actions$.pipe(filter(updateInvoicingCustomerDetail.match
|
|
16
|
+
export const seedInvoicingCustomerFormDraftEpic = (actions$, state$) => actions$.pipe(filter((action) => updateInvoicingCustomerDetail.match(action) ||
|
|
17
|
+
fetchInvoicingCustomerDetailPage.match(action)), withLatestFrom(state$), mergeMap(([action, state]) => {
|
|
13
18
|
const { id } = action.payload;
|
|
19
|
+
if (id == null) {
|
|
20
|
+
return EMPTY;
|
|
21
|
+
}
|
|
22
|
+
// The entity alone does not say the whole record is loaded — the list
|
|
23
|
+
// endpoints merge their own list-shaped rows into the same store. Only a
|
|
24
|
+
// completed detail load does, which is also exactly when the page's
|
|
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.
|
|
29
|
+
if (fetchInvoicingCustomerDetailPage.match(action) &&
|
|
30
|
+
(action.payload.cacheOverride === true ||
|
|
31
|
+
state.editInvoicingCustomerDetailViewState.recordStateById[id]
|
|
32
|
+
?.fetchState !== 'Completed')) {
|
|
33
|
+
return EMPTY;
|
|
34
|
+
}
|
|
35
|
+
// Nothing to seed from on a cold open; the detail response triggers this
|
|
36
|
+
// again once it lands.
|
|
14
37
|
const customer = getInvoicingCustomerById(state.invoicingCustomerState, id);
|
|
15
38
|
if (customer == null) {
|
|
16
39
|
return EMPTY;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSlice } from '@reduxjs/toolkit';
|
|
2
2
|
import { clearAll } from '../../../rootActions';
|
|
3
|
+
import { applyInvoicingFormDraftEdit, applyInvoicingFormDraftFailure, applyInvoicingFormDraftSaved, applyInvoicingFormDraftSeed, } from '../invoicingFormDraft';
|
|
3
4
|
import { initialInvoicingSubscriptionFormLocalData } from './invoicingSubscriptionFormConfig';
|
|
4
5
|
export const initialState = {
|
|
5
6
|
fetchState: 'Not-Started',
|
|
@@ -7,6 +8,7 @@ export const initialState = {
|
|
|
7
8
|
editDraftById: {},
|
|
8
9
|
actionStateById: {},
|
|
9
10
|
recordStateById: {},
|
|
11
|
+
shippingAddressOwnerId: undefined,
|
|
10
12
|
newSubscriptionDraft: { ...initialInvoicingSubscriptionFormLocalData },
|
|
11
13
|
savedSubscriptionId: undefined,
|
|
12
14
|
hasValidState() {
|
|
@@ -65,15 +67,12 @@ const editInvoicingSubscriptionDetailView = createSlice({
|
|
|
65
67
|
fetchState: 'Error',
|
|
66
68
|
error: action.payload.error,
|
|
67
69
|
};
|
|
70
|
+
applyInvoicingFormDraftFailure(draft.editDraftById, action.payload.id, initialInvoicingSubscriptionFormLocalData);
|
|
68
71
|
},
|
|
69
|
-
/**
|
|
70
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
71
|
-
* exists so a late refetch cannot overwrite in-progress edits.
|
|
72
|
-
*/
|
|
72
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
73
73
|
seedInvoicingSubscriptionFormDraft(draft, action) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
74
|
+
const { id, localData } = action.payload;
|
|
75
|
+
applyInvoicingFormDraftSeed(draft.editDraftById, id, localData);
|
|
77
76
|
},
|
|
78
77
|
fetchInvoicingSubscriptionFormPage: {
|
|
79
78
|
reducer() {
|
|
@@ -87,7 +86,7 @@ const editInvoicingSubscriptionDetailView = createSlice({
|
|
|
87
86
|
updateInvoicingSubscriptionFormDraft(draft, action) {
|
|
88
87
|
const { id, localData } = action.payload;
|
|
89
88
|
if (id != null) {
|
|
90
|
-
draft.editDraftById
|
|
89
|
+
applyInvoicingFormDraftEdit(draft.editDraftById, id, localData);
|
|
91
90
|
}
|
|
92
91
|
else {
|
|
93
92
|
draft.newSubscriptionDraft = localData;
|
|
@@ -107,19 +106,32 @@ const editInvoicingSubscriptionDetailView = createSlice({
|
|
|
107
106
|
draft.fetchState = 'Completed';
|
|
108
107
|
draft.error = undefined;
|
|
109
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);
|
|
110
112
|
},
|
|
111
113
|
submitInvoicingSubscriptionFormFailure(draft, action) {
|
|
112
114
|
draft.fetchState = 'Error';
|
|
113
115
|
draft.error = action.payload;
|
|
114
116
|
},
|
|
115
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Discard a form's draft — the subscription's own when `id` is given,
|
|
119
|
+
* the create draft otherwise. Scoped to the one form on purpose: another
|
|
120
|
+
* subscription's half-finished edit is not this form's to throw away.
|
|
121
|
+
* Clearing every draft at once is what `clearAll` is for.
|
|
122
|
+
*/
|
|
123
|
+
resetEditInvoicingSubscriptionDetailView(draft, action) {
|
|
116
124
|
draft.fetchState = 'Not-Started';
|
|
117
125
|
draft.error = undefined;
|
|
118
126
|
draft.savedSubscriptionId = undefined;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
const id = action.payload?.id;
|
|
128
|
+
if (id == null) {
|
|
129
|
+
draft.newSubscriptionDraft = {
|
|
130
|
+
...initialInvoicingSubscriptionFormLocalData,
|
|
131
|
+
};
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
delete draft.editDraftById[id];
|
|
123
135
|
},
|
|
124
136
|
// Trigger only — handled by initializeInvoicingSubscriptionAddressEpic.
|
|
125
137
|
initializeInvoicingSubscriptionAddress: {
|
|
@@ -128,6 +140,10 @@ const editInvoicingSubscriptionDetailView = createSlice({
|
|
|
128
140
|
return { payload };
|
|
129
141
|
},
|
|
130
142
|
},
|
|
143
|
+
/** Record which subscription the shared shipping-address slot now belongs to. */
|
|
144
|
+
claimInvoicingSubscriptionShippingAddress(draft, action) {
|
|
145
|
+
draft.shippingAddressOwnerId = action.payload.id;
|
|
146
|
+
},
|
|
131
147
|
// Trigger only — handled by syncInvoicingSubscriptionCouponsEpic.
|
|
132
148
|
syncInvoicingSubscriptionCoupons: {
|
|
133
149
|
reducer() { },
|
|
@@ -142,5 +158,5 @@ const editInvoicingSubscriptionDetailView = createSlice({
|
|
|
142
158
|
});
|
|
143
159
|
},
|
|
144
160
|
});
|
|
145
|
-
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;
|
|
146
162
|
export default editInvoicingSubscriptionDetailView.reducer;
|