@visns-studio/visns-components 1.3.9 → 1.3.11
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,12 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import axios from "axios";
|
|
2
3
|
import { trackPromise } from "react-promise-tracker";
|
|
4
|
+
import { toast } from "react-toastify";
|
|
5
|
+
import parse from "html-react-parser";
|
|
3
6
|
|
|
4
7
|
const CustomDownload = async (
|
|
5
8
|
url,
|
|
6
9
|
method,
|
|
7
10
|
formData,
|
|
8
|
-
successCallback,
|
|
9
|
-
errorCallback
|
|
11
|
+
successCallback = null,
|
|
12
|
+
errorCallback = null
|
|
10
13
|
) => {
|
|
11
14
|
let headers = {};
|
|
12
15
|
let options = {};
|
|
@@ -42,22 +45,47 @@ const CustomDownload = async (
|
|
|
42
45
|
|
|
43
46
|
try {
|
|
44
47
|
const response = await trackPromise(axios(options));
|
|
45
|
-
|
|
48
|
+
|
|
49
|
+
if (successCallback) {
|
|
50
|
+
successCallback(response.data);
|
|
51
|
+
} else {
|
|
52
|
+
const error =
|
|
53
|
+
response.data.error || "Data has been updated successfully.";
|
|
54
|
+
toast.error(<div>{parse(error)}</div>);
|
|
55
|
+
}
|
|
46
56
|
} catch (error) {
|
|
57
|
+
let errorMessage = "";
|
|
58
|
+
|
|
47
59
|
if (
|
|
48
60
|
error.response &&
|
|
49
61
|
error.response.data &&
|
|
50
62
|
error.response.data.message
|
|
51
63
|
) {
|
|
52
|
-
const
|
|
64
|
+
const { data } = error.response;
|
|
53
65
|
|
|
54
|
-
if (
|
|
55
|
-
|
|
66
|
+
if (data.errors) {
|
|
67
|
+
const { errors } = data;
|
|
68
|
+
|
|
69
|
+
Object.values(errors).forEach((errorArray) => {
|
|
70
|
+
errorArray.forEach((errorMsg) => {
|
|
71
|
+
errorMessage += `${errorMsg}<br />`;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
if (data.message === "CSRF token mismatch.") {
|
|
76
|
+
window.location.replace("/login");
|
|
77
|
+
} else {
|
|
78
|
+
errorMessage = data.message;
|
|
79
|
+
}
|
|
56
80
|
}
|
|
81
|
+
} else {
|
|
82
|
+
errorMessage = error.message;
|
|
83
|
+
}
|
|
57
84
|
|
|
85
|
+
if (errorCallback) {
|
|
58
86
|
errorCallback(errorMessage);
|
|
59
87
|
} else {
|
|
60
|
-
|
|
88
|
+
toast.error(<div>{parse(errorMessage)}</div>);
|
|
61
89
|
}
|
|
62
90
|
}
|
|
63
91
|
};
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"react-dom": "^17.0.1"
|
|
35
35
|
},
|
|
36
36
|
"name": "@visns-studio/visns-components",
|
|
37
|
-
"version": "1.3.
|
|
37
|
+
"version": "1.3.11",
|
|
38
38
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
39
39
|
"main": "index.js",
|
|
40
40
|
"devDependencies": {},
|