@servicetitan/standalone-root 1.2.0 → 1.3.0
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/CHANGELOG.md +12 -0
- package/dist/components/standalone-root-provider/standalone-root-provider.d.ts +4 -2
- package/dist/components/standalone-root-provider/standalone-root-provider.d.ts.map +1 -1
- package/dist/components/standalone-root-provider/standalone-root-provider.js +9 -12
- package/dist/components/standalone-root-provider/standalone-root-provider.js.map +1 -1
- package/dist/enums/index.d.ts +2 -0
- package/dist/enums/index.d.ts.map +1 -0
- package/dist/enums/index.js +2 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/enums/root-section.d.ts +4 -0
- package/dist/enums/root-section.d.ts.map +1 -0
- package/dist/enums/root-section.js +5 -0
- package/dist/enums/root-section.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/stores/standalone-root.store.d.ts +14 -6
- package/dist/stores/standalone-root.store.d.ts.map +1 -1
- package/dist/stores/standalone-root.store.js +63 -10
- package/dist/stores/standalone-root.store.js.map +1 -1
- package/dist/utils/symbols.d.ts +1 -1
- package/dist/utils/symbols.d.ts.map +1 -1
- package/dist/utils/symbols.js +2 -1
- package/dist/utils/symbols.js.map +1 -1
- package/dist/utils/tokens.d.ts +3 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +3 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +2 -2
- package/src/components/standalone-root-provider/standalone-root-provider.tsx +13 -15
- package/src/enums/index.ts +1 -0
- package/src/enums/root-section.ts +3 -0
- package/src/index.ts +1 -0
- package/src/stores/standalone-root.store.ts +50 -14
- package/src/utils/symbols.ts +2 -1
- package/src/utils/tokens.ts +7 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
PartitionsClientApi,
|
|
7
7
|
UserDetails,
|
|
8
8
|
} from '@servicetitan/marketing-services-api/identity';
|
|
9
|
-
import { LoadStatus } from '@servicetitan/standalone-ui';
|
|
9
|
+
import { LoadStatus, SymbolTokenDataType } from '@servicetitan/standalone-ui';
|
|
10
10
|
import { inject, injectable } from '@servicetitan/react-ioc';
|
|
11
11
|
import {
|
|
12
12
|
AppConfigApi,
|
|
@@ -26,8 +26,10 @@ import {
|
|
|
26
26
|
storageKeyForAppSettings,
|
|
27
27
|
storageKeyForTenantConfigs,
|
|
28
28
|
} from '../utils/storage-keys';
|
|
29
|
+
import { ModifiableRootSection } from '../enums';
|
|
30
|
+
import { POSSIBLE_CHANGES_TOKEN } from '../utils/tokens';
|
|
29
31
|
import { cultureKeyInCoreConfigs, defaultLocale, defaultTimezone } from '../utils/constants';
|
|
30
|
-
import {
|
|
32
|
+
import { eventEmitterSymbol, isInitializedSymbol, registeredChangesSymbol } from '../utils/symbols';
|
|
31
33
|
|
|
32
34
|
@injectable()
|
|
33
35
|
export class StandaloneRootStore {
|
|
@@ -42,19 +44,22 @@ export class StandaloneRootStore {
|
|
|
42
44
|
@observable locale = defaultLocale;
|
|
43
45
|
|
|
44
46
|
private eventEmitter!: EventEmitter;
|
|
47
|
+
private currentInstanceSymbol = Symbol();
|
|
45
48
|
|
|
46
49
|
constructor(
|
|
47
50
|
@inject(TenantManagementApi) private readonly tenantManagementApi: TenantManagementApi,
|
|
48
51
|
@inject(AppConfigApi) private readonly appConfigApi: AppConfigApi,
|
|
49
52
|
@inject(CurrentUserClientApi) private readonly currentUserClientApi: CurrentUserClientApi,
|
|
50
53
|
@inject(OnboardingApi) private readonly onboardingApi: OnboardingApi,
|
|
51
|
-
@inject(PartitionsClientApi) private partitionsApi: PartitionsClientApi,
|
|
54
|
+
@inject(PartitionsClientApi) private readonly partitionsApi: PartitionsClientApi,
|
|
55
|
+
@inject(POSSIBLE_CHANGES_TOKEN)
|
|
56
|
+
private readonly possibleChanges: SymbolTokenDataType<typeof POSSIBLE_CHANGES_TOKEN>,
|
|
52
57
|
) {
|
|
53
58
|
this.initializeEventEmitter();
|
|
54
59
|
makeObservable(this);
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
initialize = async (forceRefresh: boolean
|
|
62
|
+
initialize = async (forceRefresh: boolean) => {
|
|
58
63
|
try {
|
|
59
64
|
runInAction(() => {
|
|
60
65
|
this.loadStatus = LoadStatus.Loading;
|
|
@@ -95,8 +100,14 @@ export class StandaloneRootStore {
|
|
|
95
100
|
const isSuccess = this.syncFromStorage();
|
|
96
101
|
|
|
97
102
|
if (isSuccess) {
|
|
98
|
-
if (
|
|
99
|
-
await
|
|
103
|
+
if (this.registeredChanges?.length) {
|
|
104
|
+
await Promise.all(
|
|
105
|
+
this.registeredChanges.map(section =>
|
|
106
|
+
this.mapModifiableSectionToFetcher[section](),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
this.removeRegisteredChanges();
|
|
100
111
|
}
|
|
101
112
|
} else {
|
|
102
113
|
await fetchAll();
|
|
@@ -111,7 +122,7 @@ export class StandaloneRootStore {
|
|
|
111
122
|
|
|
112
123
|
if (timezoneFetched) {
|
|
113
124
|
runInAction(() => {
|
|
114
|
-
this.timezone =
|
|
125
|
+
this.timezone = timezoneFetched;
|
|
115
126
|
});
|
|
116
127
|
}
|
|
117
128
|
|
|
@@ -146,7 +157,22 @@ export class StandaloneRootStore {
|
|
|
146
157
|
};
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
|
|
160
|
+
dispose = () => {
|
|
161
|
+
this.registerPossibleChanges();
|
|
162
|
+
this.unregisterGlobalSyncListener();
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
private registerPossibleChanges = () => {
|
|
166
|
+
if (this.possibleChanges?.length) {
|
|
167
|
+
(window as any)[registeredChangesSymbol] = this.possibleChanges;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
private removeRegisteredChanges = () => {
|
|
172
|
+
(window as any)[registeredChangesSymbol] = undefined;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
private unregisterGlobalSyncListener = () => {
|
|
150
176
|
this.eventEmitter.off(Events.SyncFromStorage, this.listenGlobalSync);
|
|
151
177
|
};
|
|
152
178
|
|
|
@@ -166,13 +192,13 @@ export class StandaloneRootStore {
|
|
|
166
192
|
};
|
|
167
193
|
|
|
168
194
|
private listenGlobalSync = (instanceSymbol: symbol) => {
|
|
169
|
-
if (instanceSymbol !== currentInstanceSymbol) {
|
|
195
|
+
if (instanceSymbol !== this.currentInstanceSymbol) {
|
|
170
196
|
this.syncFromStorage();
|
|
171
197
|
}
|
|
172
198
|
};
|
|
173
199
|
|
|
174
200
|
private emitGlobalSync = () => {
|
|
175
|
-
this.eventEmitter.emit(Events.SyncFromStorage, currentInstanceSymbol);
|
|
201
|
+
this.eventEmitter.emit(Events.SyncFromStorage, this.currentInstanceSymbol);
|
|
176
202
|
};
|
|
177
203
|
|
|
178
204
|
private syncFromStorage = () => {
|
|
@@ -225,10 +251,6 @@ export class StandaloneRootStore {
|
|
|
225
251
|
(window as any)[isInitializedSymbol] = value;
|
|
226
252
|
};
|
|
227
253
|
|
|
228
|
-
private get isInitialized() {
|
|
229
|
-
return !!(window as any)[isInitializedSymbol];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
254
|
private fetchTenant = async () => {
|
|
233
255
|
const tenantFetched = await this.tenantManagementApi.client.tenant(undefined);
|
|
234
256
|
|
|
@@ -295,4 +317,18 @@ export class StandaloneRootStore {
|
|
|
295
317
|
this.partitions = partitionsFetched;
|
|
296
318
|
});
|
|
297
319
|
};
|
|
320
|
+
|
|
321
|
+
private get isInitialized() {
|
|
322
|
+
return !!(window as any)[isInitializedSymbol];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
private get registeredChanges(): typeof this.possibleChanges {
|
|
326
|
+
return (window as any)[registeredChangesSymbol];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
private get mapModifiableSectionToFetcher(): Record<ModifiableRootSection, () => void> {
|
|
330
|
+
return {
|
|
331
|
+
[ModifiableRootSection.Onboarding]: this.fetchOnboarding,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
298
334
|
}
|
package/src/utils/symbols.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const rootSymbolKey = 'standalone-root-symbol-key';
|
|
2
2
|
const eventEmitterSymbolKey = 'standalone-root-event-emitter-symbol-key';
|
|
3
|
+
const registeredChangesSymbolKey = 'standalone-root-modifiable-changes-symbol-key';
|
|
3
4
|
|
|
4
5
|
export const isInitializedSymbol = Symbol.for(rootSymbolKey);
|
|
5
6
|
export const eventEmitterSymbol = Symbol.for(eventEmitterSymbolKey);
|
|
6
|
-
export const
|
|
7
|
+
export const registeredChangesSymbol = Symbol.for(registeredChangesSymbolKey);
|