@zeniai/client-epic-state 5.2.49 → 5.2.50
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/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +19 -11
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +4 -1
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +3 -2
- package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +26 -7
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +19 -11
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +3 -1
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +1 -1
- package/lib/esm/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +25 -6
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +19 -11
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +4 -2
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/saveInvoicingCustomerEpic.js +1 -1
- package/lib/esm/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js +25 -6
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +21 -13
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +3 -2
- package/lib/esm/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
- 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/invoicingFormDraft.js +65 -0
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewReducer.js +19 -11
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.d.ts +10 -0
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewSelector.js +4 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/editInvoicingCatalogItemDetailViewState.d.ts +2 -1
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js +3 -2
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingCatalogItemDetailView/seedInvoicingCatalogItemFormDraftEpic.js +25 -6
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js +19 -11
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts +13 -0
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js +3 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.d.ts +2 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/saveInvoicingCouponEpic.js +1 -1
- package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.d.ts +10 -6
- package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js +24 -5
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js +19 -11
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.d.ts +9 -0
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewSelector.js +4 -2
- package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts +2 -1
- 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 +24 -5
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.d.ts +3 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewReducer.js +21 -13
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.d.ts +9 -0
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewSelector.js +3 -2
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/editInvoicingSubscriptionDetailViewState.d.ts +2 -1
- package/lib/view/invoicing/editInvoicingSubscriptionDetailView/fetchInvoicingSubscriptionFormPageEpic.js +4 -1
- 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/invoicingFormDraft.d.ts +54 -0
- package/lib/view/invoicing/invoicingFormDraft.js +72 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ const invoicingCustomerSelector_2 = require("../../../entity/invoicing/invoicing
|
|
|
8
8
|
const addressViewSelector_1 = require("../../addressView/addressViewSelector");
|
|
9
9
|
const customerPaymentMethodSelector_1 = require("../customerPaymentMethod/customerPaymentMethodSelector");
|
|
10
10
|
const invoicingConfigViewSelector_1 = require("../invoicingConfigView/invoicingConfigViewSelector");
|
|
11
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
11
12
|
const invoicingSettingsHelpers_1 = require("../settingsView/invoicingSettingsHelpers");
|
|
12
13
|
const settingsViewSelector_1 = require("../settingsView/settingsViewSelector");
|
|
13
14
|
const invoicingCustomerFormConfig_1 = require("./invoicingCustomerFormConfig");
|
|
@@ -63,8 +64,7 @@ const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
63
64
|
// `seedInvoicingCustomerFormDraftEpic` when the detail load lands. Until then
|
|
64
65
|
// the page is showing its skeleton.
|
|
65
66
|
const localData = invoicingCustomerID != null
|
|
66
|
-
? (editDraftById
|
|
67
|
-
invoicingCustomerFormConfig_1.initialInvoicingCustomerFormLocalData)
|
|
67
|
+
? (0, invoicingFormDraft_1.getInvoicingFormDraftLocalData)(editDraftById, invoicingCustomerID, invoicingCustomerFormConfig_1.initialInvoicingCustomerFormLocalData)
|
|
68
68
|
: newCustomerDraft;
|
|
69
69
|
// Billing address is captured via the shared Address screen and seeded there
|
|
70
70
|
// (from the address entity) on detail load, so the formatted label comes from
|
|
@@ -82,6 +82,7 @@ const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
82
82
|
? { error: undefined, fetchState: 'Completed' }
|
|
83
83
|
: (state.editInvoicingCustomerDetailViewState.recordStateById[invoicingCustomerID] ?? { error: undefined, fetchState: 'Not-Started' });
|
|
84
84
|
const { emailPreview, emailPreviewCustomerId, emailPreviewFetchState } = state.editInvoicingCustomerDetailViewState;
|
|
85
|
+
const isFormLoading = (0, invoicingFormDraft_1.isInvoicingFormDraftPending)(editDraftById, invoicingCustomerID);
|
|
85
86
|
return {
|
|
86
87
|
// A preview cached for another customer is not this screen's.
|
|
87
88
|
emailPreview: emailPreviewCustomerId === invoicingCustomerID ? emailPreview : undefined,
|
|
@@ -96,6 +97,7 @@ const getInvoicingCustomerFormView = (state, invoicingCustomerID) => {
|
|
|
96
97
|
promotionalCreditSubmitState: state.editInvoicingCustomerDetailViewState.promotionalCreditSubmitState,
|
|
97
98
|
record: (0, exports.getInvoicingCustomerRecord)(state, invoicingCustomerID),
|
|
98
99
|
fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'customer'),
|
|
100
|
+
isFormLoading,
|
|
99
101
|
customerTypeOptions,
|
|
100
102
|
localData,
|
|
101
103
|
mode,
|
package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewState.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
|
|
2
|
+
import { InvoicingFormDraftById } from '../invoicingFormDraft';
|
|
2
3
|
/**
|
|
3
4
|
* The payment-link email the composer opens with: the backend's prefill plus
|
|
4
5
|
* the tokens the frontend splices the user's edits into. State, not wire shape
|
|
@@ -37,7 +38,7 @@ export interface InvoicingCustomerFormLocalData {
|
|
|
37
38
|
vatNumber: string;
|
|
38
39
|
}
|
|
39
40
|
export interface EditInvoicingCustomerDetailViewState extends FetchedState {
|
|
40
|
-
editDraftById:
|
|
41
|
+
editDraftById: InvoicingFormDraftById<InvoicingCustomerFormLocalData>;
|
|
41
42
|
/**
|
|
42
43
|
* The payment-link email rendered by the backend, cached per customer so
|
|
43
44
|
* reopening the composer costs nothing. `emailPreviewCustomerId` is the cache
|
|
@@ -19,7 +19,7 @@ const saveInvoicingCustomerEpic = (actions$, state$, zeniAPI) => actions$.pipe((
|
|
|
19
19
|
const rootState = state$.value;
|
|
20
20
|
const viewState = rootState.editInvoicingCustomerDetailViewState;
|
|
21
21
|
const localData = (id != null
|
|
22
|
-
? viewState.editDraftById[id]
|
|
22
|
+
? viewState.editDraftById[id]?.localData
|
|
23
23
|
: viewState.newCustomerDraft) ?? viewState.newCustomerDraft;
|
|
24
24
|
// Billing address captured via the shared Address screen is sent as an
|
|
25
25
|
// object in the payload; the backend creates it and returns its id
|
package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { RootState } from '../../../rootStateTypes';
|
|
4
|
-
import { seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail } from './editInvoicingCustomerDetailViewReducer';
|
|
5
|
-
export type ActionType = ReturnType<typeof updateInvoicingCustomerDetail> | ReturnType<typeof seedInvoicingCustomerFormDraft>;
|
|
4
|
+
import { fetchInvoicingCustomerDetailPage, seedInvoicingCustomerFormDraft, updateInvoicingCustomerDetail } from './editInvoicingCustomerDetailViewReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof fetchInvoicingCustomerDetailPage> | ReturnType<typeof updateInvoicingCustomerDetail> | ReturnType<typeof seedInvoicingCustomerFormDraft>;
|
|
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
16
|
export declare const seedInvoicingCustomerFormDraftEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|
package/lib/view/invoicing/editInvoicingCustomerDetailView/seedInvoicingCustomerFormDraftEpic.js
CHANGED
|
@@ -7,13 +7,32 @@ const invoicingCustomerSelector_1 = require("../../../entity/invoicing/invoicing
|
|
|
7
7
|
const editInvoicingCustomerDetailViewReducer_1 = require("./editInvoicingCustomerDetailViewReducer");
|
|
8
8
|
const invoicingCustomerFormConfig_1 = require("./invoicingCustomerFormConfig");
|
|
9
9
|
/**
|
|
10
|
-
* Seeds the edit draft from the record the
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Seeds the edit draft from the record, so the form has its values before it
|
|
11
|
+
* mounts. The reducer ignores a seed once the draft holds the record, which is
|
|
12
|
+
* what stops a background refetch from overwriting edits in progress.
|
|
13
|
+
*
|
|
14
|
+
* Opening the page counts as a trigger, not just the detail response: the page
|
|
15
|
+
* fetch is cache-guarded, so re-opening for a record already loaded this
|
|
16
|
+
* session issues no request at all — and a draft cleared in between (by a save
|
|
17
|
+
* or a cancel) would have nothing left to seed it.
|
|
14
18
|
*/
|
|
15
|
-
const seedInvoicingCustomerFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(editInvoicingCustomerDetailViewReducer_1.updateInvoicingCustomerDetail.match
|
|
19
|
+
const seedInvoicingCustomerFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)((action) => editInvoicingCustomerDetailViewReducer_1.updateInvoicingCustomerDetail.match(action) ||
|
|
20
|
+
editInvoicingCustomerDetailViewReducer_1.fetchInvoicingCustomerDetailPage.match(action)), (0, operators_1.withLatestFrom)(state$), (0, operators_1.mergeMap)(([action, state]) => {
|
|
16
21
|
const { id } = action.payload;
|
|
22
|
+
if (id == null) {
|
|
23
|
+
return rxjs_1.EMPTY;
|
|
24
|
+
}
|
|
25
|
+
// The entity alone does not say the whole record is loaded — the list
|
|
26
|
+
// endpoints merge their own list-shaped rows into the same store. Only a
|
|
27
|
+
// completed detail load does, which is also exactly when the page's
|
|
28
|
+
// cache-guarded fetch issues no request and this is the sole seed.
|
|
29
|
+
if (editInvoicingCustomerDetailViewReducer_1.fetchInvoicingCustomerDetailPage.match(action) &&
|
|
30
|
+
state.editInvoicingCustomerDetailViewState.recordStateById[id]
|
|
31
|
+
?.fetchState !== 'Completed') {
|
|
32
|
+
return rxjs_1.EMPTY;
|
|
33
|
+
}
|
|
34
|
+
// Nothing to seed from on a cold open; the detail response triggers this
|
|
35
|
+
// again once it lands.
|
|
17
36
|
const customer = (0, invoicingCustomerSelector_1.getInvoicingCustomerById)(state.invoicingCustomerState, id);
|
|
18
37
|
if (customer == null) {
|
|
19
38
|
return rxjs_1.EMPTY;
|
|
@@ -55,6 +55,8 @@ export declare const runInvoicingSubscriptionAction: import("@reduxjs/toolkit").
|
|
|
55
55
|
id: ID;
|
|
56
56
|
}, "editInvoicingSubscriptionDetailView/updateInvoicingSubscriptionDetailFailure">, updateInvoicingSubscriptionFormDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<UpdateInvoicingSubscriptionFormDraftPayload, "editInvoicingSubscriptionDetailView/updateInvoicingSubscriptionFormDraft">, submitInvoicingSubscriptionForm: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SubmitInvoicingSubscriptionFormPayload], SubmitInvoicingSubscriptionFormPayload, "editInvoicingSubscriptionDetailView/submitInvoicingSubscriptionForm", never, never>, submitInvoicingSubscriptionFormSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
57
57
|
subscriptionId: ID;
|
|
58
|
-
}, "editInvoicingSubscriptionDetailView/submitInvoicingSubscriptionFormSuccess">, submitInvoicingSubscriptionFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingSubscriptionDetailView/submitInvoicingSubscriptionFormFailure">, resetEditInvoicingSubscriptionDetailView: import("@reduxjs/toolkit").
|
|
58
|
+
}, "editInvoicingSubscriptionDetailView/submitInvoicingSubscriptionFormSuccess">, submitInvoicingSubscriptionFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingSubscriptionDetailView/submitInvoicingSubscriptionFormFailure">, resetEditInvoicingSubscriptionDetailView: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<{
|
|
59
|
+
id?: ID;
|
|
60
|
+
} | undefined, "editInvoicingSubscriptionDetailView/resetEditInvoicingSubscriptionDetailView">, initializeInvoicingSubscriptionAddress: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: InitializeInvoicingSubscriptionAddressPayload], InitializeInvoicingSubscriptionAddressPayload, "editInvoicingSubscriptionDetailView/initializeInvoicingSubscriptionAddress", never, never>, syncInvoicingSubscriptionCoupons: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SyncInvoicingSubscriptionCouponsPayload], SyncInvoicingSubscriptionCouponsPayload, "editInvoicingSubscriptionDetailView/syncInvoicingSubscriptionCoupons", never, never>;
|
|
59
61
|
declare const _default: import("redux").Reducer<EditInvoicingSubscriptionDetailViewState>;
|
|
60
62
|
export default _default;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.syncInvoicingSubscriptionCoupons = exports.initializeInvoicingSubscriptionAddress = exports.resetEditInvoicingSubscriptionDetailView = exports.submitInvoicingSubscriptionFormFailure = exports.submitInvoicingSubscriptionFormSuccess = exports.submitInvoicingSubscriptionForm = exports.updateInvoicingSubscriptionFormDraft = exports.updateInvoicingSubscriptionDetailFailure = exports.updateInvoicingSubscriptionDetail = exports.seedInvoicingSubscriptionFormDraft = exports.fetchInvoicingSubscriptionFormPage = exports.fetchInvoicingSubscriptionDetailPage = exports.fetchInvoicingSubscriptionDetail = exports.runInvoicingSubscriptionActionSuccess = exports.runInvoicingSubscriptionActionFailure = exports.runInvoicingSubscriptionAction = exports.initialState = void 0;
|
|
5
5
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
6
|
const rootActions_1 = require("../../../rootActions");
|
|
7
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
7
8
|
const invoicingSubscriptionFormConfig_1 = require("./invoicingSubscriptionFormConfig");
|
|
8
9
|
exports.initialState = {
|
|
9
10
|
fetchState: 'Not-Started',
|
|
@@ -69,15 +70,12 @@ const editInvoicingSubscriptionDetailView = (0, toolkit_1.createSlice)({
|
|
|
69
70
|
fetchState: 'Error',
|
|
70
71
|
error: action.payload.error,
|
|
71
72
|
};
|
|
73
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftFailure)(draft.editDraftById, action.payload.id, invoicingSubscriptionFormConfig_1.initialInvoicingSubscriptionFormLocalData);
|
|
72
74
|
},
|
|
73
|
-
/**
|
|
74
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
75
|
-
* exists so a late refetch cannot overwrite in-progress edits.
|
|
76
|
-
*/
|
|
75
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
77
76
|
seedInvoicingSubscriptionFormDraft(draft, action) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
77
|
+
const { id, localData } = action.payload;
|
|
78
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftSeed)(draft.editDraftById, id, localData);
|
|
81
79
|
},
|
|
82
80
|
fetchInvoicingSubscriptionFormPage: {
|
|
83
81
|
reducer() {
|
|
@@ -91,7 +89,7 @@ const editInvoicingSubscriptionDetailView = (0, toolkit_1.createSlice)({
|
|
|
91
89
|
updateInvoicingSubscriptionFormDraft(draft, action) {
|
|
92
90
|
const { id, localData } = action.payload;
|
|
93
91
|
if (id != null) {
|
|
94
|
-
draft.editDraftById
|
|
92
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftEdit)(draft.editDraftById, id, localData);
|
|
95
93
|
}
|
|
96
94
|
else {
|
|
97
95
|
draft.newSubscriptionDraft = localData;
|
|
@@ -116,14 +114,24 @@ const editInvoicingSubscriptionDetailView = (0, toolkit_1.createSlice)({
|
|
|
116
114
|
draft.fetchState = 'Error';
|
|
117
115
|
draft.error = action.payload;
|
|
118
116
|
},
|
|
119
|
-
|
|
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) {
|
|
120
124
|
draft.fetchState = 'Not-Started';
|
|
121
125
|
draft.error = undefined;
|
|
122
126
|
draft.savedSubscriptionId = undefined;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
const id = action.payload?.id;
|
|
128
|
+
if (id == null) {
|
|
129
|
+
draft.newSubscriptionDraft = {
|
|
130
|
+
...invoicingSubscriptionFormConfig_1.initialInvoicingSubscriptionFormLocalData,
|
|
131
|
+
};
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
delete draft.editDraftById[id];
|
|
127
135
|
},
|
|
128
136
|
// Trigger only — handled by initializeInvoicingSubscriptionAddressEpic.
|
|
129
137
|
initializeInvoicingSubscriptionAddress: {
|
|
@@ -41,6 +41,15 @@ export interface InvoicingSubscriptionFormView extends SelectorView {
|
|
|
41
41
|
* Folded in here so the screen never reaches for the config view itself.
|
|
42
42
|
*/
|
|
43
43
|
fieldHelp: InvoicingFieldHelpByCode;
|
|
44
|
+
/**
|
|
45
|
+
* True while the subscription being edited is still on its way to the form.
|
|
46
|
+
* The form holds a skeleton on this rather than mount: it seeds
|
|
47
|
+
* react-hook-form once, at first render, so fields mounted against the blank
|
|
48
|
+
* draft stay blank and the first change writes that blankness back over the
|
|
49
|
+
* subscription. A later refetch does not raise this again, so a refresh
|
|
50
|
+
* leaves the form on screen instead of blanking it mid-edit.
|
|
51
|
+
*/
|
|
52
|
+
isFormLoading: boolean;
|
|
44
53
|
localData: InvoicingSubscriptionFormLocalData;
|
|
45
54
|
mode: 'create' | 'edit';
|
|
46
55
|
/**
|
|
@@ -8,6 +8,7 @@ const couponViewSelector_1 = require("../couponView/couponViewSelector");
|
|
|
8
8
|
const invoicingCatalogListViewSelector_1 = require("../invoicingCatalogListView/invoicingCatalogListViewSelector");
|
|
9
9
|
const invoicingConfigViewSelector_1 = require("../invoicingConfigView/invoicingConfigViewSelector");
|
|
10
10
|
const invoicingCustomerListViewSelector_1 = require("../invoicingCustomerListView/invoicingCustomerListViewSelector");
|
|
11
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
11
12
|
const invoicingSubscriptionFormConfig_1 = require("./invoicingSubscriptionFormConfig");
|
|
12
13
|
const invoicingSubscriptionFormConfig_2 = require("./invoicingSubscriptionFormConfig");
|
|
13
14
|
const getEditInvoicingSubscriptionDetailViewState = (state, invoicingSubscriptionID) => {
|
|
@@ -37,8 +38,7 @@ const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
|
|
|
37
38
|
// `seedInvoicingSubscriptionFormDraftEpic` when the detail load lands. Until
|
|
38
39
|
// then the page is showing its skeleton.
|
|
39
40
|
const localData = invoicingSubscriptionID != null
|
|
40
|
-
? (editDraftById
|
|
41
|
-
invoicingSubscriptionFormConfig_1.initialInvoicingSubscriptionFormLocalData)
|
|
41
|
+
? (0, invoicingFormDraft_1.getInvoicingFormDraftLocalData)(editDraftById, invoicingSubscriptionID, invoicingSubscriptionFormConfig_1.initialInvoicingSubscriptionFormLocalData)
|
|
42
42
|
: newSubscriptionDraft;
|
|
43
43
|
// Shipping address is captured via the shared Address screen and seeded there
|
|
44
44
|
// (looked up in the shared address store by `shippingAddressId`) on detail
|
|
@@ -69,6 +69,7 @@ const getInvoicingSubscriptionFormView = (state, invoicingSubscriptionID) => {
|
|
|
69
69
|
subscriptionLifecycleActionOptions: configState.subscriptionLifecycleActionOptions,
|
|
70
70
|
subscriptionMetadataEditAllowedFromStatuses: configState.subscriptionMetadataEditAllowedFromStatuses,
|
|
71
71
|
recordState,
|
|
72
|
+
isFormLoading: (0, invoicingFormDraft_1.isInvoicingFormDraftPending)(editDraftById, invoicingSubscriptionID),
|
|
72
73
|
fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'subscription'),
|
|
73
74
|
coupons: (0, couponViewSelector_1.getInvoicingCouponListItems)(state),
|
|
74
75
|
customers: (0, invoicingCustomerListViewSelector_1.getInvoicingCustomerListView)(state).customers,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Amount } from '../../../commonStateTypes/amount';
|
|
2
2
|
import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
|
|
3
|
+
import { InvoicingFormDraftById } from '../invoicingFormDraft';
|
|
3
4
|
/**
|
|
4
5
|
* Draft form state for the create/edit subscription form. Held in CES so the
|
|
5
6
|
* form flows its data from here (mirrors the customer form / bill-pay pattern).
|
|
@@ -41,7 +42,7 @@ export interface InvoicingSubscriptionFormLocalData {
|
|
|
41
42
|
export interface EditInvoicingSubscriptionDetailViewState extends FetchedState {
|
|
42
43
|
/** Lifecycle action fetch state per subscription id. */
|
|
43
44
|
actionStateById: Record<ID, FetchStateAndError>;
|
|
44
|
-
editDraftById:
|
|
45
|
+
editDraftById: InvoicingFormDraftById<InvoicingSubscriptionFormLocalData>;
|
|
45
46
|
newSubscriptionDraft: InvoicingSubscriptionFormLocalData;
|
|
46
47
|
/** Detail-load state per subscription id. */
|
|
47
48
|
recordStateById: Record<ID, FetchStateAndError>;
|
|
@@ -19,8 +19,11 @@ const fetchInvoicingSubscriptionFormPageEpic = (actions$) => actions$.pipe((0, o
|
|
|
19
19
|
const { subscriptionId } = action.payload;
|
|
20
20
|
const pageActions = [
|
|
21
21
|
(0, invoicingCustomerListViewReducer_1.fetchInvoicingCustomerList)({ filters: {}, keepExistingListItems: false }),
|
|
22
|
+
// Plans only: the form's plan picker is the one consumer, and an
|
|
23
|
+
// unfiltered list would replace the store's plans with every catalog
|
|
24
|
+
// item.
|
|
22
25
|
(0, invoicingCatalogListViewReducer_1.fetchInvoicingCatalogPlanList)({
|
|
23
|
-
filters: {},
|
|
26
|
+
filters: { type: 'plan' },
|
|
24
27
|
keepExistingListItems: false,
|
|
25
28
|
}),
|
|
26
29
|
(0, couponViewReducer_1.fetchInvoicingCouponList)({ filters: {}, keepExistingListItems: false }),
|
package/lib/view/invoicing/editInvoicingSubscriptionDetailView/saveInvoicingSubscriptionEpic.js
CHANGED
|
@@ -20,7 +20,7 @@ const saveInvoicingSubscriptionEpic = (actions$, state$, zeniAPI) => actions$.pi
|
|
|
20
20
|
const rootState = state$.value;
|
|
21
21
|
const viewState = rootState.editInvoicingSubscriptionDetailViewState;
|
|
22
22
|
const localData = (id != null
|
|
23
|
-
? viewState.editDraftById[id]
|
|
23
|
+
? viewState.editDraftById[id]?.localData
|
|
24
24
|
: viewState.newSubscriptionDraft) ?? viewState.newSubscriptionDraft;
|
|
25
25
|
// Shipping address captured via the shared Address screen is sent as an
|
|
26
26
|
// object in the payload (same pattern as the customer save flow).
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { RootState } from '../../../rootStateTypes';
|
|
4
|
-
import { seedInvoicingSubscriptionFormDraft, updateInvoicingSubscriptionDetail } from './editInvoicingSubscriptionDetailViewReducer';
|
|
5
|
-
export type ActionType = ReturnType<typeof updateInvoicingSubscriptionDetail> | ReturnType<typeof seedInvoicingSubscriptionFormDraft>;
|
|
4
|
+
import { fetchInvoicingSubscriptionFormPage, seedInvoicingSubscriptionFormDraft, updateInvoicingSubscriptionDetail } from './editInvoicingSubscriptionDetailViewReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof fetchInvoicingSubscriptionFormPage> | ReturnType<typeof updateInvoicingSubscriptionDetail> | ReturnType<typeof seedInvoicingSubscriptionFormDraft>;
|
|
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
16
|
export declare const seedInvoicingSubscriptionFormDraftEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|
|
@@ -7,14 +7,35 @@ const editInvoicingSubscriptionDetailViewReducer_1 = require("./editInvoicingSub
|
|
|
7
7
|
const invoicingSubscriptionDetailHelper_1 = require("./invoicingSubscriptionDetailHelper");
|
|
8
8
|
const invoicingSubscriptionFormConfig_1 = require("./invoicingSubscriptionFormConfig");
|
|
9
9
|
/**
|
|
10
|
-
* Seeds the edit draft from the record the
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Seeds the edit draft from the record, so the form has its values before it
|
|
11
|
+
* mounts. The reducer ignores a seed once the draft holds the record, which is
|
|
12
|
+
* what stops a background refetch from overwriting edits in progress.
|
|
13
|
+
*
|
|
14
|
+
* Opening the page counts as a trigger, not just the detail response: the page
|
|
15
|
+
* fetch is cache-guarded, so re-opening a form for a record already loaded this
|
|
16
|
+
* session issues no request at all — and a draft cleared in between (by a save
|
|
17
|
+
* or a cancel) would have nothing left to seed it.
|
|
14
18
|
*/
|
|
15
|
-
const seedInvoicingSubscriptionFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionDetail.match
|
|
16
|
-
|
|
17
|
-
const
|
|
19
|
+
const seedInvoicingSubscriptionFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)((action) => editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionDetail.match(action) ||
|
|
20
|
+
editInvoicingSubscriptionDetailViewReducer_1.fetchInvoicingSubscriptionFormPage.match(action)), (0, operators_1.withLatestFrom)(state$), (0, operators_1.mergeMap)(([action, state]) => {
|
|
21
|
+
const id = editInvoicingSubscriptionDetailViewReducer_1.updateInvoicingSubscriptionDetail.match(action)
|
|
22
|
+
? action.payload.id
|
|
23
|
+
: action.payload.subscriptionId;
|
|
24
|
+
if (id == null) {
|
|
25
|
+
return rxjs_1.EMPTY;
|
|
26
|
+
}
|
|
27
|
+
// The entity alone does not say the whole record is loaded — the list
|
|
28
|
+
// endpoints merge their own list-shaped rows into the same store. Only a
|
|
29
|
+
// completed detail load does, which is also exactly when the page's
|
|
30
|
+
// cache-guarded fetch issues no request and this is the sole seed.
|
|
31
|
+
if (editInvoicingSubscriptionDetailViewReducer_1.fetchInvoicingSubscriptionFormPage.match(action) &&
|
|
32
|
+
state.editInvoicingSubscriptionDetailViewState.recordStateById[id]
|
|
33
|
+
?.fetchState !== 'Completed') {
|
|
34
|
+
return rxjs_1.EMPTY;
|
|
35
|
+
}
|
|
36
|
+
// Nothing to seed from on a cold open; the detail response triggers this
|
|
37
|
+
// again once it lands.
|
|
38
|
+
const subscription = id != null ? (0, invoicingSubscriptionDetailHelper_1.getInvoicingSubscriptionById)(state, id) : undefined;
|
|
18
39
|
if (subscription == null) {
|
|
19
40
|
return rxjs_1.EMPTY;
|
|
20
41
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FetchState, ID } from '../../commonStateTypes/common';
|
|
2
|
+
/**
|
|
3
|
+
* A create/edit form's draft, plus where its values came from.
|
|
4
|
+
*
|
|
5
|
+
* The status is what lets an edit form tell "these are the record's values"
|
|
6
|
+
* from "these are whatever the form had at first render". It cannot be read off
|
|
7
|
+
* the presence of a draft, because the form writes drafts too: it pushes its
|
|
8
|
+
* whole state back on every change, so a change made before the record landed
|
|
9
|
+
* leaves a draft that looks seeded but holds nothing.
|
|
10
|
+
*
|
|
11
|
+
* `Not-Started` — written by the form, never filled from a record.
|
|
12
|
+
* `Completed` — filled from the loaded record; the form may have edited it since.
|
|
13
|
+
* `Error` — the record's fetch failed, so the form starts blank and a
|
|
14
|
+
* later successful fetch is still allowed to seed it.
|
|
15
|
+
*/
|
|
16
|
+
export interface InvoicingFormDraft<TLocalData> {
|
|
17
|
+
fetchState: FetchState;
|
|
18
|
+
localData: TLocalData;
|
|
19
|
+
}
|
|
20
|
+
export type InvoicingFormDraftById<TLocalData> = Record<ID, InvoicingFormDraft<TLocalData>>;
|
|
21
|
+
/**
|
|
22
|
+
* The form's own write. Keeps the status: an edit on top of a seeded draft is
|
|
23
|
+
* still the record's draft, and an edit made before the record arrived must not
|
|
24
|
+
* pass for one.
|
|
25
|
+
*/
|
|
26
|
+
export declare function applyInvoicingFormDraftEdit<TLocalData>(draftById: InvoicingFormDraftById<TLocalData>, id: ID, localData: TLocalData): void;
|
|
27
|
+
/**
|
|
28
|
+
* Fill the draft from the loaded record, once. A second seed is ignored so a
|
|
29
|
+
* late refetch cannot overwrite edits in progress — but a draft the form wrote
|
|
30
|
+
* before the record landed is replaced, since it was never the record's.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyInvoicingFormDraftSeed<TLocalData>(draftById: InvoicingFormDraftById<TLocalData>, id: ID, localData: TLocalData): void;
|
|
33
|
+
/**
|
|
34
|
+
* Record that the fetch failed, so the form renders instead of waiting behind a
|
|
35
|
+
* skeleton that will never resolve.
|
|
36
|
+
*
|
|
37
|
+
* Mirrors the seed: a draft holding the record is left alone, since a
|
|
38
|
+
* background refetch failing is no reason to discard it, and anything else is
|
|
39
|
+
* marked failed. A draft the form wrote before the record landed keeps its
|
|
40
|
+
* values — there is no reason to throw away what the user typed — but stops
|
|
41
|
+
* counting as still loading, and a later successful fetch can still seed it.
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyInvoicingFormDraftFailure<TLocalData>(draftById: InvoicingFormDraftById<TLocalData>, id: ID, blankLocalData: TLocalData): void;
|
|
44
|
+
/** The draft's values, or the blank form when nothing is drafted yet. */
|
|
45
|
+
export declare function getInvoicingFormDraftLocalData<TLocalData>(draftById: InvoicingFormDraftById<TLocalData>, id: ID | undefined, blankLocalData: TLocalData): TLocalData;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the form should still be showing its skeleton — the record has
|
|
48
|
+
* neither reached the draft nor failed trying.
|
|
49
|
+
*
|
|
50
|
+
* Settles once and stays settled, which is what keeps a later refetch from
|
|
51
|
+
* swapping a form the user is typing into back for a skeleton. Create mode
|
|
52
|
+
* (no id) has no record to wait for.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isInvoicingFormDraftPending<TLocalData>(draftById: InvoicingFormDraftById<TLocalData>, id: ID | undefined): boolean;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyInvoicingFormDraftEdit = applyInvoicingFormDraftEdit;
|
|
4
|
+
exports.applyInvoicingFormDraftSeed = applyInvoicingFormDraftSeed;
|
|
5
|
+
exports.applyInvoicingFormDraftFailure = applyInvoicingFormDraftFailure;
|
|
6
|
+
exports.getInvoicingFormDraftLocalData = getInvoicingFormDraftLocalData;
|
|
7
|
+
exports.isInvoicingFormDraftPending = isInvoicingFormDraftPending;
|
|
8
|
+
/**
|
|
9
|
+
* The form's own write. Keeps the status: an edit on top of a seeded draft is
|
|
10
|
+
* still the record's draft, and an edit made before the record arrived must not
|
|
11
|
+
* pass for one.
|
|
12
|
+
*/
|
|
13
|
+
function applyInvoicingFormDraftEdit(draftById, id, localData) {
|
|
14
|
+
draftById[id] = {
|
|
15
|
+
fetchState: draftById[id]?.fetchState ?? 'Not-Started',
|
|
16
|
+
localData,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fill the draft from the loaded record, once. A second seed is ignored so a
|
|
21
|
+
* late refetch cannot overwrite edits in progress — but a draft the form wrote
|
|
22
|
+
* before the record landed is replaced, since it was never the record's.
|
|
23
|
+
*/
|
|
24
|
+
function applyInvoicingFormDraftSeed(draftById, id, localData) {
|
|
25
|
+
if (draftById[id]?.fetchState === 'Completed') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
draftById[id] = { fetchState: 'Completed', localData };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Record that the fetch failed, so the form renders instead of waiting behind a
|
|
32
|
+
* skeleton that will never resolve.
|
|
33
|
+
*
|
|
34
|
+
* Mirrors the seed: a draft holding the record is left alone, since a
|
|
35
|
+
* background refetch failing is no reason to discard it, and anything else is
|
|
36
|
+
* marked failed. A draft the form wrote before the record landed keeps its
|
|
37
|
+
* values — there is no reason to throw away what the user typed — but stops
|
|
38
|
+
* counting as still loading, and a later successful fetch can still seed it.
|
|
39
|
+
*/
|
|
40
|
+
function applyInvoicingFormDraftFailure(draftById, id, blankLocalData) {
|
|
41
|
+
const existing = draftById[id];
|
|
42
|
+
if (existing == null) {
|
|
43
|
+
draftById[id] = { fetchState: 'Error', localData: blankLocalData };
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (existing.fetchState === 'Completed') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
existing.fetchState = 'Error';
|
|
50
|
+
}
|
|
51
|
+
/** The draft's values, or the blank form when nothing is drafted yet. */
|
|
52
|
+
function getInvoicingFormDraftLocalData(draftById, id, blankLocalData) {
|
|
53
|
+
if (id == null) {
|
|
54
|
+
return blankLocalData;
|
|
55
|
+
}
|
|
56
|
+
return draftById[id]?.localData ?? blankLocalData;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether the form should still be showing its skeleton — the record has
|
|
60
|
+
* neither reached the draft nor failed trying.
|
|
61
|
+
*
|
|
62
|
+
* Settles once and stays settled, which is what keeps a later refetch from
|
|
63
|
+
* swapping a form the user is typing into back for a skeleton. Create mode
|
|
64
|
+
* (no id) has no record to wait for.
|
|
65
|
+
*/
|
|
66
|
+
function isInvoicingFormDraftPending(draftById, id) {
|
|
67
|
+
if (id == null) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const fetchState = draftById[id]?.fetchState;
|
|
71
|
+
return fetchState !== 'Completed' && fetchState !== 'Error';
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.50",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|