@jsb188/react 1.1.10 → 1.1.12
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/libs/README.md +75 -0
- package/libs/page-filters.helpers.ts +65 -0
- package/libs/page-filters.ts +223 -0
- package/libs/use-page-filters.ts +147 -0
- package/package.json +24 -20
- package/states/apiData.ts +18 -16
- package/states/appContext.ts +327 -312
- package/states/connected.ts +135 -11
- package/states/index.ts +2 -1
- package/states/keyDown.ts +148 -47
- package/states/keyboardLayer.ts +57 -0
- package/states/modal.ts +369 -268
- package/states/popOver.ts +374 -244
- package/states/reactiveEvents.ts +99 -0
- package/states/uploads.ts +39 -27
- package/types/PopOver.d.ts +552 -223
- package/utils/hooks.ts +387 -272
- package/utils/lazy.ts +183 -0
- package/states/toasts.ts +0 -30
- package/utils/schema.ts +0 -158
package/states/appContext.ts
CHANGED
|
@@ -9,21 +9,20 @@ import { createContext, useContext } from 'react';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
type AppContextAction = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data?: any;
|
|
12
|
+
__type: // App initialization
|
|
13
|
+
| 'APP_INIT'
|
|
14
|
+
// Auth setup
|
|
15
|
+
| 'APP_LOGIN'
|
|
16
|
+
| 'APP_GUEST'
|
|
17
|
+
| 'APP_REFRESH_AUTH'
|
|
18
|
+
| 'APP_EDIT_AUTH'
|
|
19
|
+
| 'APP_EDIT_ACCOUNT'
|
|
20
|
+
| 'APP_SWITCH_PRIMARY_ORGANIZATION'
|
|
21
|
+
// Account theme
|
|
22
|
+
| 'APP_THEME'
|
|
23
|
+
| 'APP_SYSTEM_LIGHT_MODE'
|
|
24
|
+
| 'APP_LIGHT_MODE';
|
|
25
|
+
data?: any;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
export type AppContextDispatch = (action: AppContextAction) => void;
|
|
@@ -35,33 +34,34 @@ export type CurrentAccountObj = ReturnType<typeof useCurrentAccount>;
|
|
|
35
34
|
*/
|
|
36
35
|
|
|
37
36
|
export type AppAppearanceType = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
realLightMode: LightModeEnum;
|
|
38
|
+
lightMode: LightModeEnum;
|
|
39
|
+
previewLightMode: LightModeEnum;
|
|
40
|
+
previewTheme: Record<string, any> | null;
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
export type AppContextData = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
// Required for app
|
|
45
|
+
init: 0 | 1 | 2; // 0 = not initialized,; 1 = loading; 2 = initialized
|
|
46
|
+
authorization: string; // This is token
|
|
47
|
+
networkError: boolean;
|
|
48
|
+
|
|
49
|
+
// Authentication data
|
|
50
|
+
account: AccountData | null;
|
|
51
|
+
primaryOrganizationId: string | null;
|
|
52
|
+
cacheAuthorizationEpoch: string | null;
|
|
53
|
+
|
|
54
|
+
// Account settings & state
|
|
55
|
+
settings: AccountSettings;
|
|
56
|
+
activated: boolean;
|
|
57
|
+
hasPassword: boolean;
|
|
58
|
+
webVersion: string | null;
|
|
59
|
+
alertUpdatesOnMount: boolean;
|
|
60
|
+
|
|
61
|
+
// Preview theme overrides active theme
|
|
62
|
+
systemLightMode: 'LIGHT' | 'DARK';
|
|
63
|
+
previewLightMode: LightModeEnum | null;
|
|
64
|
+
previewTheme: Record<string, any> | null;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -69,29 +69,27 @@ export type AppContextData = {
|
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
71
|
export const DEFAULT_APP_CONTEXT = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
previewLightMode: null,
|
|
94
|
-
previewTheme: null,
|
|
72
|
+
init: 0,
|
|
73
|
+
authorization: '',
|
|
74
|
+
networkError: false,
|
|
75
|
+
|
|
76
|
+
account: null,
|
|
77
|
+
primaryOrganizationId: null,
|
|
78
|
+
cacheAuthorizationEpoch: null,
|
|
79
|
+
|
|
80
|
+
settings: {
|
|
81
|
+
theme: null,
|
|
82
|
+
lightMode: 'LIGHT',
|
|
83
|
+
timeZone: null,
|
|
84
|
+
},
|
|
85
|
+
activated: false,
|
|
86
|
+
hasPassword: false,
|
|
87
|
+
webVersion: null,
|
|
88
|
+
alertUpdatesOnMount: false,
|
|
89
|
+
|
|
90
|
+
systemLightMode: 'LIGHT',
|
|
91
|
+
previewLightMode: null,
|
|
92
|
+
previewTheme: null,
|
|
95
93
|
} as AppContextData;
|
|
96
94
|
|
|
97
95
|
/**
|
|
@@ -99,7 +97,7 @@ export const DEFAULT_APP_CONTEXT = {
|
|
|
99
97
|
*/
|
|
100
98
|
|
|
101
99
|
function ensureLightModeSetting(lightMode?: LightModeEnum): LightModeEnum {
|
|
102
|
-
|
|
100
|
+
return lightMode && ['LIGHT', 'DARK', 'SYSTEM'].includes(lightMode || '') ? lightMode : 'LIGHT';
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
/**
|
|
@@ -107,24 +105,24 @@ function ensureLightModeSetting(lightMode?: LightModeEnum): LightModeEnum {
|
|
|
107
105
|
*/
|
|
108
106
|
|
|
109
107
|
export function onAccountLogin(auth: any, dispatchApp: AppContextDispatch, otherCB?: (auth: any) => void) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
108
|
+
if (auth && auth?.token && auth.activated && auth.account) {
|
|
109
|
+
console.log('.. 🥝 logged into account ..');
|
|
110
|
+
|
|
111
|
+
saveAuthTokenToPlatform(auth.token, () => {
|
|
112
|
+
clearAppCache();
|
|
113
|
+
dispatchApp({
|
|
114
|
+
__type: 'APP_LOGIN',
|
|
115
|
+
data: auth,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (otherCB) {
|
|
119
|
+
otherCB(auth);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
console.log(auth);
|
|
124
|
+
console.warn('Developer error in onAccountLogin()');
|
|
125
|
+
}
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
/**
|
|
@@ -132,40 +130,33 @@ export function onAccountLogin(auth: any, dispatchApp: AppContextDispatch, other
|
|
|
132
130
|
*/
|
|
133
131
|
|
|
134
132
|
export function onGuestInit(error: any, dispatchApp: AppContextDispatch) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
fetchLightModeSetting(null, (lightMode) => {
|
|
134
|
+
dispatchApp({
|
|
135
|
+
__type: 'APP_GUEST',
|
|
136
|
+
data: {
|
|
137
|
+
error,
|
|
138
|
+
lightMode,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
});
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
/**
|
|
147
145
|
* Get active/current or preview theme
|
|
148
146
|
*/
|
|
149
147
|
|
|
150
|
-
export function getTheme(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
''
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
lightMode: lightMode || 'LIGHT',
|
|
167
|
-
theme,
|
|
168
|
-
};
|
|
148
|
+
export function getTheme(appState: AppContextData, priority: 'PREVIEW' | 'ACCOUNT' | 'ACTIVE') {
|
|
149
|
+
let lightMode = appState.previewLightMode || appState.settings.lightMode;
|
|
150
|
+
if (lightMode === 'SYSTEM') {
|
|
151
|
+
lightMode = appState.systemLightMode;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const theme = (priority === 'PREVIEW' && appState.previewTheme) || appState.settings.theme || '';
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
lightMode: lightMode || 'LIGHT',
|
|
158
|
+
theme,
|
|
159
|
+
};
|
|
169
160
|
}
|
|
170
161
|
|
|
171
162
|
/**
|
|
@@ -173,69 +164,67 @@ export function getTheme(
|
|
|
173
164
|
*/
|
|
174
165
|
|
|
175
166
|
export function getPreviewAppearance(appState: AppContextData) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
167
|
+
let realLightMode = appState.previewLightMode || appState.settings.lightMode;
|
|
168
|
+
if (realLightMode === 'SYSTEM') {
|
|
169
|
+
realLightMode = appState.systemLightMode;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
realLightMode,
|
|
174
|
+
lightMode: appState.settings.lightMode,
|
|
175
|
+
previewLightMode: appState.previewLightMode,
|
|
176
|
+
previewTheme: appState.previewTheme,
|
|
177
|
+
};
|
|
187
178
|
}
|
|
188
179
|
|
|
189
180
|
/**
|
|
190
181
|
* Merge sign in mutation auth values to context
|
|
191
182
|
*/
|
|
192
183
|
|
|
193
|
-
export function mergeAuthToDefaultValues(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
setAuthToken(null);
|
|
238
|
-
return DEFAULT_APP_CONTEXT;
|
|
184
|
+
export function mergeAuthToDefaultValues(auth?: AuthenticationData | null, authToken?: string | null) {
|
|
185
|
+
if (auth?.token && auth?.account?.id) {
|
|
186
|
+
let systemLightMode = 'LIGHT';
|
|
187
|
+
if (isSystemDarkMode()) {
|
|
188
|
+
systemLightMode = 'DARK';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
setAuthToken(auth.token);
|
|
192
|
+
|
|
193
|
+
const authSettings = {
|
|
194
|
+
...DEFAULT_APP_CONTEXT.settings,
|
|
195
|
+
...auth.account.settings,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
authSettings.lightMode = ensureLightModeSetting(authSettings.lightMode);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
...DEFAULT_APP_CONTEXT,
|
|
202
|
+
init: 1, // Always 1 because we're always using SSR for authentication
|
|
203
|
+
authorization: auth.token,
|
|
204
|
+
account: auth.account,
|
|
205
|
+
primaryOrganizationId: auth.primaryOrganizationId || null,
|
|
206
|
+
cacheAuthorizationEpoch: auth.cacheAuthorizationEpoch || null,
|
|
207
|
+
settings: authSettings,
|
|
208
|
+
|
|
209
|
+
alertUpdatesOnMount: auth.alertUpdatesOnMount,
|
|
210
|
+
hasPassword: auth.hasPassword,
|
|
211
|
+
webVersion: auth.webVersion,
|
|
212
|
+
|
|
213
|
+
// Theme
|
|
214
|
+
systemLightMode,
|
|
215
|
+
previewLightMode: null,
|
|
216
|
+
previewTheme: null,
|
|
217
|
+
};
|
|
218
|
+
} else if (authToken) {
|
|
219
|
+
setAuthToken(authToken);
|
|
220
|
+
return {
|
|
221
|
+
...DEFAULT_APP_CONTEXT,
|
|
222
|
+
authorization: authToken || '',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setAuthToken(null);
|
|
227
|
+
return DEFAULT_APP_CONTEXT;
|
|
239
228
|
}
|
|
240
229
|
|
|
241
230
|
/**
|
|
@@ -243,129 +232,149 @@ export function mergeAuthToDefaultValues(
|
|
|
243
232
|
*/
|
|
244
233
|
|
|
245
234
|
export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
235
|
+
const { __type, data } = action;
|
|
236
|
+
|
|
237
|
+
switch (__type) {
|
|
238
|
+
case 'APP_INIT': {
|
|
239
|
+
return {
|
|
240
|
+
...state,
|
|
241
|
+
init: state.init === 1 ? 2 : 1,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
case 'APP_LOGIN': {
|
|
245
|
+
const nextState = mergeAuthToDefaultValues(data);
|
|
246
|
+
// Inline sign-in keeps the mounted app's completed initialization.
|
|
247
|
+
return { ...nextState, init: state.init === 2 ? 2 : nextState.init };
|
|
248
|
+
}
|
|
249
|
+
case 'APP_REFRESH_AUTH': {
|
|
250
|
+
const authorization = data?.authorization || '';
|
|
251
|
+
if (!authorization) {
|
|
252
|
+
return state;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
setAuthToken(authorization);
|
|
256
|
+
return {
|
|
257
|
+
...state,
|
|
258
|
+
authorization,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
case 'APP_GUEST': {
|
|
262
|
+
const networkError = data.error?.errorCode === 'network_error';
|
|
263
|
+
if (networkError) {
|
|
264
|
+
console.log('.. ❌ network error ..');
|
|
265
|
+
} else {
|
|
266
|
+
console.log('.. 🥝 guest entered ..');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
clearAppCache();
|
|
270
|
+
setAuthToken(null);
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
...DEFAULT_APP_CONTEXT,
|
|
274
|
+
init: 2,
|
|
275
|
+
authorization: '',
|
|
276
|
+
networkError,
|
|
277
|
+
|
|
278
|
+
// Theme
|
|
279
|
+
previewLightMode: null,
|
|
280
|
+
previewTheme: null,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
case 'APP_EDIT_AUTH': {
|
|
284
|
+
if (data.id === state.account?.id) {
|
|
285
|
+
return {
|
|
286
|
+
...state,
|
|
287
|
+
hasPassword: typeof data.hasPassword === 'boolean' ? data.hasPassword : state.hasPassword,
|
|
288
|
+
account: !data.email
|
|
289
|
+
? state.account
|
|
290
|
+
: {
|
|
291
|
+
...state.account,
|
|
292
|
+
email: data.email,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
return state;
|
|
297
|
+
}
|
|
298
|
+
case 'APP_EDIT_ACCOUNT': {
|
|
299
|
+
if (data.id === state.account?.id) {
|
|
300
|
+
return {
|
|
301
|
+
...state,
|
|
302
|
+
|
|
303
|
+
// Account
|
|
304
|
+
account: {
|
|
305
|
+
...state.account,
|
|
306
|
+
...data,
|
|
307
|
+
plus: !data.plus
|
|
308
|
+
? state.account?.plus
|
|
309
|
+
: {
|
|
310
|
+
...state.account?.plus,
|
|
311
|
+
...data.plus,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
settings: !data.settings
|
|
315
|
+
? state.settings
|
|
316
|
+
: {
|
|
317
|
+
...DEFAULT_APP_CONTEXT.settings,
|
|
318
|
+
...data.settings,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return state;
|
|
323
|
+
}
|
|
324
|
+
case 'APP_SWITCH_PRIMARY_ORGANIZATION': {
|
|
325
|
+
return {
|
|
326
|
+
...state,
|
|
327
|
+
primaryOrganizationId: data.primaryOrganizationId,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
case 'APP_THEME': {
|
|
331
|
+
if (!data?.preview) {
|
|
332
|
+
// Active theme
|
|
333
|
+
return {
|
|
334
|
+
...state,
|
|
335
|
+
previewTheme: null,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Is preview theme
|
|
340
|
+
return {
|
|
341
|
+
...state,
|
|
342
|
+
previewTheme: data.theme,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
case 'APP_LIGHT_MODE': {
|
|
346
|
+
if (!data.lightMode && !data.preview) {
|
|
347
|
+
console.warn('Developer error in setLightMode(): You cannot set active lightMode to null.');
|
|
348
|
+
return state;
|
|
349
|
+
} else if (data.preview) {
|
|
350
|
+
return {
|
|
351
|
+
...state,
|
|
352
|
+
previewLightMode: data.lightMode,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return {
|
|
357
|
+
...state,
|
|
358
|
+
previewLightMode: null,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
case 'APP_SYSTEM_LIGHT_MODE': {
|
|
362
|
+
return {
|
|
363
|
+
...state,
|
|
364
|
+
systemLightMode: data.lightMode,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
default:
|
|
368
|
+
console.dev('Unknown app reducer action type:', __type);
|
|
369
|
+
return state;
|
|
370
|
+
}
|
|
362
371
|
};
|
|
363
372
|
|
|
364
373
|
export const AppContext = createContext({
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
374
|
+
appState: DEFAULT_APP_CONTEXT as AppContextData,
|
|
375
|
+
dispatchApp: (() => {
|
|
376
|
+
console.warn('AppContext has been re-initialized due to hot refresh.');
|
|
377
|
+
}) as AppContextDispatch,
|
|
369
378
|
});
|
|
370
379
|
|
|
371
380
|
/**
|
|
@@ -373,30 +382,34 @@ export const AppContext = createContext({
|
|
|
373
382
|
*/
|
|
374
383
|
|
|
375
384
|
export function useCurrentAccount() {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
385
|
+
const {
|
|
386
|
+
appState: { init, activated, hasPassword, webVersion, alertUpdatesOnMount, account, settings, primaryOrganizationId },
|
|
387
|
+
dispatchApp,
|
|
388
|
+
} = useContext(AppContext);
|
|
389
|
+
const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
|
|
390
|
+
const { fullName, displayName } = getDisplayName(account?.profile?.firstName, account?.profile?.lastName);
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
// Dispatch
|
|
394
|
+
dispatchApp,
|
|
395
|
+
|
|
396
|
+
// App state
|
|
397
|
+
init,
|
|
398
|
+
account,
|
|
399
|
+
settings,
|
|
400
|
+
activated,
|
|
401
|
+
hasPassword,
|
|
402
|
+
webVersion,
|
|
403
|
+
alertUpdatesOnMount,
|
|
404
|
+
|
|
405
|
+
// Computed
|
|
406
|
+
isLoggedIn: !!account?.id,
|
|
407
|
+
hasName,
|
|
408
|
+
fullName,
|
|
409
|
+
displayName,
|
|
410
|
+
labelName: displayName || account?.email?.address || '?',
|
|
411
|
+
primaryOrganizationId,
|
|
412
|
+
};
|
|
400
413
|
}
|
|
401
414
|
|
|
402
415
|
/**
|
|
@@ -404,6 +417,8 @@ export function useCurrentAccount() {
|
|
|
404
417
|
*/
|
|
405
418
|
|
|
406
419
|
export function useIsLoggedIn() {
|
|
407
|
-
|
|
408
|
-
|
|
420
|
+
const {
|
|
421
|
+
appState: { account },
|
|
422
|
+
} = useContext(AppContext);
|
|
423
|
+
return !!account?.id;
|
|
409
424
|
}
|