@campxdev/campx-web-utils 0.1.11 → 0.1.13
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/exports.ts +1 -2
- package/package.json +2 -2
- package/src/App.tsx +2 -1
- package/src/config/axios.ts +12 -1
- package/src/{ErrorBoundary → context/ErrorBoundary}/ErrorBoundary.tsx +1 -11
- package/src/context/Providers.tsx +21 -15
- package/src/context/export.ts +4 -0
- package/types/theme.d.ts +1 -0
- package/src/ErrorBoundary/GlobalNetworkLoadingIndicator.tsx +0 -13
- package/src/ErrorBoundary/export.ts +0 -1
- package/src/context/LoginDialogProvider.tsx +0 -5
- /package/src/{ErrorBoundary → context/ErrorBoundary}/Login.tsx +0 -0
package/exports.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campxdev/campx-web-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"main": "./exports.ts",
|
|
5
5
|
"private": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@campxdev/react-blueprint": "^1.1.
|
|
7
|
+
"@campxdev/react-blueprint": "^1.1.3",
|
|
8
8
|
"@hookform/resolvers": "^3.9.0",
|
|
9
9
|
"@mui/x-date-pickers": "^7.11.0",
|
|
10
10
|
"@testing-library/jest-dom": "^5.14.1",
|
package/src/App.tsx
CHANGED
package/src/config/axios.ts
CHANGED
|
@@ -70,13 +70,24 @@ axios.interceptors.response.use(
|
|
|
70
70
|
return response;
|
|
71
71
|
},
|
|
72
72
|
function (err) {
|
|
73
|
-
if ([400,
|
|
73
|
+
if ([400, 422].includes(err.response.status)) {
|
|
74
74
|
SnackbarStore.update((s) => {
|
|
75
75
|
s.open = true;
|
|
76
76
|
s.message = err.response.data.message || "Bad Request";
|
|
77
77
|
s.severity = "error";
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
+
if (
|
|
81
|
+
err.response.config.method &&
|
|
82
|
+
["put", "post", "delete", "patch"].includes(err.response.config.method) &&
|
|
83
|
+
[404].includes(err.response.status)
|
|
84
|
+
) {
|
|
85
|
+
SnackbarStore.update((s) => {
|
|
86
|
+
s.open = true;
|
|
87
|
+
s.message = err.response.data.message;
|
|
88
|
+
s.severity = "success";
|
|
89
|
+
});
|
|
90
|
+
}
|
|
80
91
|
|
|
81
92
|
return Promise.reject(err);
|
|
82
93
|
}
|
|
@@ -12,12 +12,10 @@ import { ReactNode, useState } from "react";
|
|
|
12
12
|
import { ErrorBoundary as ReactErrorBoundary } from "react-error-boundary";
|
|
13
13
|
import { QueryErrorResetBoundary } from "react-query";
|
|
14
14
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
15
|
-
import { axios } from "../config/axios";
|
|
16
15
|
import { Login } from "./Login";
|
|
17
16
|
|
|
18
17
|
export type ErrorBoundaryProps = {
|
|
19
18
|
children: ReactNode;
|
|
20
|
-
resetKey?: string;
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
const StyledAlert = styled(Alert)(({ theme }) => ({
|
|
@@ -57,7 +55,7 @@ export const ErrorBoundary = (props: ErrorBoundaryProps) => {
|
|
|
57
55
|
);
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
const ErrorFallback = ({ error, resetErrorBoundary }: any) => {
|
|
61
59
|
if (error?.response?.status) {
|
|
62
60
|
switch (error?.response?.status) {
|
|
63
61
|
case 401:
|
|
@@ -98,20 +96,12 @@ const UnAuth = () => {
|
|
|
98
96
|
|
|
99
97
|
const sessionCookie = Cookies.get("campx_session_key");
|
|
100
98
|
|
|
101
|
-
const appinit = async () => {
|
|
102
|
-
await axios.get("/auth/my-permissions").catch((e: any) => {
|
|
103
|
-
navigate("/auth/login");
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
99
|
const handleLoginClick = () => {
|
|
108
100
|
if (window.location.hostname == "localhost") {
|
|
109
101
|
setModalOpen(true);
|
|
110
102
|
} else {
|
|
111
103
|
if (!sessionCookie) {
|
|
112
104
|
navigate("/auth/login");
|
|
113
|
-
} else {
|
|
114
|
-
appinit();
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
};
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import { MuiThemeProvider } from "@campxdev/react-blueprint";
|
|
1
|
+
import { lightTheme, MuiThemeProvider } from "@campxdev/react-blueprint";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import { QueryClient, QueryClientProvider } from "react-query";
|
|
4
4
|
import { BrowserRouter } from "react-router-dom";
|
|
5
|
-
import { ErrorBoundary } from "../ErrorBoundary/ErrorBoundary";
|
|
6
5
|
import { SnackbarProvider } from "./SnackbarProvider";
|
|
6
|
+
import { ErrorBoundary } from "./export";
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export const Providers = ({
|
|
9
|
+
children,
|
|
10
|
+
baseName = "/",
|
|
11
|
+
theme = lightTheme,
|
|
12
|
+
}: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
baseName?: string;
|
|
15
|
+
theme?: any;
|
|
16
|
+
}) => {
|
|
17
|
+
const queryClient = new QueryClient({
|
|
18
|
+
defaultOptions: {
|
|
19
|
+
queries: {
|
|
20
|
+
refetchOnWindowFocus: false,
|
|
21
|
+
retry: false,
|
|
22
|
+
useErrorBoundary: true,
|
|
23
|
+
},
|
|
14
24
|
},
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export default function Providers({ children }: { children: ReactNode }) {
|
|
19
|
-
var baseName = "/";
|
|
25
|
+
});
|
|
20
26
|
|
|
21
27
|
return (
|
|
22
28
|
<BrowserRouter basename={baseName}>
|
|
23
29
|
<QueryClientProvider client={queryClient}>
|
|
24
|
-
<MuiThemeProvider>
|
|
30
|
+
<MuiThemeProvider theme={theme}>
|
|
25
31
|
<SnackbarProvider>
|
|
26
32
|
<ErrorBoundary>{children}</ErrorBoundary>
|
|
27
33
|
</SnackbarProvider>
|
|
@@ -29,4 +35,4 @@ export default function Providers({ children }: { children: ReactNode }) {
|
|
|
29
35
|
</QueryClientProvider>
|
|
30
36
|
</BrowserRouter>
|
|
31
37
|
);
|
|
32
|
-
}
|
|
38
|
+
};
|
package/types/theme.d.ts
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LinearProgress } from "@mui/material";
|
|
2
|
-
import { Store } from "pullstate";
|
|
3
|
-
|
|
4
|
-
export const NetworkStore = new Store({
|
|
5
|
-
loading: false,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export default function GlobalNetworkLoadingIndicator() {
|
|
9
|
-
const { loading } = NetworkStore.useState();
|
|
10
|
-
|
|
11
|
-
if (loading) return <LinearProgress />;
|
|
12
|
-
if (loading) return null;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./ErrorBoundary";
|
|
File without changes
|