@visns-studio/visns-components 3.8.5 → 3.8.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.
@@ -701,11 +701,9 @@ function Field({
701
701
  : true
702
702
  }
703
703
  decimalSeparator={
704
- settings.type === 'decimal' ? '.' : undefined
705
- }
706
- decimalScale={
707
- settings.type === 'decimal' ? 2 : undefined
704
+ settings.type === 'decimal' ? '.' : '.'
708
705
  }
706
+ decimalScale={settings.type === 'decimal' ? 2 : 2}
709
707
  value={
710
708
  inputValue && inputValue !== 'null'
711
709
  ? inputValue
@@ -920,12 +918,28 @@ function Field({
920
918
  alignItems: 'center',
921
919
  }}
922
920
  >
921
+ <label
922
+ htmlFor={settings.id}
923
+ style={{
924
+ padding: '6px 12px',
925
+ border: '1px solid #ccc',
926
+ display: 'inline-block',
927
+ backgroundColor: '#f8f8f8',
928
+ cursor: 'pointer',
929
+ }}
930
+ >
931
+ Choose file...
932
+ </label>
923
933
  <input
934
+ id={settings.id}
924
935
  type="file"
925
- data-name={settings.id}
926
- className={inputClass[settings.id]}
936
+ className={inputClass[settings.id]} // Ensure inputClass is defined or passed
927
937
  onChange={onChange}
928
- />{' '}
938
+ style={{ display: 'none' }}
939
+ />
940
+ <span style={{ marginLeft: '10px' }}>
941
+ {inputValue.filename}
942
+ </span>
929
943
  {inputValue &&
930
944
  inputValue.key &&
931
945
  inputValue.uuid && (
@@ -940,7 +954,6 @@ function Field({
940
954
  }
941
955
  onClick={(e) => {
942
956
  e.preventDefault();
943
-
944
957
  onFileDownload(inputValue);
945
958
  }}
946
959
  >
@@ -72,6 +72,16 @@ const renderValue = (field, data) => {
72
72
  }
73
73
  };
74
74
 
75
+ const slugify = (text) => {
76
+ return text
77
+ .toString()
78
+ .toLowerCase()
79
+ .trim()
80
+ .replace(/\s+/g, '-') // Replace spaces with -
81
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
82
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
83
+ };
84
+
75
85
  const GenericDynamic = ({
76
86
  data,
77
87
  fetchData,
@@ -104,7 +114,6 @@ const GenericDynamic = ({
104
114
  updateField(prevState, name, newValue)
105
115
  );
106
116
  } else if (files && files[0]) {
107
- console.info('aa');
108
117
  const toastId = toast.loading('Uploading file...'); // Show loading toast
109
118
  // Start the upload process and read the file if it's an image
110
119
  Vapor.store(files[0], {
@@ -199,6 +208,10 @@ const GenericDynamic = ({
199
208
  setActiveForm((prevState) => updateField(prevState, id, value));
200
209
  };
201
210
 
211
+ const handleChangeNumberFormat = (value, id) => {
212
+ setActiveForm((prevState) => updateField(prevState, id, value.value));
213
+ };
214
+
202
215
  const handleChangeToggle = (e) => {
203
216
  if (!e) {
204
217
  return;
@@ -285,17 +298,38 @@ const GenericDynamic = ({
285
298
  };
286
299
 
287
300
  const handleDownloadForm = async (item, label, data) => {
288
- // Show loading toast and keep its ID
289
301
  const toastId = toast.loading('Downloading form...');
290
302
 
291
303
  try {
292
- const res = await Download(setting.download, 'POST', {
304
+ // Assuming Download returns an object with { data: Blob, headers: Headers }
305
+ const response = await Download(setting.download, 'POST', {
293
306
  data: item,
294
307
  dynamicData: data,
295
308
  label: label,
296
309
  });
297
310
 
298
- if (res.data) {
311
+ if (response && response.data) {
312
+ const contentDisposition = response.headers.get(
313
+ 'Content-Disposition'
314
+ );
315
+ let filename = null; // Default to null, letting saveAs decide the filename
316
+
317
+ if (contentDisposition) {
318
+ const filenameMatch = contentDisposition.match(
319
+ /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
320
+ );
321
+ if (filenameMatch && filenameMatch[1]) {
322
+ filename = filenameMatch[1].replace(/['"]/g, ''); // Remove potential quotes
323
+ }
324
+ }
325
+
326
+ // Perform the download using FileSaver.js
327
+ if (filename) {
328
+ saveAs(response.data, filename);
329
+ } else {
330
+ saveAs(response.data); // No filename extracted, let FileSaver handle it
331
+ }
332
+
299
333
  // Update loading toast to a success message before closing it
300
334
  toast.update(toastId, {
301
335
  render: 'Download successful!',
@@ -304,26 +338,15 @@ const GenericDynamic = ({
304
338
  autoClose: 5000,
305
339
  closeButton: true,
306
340
  });
307
- // Perform the download
308
-
309
- // const fileName = slugify(label) + '.pdf';
310
- // saveAs(res.data, fileName);
311
- saveAs(res.data);
312
341
  } else {
313
- // Update the toast to show an error message
314
- toast.update(toastId, {
315
- render: 'Error downloading form',
316
- type: 'error',
317
- isLoading: false,
318
- autoClose: 5000,
319
- closeButton: true,
320
- });
342
+ // Handle the case where there is no data in the response
343
+ throw new Error('No data received from the server');
321
344
  }
322
345
  } catch (err) {
323
346
  console.error(err);
324
347
  // Update the toast to show an error message
325
348
  toast.update(toastId, {
326
- render: 'Error downloading form',
349
+ render: 'Error downloading form: ' + err.message,
327
350
  type: 'error',
328
351
  isLoading: false,
329
352
  autoClose: 5000,
@@ -629,6 +652,9 @@ const GenericDynamic = ({
629
652
  onChangeDate={
630
653
  handleChangeDate
631
654
  }
655
+ onChangeNumberFormat={
656
+ handleChangeNumberFormat
657
+ }
632
658
  onChangeToggle={
633
659
  handleChangeToggle
634
660
  }
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "awesome-debounce-promise": "^2.1.0",
13
13
  "axios": "^1.6.8",
14
14
  "file-saver": "^2.0.5",
15
- "framer-motion": "^11.0.24",
15
+ "framer-motion": "^11.1.7",
16
16
  "html-react-parser": "^5.1.10",
17
17
  "lodash": "^4.17.21",
18
18
  "lodash.debounce": "^4.0.8",
@@ -24,7 +24,7 @@
24
24
  "react-color": "^2.19.3",
25
25
  "react-confirm-alert": "^3.0.6",
26
26
  "react-copy-to-clipboard": "^5.1.0",
27
- "react-datepicker": "^6.6.0",
27
+ "react-datepicker": "^6.9.0",
28
28
  "react-dropzone": "^14.2.3",
29
29
  "react-number-format": "^5.3.4",
30
30
  "react-password-strength-bar": "^0.4.1",
@@ -54,7 +54,7 @@
54
54
  "react-dom": "^17.0.1"
55
55
  },
56
56
  "name": "@visns-studio/visns-components",
57
- "version": "3.8.5",
57
+ "version": "3.8.7",
58
58
  "description": "Various packages to assist in the development of our Custom Applications.",
59
59
  "main": "index.js",
60
60
  "scripts": {