dce-reactkit 2.0.11 → 3.0.0-beta.10

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.
Files changed (129) hide show
  1. package/dist/cjs/index.js +921 -0
  2. package/dist/cjs/index.js.map +1 -0
  3. package/{lib → dist/cjs/types}/components/AppWrapper.d.ts +9 -4
  4. package/{lib → dist/cjs/types}/components/ErrorBox.d.ts +0 -0
  5. package/{lib → dist/cjs/types}/components/LoadingSpinner.d.ts +1 -0
  6. package/{lib → dist/cjs/types}/components/Modal.d.ts +5 -36
  7. package/{lib → dist/cjs/types}/components/TabBox.d.ts +0 -0
  8. package/{lib → dist/cjs/types}/errors/ErrorWithCode.d.ts +0 -0
  9. package/{lib → dist/cjs/types}/helpers/abbreviate.d.ts +1 -0
  10. package/{lib → dist/cjs/types}/helpers/avg.d.ts +0 -0
  11. package/{lib → dist/cjs/types}/helpers/ceilToNumDecimals.d.ts +0 -0
  12. package/{lib → dist/cjs/types}/helpers/floorToNumDecimals.d.ts +0 -0
  13. package/{lib → dist/cjs/types}/helpers/forceNumIntoBounds.d.ts +0 -0
  14. package/{lib → dist/cjs/types}/helpers/padDecimalZeros.d.ts +0 -0
  15. package/{lib → dist/cjs/types}/helpers/padZerosLeft.d.ts +0 -0
  16. package/{lib → dist/cjs/types}/helpers/roundToNumDecimals.d.ts +0 -0
  17. package/{lib → dist/cjs/types}/helpers/sum.d.ts +0 -0
  18. package/{lib → dist/cjs/types}/helpers/waitMs.d.ts +0 -0
  19. package/dist/cjs/types/index.d.ts +22 -0
  20. package/dist/cjs/types/types/ModalButtonType.d.ts +17 -0
  21. package/dist/cjs/types/types/ModalSize.d.ts +11 -0
  22. package/dist/cjs/types/types/ModalType.d.ts +16 -0
  23. package/{lib → dist/cjs/types}/types/ReactKitErrorCode.d.ts +0 -0
  24. package/{lib → dist/cjs/types}/types/Variant.d.ts +0 -0
  25. package/dist/esm/index.js +890 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/types/components/AppWrapper.d.ts +40 -0
  28. package/dist/esm/types/components/ErrorBox.d.ts +12 -0
  29. package/dist/esm/types/components/LoadingSpinner.d.ts +7 -0
  30. package/dist/esm/types/components/Modal.d.ts +40 -0
  31. package/dist/esm/types/components/TabBox.d.ts +11 -0
  32. package/dist/esm/types/errors/ErrorWithCode.d.ts +9 -0
  33. package/dist/esm/types/helpers/abbreviate.d.ts +10 -0
  34. package/dist/esm/types/helpers/avg.d.ts +8 -0
  35. package/dist/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
  36. package/dist/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
  37. package/dist/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
  38. package/dist/esm/types/helpers/padDecimalZeros.d.ts +10 -0
  39. package/dist/esm/types/helpers/padZerosLeft.d.ts +9 -0
  40. package/dist/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
  41. package/dist/esm/types/helpers/sum.d.ts +8 -0
  42. package/dist/esm/types/helpers/waitMs.d.ts +7 -0
  43. package/dist/esm/types/index.d.ts +22 -0
  44. package/dist/esm/types/types/ModalButtonType.d.ts +17 -0
  45. package/dist/esm/types/types/ModalSize.d.ts +11 -0
  46. package/dist/esm/types/types/ModalType.d.ts +16 -0
  47. package/dist/esm/types/types/ReactKitErrorCode.d.ts +13 -0
  48. package/dist/esm/types/types/Variant.d.ts +15 -0
  49. package/dist/index.d.ts +274 -0
  50. package/package.json +23 -15
  51. package/rollup.config.js +45 -0
  52. package/src/components/AppWrapper.tsx +38 -37
  53. package/src/components/LoadingSpinner.tsx +3 -0
  54. package/src/components/Modal.tsx +86 -173
  55. package/src/helpers/abbreviate.tsx +2 -0
  56. package/src/helpers/padDecimalZeros.tsx +1 -1
  57. package/src/index.ts +61 -0
  58. package/src/types/ModalButtonType.tsx +18 -0
  59. package/src/types/ModalSize.tsx +12 -0
  60. package/src/types/ModalType.tsx +17 -0
  61. package/tsconfig.json +16 -17
  62. package/lib/components/AppWrapper.js +0 -277
  63. package/lib/components/AppWrapper.js.map +0 -1
  64. package/lib/components/ErrorBox.js +0 -65
  65. package/lib/components/ErrorBox.js.map +0 -1
  66. package/lib/components/LoadingSpinner.js +0 -41
  67. package/lib/components/LoadingSpinner.js.map +0 -1
  68. package/lib/components/Modal.js +0 -321
  69. package/lib/components/Modal.js.map +0 -1
  70. package/lib/components/TabBox.js +0 -42
  71. package/lib/components/TabBox.js.map +0 -1
  72. package/lib/errors/ErrorWithCode.js +0 -33
  73. package/lib/errors/ErrorWithCode.js.map +0 -1
  74. package/lib/helpers/abbreviate.js +0 -21
  75. package/lib/helpers/abbreviate.js.map +0 -1
  76. package/lib/helpers/alert.d.ts +0 -2
  77. package/lib/helpers/alert.js +0 -5
  78. package/lib/helpers/alert.js.map +0 -1
  79. package/lib/helpers/avg.js +0 -24
  80. package/lib/helpers/avg.js.map +0 -1
  81. package/lib/helpers/ceilToNumDecimals.js +0 -15
  82. package/lib/helpers/ceilToNumDecimals.js.map +0 -1
  83. package/lib/helpers/confirm.d.ts +0 -2
  84. package/lib/helpers/confirm.js +0 -5
  85. package/lib/helpers/confirm.js.map +0 -1
  86. package/lib/helpers/floorToNumDecimals.js +0 -15
  87. package/lib/helpers/floorToNumDecimals.js.map +0 -1
  88. package/lib/helpers/forceNumIntoBounds.js +0 -15
  89. package/lib/helpers/forceNumIntoBounds.js.map +0 -1
  90. package/lib/helpers/handleError.d.ts +0 -14
  91. package/lib/helpers/handleError.js +0 -54
  92. package/lib/helpers/handleError.js.map +0 -1
  93. package/lib/helpers/handleSuccess.d.ts +0 -8
  94. package/lib/helpers/handleSuccess.js +0 -20
  95. package/lib/helpers/handleSuccess.js.map +0 -1
  96. package/lib/helpers/padDecimalZeros.js +0 -30
  97. package/lib/helpers/padDecimalZeros.js.map +0 -1
  98. package/lib/helpers/padZerosLeft.js +0 -21
  99. package/lib/helpers/padZerosLeft.js.map +0 -1
  100. package/lib/helpers/parseRequest.d.ts +0 -21
  101. package/lib/helpers/parseRequest.js +0 -240
  102. package/lib/helpers/parseRequest.js.map +0 -1
  103. package/lib/helpers/roundToNumDecimals.js +0 -15
  104. package/lib/helpers/roundToNumDecimals.js.map +0 -1
  105. package/lib/helpers/showFatalError.d.ts +0 -2
  106. package/lib/helpers/showFatalError.js +0 -5
  107. package/lib/helpers/showFatalError.js.map +0 -1
  108. package/lib/helpers/sum.js +0 -15
  109. package/lib/helpers/sum.js.map +0 -1
  110. package/lib/helpers/visitServerEndpoint.d.ts +0 -23
  111. package/lib/helpers/visitServerEndpoint.js +0 -135
  112. package/lib/helpers/visitServerEndpoint.js.map +0 -1
  113. package/lib/helpers/waitMs.js +0 -55
  114. package/lib/helpers/waitMs.js.map +0 -1
  115. package/lib/types/ParamType.d.ts +0 -17
  116. package/lib/types/ParamType.js +0 -21
  117. package/lib/types/ParamType.js.map +0 -1
  118. package/lib/types/ReactKitErrorCode.js +0 -18
  119. package/lib/types/ReactKitErrorCode.js.map +0 -1
  120. package/lib/types/Variant.js +0 -19
  121. package/lib/types/Variant.js.map +0 -1
  122. package/src/helpers/alert.tsx +0 -3
  123. package/src/helpers/confirm.tsx +0 -3
  124. package/src/helpers/handleError.ts +0 -65
  125. package/src/helpers/handleSuccess.ts +0 -18
  126. package/src/helpers/parseRequest.ts +0 -299
  127. package/src/helpers/showFatalError.tsx +0 -3
  128. package/src/helpers/visitServerEndpoint.tsx +0 -110
  129. package/src/types/ParamType.ts +0 -18
@@ -0,0 +1,274 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+
4
+ /**
5
+ * A wrapper for the entire React app that adds global functionality like
6
+ * handling for fatal error messages, adds bootstrap support
7
+ * @author Gabe Abrams
8
+ */
9
+
10
+ declare type Props$3 = {
11
+ children: React.ReactNode;
12
+ dark?: boolean;
13
+ sessionExpiredMessage?: string;
14
+ };
15
+ /**
16
+ * Show an alert modal with an "Okay" button
17
+ * @author Gabe Abrams
18
+ * @param title the title text to display at the top of the alert
19
+ * @param text the text to display in the alert
20
+ */
21
+ declare const alert: (title: string, text: string) => Promise<undefined>;
22
+ /**
23
+ * Show a confirmation modal with an "Okay" and a "Cancel" button
24
+ * @author Gabe Abrams
25
+ * @param title the title text to display at the top of the alert
26
+ * @param text the text to display in the alert
27
+ * @returns true if the user confirmed
28
+ */
29
+ declare const confirm: (title: string, text: string) => Promise<boolean>;
30
+ /**
31
+ * Show a fatal error message
32
+ * @author Gabe Abrams
33
+ * @param error the error to show
34
+ * @param [errorTitle] title of the error box
35
+ */
36
+ declare const showFatalError: (error: any, errorTitle?: string) => undefined;
37
+ declare const AppWrapper: React.FC<Props$3>;
38
+
39
+ /**
40
+ * Loading spinner/indicator
41
+ * @author Gabe Abrams
42
+ */
43
+ declare const LoadingSpinner: () => JSX.Element;
44
+
45
+ /**
46
+ * Displays an error
47
+ * @author Gabe Abrams
48
+ */
49
+
50
+ declare type Props$2 = {
51
+ error: any;
52
+ title?: string;
53
+ onClose?: () => void;
54
+ };
55
+ declare const ErrorBox: React.FC<Props$2>;
56
+
57
+ /**
58
+ * Bootstrap variants
59
+ * @author Gabe Abrams
60
+ */
61
+ declare enum Variant {
62
+ Primary = "primary",
63
+ Secondary = "secondary",
64
+ Success = "success",
65
+ Warning = "warning",
66
+ Info = "info",
67
+ Danger = "danger",
68
+ Light = "light",
69
+ Dark = "dark"
70
+ }
71
+
72
+ /**
73
+ * Types of buttons in the modal
74
+ * @author Gabe Abrams
75
+ */
76
+ declare enum ModalButtonType {
77
+ Okay = "okay",
78
+ Cancel = "cancel",
79
+ Yes = "yes",
80
+ No = "no",
81
+ Abandon = "abandon",
82
+ GoBack = "goBack",
83
+ Continue = "continue",
84
+ ImSure = "imSure",
85
+ Delete = "delete",
86
+ Confirm = "confirm"
87
+ }
88
+
89
+ /**
90
+ * Modal sizes
91
+ * @author Gabe Abrams
92
+ */
93
+ declare enum ModalSize {
94
+ Small = "sm",
95
+ Medium = "md",
96
+ Large = "lg",
97
+ ExtraLarge = "xl"
98
+ }
99
+
100
+ /**
101
+ * Types of modals
102
+ * @author Gabe Abrams
103
+ */
104
+ declare enum ModalType {
105
+ Okay = "okay",
106
+ OkayCancel = "okay-cancel",
107
+ YesNo = "yes-no",
108
+ YesNoCancel = "yes-no-cancel",
109
+ AbandonGoBack = "abandon-goBack",
110
+ ImSureCancel = "imSure-cancel",
111
+ DeleteCancel = "delete-cancel",
112
+ ConfirmCancel = "confirm-cancel",
113
+ NoButtons = "-"
114
+ }
115
+
116
+ /**
117
+ * A generic popup modal
118
+ * @author Gabe Abrams
119
+ */
120
+
121
+ declare type Props$1 = {
122
+ type?: ModalType;
123
+ size?: ModalSize;
124
+ title?: React.ReactNode;
125
+ children?: React.ReactNode;
126
+ onClose?: (type: ModalButtonType) => void;
127
+ dontAllowBackdropExit?: boolean;
128
+ okayLabel?: string;
129
+ okayVariant?: Variant;
130
+ cancelLabel?: string;
131
+ cancelVariant?: Variant;
132
+ yesLabel?: string;
133
+ yesVariant?: Variant;
134
+ noLabel?: string;
135
+ noVariant?: Variant;
136
+ abandonLabel?: string;
137
+ abandonVariant?: Variant;
138
+ goBackLabel?: string;
139
+ goBackVariant?: Variant;
140
+ continueLabel?: string;
141
+ continueVariant?: Variant;
142
+ imSureLabel?: string;
143
+ imSureVariant?: Variant;
144
+ deleteLabel?: string;
145
+ deleteVariant?: Variant;
146
+ confirmLabel?: string;
147
+ confirmVariant?: Variant;
148
+ onTopOfOtherModals?: boolean;
149
+ };
150
+ declare const Modal: React.FC<Props$1>;
151
+
152
+ /**
153
+ * A box with a tab on the top that holds buttons and other content
154
+ * @author Gabe Abrams
155
+ */
156
+
157
+ declare type Props = {
158
+ title: React.ReactNode;
159
+ children: React.ReactNode;
160
+ };
161
+ declare const TabBox: React.FC<Props>;
162
+
163
+ /**
164
+ * An error with a code
165
+ * @author Gabe Abrams
166
+ */
167
+ declare class ErrorWithCode extends Error {
168
+ code: string;
169
+ constructor(message: string, code: string);
170
+ }
171
+
172
+ /**
173
+ * Shorten text so it fits into a certain number of chars
174
+ * @author Gabe Abrams
175
+ * @param text the text to abbreviate
176
+ * @param maxChars the maximum number of chars to include
177
+ * @returns abbreviated text with length no greater than maxChars
178
+ * (including ellipses if applicable)
179
+ */
180
+ declare const abbreviate: (text: string, maxChars: number) => string;
181
+
182
+ /**
183
+ * Get the average of a set of numbers
184
+ * @author Gabe Abrams
185
+ * @param nums the numbers to average
186
+ * @returns average value or 0 if no numbers
187
+ */
188
+ declare const avg: (nums: number[]) => number;
189
+
190
+ /**
191
+ * Round a number (ceiling) to a certain number of decimals
192
+ * @author Gabe Abrams
193
+ * @param num the number to round
194
+ * @param numDecimals the number of decimals to round to
195
+ * @returns rounded number
196
+ */
197
+ declare const ceilToNumDecimals: (num: number, numDecimals: number) => number;
198
+
199
+ /**
200
+ * Round a number (floor) to a certain number of decimals
201
+ * @author Gabe Abrams
202
+ * @param num the number to round
203
+ * @param numDecimals the number of decimals to round to
204
+ * @returns rounded number
205
+ */
206
+ declare const floorToNumDecimals: (num: number, numDecimals: number) => number;
207
+
208
+ /**
209
+ * Force a number to stay within specific bounds
210
+ * @author Gabe Abrams
211
+ * @param num the number to move into the bounds
212
+ * @param min the minimum number in the bound
213
+ * @param max the maximum number in the bound
214
+ * @returns bounded number
215
+ */
216
+ declare const forceNumIntoBounds: (num: number, min: number, max: number) => number;
217
+
218
+ /**
219
+ * Pad a number's decimal with zeros on the right
220
+ * (e.g. 5.2 becomes 5.20 with 2 digit padding)
221
+ * @author Gabe Abrams
222
+ * @param num the number to pad
223
+ * @param numDigits the minimum number of digits after the decimal
224
+ * @returns padded number
225
+ */
226
+ declare const padDecimalZeros: (num: number, numDigits: number) => string;
227
+
228
+ /**
229
+ * Pad a number with zeros on the left (e.g. 5 becomes 05 with 2 digit padding)
230
+ * @author Gabe Abrams
231
+ * @param num the number to pad
232
+ * @param numDigits the minimum number of digits before the decimal
233
+ * @returns padded number
234
+ */
235
+ declare const padZerosLeft: (num: number, numDigits: number) => string;
236
+
237
+ /**
238
+ * Round a number to a certain number of decimals
239
+ * @author Gabe Abrams
240
+ * @param num the number to round
241
+ * @param numDecimals the number of decimals to round to
242
+ * @returns rounded number
243
+ */
244
+ declare const roundToNumDecimals: (num: number, numDecimals: number) => number;
245
+
246
+ /**
247
+ * Sum the numbers in an array
248
+ * @author Gabe Abrams
249
+ * @param nums the numbers to sum
250
+ * @returns the sum of the numbers
251
+ */
252
+ declare const sum: (nums: number[]) => number;
253
+
254
+ /**
255
+ * Wait for a certain number of ms
256
+ * @author Gabe Abrams
257
+ * @param ms number of ms to wait
258
+ */
259
+ declare const waitMs: (ms?: number) => Promise<unknown>;
260
+
261
+ /**
262
+ * List of error codes built into the react kit
263
+ * @author Gabe Abrams
264
+ */
265
+ declare enum ReactKitErrorCode {
266
+ NoResponse = "DRK1",
267
+ NoCode = "DRK2",
268
+ SessionExpired = "DRK3",
269
+ MissingParameter = "DRK4",
270
+ InvalidParameter = "DRK5",
271
+ WrongCourse = "DRK6"
272
+ }
273
+
274
+ export { AppWrapper, ErrorBox, ErrorWithCode, LoadingSpinner, Modal, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, TabBox, Variant, abbreviate, alert, avg, ceilToNumDecimals, confirm, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, showFatalError, sum, waitMs };
package/package.json CHANGED
@@ -1,38 +1,46 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "2.0.11",
4
- "main": "index.js",
5
- "module": "index.js",
3
+ "version": "3.0.0-beta.10",
4
+ "description": "Shared components for Harvard DCE apps",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/index.d.ts",
6
8
  "scripts": {
7
- "build": "tsc --project ./tsconfig.json"
9
+ "build": "rm -rf dist && rollup -c"
8
10
  },
9
11
  "repository": {
10
12
  "type": "git",
11
- "url": "git+https://github.com/harvard-edtech/dce-reactkit"
13
+ "url": "git+https://github.com/harvard-edtech/dce-reactkit.git"
12
14
  },
13
15
  "author": "Gabe Abrams <gabeabrams@gmail.com>",
14
16
  "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/harvard-edtech/dce-reactkit/issues"
19
+ },
15
20
  "homepage": "https://github.com/harvard-edtech/dce-reactkit#readme",
16
- "dependencies": {
17
- "@fortawesome/fontawesome-svg-core": "^6.1.1",
18
- "@fortawesome/free-regular-svg-icons": "^6.1.1",
21
+ "peerDependencies": {
19
22
  "@fortawesome/free-solid-svg-icons": "^6.1.1",
20
23
  "@fortawesome/react-fontawesome": "^0.1.18",
21
- "caccl": "^2.0.0-beta.39",
22
- "react-bootstrap": "^2.2.3"
24
+ "bootstrap": "^5.1.3",
25
+ "react": "^18.0.0"
23
26
  },
24
27
  "devDependencies": {
25
- "@types/express": "^4.17.13",
26
- "@typescript-eslint/eslint-plugin": "^5.18.0",
27
- "@typescript-eslint/parser": "^5.18.0",
28
- "eslint": "^8.12.0",
28
+ "@rollup/plugin-commonjs": "^22.0.0",
29
+ "@rollup/plugin-node-resolve": "^13.2.1",
30
+ "@rollup/plugin-typescript": "^8.3.2",
31
+ "@types/react": "^18.0.7",
32
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
33
+ "@typescript-eslint/parser": "^5.21.0",
34
+ "eslint": "^8.14.0",
29
35
  "eslint-config-airbnb": "^19.0.4",
30
36
  "eslint-config-airbnb-typescript": "^17.0.0",
31
37
  "eslint-plugin-import": "^2.26.0",
32
- "eslint-plugin-jest": "^26.1.3",
33
38
  "eslint-plugin-jsx-a11y": "^6.5.1",
34
39
  "eslint-plugin-react": "^7.29.4",
35
40
  "eslint-plugin-react-hooks": "^4.4.0",
41
+ "rollup": "^2.70.2",
42
+ "rollup-plugin-dts": "^4.2.1",
43
+ "rollup-plugin-sourcemaps": "^0.6.3",
36
44
  "typescript": "^4.6.3"
37
45
  }
38
46
  }
@@ -0,0 +1,45 @@
1
+ import resolve from "@rollup/plugin-node-resolve";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import typescript from "@rollup/plugin-typescript";
4
+ import dts from "rollup-plugin-dts";
5
+ import sourcemaps from 'rollup-plugin-sourcemaps';
6
+
7
+
8
+ const packageJson = require("./package.json");
9
+
10
+ export default [
11
+ {
12
+ input: "src/index.ts",
13
+ output: [
14
+ {
15
+ file: packageJson.main,
16
+ format: "cjs",
17
+ sourcemap: true,
18
+ },
19
+ {
20
+ file: packageJson.module,
21
+ format: "esm",
22
+ sourcemap: true,
23
+ },
24
+ ],
25
+ plugins: [
26
+ resolve(),
27
+ commonjs(),
28
+ typescript({ tsconfig: "./tsconfig.json" }),
29
+ sourcemaps(),
30
+ ],
31
+ external: [
32
+ ...Object.keys(packageJson.dependencies || {}),
33
+ ...Object.keys(packageJson.peerDependencies || {}),
34
+ ],
35
+ },
36
+ {
37
+ input: "dist/esm/types/index.d.ts",
38
+ output: [{ file: "dist/index.d.ts", format: "esm" }],
39
+ plugins: [dts()],
40
+ external: [
41
+ ...Object.keys(packageJson.dependencies || {}),
42
+ ...Object.keys(packageJson.peerDependencies || {}),
43
+ ],
44
+ },
45
+ ];
@@ -1,20 +1,19 @@
1
1
  /**
2
2
  * A wrapper for the entire React app that adds global functionality like
3
- * handling for fatal error messages
3
+ * handling for fatal error messages, adds bootstrap support
4
4
  * @author Gabe Abrams
5
5
  */
6
6
 
7
7
  // Import React
8
- import React, { useState, useEffect } from 'react';
8
+ import React, { useState } from 'react';
9
9
 
10
10
  // Import shared components
11
11
  import ErrorBox from './ErrorBox';
12
12
 
13
- // Import helpers
14
- import { setSessionExpiryHandler } from '../helpers/visitServerEndpoint';
15
-
16
13
  // Import shared types
17
14
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
15
+ import ModalButtonType from '../types/ModalButtonType';
16
+ import ModalType from '../types/ModalType';
18
17
 
19
18
  // Import shared components
20
19
  import Modal from './Modal';
@@ -53,17 +52,18 @@ let onAlertClosed: () => void;
53
52
  * @param title the title text to display at the top of the alert
54
53
  * @param text the text to display in the alert
55
54
  */
56
- export const alert = async (title: string, text: string) => {
55
+ export const alert = async (title: string, text: string): Promise<undefined> => {
57
56
  // Fallback if alert not available
58
57
  if (!setAlertInfo) {
59
- return window.alert(`${title}\n\n${text}`);
58
+ window.alert(`${title}\n\n${text}`);
59
+ return undefined;
60
60
  }
61
61
 
62
62
  // Return promise that resolves when alert is closed
63
63
  return new Promise((resolve) => {
64
64
  // Setup handler
65
65
  onAlertClosed = () => {
66
- resolve(null);
66
+ resolve(undefined);
67
67
  };
68
68
 
69
69
  // Show the alert
@@ -131,7 +131,7 @@ let setFatalErrorTitle: (title: string) => void;
131
131
  export const showFatalError = (
132
132
  error: any,
133
133
  errorTitle: string = 'An Error Occurred',
134
- ) => {
134
+ ): undefined => {
135
135
  // Determine message and code
136
136
  const message: string = (
137
137
  typeof error === 'string'
@@ -146,23 +146,42 @@ export const showFatalError = (
146
146
 
147
147
  // Handle case where app hasn't loaded
148
148
  if (!setFatalErrorMessage || !setFatalErrorCode) {
149
- return alert(
149
+ alert(
150
150
  errorTitle,
151
151
  `${message} (code: ${code}). Please contact support.`,
152
152
  );
153
+ return undefined;
153
154
  }
154
155
 
155
156
  // Use setters
156
157
  setFatalErrorMessage(message);
157
158
  setFatalErrorCode(code);
158
159
  setFatalErrorTitle(errorTitle);
160
+
161
+ return undefined;
162
+ };
163
+
164
+ /*----------------------------------------*/
165
+ /* Session Expired */
166
+ /*----------------------------------------*/
167
+
168
+ // Stored copies of setters
169
+ let setSessionHasExpired: (isExpired: boolean) => void;
170
+
171
+ /**
172
+ * Show the "session expired" message
173
+ * @author Gabe Abrams
174
+ */
175
+ export const showSessionExpiredMessage = (): undefined => {
176
+ setSessionHasExpired(true);
177
+ return undefined;
159
178
  };
160
179
 
161
180
  /*------------------------------------------------------------------------*/
162
181
  /* Component */
163
182
  /*------------------------------------------------------------------------*/
164
183
 
165
- const AppWrapper = (props: Props): React.ReactElement => {
184
+ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
166
185
  /*------------------------------------------------------------------------*/
167
186
  /* Setup */
168
187
  /*------------------------------------------------------------------------*/
@@ -217,27 +236,9 @@ const AppWrapper = (props: Props): React.ReactElement => {
217
236
  // Session expired
218
237
  const [
219
238
  sessionHasExpired,
220
- setSessionHasExpired,
239
+ setSessionHasExpiredInner,
221
240
  ] = useState<boolean>(false);
222
-
223
- /*------------------------------------------------------------------------*/
224
- /* Lifecycle Functions */
225
- /*------------------------------------------------------------------------*/
226
-
227
- /**
228
- * Mount
229
- * @author Gabe Abrams
230
- */
231
- useEffect(
232
- () => {
233
- // Add session expired handler
234
- setSessionExpiryHandler(() => {
235
- // Session expired!
236
- setSessionHasExpired(true);
237
- });
238
- },
239
- [],
240
- );
241
+ setSessionHasExpired = setSessionHasExpiredInner;
241
242
 
242
243
  /*------------------------------------------------------------------------*/
243
244
  /* Render */
@@ -256,7 +257,7 @@ const AppWrapper = (props: Props): React.ReactElement => {
256
257
  modal = (
257
258
  <Modal
258
259
  title={alertInfo.title}
259
- type={Modal.ModalType.Okay}
260
+ type={ModalType.Okay}
260
261
  onClose={() => {
261
262
  // Alert closed
262
263
  if (onAlertClosed) {
@@ -276,10 +277,10 @@ const AppWrapper = (props: Props): React.ReactElement => {
276
277
  modal = (
277
278
  <Modal
278
279
  title={confirmInfo.title}
279
- type={Modal.ModalType.OkayCancel}
280
+ type={ModalType.OkayCancel}
280
281
  onClose={(buttonType) => {
281
282
  if (onConfirmClosed) {
282
- onConfirmClosed(buttonType === Modal.ButtonType.Okay);
283
+ onConfirmClosed(buttonType === ModalButtonType.Okay);
283
284
  }
284
285
  }}
285
286
  dontAllowBackdropExit
@@ -303,8 +304,8 @@ const AppWrapper = (props: Props): React.ReactElement => {
303
304
  const error = (
304
305
  sessionHasExpired
305
306
  ? new ErrorWithCode(
306
- fatalErrorMessage,
307
- fatalErrorCode,
307
+ (fatalErrorMessage ?? 'An unknown error has occurred. Please contact support.'),
308
+ (fatalErrorCode ?? ReactKitErrorCode.NoCode),
308
309
  )
309
310
  : new ErrorWithCode(
310
311
  sessionExpiredMessage,
@@ -319,7 +320,7 @@ const AppWrapper = (props: Props): React.ReactElement => {
319
320
  display: 'block',
320
321
  width: '100vw',
321
322
  minHeight: '100vh',
322
- paddingTop: '10rem',
323
+ paddingTop: '2rem',
323
324
  backgroundColor: (
324
325
  dark
325
326
  ? '#222'
@@ -3,6 +3,9 @@
3
3
  * @author Gabe Abrams
4
4
  */
5
5
 
6
+ // Import react
7
+ import React from 'react';
8
+
6
9
  // Import FontAwesome Icons
7
10
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8
11
  import { faCircle } from '@fortawesome/free-solid-svg-icons';