dce-reactkit 2.0.10 → 3.0.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.
Files changed (187) hide show
  1. package/lib/cjs/index.js +2 -0
  2. package/lib/cjs/index.js.map +1 -0
  3. package/lib/cjs/lib/components/AppWrapper.d.ts +35 -0
  4. package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
  5. package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
  6. package/lib/cjs/lib/components/Modal.d.ts +40 -0
  7. package/lib/cjs/lib/components/TabBox.d.ts +11 -0
  8. package/lib/{errors → cjs/lib/errors}/ErrorWithCode.d.ts +0 -0
  9. package/lib/{helpers → cjs/lib/helpers}/abbreviate.d.ts +1 -0
  10. package/lib/{helpers → cjs/lib/helpers}/avg.d.ts +0 -0
  11. package/lib/{helpers → cjs/lib/helpers}/ceilToNumDecimals.d.ts +0 -0
  12. package/lib/{helpers → cjs/lib/helpers}/floorToNumDecimals.d.ts +0 -0
  13. package/lib/{helpers → cjs/lib/helpers}/forceNumIntoBounds.d.ts +0 -0
  14. package/lib/{helpers → cjs/lib/helpers}/handleError.d.ts +0 -0
  15. package/lib/{helpers → cjs/lib/helpers}/handleSuccess.d.ts +0 -0
  16. package/lib/{helpers → cjs/lib/helpers}/padDecimalZeros.d.ts +0 -0
  17. package/lib/{helpers → cjs/lib/helpers}/padZerosLeft.d.ts +0 -0
  18. package/lib/{helpers → cjs/lib/helpers}/parseRequest.d.ts +1 -1
  19. package/lib/{helpers → cjs/lib/helpers}/roundToNumDecimals.d.ts +0 -0
  20. package/lib/{helpers → cjs/lib/helpers}/sum.d.ts +0 -0
  21. package/lib/{helpers → cjs/lib/helpers}/visitServerEndpoint.d.ts +2 -2
  22. package/lib/{helpers → cjs/lib/helpers}/waitMs.d.ts +0 -0
  23. package/lib/cjs/lib/index.d.ts +27 -0
  24. package/lib/cjs/lib/types/ModalButtonType.d.ts +17 -0
  25. package/lib/cjs/lib/types/ModalSize.d.ts +11 -0
  26. package/lib/cjs/lib/types/ModalType.d.ts +16 -0
  27. package/lib/{types → cjs/lib/types}/ParamType.d.ts +0 -0
  28. package/lib/{types → cjs/lib/types}/ReactKitErrorCode.d.ts +0 -0
  29. package/lib/{types → cjs/lib/types}/Variant.d.ts +0 -0
  30. package/lib/cjs/types/components/AppWrapper.d.ts +40 -0
  31. package/lib/cjs/types/components/ErrorBox.d.ts +12 -0
  32. package/lib/cjs/types/components/LoadingSpinner.d.ts +7 -0
  33. package/lib/cjs/types/components/Modal.d.ts +40 -0
  34. package/lib/cjs/types/components/TabBox.d.ts +11 -0
  35. package/lib/cjs/types/errors/ErrorWithCode.d.ts +9 -0
  36. package/lib/cjs/types/helpers/abbreviate.d.ts +10 -0
  37. package/lib/cjs/types/helpers/alert.d.ts +2 -0
  38. package/lib/cjs/types/helpers/avg.d.ts +8 -0
  39. package/lib/cjs/types/helpers/ceilToNumDecimals.d.ts +9 -0
  40. package/lib/cjs/types/helpers/confirm.d.ts +2 -0
  41. package/lib/cjs/types/helpers/floorToNumDecimals.d.ts +9 -0
  42. package/lib/cjs/types/helpers/forceNumIntoBounds.d.ts +10 -0
  43. package/lib/cjs/types/helpers/handleError.d.ts +14 -0
  44. package/lib/cjs/types/helpers/handleSuccess.d.ts +8 -0
  45. package/lib/cjs/types/helpers/padDecimalZeros.d.ts +10 -0
  46. package/lib/cjs/types/helpers/padZerosLeft.d.ts +9 -0
  47. package/lib/cjs/types/helpers/parseRequest.d.ts +21 -0
  48. package/lib/cjs/types/helpers/roundToNumDecimals.d.ts +9 -0
  49. package/lib/cjs/types/helpers/showFatalError.d.ts +2 -0
  50. package/lib/cjs/types/helpers/sum.d.ts +8 -0
  51. package/lib/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
  52. package/lib/cjs/types/helpers/waitMs.d.ts +7 -0
  53. package/lib/cjs/types/index.d.ts +22 -0
  54. package/lib/cjs/types/types/ModalButtonType.d.ts +17 -0
  55. package/lib/cjs/types/types/ModalSize.d.ts +11 -0
  56. package/lib/cjs/types/types/ModalType.d.ts +16 -0
  57. package/lib/cjs/types/types/ParamType.d.ts +17 -0
  58. package/lib/cjs/types/types/ReactKitErrorCode.d.ts +13 -0
  59. package/lib/cjs/types/types/Variant.d.ts +15 -0
  60. package/lib/esm/index.js +16 -0
  61. package/lib/esm/index.js.map +1 -0
  62. package/lib/esm/lib/components/AppWrapper.d.ts +35 -0
  63. package/lib/esm/lib/components/ErrorBox.d.ts +12 -0
  64. package/lib/esm/lib/components/LoadingSpinner.d.ts +7 -0
  65. package/lib/esm/lib/components/Modal.d.ts +40 -0
  66. package/lib/esm/lib/components/TabBox.d.ts +11 -0
  67. package/lib/esm/lib/errors/ErrorWithCode.d.ts +9 -0
  68. package/lib/esm/lib/helpers/abbreviate.d.ts +10 -0
  69. package/lib/esm/lib/helpers/avg.d.ts +8 -0
  70. package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  71. package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +9 -0
  72. package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  73. package/lib/esm/lib/helpers/handleError.d.ts +14 -0
  74. package/lib/esm/lib/helpers/handleSuccess.d.ts +8 -0
  75. package/lib/esm/lib/helpers/padDecimalZeros.d.ts +10 -0
  76. package/lib/esm/lib/helpers/padZerosLeft.d.ts +9 -0
  77. package/lib/esm/lib/helpers/parseRequest.d.ts +21 -0
  78. package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +9 -0
  79. package/lib/esm/lib/helpers/sum.d.ts +8 -0
  80. package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +23 -0
  81. package/lib/esm/lib/helpers/waitMs.d.ts +7 -0
  82. package/lib/esm/lib/index.d.ts +27 -0
  83. package/lib/esm/lib/types/ModalButtonType.d.ts +17 -0
  84. package/lib/esm/lib/types/ModalSize.d.ts +11 -0
  85. package/lib/esm/lib/types/ModalType.d.ts +16 -0
  86. package/lib/esm/lib/types/ParamType.d.ts +17 -0
  87. package/lib/esm/lib/types/ReactKitErrorCode.d.ts +13 -0
  88. package/lib/esm/lib/types/Variant.d.ts +15 -0
  89. package/lib/esm/types/components/AppWrapper.d.ts +40 -0
  90. package/lib/esm/types/components/ErrorBox.d.ts +12 -0
  91. package/lib/esm/types/components/LoadingSpinner.d.ts +7 -0
  92. package/lib/esm/types/components/Modal.d.ts +40 -0
  93. package/lib/esm/types/components/TabBox.d.ts +11 -0
  94. package/lib/esm/types/errors/ErrorWithCode.d.ts +9 -0
  95. package/lib/esm/types/helpers/abbreviate.d.ts +10 -0
  96. package/lib/esm/types/helpers/alert.d.ts +2 -0
  97. package/lib/esm/types/helpers/avg.d.ts +8 -0
  98. package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
  99. package/lib/esm/types/helpers/confirm.d.ts +2 -0
  100. package/lib/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
  101. package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
  102. package/lib/esm/types/helpers/handleError.d.ts +14 -0
  103. package/lib/esm/types/helpers/handleSuccess.d.ts +8 -0
  104. package/lib/esm/types/helpers/padDecimalZeros.d.ts +10 -0
  105. package/lib/esm/types/helpers/padZerosLeft.d.ts +9 -0
  106. package/lib/esm/types/helpers/parseRequest.d.ts +21 -0
  107. package/lib/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
  108. package/lib/esm/types/helpers/showFatalError.d.ts +2 -0
  109. package/lib/esm/types/helpers/sum.d.ts +8 -0
  110. package/lib/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
  111. package/lib/esm/types/helpers/waitMs.d.ts +7 -0
  112. package/lib/esm/types/index.d.ts +22 -0
  113. package/lib/esm/types/types/ModalButtonType.d.ts +17 -0
  114. package/lib/esm/types/types/ModalSize.d.ts +11 -0
  115. package/lib/esm/types/types/ModalType.d.ts +16 -0
  116. package/lib/esm/types/types/ParamType.d.ts +17 -0
  117. package/lib/esm/types/types/ReactKitErrorCode.d.ts +13 -0
  118. package/lib/esm/types/types/Variant.d.ts +15 -0
  119. package/lib/index.d.ts +274 -0
  120. package/package.json +26 -5
  121. package/rollup.config.js +43 -0
  122. package/src/components/AppWrapper.tsx +212 -36
  123. package/src/components/LoadingSpinner.tsx +3 -0
  124. package/src/components/Modal.tsx +65 -95
  125. package/src/components/TabBox.tsx +136 -0
  126. package/src/helpers/abbreviate.tsx +2 -0
  127. package/src/helpers/padDecimalZeros.tsx +1 -1
  128. package/src/index.ts +61 -0
  129. package/src/types/ModalButtonType.tsx +18 -0
  130. package/src/types/ModalSize.tsx +12 -0
  131. package/src/types/ModalType.tsx +17 -0
  132. package/tsconfig.json +14 -17
  133. package/lib/components/AppWrapper.d.ts +0 -20
  134. package/lib/components/AppWrapper.js +0 -133
  135. package/lib/components/AppWrapper.js.map +0 -1
  136. package/lib/components/ErrorBox.js +0 -65
  137. package/lib/components/ErrorBox.js.map +0 -1
  138. package/lib/components/LoadingSpinner.js +0 -41
  139. package/lib/components/LoadingSpinner.js.map +0 -1
  140. package/lib/components/Modal.d.ts +0 -69
  141. package/lib/components/Modal.js +0 -315
  142. package/lib/components/Modal.js.map +0 -1
  143. package/lib/errors/ErrorWithCode.js +0 -33
  144. package/lib/errors/ErrorWithCode.js.map +0 -1
  145. package/lib/helpers/abbreviate.js +0 -21
  146. package/lib/helpers/abbreviate.js.map +0 -1
  147. package/lib/helpers/avg.js +0 -24
  148. package/lib/helpers/avg.js.map +0 -1
  149. package/lib/helpers/ceilToNumDecimals.js +0 -15
  150. package/lib/helpers/ceilToNumDecimals.js.map +0 -1
  151. package/lib/helpers/floorToNumDecimals.js +0 -15
  152. package/lib/helpers/floorToNumDecimals.js.map +0 -1
  153. package/lib/helpers/forceNumIntoBounds.js +0 -15
  154. package/lib/helpers/forceNumIntoBounds.js.map +0 -1
  155. package/lib/helpers/handleError.js +0 -54
  156. package/lib/helpers/handleError.js.map +0 -1
  157. package/lib/helpers/handleSuccess.js +0 -20
  158. package/lib/helpers/handleSuccess.js.map +0 -1
  159. package/lib/helpers/padDecimalZeros.js +0 -30
  160. package/lib/helpers/padDecimalZeros.js.map +0 -1
  161. package/lib/helpers/padZerosLeft.js +0 -21
  162. package/lib/helpers/padZerosLeft.js.map +0 -1
  163. package/lib/helpers/parseRequest.js +0 -240
  164. package/lib/helpers/parseRequest.js.map +0 -1
  165. package/lib/helpers/roundToNumDecimals.js +0 -15
  166. package/lib/helpers/roundToNumDecimals.js.map +0 -1
  167. package/lib/helpers/showFatalError.d.ts +0 -2
  168. package/lib/helpers/showFatalError.js +0 -5
  169. package/lib/helpers/showFatalError.js.map +0 -1
  170. package/lib/helpers/sum.js +0 -15
  171. package/lib/helpers/sum.js.map +0 -1
  172. package/lib/helpers/visitServerEndpoint.js +0 -135
  173. package/lib/helpers/visitServerEndpoint.js.map +0 -1
  174. package/lib/helpers/waitMs.js +0 -55
  175. package/lib/helpers/waitMs.js.map +0 -1
  176. package/lib/types/ParamType.js +0 -21
  177. package/lib/types/ParamType.js.map +0 -1
  178. package/lib/types/ReactKitErrorCode.js +0 -18
  179. package/lib/types/ReactKitErrorCode.js.map +0 -1
  180. package/lib/types/Variant.js +0 -19
  181. package/lib/types/Variant.js.map +0 -1
  182. package/src/helpers/handleError.ts +0 -65
  183. package/src/helpers/handleSuccess.ts +0 -18
  184. package/src/helpers/parseRequest.ts +0 -299
  185. package/src/helpers/showFatalError.tsx +0 -3
  186. package/src/helpers/visitServerEndpoint.tsx +0 -110
  187. package/src/types/ParamType.ts +0 -18
package/lib/index.d.ts ADDED
@@ -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
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<unknown>;
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) => Promise<unknown> | 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,10 +1,11 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "2.0.10",
4
- "main": "index.js",
5
- "module": "index.js",
3
+ "version": "3.0.0",
4
+ "main": "lib/cjs/index.js",
5
+ "module": "lib/esm/index.js",
6
+ "types": "lib/index.d.ts",
6
7
  "scripts": {
7
- "build": "tsc --project ./tsconfig.json"
8
+ "build": "rollup -c"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -19,10 +20,16 @@
19
20
  "@fortawesome/free-solid-svg-icons": "^6.1.1",
20
21
  "@fortawesome/react-fontawesome": "^0.1.18",
21
22
  "caccl": "^2.0.0-beta.39",
22
- "react-bootstrap": "^2.2.3"
23
+ "react-bootstrap": "^2.2.3",
24
+ "react": "^18.0.0"
23
25
  },
24
26
  "devDependencies": {
27
+ "@rollup/plugin-commonjs": "^21.1.0",
28
+ "@rollup/plugin-json": "^4.1.0",
29
+ "@rollup/plugin-node-resolve": "^13.2.1",
30
+ "@rollup/plugin-typescript": "^8.3.2",
25
31
  "@types/express": "^4.17.13",
32
+ "@types/react": "^18.0.5",
26
33
  "@typescript-eslint/eslint-plugin": "^5.18.0",
27
34
  "@typescript-eslint/parser": "^5.18.0",
28
35
  "eslint": "^8.12.0",
@@ -33,6 +40,20 @@
33
40
  "eslint-plugin-jsx-a11y": "^6.5.1",
34
41
  "eslint-plugin-react": "^7.29.4",
35
42
  "eslint-plugin-react-hooks": "^4.4.0",
43
+ "react": "^18.0.0",
44
+ "rollup": "^2.70.2",
45
+ "rollup-plugin-dts": "^4.2.1",
46
+ "rollup-plugin-peer-deps-external": "^2.2.4",
47
+ "rollup-plugin-terser": "^7.0.2",
36
48
  "typescript": "^4.6.3"
49
+ },
50
+ "peerDependencies": {
51
+ "@fortawesome/fontawesome-svg-core": "^6.1.1",
52
+ "@fortawesome/free-regular-svg-icons": "^6.1.1",
53
+ "@fortawesome/free-solid-svg-icons": "^6.1.1",
54
+ "@fortawesome/react-fontawesome": "^0.1.18",
55
+ "caccl": "^2.0.0-beta.39",
56
+ "react-bootstrap": "^2.2.3",
57
+ "react": "^18.0.0"
37
58
  }
38
59
  }
@@ -0,0 +1,43 @@
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 { terser } from "rollup-plugin-terser";
6
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
7
+ import json from "@rollup/plugin-json";
8
+
9
+ const packageJson = require("./package.json");
10
+
11
+ export default [
12
+ {
13
+ input: "src/index.ts",
14
+ output: [
15
+ {
16
+ file: packageJson.main,
17
+ format: "cjs",
18
+ sourcemap: true,
19
+ },
20
+ {
21
+ file: packageJson.module,
22
+ format: "esm",
23
+ sourcemap: true,
24
+ },
25
+ ],
26
+ plugins: [
27
+ peerDepsExternal(),
28
+ resolve({
29
+ preferBuiltins: false,
30
+ }),
31
+ commonjs(),
32
+ typescript({ tsconfig: "./tsconfig.json" }),
33
+ terser(),
34
+ json(),
35
+ ],
36
+ external: ["react", "react-dom", "styled-components"]
37
+ },
38
+ {
39
+ input: "lib/esm/types/index.d.ts",
40
+ output: [{ file: "lib/index.d.ts", format: "esm" }],
41
+ plugins: [dts()],
42
+ },
43
+ ];
@@ -5,16 +5,18 @@
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';
17
+
18
+ // Import shared components
19
+ import Modal from './Modal';
18
20
 
19
21
  // Import custom errors
20
22
  import ErrorWithCode from '../errors/ErrorWithCode';
@@ -36,6 +38,84 @@ type Props = {
36
38
  /* Static Helpers */
37
39
  /*------------------------------------------------------------------------*/
38
40
 
41
+ /*----------------------------------------*/
42
+ /* Alert */
43
+ /*----------------------------------------*/
44
+
45
+ // Stored copies of setters
46
+ let setAlertInfo: (info: { title: string, text: string }) => void;
47
+ let onAlertClosed: () => void;
48
+
49
+ /**
50
+ * Show an alert modal with an "Okay" button
51
+ * @author Gabe Abrams
52
+ * @param title the title text to display at the top of the alert
53
+ * @param text the text to display in the alert
54
+ */
55
+ export const alert = async (title: string, text: string) => {
56
+ // Fallback if alert not available
57
+ if (!setAlertInfo) {
58
+ return window.alert(`${title}\n\n${text}`);
59
+ }
60
+
61
+ // Return promise that resolves when alert is closed
62
+ return new Promise((resolve) => {
63
+ // Setup handler
64
+ onAlertClosed = () => {
65
+ resolve(null);
66
+ };
67
+
68
+ // Show the alert
69
+ setAlertInfo({
70
+ title,
71
+ text,
72
+ });
73
+ });
74
+ };
75
+
76
+ /*----------------------------------------*/
77
+ /* Confirm */
78
+ /*----------------------------------------*/
79
+
80
+ // Stored copies of setters
81
+ let setConfirmInfo: (info: { title: string, text: string }) => void;
82
+ let onConfirmClosed: (confirmed: boolean) => void;
83
+
84
+ /**
85
+ * Show a confirmation modal with an "Okay" and a "Cancel" button
86
+ * @author Gabe Abrams
87
+ * @param title the title text to display at the top of the alert
88
+ * @param text the text to display in the alert
89
+ * @returns true if the user confirmed
90
+ */
91
+ export const confirm = async (
92
+ title: string,
93
+ text: string,
94
+ ): Promise<boolean> => {
95
+ // Fallback if confirm is not available
96
+ if (!setConfirmInfo) {
97
+ return window.confirm(`${title}\n\n${text}`);
98
+ }
99
+
100
+ // Return promise that resolves with result of confirmation
101
+ return new Promise((resolve) => {
102
+ // Setup handler
103
+ onConfirmClosed = (confirmed: boolean) => {
104
+ resolve(confirmed)
105
+ };
106
+
107
+ // Show the confirm
108
+ setConfirmInfo({
109
+ title,
110
+ text,
111
+ });
112
+ });
113
+ };
114
+
115
+ /*----------------------------------------*/
116
+ /* Fatal Error */
117
+ /*----------------------------------------*/
118
+
39
119
  // Stored copies of setters
40
120
  let setFatalErrorMessage: (message: string) => void;
41
121
  let setFatalErrorCode: (code: string) => void;
@@ -65,7 +145,10 @@ export const showFatalError = (
65
145
 
66
146
  // Handle case where app hasn't loaded
67
147
  if (!setFatalErrorMessage || !setFatalErrorCode) {
68
- return alert(`An error has occurred: ${message} (code: ${code}). Please contact support.`);
148
+ return alert(
149
+ errorTitle,
150
+ `${message} (code: ${code}). Please contact support.`,
151
+ );
69
152
  }
70
153
 
71
154
  // Use setters
@@ -74,11 +157,26 @@ export const showFatalError = (
74
157
  setFatalErrorTitle(errorTitle);
75
158
  };
76
159
 
160
+ /*----------------------------------------*/
161
+ /* Session Expired */
162
+ /*----------------------------------------*/
163
+
164
+ // Stored copies of setters
165
+ let setSessionHasExpired: (isExpired: boolean) => void;
166
+
167
+ /**
168
+ * Show the "session expired" message
169
+ * @author Gabe Abrams
170
+ */
171
+ export const showSessionExpiredMessage = () => {
172
+ setSessionHasExpired(true);
173
+ };
174
+
77
175
  /*------------------------------------------------------------------------*/
78
176
  /* Component */
79
177
  /*------------------------------------------------------------------------*/
80
178
 
81
- const AppWrapper = (props: Props): React.ReactElement => {
179
+ const AppWrapper: React.FC<Props> = (props: Props): React.ReactElement => {
82
180
  /*------------------------------------------------------------------------*/
83
181
  /* Setup */
84
182
  /*------------------------------------------------------------------------*/
@@ -94,51 +192,115 @@ const AppWrapper = (props: Props): React.ReactElement => {
94
192
  /* -------------- State ------------- */
95
193
 
96
194
  // Fatal error
97
- const [fatalErrorMessage, setFatalErrorMessageInner] = useState(null);
195
+ const [
196
+ fatalErrorMessage,
197
+ setFatalErrorMessageInner,
198
+ ] = useState<string | undefined>();
98
199
  setFatalErrorMessage = setFatalErrorMessageInner;
99
- const [fatalErrorCode, setFatalErrorCodeInner] = useState(null);
200
+ const [
201
+ fatalErrorCode,
202
+ setFatalErrorCodeInner,
203
+ ] = useState<string | undefined>();
100
204
  setFatalErrorCode = setFatalErrorCodeInner;
101
- const [fatalErrorTitle, setFatalErrorTitleInner] = useState(null);
205
+ const [
206
+ fatalErrorTitle,
207
+ setFatalErrorTitleInner,
208
+ ] = useState<string | undefined>();
102
209
  setFatalErrorTitle = setFatalErrorTitleInner;
103
210
 
104
- // Session expired
105
- const [sessionHasExpired, setSessionHasExpired] = useState(false);
211
+ // Alert
212
+ const [
213
+ alertInfo,
214
+ setAlertInfoInner,
215
+ ] = useState<{
216
+ title: string,
217
+ text: string
218
+ }>();
219
+ setAlertInfo = setAlertInfoInner;
106
220
 
107
- /*------------------------------------------------------------------------*/
108
- /* Lifecycle Functions */
109
- /*------------------------------------------------------------------------*/
221
+ // Confirm
222
+ const [
223
+ confirmInfo,
224
+ setConfirmInfoInner,
225
+ ] = useState<{
226
+ title: string,
227
+ text: string
228
+ }>();
229
+ setConfirmInfo = setConfirmInfoInner;
110
230
 
111
- /**
112
- * Mount
113
- * @author Gabe Abrams
114
- */
115
- useEffect(
116
- () => {
117
- // Add session expired handler
118
- setSessionExpiryHandler(() => {
119
- // Session expired!
120
- setSessionHasExpired(true);
121
- });
122
- },
123
- [],
124
- );
231
+ // Session expired
232
+ const [
233
+ sessionHasExpired,
234
+ setSessionHasExpiredInner,
235
+ ] = useState<boolean>(false);
236
+ setSessionHasExpired = setSessionHasExpiredInner;
125
237
 
126
238
  /*------------------------------------------------------------------------*/
127
239
  /* Render */
128
240
  /*------------------------------------------------------------------------*/
129
241
 
130
242
  /*----------------------------------------*/
131
- /* Main UI */
243
+ /* Modal */
244
+ /*----------------------------------------*/
245
+
246
+ // Modal that may be defined
247
+ let modal: React.ReactNode;
248
+
249
+ /* -------------- Alert ------------- */
250
+
251
+ if (alertInfo) {
252
+ modal = (
253
+ <Modal
254
+ title={alertInfo.title}
255
+ type={ModalType.Okay}
256
+ onClose={() => {
257
+ // Alert closed
258
+ if (onAlertClosed) {
259
+ onAlertClosed();
260
+ }
261
+ }}
262
+ onTopOfOtherModals
263
+ >
264
+ {alertInfo.text}
265
+ </Modal>
266
+ );
267
+ }
268
+
269
+ /* ------------- Confirm ------------ */
270
+
271
+ if (confirmInfo) {
272
+ modal = (
273
+ <Modal
274
+ title={confirmInfo.title}
275
+ type={ModalType.OkayCancel}
276
+ onClose={(buttonType) => {
277
+ if (onConfirmClosed) {
278
+ onConfirmClosed(buttonType === ModalButtonType.Okay);
279
+ }
280
+ }}
281
+ dontAllowBackdropExit
282
+ >
283
+
284
+ </Modal>
285
+ );
286
+ }
287
+
288
+ /*----------------------------------------*/
289
+ /* Views */
132
290
  /*----------------------------------------*/
133
291
 
134
- // Show error
292
+ // Body that will be filled with the current view
293
+ let body: React.ReactNode;
294
+
295
+ /* ----------- Fatal Error ---------- */
296
+
135
297
  if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
136
298
  // Re-encapsulate in an error
137
299
  const error = (
138
300
  sessionHasExpired
139
301
  ? new ErrorWithCode(
140
- fatalErrorMessage,
141
- fatalErrorCode,
302
+ (fatalErrorMessage ?? 'An unknown error has occurred. Please contact support.'),
303
+ (fatalErrorCode ?? ReactKitErrorCode.NoCode),
142
304
  )
143
305
  : new ErrorWithCode(
144
306
  sessionExpiredMessage,
@@ -147,13 +309,13 @@ const AppWrapper = (props: Props): React.ReactElement => {
147
309
  );
148
310
 
149
311
  // Build error screen
150
- return (
312
+ body = (
151
313
  <div
152
314
  style={{
153
315
  display: 'block',
154
316
  width: '100vw',
155
317
  minHeight: '100vh',
156
- paddingTop: '10rem',
318
+ paddingTop: '2rem',
157
319
  backgroundColor: (
158
320
  dark
159
321
  ? '#222'
@@ -173,10 +335,24 @@ const AppWrapper = (props: Props): React.ReactElement => {
173
335
  );
174
336
  }
175
337
 
176
- // Show the app itself
338
+ /* --------------- App -------------- */
339
+
340
+ if (!body) {
341
+ body = (
342
+ <>
343
+ {children}
344
+ </>
345
+ );
346
+ }
347
+
348
+ /*----------------------------------------*/
349
+ /* Main UI */
350
+ /*----------------------------------------*/
351
+
177
352
  return (
178
353
  <>
179
- {children}
354
+ {modal}
355
+ {body}
180
356
  </>
181
357
  );
182
358
  };