@visns-studio/visns-components 3.8.4 → 3.8.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.
package/components/crm/Field.jsx
CHANGED
|
@@ -977,13 +977,11 @@ function Field({
|
|
|
977
977
|
return (
|
|
978
978
|
<div
|
|
979
979
|
style={{
|
|
980
|
+
position: 'relative', // Parent container positioned relatively
|
|
980
981
|
display: 'inline-flex',
|
|
981
982
|
alignItems: 'center',
|
|
982
983
|
cursor: 'pointer',
|
|
983
984
|
}}
|
|
984
|
-
onClick={() => {
|
|
985
|
-
fileImageInputRef.current.click();
|
|
986
|
-
}}
|
|
987
985
|
>
|
|
988
986
|
<input
|
|
989
987
|
type="file"
|
|
@@ -991,7 +989,15 @@ function Field({
|
|
|
991
989
|
className={inputClass[settings.id]} // Assuming inputClass is defined elsewhere in your code
|
|
992
990
|
onChange={onChange}
|
|
993
991
|
ref={fileImageInputRef}
|
|
994
|
-
style={{
|
|
992
|
+
style={{
|
|
993
|
+
position: 'absolute',
|
|
994
|
+
left: 0,
|
|
995
|
+
top: 0,
|
|
996
|
+
width: '100%',
|
|
997
|
+
height: '100%',
|
|
998
|
+
opacity: 0, // Make the input invisible
|
|
999
|
+
cursor: 'pointer',
|
|
1000
|
+
}}
|
|
995
1001
|
/>
|
|
996
1002
|
{inputValue.imageSrc ? (
|
|
997
1003
|
<img
|
|
@@ -1004,7 +1010,7 @@ function Field({
|
|
|
1004
1010
|
/>
|
|
1005
1011
|
) : (
|
|
1006
1012
|
<img
|
|
1007
|
-
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAJ3UlEQVR4nO3b60/aXhwG8KflJijIJQgTt8y5mLkxl73w//8HzBbdXLLFqJsg3rjKnUJ/L0wJpYUC9ovbL8/nlRbac077tOf0tCiHh4c6iFymPncF6P+
|
|
1013
|
+
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAJ3UlEQVR4nO3b60/aXhwG8KflJijIJQgTt8y5mLkxl73w//8HzBbdXLLFqJsg3rjKnUJ/L0wJpYUC9ovbL8/nlRbac077tOf0tCiHh4c6iFymPncF6P+JwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEsFgkQgGi0QwWCSCwSIRDBaJYLBIBINFIhgsEvEfmhiBahNiQpEAAAAASUVORK5CYII="
|
|
1008
1014
|
alt="Placeholder"
|
|
1009
1015
|
/>
|
|
1010
1016
|
)}
|
|
@@ -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,
|
|
@@ -284,17 +294,38 @@ const GenericDynamic = ({
|
|
|
284
294
|
};
|
|
285
295
|
|
|
286
296
|
const handleDownloadForm = async (item, label, data) => {
|
|
287
|
-
// Show loading toast and keep its ID
|
|
288
297
|
const toastId = toast.loading('Downloading form...');
|
|
289
298
|
|
|
290
299
|
try {
|
|
291
|
-
|
|
300
|
+
// Assuming Download returns an object with { data: Blob, headers: Headers }
|
|
301
|
+
const response = await Download(setting.download, 'POST', {
|
|
292
302
|
data: item,
|
|
293
303
|
dynamicData: data,
|
|
294
304
|
label: label,
|
|
295
305
|
});
|
|
296
306
|
|
|
297
|
-
if (
|
|
307
|
+
if (response && response.data) {
|
|
308
|
+
const contentDisposition = response.headers.get(
|
|
309
|
+
'Content-Disposition'
|
|
310
|
+
);
|
|
311
|
+
let filename = null; // Default to null, letting saveAs decide the filename
|
|
312
|
+
|
|
313
|
+
if (contentDisposition) {
|
|
314
|
+
const filenameMatch = contentDisposition.match(
|
|
315
|
+
/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
|
316
|
+
);
|
|
317
|
+
if (filenameMatch && filenameMatch[1]) {
|
|
318
|
+
filename = filenameMatch[1].replace(/['"]/g, ''); // Remove potential quotes
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Perform the download using FileSaver.js
|
|
323
|
+
if (filename) {
|
|
324
|
+
saveAs(response.data, filename);
|
|
325
|
+
} else {
|
|
326
|
+
saveAs(response.data); // No filename extracted, let FileSaver handle it
|
|
327
|
+
}
|
|
328
|
+
|
|
298
329
|
// Update loading toast to a success message before closing it
|
|
299
330
|
toast.update(toastId, {
|
|
300
331
|
render: 'Download successful!',
|
|
@@ -303,26 +334,15 @@ const GenericDynamic = ({
|
|
|
303
334
|
autoClose: 5000,
|
|
304
335
|
closeButton: true,
|
|
305
336
|
});
|
|
306
|
-
// Perform the download
|
|
307
|
-
|
|
308
|
-
// const fileName = slugify(label) + '.pdf';
|
|
309
|
-
// saveAs(res.data, fileName);
|
|
310
|
-
saveAs(res.data);
|
|
311
337
|
} else {
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
render: 'Error downloading form',
|
|
315
|
-
type: 'error',
|
|
316
|
-
isLoading: false,
|
|
317
|
-
autoClose: 5000,
|
|
318
|
-
closeButton: true,
|
|
319
|
-
});
|
|
338
|
+
// Handle the case where there is no data in the response
|
|
339
|
+
throw new Error('No data received from the server');
|
|
320
340
|
}
|
|
321
341
|
} catch (err) {
|
|
322
342
|
console.error(err);
|
|
323
343
|
// Update the toast to show an error message
|
|
324
344
|
toast.update(toastId, {
|
|
325
|
-
render: 'Error downloading form',
|
|
345
|
+
render: 'Error downloading form: ' + err.message,
|
|
326
346
|
type: 'error',
|
|
327
347
|
isLoading: false,
|
|
328
348
|
autoClose: 5000,
|
package/package.json
CHANGED