dce-reactkit 3.6.1 → 3.6.3
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/dist/cjs/index.js +72 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +2 -2
- package/dist/esm/index.js +72 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +63 -8
- package/src/helpers/visitServerEndpoint.tsx +38 -0
|
@@ -50,7 +50,7 @@ export declare const confirm: (title: string, text: string, opts?: {
|
|
|
50
50
|
* @param error the error to show
|
|
51
51
|
* @param [errorTitle] title of the error box
|
|
52
52
|
*/
|
|
53
|
-
export declare const showFatalError: (error: any, errorTitle?: string) =>
|
|
53
|
+
export declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* Add a handler for when a fatal error occurs
|
|
56
56
|
* @author Gabe Abrams
|
|
@@ -60,6 +60,6 @@ export declare const addFatalErrorHandler: (handler: () => void) => void;
|
|
|
60
60
|
* Show the "session expired" message
|
|
61
61
|
* @author Gabe Abrams
|
|
62
62
|
*/
|
|
63
|
-
export declare const showSessionExpiredMessage: () =>
|
|
63
|
+
export declare const showSessionExpiredMessage: () => Promise<void>;
|
|
64
64
|
declare const AppWrapper: React.FC<Props>;
|
|
65
65
|
export default AppWrapper;
|
package/dist/index.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ declare const confirm: (title: string, text: string, opts?: {
|
|
|
69
69
|
* @param error the error to show
|
|
70
70
|
* @param [errorTitle] title of the error box
|
|
71
71
|
*/
|
|
72
|
-
declare const showFatalError: (error: any, errorTitle?: string) =>
|
|
72
|
+
declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>;
|
|
73
73
|
/**
|
|
74
74
|
* Add a handler for when a fatal error occurs
|
|
75
75
|
* @author Gabe Abrams
|
package/package.json
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
getSessionExpiredMessage,
|
|
34
34
|
isDarkModeOn,
|
|
35
35
|
} from '../client/initClient';
|
|
36
|
+
import waitMs from '../helpers/waitMs';
|
|
36
37
|
|
|
37
38
|
/*------------------------------------------------------------------------*/
|
|
38
39
|
/* -------------------------------- Props ------------------------------- */
|
|
@@ -47,6 +48,32 @@ type Props = {
|
|
|
47
48
|
/* --------------------------- Static Helpers --------------------------- */
|
|
48
49
|
/*------------------------------------------------------------------------*/
|
|
49
50
|
|
|
51
|
+
// Timestamp after initialization when helpers should be available
|
|
52
|
+
const timestampWhenHelpersShouldBeAvailable = Date.now() + 2000;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wait for a little while for a helper to exist
|
|
56
|
+
* @author Gabe Abrams
|
|
57
|
+
* @param checkForHelper a function that returns true if the helper exists
|
|
58
|
+
* @returns true if the helper exists, false if the process timed out
|
|
59
|
+
*/
|
|
60
|
+
const waitForHelper = async (checkForHelper: () => boolean): Promise<boolean> => {
|
|
61
|
+
// Wait for helper to exist
|
|
62
|
+
while (!checkForHelper()) {
|
|
63
|
+
// Check if we should stop waiting
|
|
64
|
+
if (Date.now() > timestampWhenHelpersShouldBeAvailable) {
|
|
65
|
+
// Stop waiting
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Wait a little while
|
|
70
|
+
await waitMs(10);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Helper exists
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
|
|
50
77
|
/*----------------------------------------*/
|
|
51
78
|
/* ----------- Redirect/Leave ----------- */
|
|
52
79
|
/*----------------------------------------*/
|
|
@@ -103,6 +130,11 @@ let onAlertClosed: () => void;
|
|
|
103
130
|
* @param text the text to display in the alert
|
|
104
131
|
*/
|
|
105
132
|
export const alert = async (title: string, text: string): Promise<undefined> => {
|
|
133
|
+
// Wait for helper to exist
|
|
134
|
+
await waitForHelper(() => {
|
|
135
|
+
return !!setAlertInfo;
|
|
136
|
+
});
|
|
137
|
+
|
|
106
138
|
// Fallback if alert not available
|
|
107
139
|
if (!setAlertInfo) {
|
|
108
140
|
// eslint-disable-next-line no-alert
|
|
@@ -172,6 +204,11 @@ export const confirm = async (
|
|
|
172
204
|
cancelButtonVariant?: Variant,
|
|
173
205
|
},
|
|
174
206
|
): Promise<boolean> => {
|
|
207
|
+
// Wait for helper to exist
|
|
208
|
+
await waitForHelper(() => {
|
|
209
|
+
return !!setConfirmInfo;
|
|
210
|
+
});
|
|
211
|
+
|
|
175
212
|
// Fallback if confirm is not available
|
|
176
213
|
if (!setConfirmInfo) {
|
|
177
214
|
// eslint-disable-next-line no-alert
|
|
@@ -212,10 +249,10 @@ const fatalErrorHandlers: (() => void)[] = [];
|
|
|
212
249
|
* @param error the error to show
|
|
213
250
|
* @param [errorTitle] title of the error box
|
|
214
251
|
*/
|
|
215
|
-
export const showFatalError = (
|
|
252
|
+
export const showFatalError = async (
|
|
216
253
|
error: any,
|
|
217
254
|
errorTitle: string = 'An Error Occurred',
|
|
218
|
-
)
|
|
255
|
+
) => {
|
|
219
256
|
// Determine message and code
|
|
220
257
|
const message: string = (
|
|
221
258
|
typeof error === 'string'
|
|
@@ -250,21 +287,27 @@ export const showFatalError = (
|
|
|
250
287
|
},
|
|
251
288
|
});
|
|
252
289
|
|
|
290
|
+
// Wait for helper to exist
|
|
291
|
+
await waitForHelper(() => {
|
|
292
|
+
return (
|
|
293
|
+
!!setFatalErrorMessage
|
|
294
|
+
&& !!setFatalErrorCode
|
|
295
|
+
);
|
|
296
|
+
});
|
|
297
|
+
|
|
253
298
|
// Handle case where app hasn't loaded
|
|
254
299
|
if (!setFatalErrorMessage || !setFatalErrorCode) {
|
|
255
300
|
alert(
|
|
256
301
|
errorTitle,
|
|
257
302
|
`${message} (code: ${code}). Please contact support.`,
|
|
258
303
|
);
|
|
259
|
-
return
|
|
304
|
+
return;
|
|
260
305
|
}
|
|
261
306
|
|
|
262
307
|
// Use setters
|
|
263
308
|
setFatalErrorMessage(message);
|
|
264
309
|
setFatalErrorCode(code);
|
|
265
310
|
setFatalErrorTitle(errorTitle);
|
|
266
|
-
|
|
267
|
-
return undefined;
|
|
268
311
|
};
|
|
269
312
|
|
|
270
313
|
/**
|
|
@@ -286,9 +329,21 @@ let setSessionHasExpired: (isExpired: boolean) => void;
|
|
|
286
329
|
* Show the "session expired" message
|
|
287
330
|
* @author Gabe Abrams
|
|
288
331
|
*/
|
|
289
|
-
export const showSessionExpiredMessage = ()
|
|
290
|
-
|
|
291
|
-
|
|
332
|
+
export const showSessionExpiredMessage = async () => {
|
|
333
|
+
// Wait for helper to exist
|
|
334
|
+
await waitForHelper(() => {
|
|
335
|
+
return !!setSessionHasExpired;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Show session expired message
|
|
339
|
+
if (setSessionHasExpired) {
|
|
340
|
+
setSessionHasExpired(true);
|
|
341
|
+
} else {
|
|
342
|
+
showFatalError(
|
|
343
|
+
'Your session has expired. Please start over.',
|
|
344
|
+
'Session Expired',
|
|
345
|
+
);
|
|
346
|
+
}
|
|
292
347
|
};
|
|
293
348
|
|
|
294
349
|
/*------------------------------------------------------------------------*/
|
|
@@ -1,9 +1,42 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
3
|
// Import custom error
|
|
2
4
|
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
3
5
|
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
4
6
|
|
|
5
7
|
// Import helpers
|
|
6
8
|
import { getSendRequest } from '../client/initClient';
|
|
9
|
+
import waitMs from './waitMs';
|
|
10
|
+
|
|
11
|
+
/*------------------------------------------------------------------------*/
|
|
12
|
+
/* --------------------------- Static Helpers --------------------------- */
|
|
13
|
+
/*------------------------------------------------------------------------*/
|
|
14
|
+
|
|
15
|
+
// Timestamp after initialization when helpers should be available
|
|
16
|
+
const timestampWhenHelpersShouldBeAvailable = Date.now() + 2000;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wait for a little while for a helper to exist
|
|
20
|
+
* @author Gabe Abrams
|
|
21
|
+
* @param checkForHelper a function that returns true if the helper exists
|
|
22
|
+
* @returns true if the helper exists, false if the process timed out
|
|
23
|
+
*/
|
|
24
|
+
const waitForHelper = async (checkForHelper: () => boolean): Promise<boolean> => {
|
|
25
|
+
// Wait for helper to exist
|
|
26
|
+
while (!checkForHelper()) {
|
|
27
|
+
// Check if we should stop waiting
|
|
28
|
+
if (Date.now() > timestampWhenHelpersShouldBeAvailable) {
|
|
29
|
+
// Stop waiting
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Wait a little while
|
|
34
|
+
await waitMs(10);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Helper exists
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
7
40
|
|
|
8
41
|
/*------------------------------------------------------------------------*/
|
|
9
42
|
/* Listener */
|
|
@@ -164,6 +197,11 @@ const visitServerEndpoint = async (
|
|
|
164
197
|
}
|
|
165
198
|
sessionAlreadyExpired = true;
|
|
166
199
|
|
|
200
|
+
// Wait for helper to exist
|
|
201
|
+
await waitForHelper(() => {
|
|
202
|
+
return !!sessionExpiryHandler;
|
|
203
|
+
});
|
|
204
|
+
|
|
167
205
|
// Show session expiration message
|
|
168
206
|
if (sessionExpiryHandler) {
|
|
169
207
|
// Use handler
|