@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The form's own write. Keeps the status: an edit on top of a seeded draft is
|
|
3
|
+
* still the record's draft, and an edit made before the record arrived must not
|
|
4
|
+
* pass for one.
|
|
5
|
+
*/
|
|
6
|
+
export function applyInvoicingFormDraftEdit(draftById, id, localData) {
|
|
7
|
+
draftById[id] = {
|
|
8
|
+
fetchState: draftById[id]?.fetchState ?? 'Not-Started',
|
|
9
|
+
localData,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fill the draft from the loaded record, once. A second seed is ignored so a
|
|
14
|
+
* late refetch cannot overwrite edits in progress — but a draft the form wrote
|
|
15
|
+
* before the record landed is replaced, since it was never the record's.
|
|
16
|
+
*/
|
|
17
|
+
export function applyInvoicingFormDraftSeed(draftById, id, localData) {
|
|
18
|
+
if (draftById[id]?.fetchState === 'Completed') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
draftById[id] = { fetchState: 'Completed', localData };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Record that the fetch failed, so the form renders instead of waiting behind a
|
|
25
|
+
* skeleton that will never resolve.
|
|
26
|
+
*
|
|
27
|
+
* Mirrors the seed: a draft holding the record is left alone, since a
|
|
28
|
+
* background refetch failing is no reason to discard it, and anything else is
|
|
29
|
+
* marked failed. A draft the form wrote before the record landed keeps its
|
|
30
|
+
* values — there is no reason to throw away what the user typed — but stops
|
|
31
|
+
* counting as still loading, and a later successful fetch can still seed it.
|
|
32
|
+
*/
|
|
33
|
+
export function applyInvoicingFormDraftFailure(draftById, id, blankLocalData) {
|
|
34
|
+
const existing = draftById[id];
|
|
35
|
+
if (existing == null) {
|
|
36
|
+
draftById[id] = { fetchState: 'Error', localData: blankLocalData };
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (existing.fetchState === 'Completed') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
existing.fetchState = 'Error';
|
|
43
|
+
}
|
|
44
|
+
/** The draft's values, or the blank form when nothing is drafted yet. */
|
|
45
|
+
export function getInvoicingFormDraftLocalData(draftById, id, blankLocalData) {
|
|
46
|
+
if (id == null) {
|
|
47
|
+
return blankLocalData;
|
|
48
|
+
}
|
|
49
|
+
return draftById[id]?.localData ?? blankLocalData;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether the form should still be showing its skeleton — the record has
|
|
53
|
+
* neither reached the draft nor failed trying.
|
|
54
|
+
*
|
|
55
|
+
* Settles once and stays settled, which is what keeps a later refetch from
|
|
56
|
+
* swapping a form the user is typing into back for a skeleton. Create mode
|
|
57
|
+
* (no id) has no record to wait for.
|
|
58
|
+
*/
|
|
59
|
+
export function isInvoicingFormDraftPending(draftById, id) {
|
|
60
|
+
if (id == null) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const fetchState = draftById[id]?.fetchState;
|
|
64
|
+
return fetchState !== 'Completed' && fetchState !== 'Error';
|
|
65
|
+
}
|
|
@@ -74,6 +74,8 @@ export declare const updateInvoicingCatalogItemFormDraft: import("@reduxjs/toolk
|
|
|
74
74
|
}, "editInvoicingCatalogItemDetailView/runInvoicingCatalogProductActionFailure">, submitInvoicingCatalogItemForm: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SubmitInvoicingCatalogItemFormPayload], SubmitInvoicingCatalogItemFormPayload, "editInvoicingCatalogItemDetailView/submitInvoicingCatalogItemForm", never, never>, submitInvoicingCatalogItemFormSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
75
75
|
itemId: ID;
|
|
76
76
|
kind: InvoicingCatalogItemKind;
|
|
77
|
-
}, "editInvoicingCatalogItemDetailView/submitInvoicingCatalogItemFormSuccess">, submitInvoicingCatalogItemFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCatalogItemDetailView/submitInvoicingCatalogItemFormFailure">, resetEditInvoicingCatalogItemDetailView: import("@reduxjs/toolkit").
|
|
77
|
+
}, "editInvoicingCatalogItemDetailView/submitInvoicingCatalogItemFormSuccess">, submitInvoicingCatalogItemFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCatalogItemDetailView/submitInvoicingCatalogItemFormFailure">, resetEditInvoicingCatalogItemDetailView: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<{
|
|
78
|
+
id?: ID;
|
|
79
|
+
} | undefined, "editInvoicingCatalogItemDetailView/resetEditInvoicingCatalogItemDetailView">;
|
|
78
80
|
declare const _default: import("redux").Reducer<EditInvoicingCatalogItemDetailViewState>;
|
|
79
81
|
export default _default;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.resetEditInvoicingCatalogItemDetailView = exports.submitInvoicingCatalogItemFormFailure = exports.submitInvoicingCatalogItemFormSuccess = exports.submitInvoicingCatalogItemForm = exports.runInvoicingCatalogProductActionFailure = exports.runInvoicingCatalogProductActionSuccess = exports.runInvoicingCatalogProductAction = exports.runInvoicingCatalogPlanActionFailure = exports.runInvoicingCatalogPlanActionSuccess = exports.runInvoicingCatalogPlanAction = exports.seedInvoicingCatalogItemFormDraft = exports.updateInvoicingCatalogItemDetailFailure = exports.updateInvoicingCatalogItemDetail = exports.fetchInvoicingCatalogItemDetailPage = exports.fetchInvoicingCatalogItemDetail = exports.updateInvoicingCatalogItemFormDraft = 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 invoicingCatalogItemFormHelper_1 = require("./invoicingCatalogItemFormHelper");
|
|
8
9
|
exports.initialState = {
|
|
9
10
|
fetchState: 'Not-Started',
|
|
@@ -25,7 +26,7 @@ const editInvoicingCatalogItemDetailView = (0, toolkit_1.createSlice)({
|
|
|
25
26
|
updateInvoicingCatalogItemFormDraft(draft, action) {
|
|
26
27
|
const { id, localData } = action.payload;
|
|
27
28
|
if (id != null) {
|
|
28
|
-
draft.editDraftById
|
|
29
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftEdit)(draft.editDraftById, id, localData);
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
draft.newItemDraft = localData;
|
|
@@ -68,6 +69,7 @@ const editInvoicingCatalogItemDetailView = (0, toolkit_1.createSlice)({
|
|
|
68
69
|
fetchState: 'Error',
|
|
69
70
|
error: action.payload.error,
|
|
70
71
|
};
|
|
72
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftFailure)(draft.editDraftById, action.payload.id, invoicingCatalogItemFormHelper_1.initialInvoicingCatalogItemFormLocalData);
|
|
71
73
|
},
|
|
72
74
|
fetchInvoicingCatalogItemDetailPage: {
|
|
73
75
|
reducer() {
|
|
@@ -83,14 +85,10 @@ const editInvoicingCatalogItemDetailView = (0, toolkit_1.createSlice)({
|
|
|
83
85
|
};
|
|
84
86
|
},
|
|
85
87
|
},
|
|
86
|
-
/**
|
|
87
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
88
|
-
* exists so a late-arriving refetch cannot overwrite in-progress edits.
|
|
89
|
-
*/
|
|
88
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
90
89
|
seedInvoicingCatalogItemFormDraft(draft, action) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
90
|
+
const { id, localData } = action.payload;
|
|
91
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftSeed)(draft.editDraftById, id, localData);
|
|
94
92
|
},
|
|
95
93
|
runInvoicingCatalogPlanAction(draft, action) {
|
|
96
94
|
draft.actionStateById[action.payload.id] = {
|
|
@@ -129,13 +127,23 @@ const editInvoicingCatalogItemDetailView = (0, toolkit_1.createSlice)({
|
|
|
129
127
|
error: action.payload.error,
|
|
130
128
|
};
|
|
131
129
|
},
|
|
132
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Discard a form's draft — the catalog item's own when `id` is given,
|
|
132
|
+
* the create draft otherwise. Scoped to the one form on purpose: another
|
|
133
|
+
* catalog item's half-finished edit is not this form's to throw away.
|
|
134
|
+
* Clearing every draft at once is what `clearAll` is for.
|
|
135
|
+
*/
|
|
136
|
+
resetEditInvoicingCatalogItemDetailView(draft, action) {
|
|
133
137
|
draft.fetchState = 'Not-Started';
|
|
134
138
|
draft.error = undefined;
|
|
135
139
|
draft.savedItemId = undefined;
|
|
136
140
|
draft.savedKind = undefined;
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
const id = action.payload?.id;
|
|
142
|
+
if (id == null) {
|
|
143
|
+
draft.newItemDraft = { ...invoicingCatalogItemFormHelper_1.initialInvoicingCatalogItemFormLocalData };
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
delete draft.editDraftById[id];
|
|
139
147
|
},
|
|
140
148
|
},
|
|
141
149
|
extraReducers: (builder) => {
|
|
@@ -44,6 +44,16 @@ export interface InvoicingCatalogItemFormView extends SelectorView {
|
|
|
44
44
|
* Folded in here so the screen never reaches for the config view itself.
|
|
45
45
|
*/
|
|
46
46
|
fieldHelp: InvoicingFieldHelpByCode;
|
|
47
|
+
/**
|
|
48
|
+
* True while anything the form's fields mount against is still loading: the
|
|
49
|
+
* accounting lists, and — until it has reached the draft — the item being
|
|
50
|
+
* edited. The form holds a skeleton on this rather than mount, because both
|
|
51
|
+
* arrive too late to be picked up: it seeds react-hook-form once, at first
|
|
52
|
+
* render, and the accounting fields choose between a picker and a text input
|
|
53
|
+
* from the lists. A later refetch does not raise this again, so a refresh
|
|
54
|
+
* leaves the form on screen instead of blanking it mid-edit.
|
|
55
|
+
*/
|
|
56
|
+
isFormLoading: boolean;
|
|
47
57
|
/**
|
|
48
58
|
* True while the accounting lists are still loading, so the form can wait
|
|
49
59
|
* instead of mounting pickers whose options are not there yet.
|
|
@@ -5,6 +5,7 @@ const toolkit_1 = require("@reduxjs/toolkit");
|
|
|
5
5
|
const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
|
|
6
6
|
const planSelector_1 = require("../../../entity/invoicing/plan/planSelector");
|
|
7
7
|
const invoicingConfigViewSelector_1 = require("../invoicingConfigView/invoicingConfigViewSelector");
|
|
8
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
8
9
|
const invoicingQboViewSelector_1 = require("../invoicingQboView/invoicingQboViewSelector");
|
|
9
10
|
const invoicingCatalogItemFormHelper_1 = require("./invoicingCatalogItemFormHelper");
|
|
10
11
|
const getEditInvoicingCatalogItemDetailViewState = (state) => ({
|
|
@@ -58,7 +59,7 @@ const getInvoicingCatalogItemFormView = (state, id) => {
|
|
|
58
59
|
// lands. Until then the page is showing its skeleton, so the blank shape here
|
|
59
60
|
// is never rendered.
|
|
60
61
|
const localData = id != null
|
|
61
|
-
? (editDraftById
|
|
62
|
+
? (0, invoicingFormDraft_1.getInvoicingFormDraftLocalData)(editDraftById, id, invoicingCatalogItemFormHelper_1.initialInvoicingCatalogItemFormLocalData)
|
|
62
63
|
: newItemDraft;
|
|
63
64
|
const allApplicableItemOptions = (0, exports.getInvoicingApplicableCatalogItemOptions)(state);
|
|
64
65
|
const applicableItemOptions = id != null
|
|
@@ -96,6 +97,8 @@ const getInvoicingCatalogItemFormView = (state, id) => {
|
|
|
96
97
|
catalogProductLifecycleActionOptions,
|
|
97
98
|
recordState,
|
|
98
99
|
fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'catalog'),
|
|
100
|
+
isFormLoading: (0, invoicingQboViewSelector_1.isInvoicingAccountingPickerDataLoading)(state) ||
|
|
101
|
+
(0, invoicingFormDraft_1.isInvoicingFormDraftPending)(editDraftById, id),
|
|
99
102
|
isQboPickerDataLoading: (0, invoicingQboViewSelector_1.isInvoicingAccountingPickerDataLoading)(state),
|
|
100
103
|
qboAccountHierarchy: qboView?.nestedAccountHierarchy ?? [],
|
|
101
104
|
qboClassHierarchy: qboView?.nestedClassHierarchy ?? [],
|
|
@@ -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
|
/** A single pricing tier within a price point (values kept as raw strings). */
|
|
4
5
|
export interface InvoicingCatalogItemFormTier {
|
|
5
6
|
endingUnit: string;
|
|
@@ -63,7 +64,7 @@ export interface EditInvoicingCatalogItemDetailViewState extends FetchedState {
|
|
|
63
64
|
*/
|
|
64
65
|
actionStateById: Record<ID, FetchStateAndError>;
|
|
65
66
|
/** Inline-edit drafts, keyed by catalog item id. */
|
|
66
|
-
editDraftById:
|
|
67
|
+
editDraftById: InvoicingFormDraftById<InvoicingCatalogItemFormLocalData>;
|
|
67
68
|
newItemDraft: InvoicingCatalogItemFormLocalData;
|
|
68
69
|
/**
|
|
69
70
|
* Detail-load state per catalog item id. Keyed rather than a single slot, so
|
package/lib/view/invoicing/editInvoicingCatalogItemDetailView/saveInvoicingCatalogItemEpic.js
CHANGED
|
@@ -20,8 +20,9 @@ const saveInvoicingCatalogItemEpic = (actions$, state$, zeniAPI) => actions$.pip
|
|
|
20
20
|
// class become the records the service stores. Price points ride along
|
|
21
21
|
// nested, so the detail page and the create/edit form share one request.
|
|
22
22
|
const viewState = state.editInvoicingCatalogItemDetailViewState;
|
|
23
|
-
const localData = (id != null
|
|
24
|
-
viewState.
|
|
23
|
+
const localData = (id != null
|
|
24
|
+
? viewState.editDraftById[id]?.localData
|
|
25
|
+
: viewState.newItemDraft) ?? viewState.newItemDraft;
|
|
25
26
|
const data = (0, editInvoicingCatalogItemDetailViewPayload_1.localDataToSaveInvoicingCatalogItemPayload)(localData, id == null, accountingLookup);
|
|
26
27
|
const baseUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0`;
|
|
27
28
|
const path = id != null
|
|
@@ -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 { seedInvoicingCatalogItemFormDraft, updateInvoicingCatalogItemDetail } from './editInvoicingCatalogItemDetailViewReducer';
|
|
5
|
-
export type ActionType = ReturnType<typeof updateInvoicingCatalogItemDetail> | ReturnType<typeof seedInvoicingCatalogItemFormDraft>;
|
|
4
|
+
import { fetchInvoicingCatalogItemDetailPage, seedInvoicingCatalogItemFormDraft, updateInvoicingCatalogItemDetail } from './editInvoicingCatalogItemDetailViewReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof fetchInvoicingCatalogItemDetailPage> | ReturnType<typeof updateInvoicingCatalogItemDetail> | ReturnType<typeof seedInvoicingCatalogItemFormDraft>;
|
|
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 seedInvoicingCatalogItemFormDraftEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|
|
@@ -7,13 +7,32 @@ const planSelector_1 = require("../../../entity/invoicing/plan/planSelector");
|
|
|
7
7
|
const editInvoicingCatalogItemDetailViewReducer_1 = require("./editInvoicingCatalogItemDetailViewReducer");
|
|
8
8
|
const invoicingCatalogItemFormHelper_1 = require("./invoicingCatalogItemFormHelper");
|
|
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 seedInvoicingCatalogItemFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(editInvoicingCatalogItemDetailViewReducer_1.updateInvoicingCatalogItemDetail.match
|
|
16
|
-
|
|
19
|
+
const seedInvoicingCatalogItemFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)((action) => editInvoicingCatalogItemDetailViewReducer_1.updateInvoicingCatalogItemDetail.match(action) ||
|
|
20
|
+
editInvoicingCatalogItemDetailViewReducer_1.fetchInvoicingCatalogItemDetailPage.match(action)), (0, operators_1.withLatestFrom)(state$), (0, operators_1.mergeMap)(([action, state]) => {
|
|
21
|
+
const id = action.payload.id;
|
|
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 (editInvoicingCatalogItemDetailViewReducer_1.fetchInvoicingCatalogItemDetailPage.match(action) &&
|
|
30
|
+
state.editInvoicingCatalogItemDetailViewState.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 plan = (0, planSelector_1.getInvoicingPlanById)(state.invoicingPlanState, id);
|
|
18
37
|
if (plan == null) {
|
|
19
38
|
return rxjs_1.EMPTY;
|
package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export declare const updateInvoicingCouponFormDraft: import("@reduxjs/toolkit").
|
|
|
48
48
|
id: ID;
|
|
49
49
|
}, "editInvoicingCouponDetailView/runInvoicingDiscountActionFailure">, submitInvoicingCouponForm: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SubmitInvoicingCouponFormPayload], SubmitInvoicingCouponFormPayload, "editInvoicingCouponDetailView/submitInvoicingCouponForm", never, never>, saveInvoicingCoupon: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SaveInvoicingCouponPayload], SaveInvoicingCouponPayload, "editInvoicingCouponDetailView/saveInvoicingCoupon", never, never>, submitInvoicingCouponFormSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
50
50
|
couponId: ID;
|
|
51
|
-
}, "editInvoicingCouponDetailView/submitInvoicingCouponFormSuccess">, submitInvoicingCouponFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCouponDetailView/submitInvoicingCouponFormFailure">, resetEditInvoicingCouponDetailView: import("@reduxjs/toolkit").
|
|
51
|
+
}, "editInvoicingCouponDetailView/submitInvoicingCouponFormSuccess">, submitInvoicingCouponFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCouponDetailView/submitInvoicingCouponFormFailure">, resetEditInvoicingCouponDetailView: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<{
|
|
52
|
+
id?: ID;
|
|
53
|
+
} | undefined, "editInvoicingCouponDetailView/resetEditInvoicingCouponDetailView">;
|
|
52
54
|
declare const _default: import("redux").Reducer<EditInvoicingCouponDetailViewState>;
|
|
53
55
|
export default _default;
|
package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewReducer.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.resetEditInvoicingCouponDetailView = exports.submitInvoicingCouponFormFailure = exports.submitInvoicingCouponFormSuccess = exports.saveInvoicingCoupon = exports.submitInvoicingCouponForm = exports.runInvoicingDiscountActionFailure = exports.runInvoicingDiscountActionSuccess = exports.runInvoicingDiscountAction = exports.updateInvoicingCouponDetailFailure = exports.updateInvoicingCouponDetail = exports.seedInvoicingCouponFormDraft = exports.fetchInvoicingCouponDetailPage = exports.fetchInvoicingCouponDetail = exports.updateInvoicingCouponFormDraft = 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 editInvoicingCouponDetailViewState_1 = require("./editInvoicingCouponDetailViewState");
|
|
8
9
|
exports.initialState = {
|
|
9
10
|
fetchState: 'Not-Started',
|
|
@@ -24,7 +25,7 @@ const editInvoicingCouponDetailView = (0, toolkit_1.createSlice)({
|
|
|
24
25
|
updateInvoicingCouponFormDraft(draft, action) {
|
|
25
26
|
const { id, localData } = action.payload;
|
|
26
27
|
if (id != null) {
|
|
27
|
-
draft.editDraftById
|
|
28
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftEdit)(draft.editDraftById, id, localData);
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
31
|
draft.newCouponDraft = localData;
|
|
@@ -89,15 +90,12 @@ const editInvoicingCouponDetailView = (0, toolkit_1.createSlice)({
|
|
|
89
90
|
fetchState: 'Error',
|
|
90
91
|
error: action.payload.status,
|
|
91
92
|
};
|
|
93
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftFailure)(draft.editDraftById, action.payload.id, editInvoicingCouponDetailViewState_1.initialInvoicingCouponFormLocalData);
|
|
92
94
|
},
|
|
93
|
-
/**
|
|
94
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
95
|
-
* exists so a late refetch cannot overwrite in-progress edits.
|
|
96
|
-
*/
|
|
95
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
97
96
|
seedInvoicingCouponFormDraft(draft, action) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
97
|
+
const { id, localData } = action.payload;
|
|
98
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftSeed)(draft.editDraftById, id, localData);
|
|
101
99
|
},
|
|
102
100
|
runInvoicingDiscountAction(draft, action) {
|
|
103
101
|
draft.actionStateById[action.payload.id] = {
|
|
@@ -117,12 +115,22 @@ const editInvoicingCouponDetailView = (0, toolkit_1.createSlice)({
|
|
|
117
115
|
error: action.payload.error,
|
|
118
116
|
};
|
|
119
117
|
},
|
|
120
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Discard a form's draft — the coupon's own when `id` is given,
|
|
120
|
+
* the create draft otherwise. Scoped to the one form on purpose: another
|
|
121
|
+
* coupon's half-finished edit is not this form's to throw away.
|
|
122
|
+
* Clearing every draft at once is what `clearAll` is for.
|
|
123
|
+
*/
|
|
124
|
+
resetEditInvoicingCouponDetailView(draft, action) {
|
|
121
125
|
draft.fetchState = 'Not-Started';
|
|
122
126
|
draft.error = undefined;
|
|
123
127
|
draft.savedCouponId = undefined;
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
const id = action.payload?.id;
|
|
129
|
+
if (id == null) {
|
|
130
|
+
draft.newCouponDraft = { ...editInvoicingCouponDetailViewState_1.initialInvoicingCouponFormLocalData };
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
delete draft.editDraftById[id];
|
|
126
134
|
},
|
|
127
135
|
},
|
|
128
136
|
extraReducers: (builder) => {
|
package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.d.ts
CHANGED
|
@@ -19,6 +19,19 @@ export interface EditInvoicingCouponDetailView extends SelectorView {
|
|
|
19
19
|
* Folded in here so the screen never reaches for the config view itself.
|
|
20
20
|
*/
|
|
21
21
|
fieldHelp: InvoicingFieldHelpByCode;
|
|
22
|
+
/**
|
|
23
|
+
* True while the coupon being edited is still on its way to the form. The
|
|
24
|
+
* form holds a skeleton on this rather than mount: it seeds react-hook-form
|
|
25
|
+
* once, at first render, so fields mounted against the blank draft stay blank
|
|
26
|
+
* and the first change writes that blankness back over the coupon. A later
|
|
27
|
+
* refetch does not raise this again, so a refresh leaves the form on screen
|
|
28
|
+
* instead of blanking it mid-edit.
|
|
29
|
+
*
|
|
30
|
+
* Narrower than `pageFetchState`, which also waits on the accounting lists:
|
|
31
|
+
* the discounts-account picker carries its own loading state, so the form is
|
|
32
|
+
* useful before the lists land.
|
|
33
|
+
*/
|
|
34
|
+
isFormLoading: boolean;
|
|
22
35
|
/**
|
|
23
36
|
* Every request the page renders from, reduced to one state: the record and
|
|
24
37
|
* the config behind its dropdowns and field help. The page holds a skeleton
|
package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewSelector.js
CHANGED
|
@@ -5,6 +5,7 @@ const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState")
|
|
|
5
5
|
const couponSelector_1 = require("../../../entity/invoicing/coupon/couponSelector");
|
|
6
6
|
const invoicingCommonPayload_1 = require("../../../entity/invoicing/invoicingCommonPayload");
|
|
7
7
|
const invoicingConfigViewSelector_1 = require("../invoicingConfigView/invoicingConfigViewSelector");
|
|
8
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
8
9
|
const invoicingQboViewSelector_1 = require("../invoicingQboView/invoicingQboViewSelector");
|
|
9
10
|
const settingsViewSelector_1 = require("../settingsView/settingsViewSelector");
|
|
10
11
|
const editInvoicingCouponDetailViewState_1 = require("./editInvoicingCouponDetailViewState");
|
|
@@ -44,6 +45,7 @@ const getEditInvoicingCouponDetailViewState = (state, couponId) => {
|
|
|
44
45
|
{ error: undefined, fetchState: configFetchState },
|
|
45
46
|
]),
|
|
46
47
|
recordState,
|
|
48
|
+
isFormLoading: (0, invoicingFormDraft_1.isInvoicingFormDraftPending)(state.editInvoicingCouponDetailViewState.editDraftById, couponId),
|
|
47
49
|
coupon,
|
|
48
50
|
discountsAccountName: (0, invoicingQboViewSelector_1.invoicingQboAccountByQboId)(state, coupon?.discountsAccountId)?.accountName,
|
|
49
51
|
savedCouponId,
|
|
@@ -74,7 +76,7 @@ const getInvoicingCouponFormView = (state, couponId) => {
|
|
|
74
76
|
// `seedInvoicingCouponFormDraftEpic` when the detail load lands. Until then
|
|
75
77
|
// the page is showing its skeleton.
|
|
76
78
|
const localData = couponId != null
|
|
77
|
-
? (editDraftById
|
|
79
|
+
? (0, invoicingFormDraft_1.getInvoicingFormDraftLocalData)(editDraftById, couponId, editInvoicingCouponDetailViewState_1.initialInvoicingCouponFormLocalData)
|
|
78
80
|
: newCouponDraft;
|
|
79
81
|
const { billingPeriodUnitOptions, discountApplyOnOptions, discountDurationTypeOptions, discountTypeOptions, qboAccountMappingKindOptions, } = (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state);
|
|
80
82
|
const isQboConnected = (0, invoicingQboViewSelector_1.isInvoicingQboConnected)(state);
|
package/lib/view/invoicing/editInvoicingCouponDetailView/editInvoicingCouponDetailViewState.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Amount } from '../../../commonStateTypes/amount';
|
|
|
2
2
|
import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
|
|
3
3
|
import { InvoicingCoupon } from '../../../entity/invoicing/coupon/couponState';
|
|
4
4
|
import { InvoicingQboAccountMappingsPayload } from '../../../entity/invoicing/invoicingCommonPayload';
|
|
5
|
+
import { InvoicingFormDraftById } from '../invoicingFormDraft';
|
|
5
6
|
/**
|
|
6
7
|
* Draft form state for the create/edit discount-coupon form. Held in CES so the
|
|
7
8
|
* form flows its data from here (mirrors the customer form pattern). Dates are
|
|
@@ -37,7 +38,7 @@ export interface InvoicingCouponFormLocalData {
|
|
|
37
38
|
export interface EditInvoicingCouponDetailViewState extends FetchedState {
|
|
38
39
|
/** Lifecycle action (archive, activate, …) fetch state per coupon id. */
|
|
39
40
|
actionStateById: Record<ID, FetchStateAndError>;
|
|
40
|
-
editDraftById:
|
|
41
|
+
editDraftById: InvoicingFormDraftById<InvoicingCouponFormLocalData>;
|
|
41
42
|
newCouponDraft: InvoicingCouponFormLocalData;
|
|
42
43
|
/** Detail-load state per coupon id. */
|
|
43
44
|
recordStateById: Record<ID, FetchStateAndError>;
|
|
@@ -23,7 +23,7 @@ const saveInvoicingCouponEpic = (actions$, state$, zeniAPI) => actions$.pipe((0,
|
|
|
23
23
|
const state = state$.value;
|
|
24
24
|
const viewState = state.editInvoicingCouponDetailViewState;
|
|
25
25
|
const draft = (id != null
|
|
26
|
-
? viewState.editDraftById[id]
|
|
26
|
+
? viewState.editDraftById[id]?.localData
|
|
27
27
|
: viewState.newCouponDraft) ?? viewState.newCouponDraft;
|
|
28
28
|
// The create default is resolved here as well as in the form view,
|
|
29
29
|
// so a create that never touched the picker still persists the
|
package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.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 { seedInvoicingCouponFormDraft, updateInvoicingCouponDetail } from './editInvoicingCouponDetailViewReducer';
|
|
5
|
-
export type ActionType = ReturnType<typeof updateInvoicingCouponDetail> | ReturnType<typeof seedInvoicingCouponFormDraft>;
|
|
4
|
+
import { fetchInvoicingCouponDetailPage, seedInvoicingCouponFormDraft, updateInvoicingCouponDetail } from './editInvoicingCouponDetailViewReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof fetchInvoicingCouponDetailPage> | ReturnType<typeof updateInvoicingCouponDetail> | ReturnType<typeof seedInvoicingCouponFormDraft>;
|
|
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 seedInvoicingCouponFormDraftEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
|
package/lib/view/invoicing/editInvoicingCouponDetailView/seedInvoicingCouponFormDraftEpic.js
CHANGED
|
@@ -7,13 +7,32 @@ const couponSelector_1 = require("../../../entity/invoicing/coupon/couponSelecto
|
|
|
7
7
|
const editInvoicingCouponDetailViewReducer_1 = require("./editInvoicingCouponDetailViewReducer");
|
|
8
8
|
const editInvoicingCouponDetailViewState_1 = require("./editInvoicingCouponDetailViewState");
|
|
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 seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(editInvoicingCouponDetailViewReducer_1.updateInvoicingCouponDetail.match
|
|
19
|
+
const seedInvoicingCouponFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)((action) => editInvoicingCouponDetailViewReducer_1.updateInvoicingCouponDetail.match(action) ||
|
|
20
|
+
editInvoicingCouponDetailViewReducer_1.fetchInvoicingCouponDetailPage.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 (editInvoicingCouponDetailViewReducer_1.fetchInvoicingCouponDetailPage.match(action) &&
|
|
30
|
+
state.editInvoicingCouponDetailViewState.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 coupon = (0, couponSelector_1.getInvoicingCouponById)(state.invoicingCouponState, id);
|
|
18
37
|
if (coupon == null) {
|
|
19
38
|
return rxjs_1.EMPTY;
|
|
@@ -54,6 +54,8 @@ export declare const fetchInvoicingPaymentLinkEmailPreview: import("@reduxjs/too
|
|
|
54
54
|
status: ZeniAPIStatus;
|
|
55
55
|
}, "editInvoicingCustomerDetailView/updateInvoicingCustomerDetailFailure">, updateInvoicingCustomerFormDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<UpdateInvoicingCustomerFormDraftPayload, "editInvoicingCustomerDetailView/updateInvoicingCustomerFormDraft">, submitInvoicingCustomerForm: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: SubmitInvoicingCustomerFormPayload], SubmitInvoicingCustomerFormPayload, "editInvoicingCustomerDetailView/submitInvoicingCustomerForm", never, never>, submitInvoicingCustomerFormSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
56
56
|
customerId: ID;
|
|
57
|
-
}, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormSuccess">, submitInvoicingCustomerFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormFailure">, resetEditInvoicingCustomerDetailView: import("@reduxjs/toolkit").
|
|
57
|
+
}, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormSuccess">, submitInvoicingCustomerFormFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "editInvoicingCustomerDetailView/submitInvoicingCustomerFormFailure">, resetEditInvoicingCustomerDetailView: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<{
|
|
58
|
+
id?: ID;
|
|
59
|
+
} | undefined, "editInvoicingCustomerDetailView/resetEditInvoicingCustomerDetailView">, initializeInvoicingCustomerAddress: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: InitializeInvoicingCustomerAddressPayload], InitializeInvoicingCustomerAddressPayload, "editInvoicingCustomerDetailView/initializeInvoicingCustomerAddress", never, never>;
|
|
58
60
|
declare const _default: import("redux").Reducer<EditInvoicingCustomerDetailViewState>;
|
|
59
61
|
export default _default;
|
package/lib/view/invoicing/editInvoicingCustomerDetailView/editInvoicingCustomerDetailViewReducer.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.initializeInvoicingCustomerAddress = exports.resetEditInvoicingCustomerDetailView = exports.submitInvoicingCustomerFormFailure = exports.submitInvoicingCustomerFormSuccess = exports.submitInvoicingCustomerForm = exports.updateInvoicingCustomerFormDraft = exports.updateInvoicingCustomerDetailFailure = exports.submitAddPromotionalCredits = exports.resetPromotionalCreditAction = exports.updateInvoicingCustomerDetail = exports.seedInvoicingCustomerFormDraft = exports.fetchInvoicingCustomerDetailPage = exports.fetchInvoicingCustomerDetail = exports.addPromotionalCreditsSuccess = exports.addPromotionalCreditsFailure = exports.updateInvoicingPaymentLinkEmailPreviewFailure = exports.updateInvoicingPaymentLinkEmailPreview = exports.fetchInvoicingPaymentLinkEmailPreviewPage = exports.fetchInvoicingPaymentLinkEmailPreview = exports.initialState = void 0;
|
|
5
5
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
6
|
const rootActions_1 = require("../../../rootActions");
|
|
7
|
+
const invoicingFormDraft_1 = require("../invoicingFormDraft");
|
|
7
8
|
const invoicingCustomerFormConfig_1 = require("./invoicingCustomerFormConfig");
|
|
8
9
|
exports.initialState = {
|
|
9
10
|
emailPreviewFetchState: { fetchState: 'Not-Started', error: undefined },
|
|
@@ -127,20 +128,17 @@ const editInvoicingCustomerDetailView = (0, toolkit_1.createSlice)({
|
|
|
127
128
|
fetchState: 'Error',
|
|
128
129
|
error: action.payload.status,
|
|
129
130
|
};
|
|
131
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftFailure)(draft.editDraftById, action.payload.id, invoicingCustomerFormConfig_1.initialInvoicingCustomerFormLocalData);
|
|
130
132
|
},
|
|
131
|
-
/**
|
|
132
|
-
* Seed the draft from the loaded record, once. Skipped when a draft already
|
|
133
|
-
* exists so a late refetch cannot overwrite in-progress edits.
|
|
134
|
-
*/
|
|
133
|
+
/** Fill the draft from the loaded record — see `applyInvoicingFormDraftSeed`. */
|
|
135
134
|
seedInvoicingCustomerFormDraft(draft, action) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
135
|
+
const { id, localData } = action.payload;
|
|
136
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftSeed)(draft.editDraftById, id, localData);
|
|
139
137
|
},
|
|
140
138
|
updateInvoicingCustomerFormDraft(draft, action) {
|
|
141
139
|
const { id, localData } = action.payload;
|
|
142
140
|
if (id != null) {
|
|
143
|
-
draft.editDraftById
|
|
141
|
+
(0, invoicingFormDraft_1.applyInvoicingFormDraftEdit)(draft.editDraftById, id, localData);
|
|
144
142
|
}
|
|
145
143
|
else {
|
|
146
144
|
draft.newCustomerDraft = localData;
|
|
@@ -165,12 +163,22 @@ const editInvoicingCustomerDetailView = (0, toolkit_1.createSlice)({
|
|
|
165
163
|
draft.fetchState = 'Error';
|
|
166
164
|
draft.error = action.payload;
|
|
167
165
|
},
|
|
168
|
-
|
|
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) {
|
|
169
173
|
draft.fetchState = 'Not-Started';
|
|
170
174
|
draft.error = undefined;
|
|
171
175
|
draft.savedCustomerId = undefined;
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
const id = action.payload?.id;
|
|
177
|
+
if (id == null) {
|
|
178
|
+
draft.newCustomerDraft = { ...invoicingCustomerFormConfig_1.initialInvoicingCustomerFormLocalData };
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
delete draft.editDraftById[id];
|
|
174
182
|
},
|
|
175
183
|
// Trigger only — handled by initializeInvoicingCustomerAddressEpic.
|
|
176
184
|
initializeInvoicingCustomerAddress: {
|
|
@@ -53,6 +53,15 @@ export interface InvoicingCustomerFormView extends SelectorView {
|
|
|
53
53
|
* Folded in here so the screen never reaches for the config view itself.
|
|
54
54
|
*/
|
|
55
55
|
fieldHelp: InvoicingFieldHelpByCode;
|
|
56
|
+
/**
|
|
57
|
+
* True while the customer being edited is still on its way to the form. The
|
|
58
|
+
* form holds a skeleton on this rather than mount: it seeds react-hook-form
|
|
59
|
+
* once, at first render, so fields mounted against the blank draft stay blank
|
|
60
|
+
* and the first change writes that blankness back over the customer. A later
|
|
61
|
+
* refetch does not raise this again, so a refresh leaves the form on screen
|
|
62
|
+
* instead of blanking it mid-edit.
|
|
63
|
+
*/
|
|
64
|
+
isFormLoading: boolean;
|
|
56
65
|
localData: InvoicingCustomerFormLocalData;
|
|
57
66
|
mode: 'create' | 'edit';
|
|
58
67
|
netTermDayOptions: InvoicingNamedOption[];
|