react-session.manager.sk 2.0.0 → 2.0.2

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.
@@ -17,3 +17,12 @@
17
17
  * This source code is licensed under the MIT license found in the
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  */
20
+
21
+ /** @license React v16.13.1
22
+ * react-is.production.min.js
23
+ *
24
+ * Copyright (c) Facebook, Inc. and its affiliates.
25
+ *
26
+ * This source code is licensed under the MIT license found in the
27
+ * LICENSE file in the root directory of this source tree.
28
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-session.manager.sk",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A react component used to manage token sessions with flask backend",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,143 @@
1
+ import React from "react";
2
+ import { toast } from "react-toastify";
3
+ import { Error as ErrorIcon } from "@mui/icons-material";
4
+
5
+ class ErrorBoundary extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+ this.state = { hasError: false, error: null, errorInfo: null };
9
+ }
10
+
11
+ static getDerivedStateFromError(error) {
12
+ // Update state so the next render will show the fallback UI
13
+ return { hasError: true };
14
+ }
15
+
16
+ componentDidCatch(error, errorInfo) {
17
+ console.error("ErrorBoundary caught an error:", error, errorInfo);
18
+
19
+ this.setState({
20
+ error: error,
21
+ errorInfo: errorInfo,
22
+ });
23
+
24
+ // Check if this is a theme-related error
25
+ const isThemeError =
26
+ error?.message?.includes("Cannot convert undefined or null to object") &&
27
+ (error?.stack?.includes("Object.entries") ||
28
+ error?.stack?.includes("theme") ||
29
+ error?.stack?.includes("Styled"));
30
+
31
+ const errorMessage = isThemeError
32
+ ? "A theme error occurred. This might be due to connection issues. Please refresh the page."
33
+ : "Something went wrong. Please refresh the page or try again later.";
34
+
35
+ // Show a toast notification for the error
36
+ toast.error(errorMessage, {
37
+ toastId: "error-boundary",
38
+ icon: <ErrorIcon />,
39
+ autoClose: 10000,
40
+ });
41
+
42
+ // Log error to external service if needed
43
+ if (this.props.onError) {
44
+ this.props.onError(error, errorInfo);
45
+ }
46
+ }
47
+
48
+ handleRetry = () => {
49
+ this.setState({ hasError: false, error: null, errorInfo: null });
50
+ };
51
+
52
+ render() {
53
+ if (this.state.hasError) {
54
+ // Custom error UI
55
+ if (this.props.fallback) {
56
+ return this.props.fallback;
57
+ }
58
+
59
+ return (
60
+ <div
61
+ style={{
62
+ padding: "20px",
63
+ textAlign: "center",
64
+ backgroundColor: "#f8f9fa",
65
+ border: "1px solid #dee2e6",
66
+ borderRadius: "8px",
67
+ margin: "20px",
68
+ minHeight: "200px",
69
+ display: "flex",
70
+ flexDirection: "column",
71
+ justifyContent: "center",
72
+ alignItems: "center",
73
+ }}
74
+ >
75
+ <div style={{ fontSize: "48px", marginBottom: "16px" }}>⚠️</div>
76
+ <h2 style={{ color: "#343a40", marginBottom: "16px" }}>
77
+ Something went wrong
78
+ </h2>
79
+ <p style={{ color: "#6c757d", marginBottom: "20px" }}>
80
+ An unexpected error occurred. Please try refreshing the page.
81
+ </p>
82
+ <button
83
+ onClick={this.handleRetry}
84
+ style={{
85
+ backgroundColor: "#007bff",
86
+ color: "white",
87
+ border: "none",
88
+ padding: "10px 20px",
89
+ borderRadius: "4px",
90
+ cursor: "pointer",
91
+ marginRight: "10px",
92
+ }}
93
+ >
94
+ Try Again
95
+ </button>
96
+ <button
97
+ onClick={() => window.location.reload()}
98
+ style={{
99
+ backgroundColor: "#28a745",
100
+ color: "white",
101
+ border: "none",
102
+ padding: "10px 20px",
103
+ borderRadius: "4px",
104
+ cursor: "pointer",
105
+ }}
106
+ >
107
+ Refresh Page
108
+ </button>
109
+
110
+ {process.env.NODE_ENV === "development" && this.state.error && (
111
+ <details
112
+ style={{ marginTop: "20px", textAlign: "left", width: "100%" }}
113
+ >
114
+ <summary style={{ cursor: "pointer", fontWeight: "bold" }}>
115
+ Error Details (Development)
116
+ </summary>
117
+ <pre
118
+ style={{
119
+ backgroundColor: "#f8f9fa",
120
+ padding: "10px",
121
+ borderRadius: "4px",
122
+ overflow: "auto",
123
+ fontSize: "12px",
124
+ marginTop: "10px",
125
+ maxHeight: "300px",
126
+ textAlign: "left",
127
+ }}
128
+ >
129
+ {this.state.error && this.state.error.toString()}
130
+ <br />
131
+ {this.state.errorInfo?.componentStack}
132
+ </pre>
133
+ </details>
134
+ )}
135
+ </div>
136
+ );
137
+ }
138
+
139
+ return this.props.children;
140
+ }
141
+ }
142
+
143
+ export default ErrorBoundary;
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { ThemeProvider, createTheme } from "@mui/material/styles";
3
+
4
+ // Fallback theme for when the main app theme is not available
5
+ const fallbackTheme = createTheme({
6
+ palette: {
7
+ mode: "light",
8
+ primary: {
9
+ main: "#1976d2",
10
+ },
11
+ secondary: {
12
+ main: "#dc3545",
13
+ },
14
+ error: {
15
+ main: "#d32f2f",
16
+ },
17
+ warning: {
18
+ main: "#ed6c02",
19
+ },
20
+ info: {
21
+ main: "#0288d1",
22
+ },
23
+ success: {
24
+ main: "#2e7d32",
25
+ },
26
+ },
27
+ });
28
+
29
+ const ThemeWrapper = ({ children, theme }) => {
30
+ // Use the provided theme or fallback theme
31
+ const safeTheme = theme || fallbackTheme;
32
+
33
+ return <ThemeProvider theme={safeTheme}>{children}</ThemeProvider>;
34
+ };
35
+
36
+ export default ThemeWrapper;