tycho-components 0.9.4 → 0.9.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { message, silentLoading, toastLoading } from
|
|
3
|
-
import CommonContext from
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { message, silentLoading, toastLoading } from "../configs/store/actions";
|
|
3
|
+
import CommonContext from "./CommonContext";
|
|
4
4
|
export const useMessageUtils = () => {
|
|
5
5
|
const { state, dispatch } = useContext(CommonContext);
|
|
6
6
|
const isSilentLoading = () => {
|
|
@@ -17,33 +17,36 @@ export const useMessageUtils = () => {
|
|
|
17
17
|
};
|
|
18
18
|
const dispatchError = ({ err, t, key }) => {
|
|
19
19
|
if (!err.response) {
|
|
20
|
-
const value = t(`${key ??
|
|
21
|
-
dispatch(message({ value, type:
|
|
20
|
+
const value = t(`${key ?? "message"}:${err}`);
|
|
21
|
+
dispatch(message({ value, type: "error" }));
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
if (err.response.status === 403) {
|
|
25
|
-
dispatch(message({ value: t(
|
|
25
|
+
dispatch(message({ value: t("error.access.authorization"), type: "error" }));
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
let errorKey =
|
|
29
|
-
if (err.response.data?.
|
|
28
|
+
let errorKey = "";
|
|
29
|
+
if (err.response.data?.message) {
|
|
30
|
+
errorKey = err.response.data.message;
|
|
31
|
+
}
|
|
32
|
+
else if (err.response.data?.description) {
|
|
30
33
|
errorKey = err.response.data.description;
|
|
31
34
|
}
|
|
32
35
|
else if (err.response.data?.errors?.length > 0) {
|
|
33
36
|
errorKey = err.response.data.errors[0].description;
|
|
34
37
|
}
|
|
35
38
|
else {
|
|
36
|
-
key =
|
|
37
|
-
errorKey =
|
|
39
|
+
key = "common";
|
|
40
|
+
errorKey = "internal.server.error";
|
|
38
41
|
}
|
|
39
|
-
const value = t(`${key ??
|
|
40
|
-
dispatch(message({ value, type:
|
|
42
|
+
const value = t(`${key ?? "message"}:${errorKey}`);
|
|
43
|
+
dispatch(message({ value, type: "error" }));
|
|
41
44
|
};
|
|
42
45
|
const dispatchMessage = ({ key, ns, t }) => {
|
|
43
46
|
const entry = ns ? `${ns}:${key}` : `message:${key}`;
|
|
44
|
-
dispatch(message({ value: t(entry), type:
|
|
47
|
+
dispatch(message({ value: t(entry), type: "success" }));
|
|
45
48
|
};
|
|
46
|
-
const dispatchMessageDirect = (value, type =
|
|
49
|
+
const dispatchMessageDirect = (value, type = "success") => {
|
|
47
50
|
dispatch(message({ value, type }));
|
|
48
51
|
};
|
|
49
52
|
return {
|