@campxdev/campx-web-utils 0.1.4 → 0.1.5
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/package.json +1 -1
- package/src/config/axios.ts +2 -56
package/package.json
CHANGED
package/src/config/axios.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import Axios
|
|
1
|
+
import Axios from "axios";
|
|
2
2
|
import Cookies from "js-cookie";
|
|
3
|
-
import { toast } from "react-toastify";
|
|
4
|
-
// import { NetworkStore } from "../components/ErrorBoundary/GlobalNetworkLoadingIndicator";
|
|
5
3
|
|
|
6
4
|
const isDevelopment = process.env.NODE_ENV == "development";
|
|
7
5
|
|
|
@@ -13,16 +11,7 @@ const institutionCode = window.location.pathname.split("/")[1];
|
|
|
13
11
|
|
|
14
12
|
const openPaymentsKey = Cookies.get("campx_open_payments_key");
|
|
15
13
|
|
|
16
|
-
export const
|
|
17
|
-
return Object.fromEntries(
|
|
18
|
-
Object.entries(params ?? {})?.map((i) => [
|
|
19
|
-
i[0],
|
|
20
|
-
i[1] === "__empty__" ? "" : i[1],
|
|
21
|
-
])
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
let axios = Axios.create({
|
|
14
|
+
export const axios = Axios.create({
|
|
26
15
|
baseURL: process.env.REACT_APP_API_HOST,
|
|
27
16
|
withCredentials: true,
|
|
28
17
|
headers: {
|
|
@@ -34,46 +23,3 @@ let axios = Axios.create({
|
|
|
34
23
|
}),
|
|
35
24
|
},
|
|
36
25
|
});
|
|
37
|
-
|
|
38
|
-
axios.interceptors.request.use(
|
|
39
|
-
function (config: InternalAxiosRequestConfig) {
|
|
40
|
-
const params = formatParams(config?.params);
|
|
41
|
-
// NetworkStore.update((s) => {
|
|
42
|
-
// s.loading = true;
|
|
43
|
-
// });
|
|
44
|
-
return { ...config, params };
|
|
45
|
-
},
|
|
46
|
-
function (error) {
|
|
47
|
-
// NetworkStore.update((s) => {
|
|
48
|
-
// s.loading = false;
|
|
49
|
-
// });
|
|
50
|
-
return Promise.reject(error);
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
axios.interceptors.response.use(
|
|
55
|
-
function (response) {
|
|
56
|
-
// NetworkStore.update((s) => {
|
|
57
|
-
// s.loading = false;
|
|
58
|
-
// });
|
|
59
|
-
return response;
|
|
60
|
-
},
|
|
61
|
-
function (err) {
|
|
62
|
-
// NetworkStore.update((s) => {
|
|
63
|
-
// s.loading = false;
|
|
64
|
-
// });
|
|
65
|
-
return Promise.reject(err);
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
export default axios;
|
|
70
|
-
|
|
71
|
-
export const axiosErrorToast = (error: any, fallback?: string) => {
|
|
72
|
-
const fallbackMessage = fallback ?? "Something went wrong.";
|
|
73
|
-
const errorMessage =
|
|
74
|
-
typeof error?.response?.data?.message !== "string"
|
|
75
|
-
? error?.response?.data?.message?.join("\n") ?? fallbackMessage
|
|
76
|
-
: error?.response?.data?.message;
|
|
77
|
-
|
|
78
|
-
return toast.error(errorMessage);
|
|
79
|
-
};
|