@visns-studio/visns-components 3.1.4 → 3.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/components/crm/Download.jsx +86 -79
- package/components/crm/Fetch.jsx +12 -12
- package/package.json +1 -1
|
@@ -1,93 +1,100 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import axios from
|
|
3
|
-
import { trackPromise } from
|
|
4
|
-
import { toast } from
|
|
5
|
-
import parse from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { trackPromise } from 'react-promise-tracker';
|
|
4
|
+
import { toast } from 'react-toastify';
|
|
5
|
+
import parse from 'html-react-parser';
|
|
6
6
|
|
|
7
|
-
const CustomDownload =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const CustomDownload = (
|
|
8
|
+
url,
|
|
9
|
+
method,
|
|
10
|
+
formData,
|
|
11
|
+
successCallback = null,
|
|
12
|
+
errorCallback = null
|
|
13
13
|
) => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
let headers = {};
|
|
15
|
+
let options = {};
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (method.toUpperCase() === 'PUT' || method.toUpperCase() === 'PATCH') {
|
|
18
|
+
formData = { ...formData, _method: method };
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (!(formData instanceof FormData)) {
|
|
22
|
+
headers['Content-Type'] = 'application/json';
|
|
23
|
+
formData = JSON.stringify(formData);
|
|
24
|
+
} else {
|
|
25
|
+
headers['Content-Type'] = 'multipart/form-data';
|
|
26
|
+
headers.contentType = false;
|
|
27
|
+
headers.processData = false;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
if (
|
|
30
|
+
method.toUpperCase() === 'PUT' ||
|
|
31
|
+
method.toUpperCase() === 'PATCH'
|
|
32
|
+
) {
|
|
33
|
+
formData.append('_method', method);
|
|
34
|
+
method = 'POST';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
options = {
|
|
39
|
+
method: method,
|
|
40
|
+
data: formData,
|
|
41
|
+
headers: headers,
|
|
42
|
+
url: url,
|
|
43
|
+
responseType: 'blob',
|
|
44
|
+
};
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
return trackPromise(
|
|
47
|
+
new Promise((resolve, reject) => {
|
|
48
|
+
axios(options)
|
|
49
|
+
.then((response) => {
|
|
50
|
+
if (successCallback) {
|
|
51
|
+
successCallback(response.data);
|
|
52
|
+
} else {
|
|
53
|
+
const error =
|
|
54
|
+
response.data.error ||
|
|
55
|
+
'Data has been downloaded successfully.';
|
|
56
|
+
toast.error(<div>{parse(error)}</div>);
|
|
57
|
+
}
|
|
58
|
+
resolve(response);
|
|
59
|
+
})
|
|
60
|
+
.catch((error) => {
|
|
61
|
+
let errorMessage = '';
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
let errorMessage = "";
|
|
63
|
+
if (
|
|
64
|
+
error.response &&
|
|
65
|
+
error.response.data &&
|
|
66
|
+
error.response.data.message
|
|
67
|
+
) {
|
|
68
|
+
const { data } = error.response;
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
error.response.data &&
|
|
62
|
-
error.response.data.message
|
|
63
|
-
) {
|
|
64
|
-
const { data } = error.response;
|
|
70
|
+
if (data.errors) {
|
|
71
|
+
const { errors } = data;
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
Object.values(errors).forEach((errorArray) => {
|
|
74
|
+
errorArray.forEach((errorMsg) => {
|
|
75
|
+
errorMessage += `${errorMsg}<br />`;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
if (data.message === 'CSRF token mismatch.') {
|
|
80
|
+
window.location.replace('/login');
|
|
81
|
+
} else {
|
|
82
|
+
errorMessage = data.message;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
errorMessage = error.message;
|
|
87
|
+
}
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
errorMessage = data.message;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
errorMessage = error.message;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (errorCallback) {
|
|
86
|
-
errorCallback(errorMessage);
|
|
87
|
-
} else {
|
|
88
|
-
toast.error(<div>{parse(errorMessage)}</div>);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
89
|
+
if (errorCallback) {
|
|
90
|
+
errorCallback(errorMessage);
|
|
91
|
+
} else {
|
|
92
|
+
toast.error(<div>{parse(errorMessage)}</div>);
|
|
93
|
+
}
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
})
|
|
97
|
+
);
|
|
91
98
|
};
|
|
92
99
|
|
|
93
100
|
export default CustomDownload;
|
package/components/crm/Fetch.jsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import axios from
|
|
3
|
-
import { trackPromise } from
|
|
4
|
-
import { toast } from
|
|
5
|
-
import parse from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { trackPromise } from 'react-promise-tracker';
|
|
4
|
+
import { toast } from 'react-toastify';
|
|
5
|
+
import parse from 'html-react-parser';
|
|
6
6
|
|
|
7
7
|
const CustomFetch = (
|
|
8
8
|
url,
|
|
@@ -11,12 +11,12 @@ const CustomFetch = (
|
|
|
11
11
|
successCallback = null,
|
|
12
12
|
errorCallback = null
|
|
13
13
|
) => {
|
|
14
|
-
const baseUrl =
|
|
14
|
+
const baseUrl = '';
|
|
15
15
|
const headers = {
|
|
16
|
-
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
if (method.toUpperCase() ===
|
|
19
|
+
if (method.toUpperCase() === 'PUT' || method.toUpperCase() === 'PATCH') {
|
|
20
20
|
formData = {
|
|
21
21
|
...formData,
|
|
22
22
|
_method: method,
|
|
@@ -39,14 +39,14 @@ const CustomFetch = (
|
|
|
39
39
|
} else {
|
|
40
40
|
const error = response.data.error;
|
|
41
41
|
|
|
42
|
-
if (error && error !==
|
|
42
|
+
if (error && error !== '') {
|
|
43
43
|
toast.error(<div>{parse(error)}</div>);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
resolve(response);
|
|
47
47
|
})
|
|
48
48
|
.catch((error) => {
|
|
49
|
-
let errorMessage =
|
|
49
|
+
let errorMessage = '';
|
|
50
50
|
|
|
51
51
|
if (
|
|
52
52
|
error.response &&
|
|
@@ -64,8 +64,8 @@ const CustomFetch = (
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
} else {
|
|
67
|
-
if (data.message ===
|
|
68
|
-
window.location.replace(
|
|
67
|
+
if (data.message === 'CSRF token mismatch.') {
|
|
68
|
+
window.location.replace('/login');
|
|
69
69
|
} else {
|
|
70
70
|
errorMessage = data.message;
|
|
71
71
|
}
|
package/package.json
CHANGED