@visns-studio/visns-components 3.1.4 → 3.1.6

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,93 +1,101 @@
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";
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 = async (
8
- url,
9
- method,
10
- formData,
11
- successCallback = null,
12
- errorCallback = null
7
+ const CustomDownload = (
8
+ url,
9
+ method,
10
+ formData,
11
+ successCallback = null,
12
+ errorCallback = null
13
13
  ) => {
14
- let headers = {};
15
- let options = {};
14
+ let headers = {};
15
+ let options = {};
16
16
 
17
- if (method.toUpperCase() === "PUT" || method.toUpperCase() === "PATCH") {
18
- formData = { ...formData, _method: method };
19
- }
17
+ if (method.toUpperCase() === 'PUT' || method.toUpperCase() === 'PATCH') {
18
+ formData = { ...formData, _method: method };
19
+ }
20
20
 
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;
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
- if (
30
- method.toUpperCase() === "PUT" ||
31
- method.toUpperCase() === "PATCH"
32
- ) {
33
- formData.append("_method", method);
34
- method = "POST";
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
- options = {
39
- method: method,
40
- data: formData,
41
- headers: headers,
42
- url: url,
43
- responseType: "blob",
44
- };
38
+ options = {
39
+ method: method,
40
+ data: formData,
41
+ headers: headers,
42
+ url: url,
43
+ responseType: 'blob',
44
+ };
45
45
 
46
- try {
47
- const response = await trackPromise(axios(options));
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 = response.data.error;
48
54
 
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
- }
56
- } catch (error) {
57
- let errorMessage = "";
55
+ if (error && error !== '') {
56
+ toast.error(<div>{parse(error)}</div>);
57
+ }
58
+ }
59
+ resolve(response);
60
+ })
61
+ .catch((error) => {
62
+ let errorMessage = '';
58
63
 
59
- if (
60
- error.response &&
61
- error.response.data &&
62
- error.response.data.message
63
- ) {
64
- const { data } = error.response;
64
+ if (
65
+ error.response &&
66
+ error.response.data &&
67
+ error.response.data.message
68
+ ) {
69
+ const { data } = error.response;
65
70
 
66
- if (data.errors) {
67
- const { errors } = data;
71
+ if (data.errors) {
72
+ const { errors } = data;
68
73
 
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
- }
80
- }
81
- } else {
82
- errorMessage = error.message;
83
- }
74
+ Object.values(errors).forEach((errorArray) => {
75
+ errorArray.forEach((errorMsg) => {
76
+ errorMessage += `${errorMsg}<br />`;
77
+ });
78
+ });
79
+ } else {
80
+ if (data.message === 'CSRF token mismatch.') {
81
+ window.location.replace('/login');
82
+ } else {
83
+ errorMessage = data.message;
84
+ }
85
+ }
86
+ } else {
87
+ errorMessage = error.message;
88
+ }
84
89
 
85
- if (errorCallback) {
86
- errorCallback(errorMessage);
87
- } else {
88
- toast.error(<div>{parse(errorMessage)}</div>);
89
- }
90
- }
90
+ if (errorCallback) {
91
+ errorCallback(errorMessage);
92
+ } else {
93
+ toast.error(<div>{parse(errorMessage)}</div>);
94
+ }
95
+ reject(error);
96
+ });
97
+ })
98
+ );
91
99
  };
92
100
 
93
101
  export default CustomDownload;
@@ -1,8 +1,8 @@
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";
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
- "Content-Type": "application/json",
16
+ 'Content-Type': 'application/json',
17
17
  };
18
18
 
19
- if (method.toUpperCase() === "PUT" || method.toUpperCase() === "PATCH") {
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 === "CSRF token mismatch.") {
68
- window.location.replace("/login");
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
@@ -46,7 +46,7 @@
46
46
  "react-dom": "^17.0.1"
47
47
  },
48
48
  "name": "@visns-studio/visns-components",
49
- "version": "3.1.4",
49
+ "version": "3.1.6",
50
50
  "description": "Various packages to assist in the development of our Custom Applications.",
51
51
  "main": "index.js",
52
52
  "scripts": {