@visns-studio/visns-components 3.1.6 → 3.1.7
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/Form.jsx +35 -1
- package/package.json +2 -1
package/components/crm/Form.jsx
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
2
2
|
import { useNavigate } from 'react-router-dom';
|
|
3
3
|
import { motion } from 'framer-motion';
|
|
4
4
|
import { toast } from 'react-toastify';
|
|
5
|
+
import { saveAs } from 'file-saver';
|
|
5
6
|
import moment from 'moment';
|
|
6
7
|
import parse from 'html-react-parser';
|
|
7
8
|
import _ from 'lodash';
|
|
@@ -11,6 +12,7 @@ import { CircleX } from 'akar-icons';
|
|
|
11
12
|
import '@inovua/reactdatagrid-community/index.css';
|
|
12
13
|
|
|
13
14
|
import CustomFetch from './Fetch';
|
|
15
|
+
import Download from './Download';
|
|
14
16
|
import Field from './Field';
|
|
15
17
|
import Table from './DataGrid';
|
|
16
18
|
|
|
@@ -377,8 +379,34 @@ function Form({
|
|
|
377
379
|
);
|
|
378
380
|
};
|
|
379
381
|
|
|
382
|
+
const handleDownload = async (e) => {
|
|
383
|
+
try {
|
|
384
|
+
if (e) {
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const extension = formSettings.download.extension;
|
|
389
|
+
const filename = formSettings.download.filename;
|
|
390
|
+
const method = 'POST';
|
|
391
|
+
const url = formSettings.download.url;
|
|
392
|
+
|
|
393
|
+
const res = await Download(url, method, formData);
|
|
394
|
+
|
|
395
|
+
// Using file-saver to save the file
|
|
396
|
+
const blob = new Blob([res.data], {
|
|
397
|
+
type: 'application/octet-stream',
|
|
398
|
+
});
|
|
399
|
+
saveAs(blob, `${filename}.${extension}`);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
console.error(error);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
380
405
|
const handleSubmit = (e) => {
|
|
381
|
-
e
|
|
406
|
+
if (e) {
|
|
407
|
+
e.preventDefault();
|
|
408
|
+
}
|
|
409
|
+
|
|
382
410
|
let fields = formSettings.fields;
|
|
383
411
|
let _inputClass = inputClass;
|
|
384
412
|
let validation = '';
|
|
@@ -1098,6 +1126,12 @@ function Form({
|
|
|
1098
1126
|
)}
|
|
1099
1127
|
</form>
|
|
1100
1128
|
<div className="polActions">
|
|
1129
|
+
{formSettings?.download?.button?.label && (
|
|
1130
|
+
<button className="btn" onClick={handleDownload}>
|
|
1131
|
+
{formSettings.download.button.label}
|
|
1132
|
+
</button>
|
|
1133
|
+
)}
|
|
1134
|
+
|
|
1101
1135
|
<button className="btn" onClick={handleSubmit}>
|
|
1102
1136
|
{formSettings?.save?.button?.label
|
|
1103
1137
|
? formSettings.save.button.label
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"array-move": "^4.0.0",
|
|
8
8
|
"awesome-debounce-promise": "^2.1.0",
|
|
9
9
|
"axios": "^1.6.5",
|
|
10
|
+
"file-saver": "^2.0.5",
|
|
10
11
|
"framer-motion": "^10.18.0",
|
|
11
12
|
"html-react-parser": "^5.1.1",
|
|
12
13
|
"lodash": "^4.17.21",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"react-dom": "^17.0.1"
|
|
47
48
|
},
|
|
48
49
|
"name": "@visns-studio/visns-components",
|
|
49
|
-
"version": "3.1.
|
|
50
|
+
"version": "3.1.7",
|
|
50
51
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
51
52
|
"main": "index.js",
|
|
52
53
|
"scripts": {
|