@zeniai/client-epic-state 5.2.63 → 5.2.65

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.
@@ -1,10 +1,11 @@
1
1
  import { getInvoicingQboAccountMappingId, } from '../../../entity/invoicing/invoicingCommonPayload';
2
+ import { getAddressByAddressId } from '../../../entity/address/addressSelector';
2
3
  import { getFileByFileId } from '../../../entity/file/fileSelector';
3
4
  import { getFormattedAddress } from '../../addressView/addressViewSelector';
4
5
  import { getInvoicingConfigView, invoicingFieldHelpForGroup, } from '../invoicingConfigView/invoicingConfigViewSelector';
5
6
  import { getInvoicingQboView, isInvoicingAccountingPickerDataLoading, } from '../invoicingQboView/invoicingQboViewSelector';
6
7
  import { INVOICING_BUSINESS_ADDRESS_TYPE, entityToInvoicingBrandingFormLocalData, } from './invoicingBrandingFormConfig';
7
- import { initialInvoicingQboSettingsLocalData, } from './invoicingQboSettingsFormConfig';
8
+ import { entityToInvoicingQboSettingsLocalData, initialInvoicingQboSettingsLocalData, } from './invoicingQboSettingsFormConfig';
8
9
  /**
9
10
  * Shared primitive: the raw invoicing settings. Consumed internally by other
10
11
  * CES selectors (create-invoice, customer-detail, overview) and by non-settings
@@ -118,6 +119,7 @@ export const getInvoicingQboSettingsFormView = (state) => {
118
119
  fieldHelp: invoicingFieldHelpForGroup(state, 'settings'),
119
120
  accountMappingKindOptions: qboAccountMappingKindOptions,
120
121
  accounts: qboView.accounts,
122
+ savedLocalData: entityToInvoicingQboSettingsLocalData(settings?.qbo),
121
123
  backfillState: qboView.backfillState,
122
124
  connection: qboView.connection,
123
125
  configFetchState,
@@ -143,20 +145,27 @@ export const getInvoicingQboSettingsFormView = (state) => {
143
145
  };
144
146
  /**
145
147
  * Bundled view for the branding settings form: the draft `localData` (seeded
146
- * from the existing settings until the user edits), the business-address label
147
- * (from the shared Address screen, seeded on load from `address_id`), the raw
148
- * settings (for the logo/preview), the backend date-format choices and the
148
+ * from the existing settings until the user edits), the business address, the
149
+ * raw settings (for the logo/preview), the backend date-format choices and the
149
150
  * save fetch state.
151
+ *
152
+ * The address is resolved here rather than read from the Address screen's
153
+ * staging store alone: that store is only seeded when settings are fetched, and
154
+ * returning to this page does not refetch, so a saved address would otherwise
155
+ * have no way to reach the screen.
150
156
  */
151
157
  export const getInvoicingBrandingFormView = (state) => {
152
158
  const { brandingDraft, saveFetchState, settings } = state.invoicingSettingsViewState;
153
- const newAddress = state.addressViewState.newAddressState?.[INVOICING_BUSINESS_ADDRESS_TYPE];
154
- const addressLabel = newAddress?.addressToCreate != null
155
- ? getFormattedAddress(newAddress.addressToCreate)
156
- : undefined;
159
+ const savedAddressId = settings?.address?.address_id;
160
+ const address = state.addressViewState.newAddressState?.[INVOICING_BUSINESS_ADDRESS_TYPE]
161
+ ?.addressToCreate ??
162
+ (savedAddressId != null
163
+ ? getAddressByAddressId(state.addressState, savedAddressId)
164
+ : undefined);
157
165
  return {
158
166
  fieldHelp: invoicingFieldHelpForGroup(state, 'settings'),
159
- addressLabel,
167
+ address,
168
+ addressLabel: address != null ? getFormattedAddress(address) : undefined,
160
169
  dateFormatOptions: getInvoicingConfigView(state).dateFormatOptions,
161
170
  localData: brandingDraft ?? entityToInvoicingBrandingFormLocalData(settings),
162
171
  saveState: saveFetchState,
@@ -1,6 +1,7 @@
1
1
  import { of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateAddresses } from '../../../entity/address/addressReducer';
4
+ import { getAddressByAddressId } from '../../../entity/address/addressSelector';
4
5
  import { updateFiles } from '../../../entity/file/fileReducer';
5
6
  import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
6
7
  import { resetNewAddressDataInLocalStore } from '../../addressView/addressViewReducer';
@@ -16,7 +17,11 @@ export const submitInvoicingBrandingFormEpic = (actions$, state$, zeniAPI) => ac
16
17
  const state = state$.value;
17
18
  const { brandingDraft, settings } = state.invoicingSettingsViewState;
18
19
  const localData = brandingDraft ?? entityToInvoicingBrandingFormLocalData(settings);
19
- const address = state.addressViewState.newAddressState?.[INVOICING_BUSINESS_ADDRESS_TYPE]?.addressToCreate;
20
+ const savedAddressId = settings?.address?.address_id;
21
+ const address = state.addressViewState.newAddressState?.[INVOICING_BUSINESS_ADDRESS_TYPE]?.addressToCreate ??
22
+ (savedAddressId != null
23
+ ? getAddressByAddressId(state.addressState, savedAddressId)
24
+ : undefined);
20
25
  const data = brandingLocalDataToSettingsPayload(localData, address);
21
26
  const apiUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/settings`;
22
27
  return zeniAPI
@@ -37,7 +42,11 @@ export const submitInvoicingBrandingFormEpic = (actions$, state$, zeniAPI) => ac
37
42
  ? [updateFiles({ files: [savedLogoFile] })]
38
43
  : []),
39
44
  saveInvoicingSettingsSuccess(response.data),
40
- resetNewAddressDataInLocalStore(INVOICING_BUSINESS_ADDRESS_TYPE),
45
+ ...(savedAddress == null
46
+ ? [
47
+ resetNewAddressDataInLocalStore(INVOICING_BUSINESS_ADDRESS_TYPE),
48
+ ]
49
+ : []),
41
50
  ];
42
51
  }
43
52
  return of(saveInvoicingSettingsFailure(response.status));
@@ -4,6 +4,7 @@ import { InvoicingDunningActionOption, InvoicingFieldHelpByCode, InvoicingNamedO
4
4
  import { File } from '../../../entity/file/fileState';
5
5
  import { ZeniAPIStatus } from '../../../responsePayload';
6
6
  import { RootState } from '../../../rootStateTypes';
7
+ import { AddressUpdatableInfo } from '../../addressView/addressViewState';
7
8
  import { InvoicingQboConnection, InvoicingQboSyncHealth } from '../invoicingQboView/invoicingQboViewPayload';
8
9
  import { InvoicingAccountingOption } from '../invoicingQboView/invoicingQboViewSelector';
9
10
  import { InvoicingBrandingFormLocalData } from './invoicingBrandingFormConfig';
@@ -113,6 +114,8 @@ export interface InvoicingQboSettingsFormView {
113
114
  localData: InvoicingQboSettingsLocalData;
114
115
  nestedAccountHierarchy: NestedAccountHierarchyForReport[];
115
116
  retryFetchStateByTaskId: Record<string, FetchStateAndError>;
117
+ /** The saved values the draft is compared against. */
118
+ savedLocalData: InvoicingQboSettingsLocalData;
116
119
  saveState: FetchStateAndError;
117
120
  settingsFetchState: FetchState;
118
121
  syncStatusOptions: InvoicingNamedOption[];
@@ -134,14 +137,20 @@ export interface InvoicingBrandingFormView {
134
137
  fieldHelp: InvoicingFieldHelpByCode;
135
138
  localData: InvoicingBrandingFormLocalData;
136
139
  saveState: FetchStateAndError;
140
+ /** The business address to show: the in-progress edit, else what is saved. */
141
+ address?: AddressUpdatableInfo;
137
142
  addressLabel?: string;
138
143
  settings?: InvoicingSettingsPayload;
139
144
  }
140
145
  /**
141
146
  * Bundled view for the branding settings form: the draft `localData` (seeded
142
- * from the existing settings until the user edits), the business-address label
143
- * (from the shared Address screen, seeded on load from `address_id`), the raw
144
- * settings (for the logo/preview), the backend date-format choices and the
147
+ * from the existing settings until the user edits), the business address, the
148
+ * raw settings (for the logo/preview), the backend date-format choices and the
145
149
  * save fetch state.
150
+ *
151
+ * The address is resolved here rather than read from the Address screen's
152
+ * staging store alone: that store is only seeded when settings are fetched, and
153
+ * returning to this page does not refetch, so a saved address would otherwise
154
+ * have no way to reach the screen.
146
155
  */
147
156
  export declare const getInvoicingBrandingFormView: (state: RootState) => InvoicingBrandingFormView;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInvoicingBrandingFormView = exports.getInvoicingQboSettingsFormView = exports.getInvoicingSettingsHubView = exports.getInvoicingSettingsView = exports.getInvoicingSettingsFetchState = exports.getInvoicingSettings = void 0;
4
4
  exports.deriveInvoicingEnablePrerequisites = deriveInvoicingEnablePrerequisites;
5
5
  const invoicingCommonPayload_1 = require("../../../entity/invoicing/invoicingCommonPayload");
6
+ const addressSelector_1 = require("../../../entity/address/addressSelector");
6
7
  const fileSelector_1 = require("../../../entity/file/fileSelector");
7
8
  const addressViewSelector_1 = require("../../addressView/addressViewSelector");
8
9
  const invoicingConfigViewSelector_1 = require("../invoicingConfigView/invoicingConfigViewSelector");
@@ -126,6 +127,7 @@ const getInvoicingQboSettingsFormView = (state) => {
126
127
  fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'settings'),
127
128
  accountMappingKindOptions: qboAccountMappingKindOptions,
128
129
  accounts: qboView.accounts,
130
+ savedLocalData: (0, invoicingQboSettingsFormConfig_1.entityToInvoicingQboSettingsLocalData)(settings?.qbo),
129
131
  backfillState: qboView.backfillState,
130
132
  connection: qboView.connection,
131
133
  configFetchState,
@@ -152,20 +154,27 @@ const getInvoicingQboSettingsFormView = (state) => {
152
154
  exports.getInvoicingQboSettingsFormView = getInvoicingQboSettingsFormView;
153
155
  /**
154
156
  * Bundled view for the branding settings form: the draft `localData` (seeded
155
- * from the existing settings until the user edits), the business-address label
156
- * (from the shared Address screen, seeded on load from `address_id`), the raw
157
- * settings (for the logo/preview), the backend date-format choices and the
157
+ * from the existing settings until the user edits), the business address, the
158
+ * raw settings (for the logo/preview), the backend date-format choices and the
158
159
  * save fetch state.
160
+ *
161
+ * The address is resolved here rather than read from the Address screen's
162
+ * staging store alone: that store is only seeded when settings are fetched, and
163
+ * returning to this page does not refetch, so a saved address would otherwise
164
+ * have no way to reach the screen.
159
165
  */
160
166
  const getInvoicingBrandingFormView = (state) => {
161
167
  const { brandingDraft, saveFetchState, settings } = state.invoicingSettingsViewState;
162
- const newAddress = state.addressViewState.newAddressState?.[invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE];
163
- const addressLabel = newAddress?.addressToCreate != null
164
- ? (0, addressViewSelector_1.getFormattedAddress)(newAddress.addressToCreate)
165
- : undefined;
168
+ const savedAddressId = settings?.address?.address_id;
169
+ const address = state.addressViewState.newAddressState?.[invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE]
170
+ ?.addressToCreate ??
171
+ (savedAddressId != null
172
+ ? (0, addressSelector_1.getAddressByAddressId)(state.addressState, savedAddressId)
173
+ : undefined);
166
174
  return {
167
175
  fieldHelp: (0, invoicingConfigViewSelector_1.invoicingFieldHelpForGroup)(state, 'settings'),
168
- addressLabel,
176
+ address,
177
+ addressLabel: address != null ? (0, addressViewSelector_1.getFormattedAddress)(address) : undefined,
169
178
  dateFormatOptions: (0, invoicingConfigViewSelector_1.getInvoicingConfigView)(state).dateFormatOptions,
170
179
  localData: brandingDraft ?? (0, invoicingBrandingFormConfig_1.entityToInvoicingBrandingFormLocalData)(settings),
171
180
  saveState: saveFetchState,
@@ -4,6 +4,7 @@ exports.submitInvoicingBrandingFormEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
6
  const addressReducer_1 = require("../../../entity/address/addressReducer");
7
+ const addressSelector_1 = require("../../../entity/address/addressSelector");
7
8
  const fileReducer_1 = require("../../../entity/file/fileReducer");
8
9
  const responsePayload_1 = require("../../../responsePayload");
9
10
  const addressViewReducer_1 = require("../../addressView/addressViewReducer");
@@ -19,7 +20,11 @@ const submitInvoicingBrandingFormEpic = (actions$, state$, zeniAPI) => actions$.
19
20
  const state = state$.value;
20
21
  const { brandingDraft, settings } = state.invoicingSettingsViewState;
21
22
  const localData = brandingDraft ?? (0, invoicingBrandingFormConfig_1.entityToInvoicingBrandingFormLocalData)(settings);
22
- const address = state.addressViewState.newAddressState?.[invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE]?.addressToCreate;
23
+ const savedAddressId = settings?.address?.address_id;
24
+ const address = state.addressViewState.newAddressState?.[invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE]?.addressToCreate ??
25
+ (savedAddressId != null
26
+ ? (0, addressSelector_1.getAddressByAddressId)(state.addressState, savedAddressId)
27
+ : undefined);
23
28
  const data = (0, invoicingBrandingFormConfig_1.brandingLocalDataToSettingsPayload)(localData, address);
24
29
  const apiUrl = `${zeniAPI.apiEndPoints.invoicingMicroServiceBaseUrl}/1.0/settings`;
25
30
  return zeniAPI
@@ -40,7 +45,11 @@ const submitInvoicingBrandingFormEpic = (actions$, state$, zeniAPI) => actions$.
40
45
  ? [(0, fileReducer_1.updateFiles)({ files: [savedLogoFile] })]
41
46
  : []),
42
47
  (0, settingsViewReducer_1.saveInvoicingSettingsSuccess)(response.data),
43
- (0, addressViewReducer_1.resetNewAddressDataInLocalStore)(invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE),
48
+ ...(savedAddress == null
49
+ ? [
50
+ (0, addressViewReducer_1.resetNewAddressDataInLocalStore)(invoicingBrandingFormConfig_1.INVOICING_BUSINESS_ADDRESS_TYPE),
51
+ ]
52
+ : []),
44
53
  ];
45
54
  }
46
55
  return (0, rxjs_1.of)((0, settingsViewReducer_1.saveInvoicingSettingsFailure)(response.status));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.2.63",
3
+ "version": "5.2.65",
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",