@visns-studio/visns-components 5.15.32 → 5.15.34
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/package.json +5 -5
- package/src/components/Form.jsx +90 -20
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@nivo/line": "^0.87.0",
|
|
14
14
|
"@nivo/pie": "^0.87.0",
|
|
15
15
|
"@react-pdf/renderer": "^4.3.2",
|
|
16
|
-
"@tanstack/react-query": "^5.
|
|
16
|
+
"@tanstack/react-query": "^5.95.2",
|
|
17
17
|
"@tinymce/miniature": "^6.0.0",
|
|
18
18
|
"@tinymce/tinymce-react": "^6.3.0",
|
|
19
19
|
"@uiw/react-color": "^2.9.6",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-datepicker": "^8.10.0",
|
|
47
47
|
"react-dropzone": "^14.4.1",
|
|
48
48
|
"react-grid-gallery": "^1.0.1",
|
|
49
|
-
"react-number-format": "^5.4.
|
|
49
|
+
"react-number-format": "^5.4.5",
|
|
50
50
|
"react-password-strength-bar": "^0.4.1",
|
|
51
51
|
"react-promise-tracker": "^2.1.1",
|
|
52
52
|
"react-quill": "^2.0.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"reactjs-popup": "^2.0.6",
|
|
65
65
|
"style-loader": "^4.0.0",
|
|
66
66
|
"swapy": "^1.0.5",
|
|
67
|
-
"sweetalert2": "^11.26.
|
|
67
|
+
"sweetalert2": "^11.26.24",
|
|
68
68
|
"tesseract.js": "^6.0.1",
|
|
69
69
|
"truncate": "^3.0.0",
|
|
70
70
|
"uuid": "^11.1.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"vite": "^6.4.1",
|
|
73
73
|
"xlsx": "^0.18.5",
|
|
74
74
|
"yarn": "^1.22.22",
|
|
75
|
-
"yet-another-react-lightbox": "^3.29.
|
|
75
|
+
"yet-another-react-lightbox": "^3.29.2"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@babel/core": "^7.29.0",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
95
95
|
},
|
|
96
96
|
"name": "@visns-studio/visns-components",
|
|
97
|
-
"version": "5.15.
|
|
97
|
+
"version": "5.15.34",
|
|
98
98
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
99
99
|
"main": "src/index.js",
|
|
100
100
|
"files": [
|
package/src/components/Form.jsx
CHANGED
|
@@ -1508,11 +1508,11 @@ function Form({
|
|
|
1508
1508
|
Object.keys(formData).forEach((item) => {
|
|
1509
1509
|
const value = formData[item];
|
|
1510
1510
|
|
|
1511
|
-
// Check if it's a single File or an array
|
|
1511
|
+
// Check if it's a single File or an array containing File objects
|
|
1512
1512
|
if (
|
|
1513
1513
|
value instanceof File ||
|
|
1514
1514
|
(Array.isArray(value) &&
|
|
1515
|
-
value.
|
|
1515
|
+
value.some(
|
|
1516
1516
|
(file) => file instanceof File
|
|
1517
1517
|
))
|
|
1518
1518
|
) {
|
|
@@ -1530,9 +1530,34 @@ function Form({
|
|
|
1530
1530
|
});
|
|
1531
1531
|
}
|
|
1532
1532
|
|
|
1533
|
+
// Separate existing file objects from new File instances for the file field
|
|
1534
|
+
// and pass existing files to the backend so it knows which to keep
|
|
1535
|
+
if (fileKey && Array.isArray(formData[fileKey])) {
|
|
1536
|
+
const existingFiles = formData[fileKey].filter(
|
|
1537
|
+
(file) => !(file instanceof File)
|
|
1538
|
+
);
|
|
1539
|
+
if (existingFiles.length > 0) {
|
|
1540
|
+
updatedFormData['existingFiles'] = existingFiles;
|
|
1541
|
+
}
|
|
1542
|
+
} else if (fileKey === null && formData) {
|
|
1543
|
+
// No new files, but check if there are existing file objects to preserve
|
|
1544
|
+
const fileFields = formSettings?.fields?.filter(f => f.type === 'file') || [];
|
|
1545
|
+
fileFields.forEach((field) => {
|
|
1546
|
+
const val = formData[field.id];
|
|
1547
|
+
if (Array.isArray(val) && val.length > 0 && val.every(f => !(f instanceof File))) {
|
|
1548
|
+
updatedFormData['existingFiles'] = val;
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1533
1553
|
if (fileUpload && formData[fileKey]) {
|
|
1534
1554
|
if (Array.isArray(formData[fileKey])) {
|
|
1535
|
-
|
|
1555
|
+
// Filter to only upload new File instances
|
|
1556
|
+
const newFiles = formData[fileKey].filter(
|
|
1557
|
+
(file) => file instanceof File
|
|
1558
|
+
);
|
|
1559
|
+
|
|
1560
|
+
const uploadPromises = newFiles.map(
|
|
1536
1561
|
async (file) => {
|
|
1537
1562
|
// Optimize image if it's an image file
|
|
1538
1563
|
const optimizedFile =
|
|
@@ -1709,29 +1734,56 @@ function Form({
|
|
|
1709
1734
|
return acc;
|
|
1710
1735
|
}, {});
|
|
1711
1736
|
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1737
|
+
// In bulk edit mode, call saveAnother for each row in the group
|
|
1738
|
+
if (bulkEditMode && bulkEditGroupData?.groupRowIds?.length) {
|
|
1739
|
+
let hasError = false;
|
|
1740
|
+
for (const rowId of bulkEditGroupData.groupRowIds) {
|
|
1741
|
+
const saveAnotherUrl = `${saveAnother.url}/${rowId}`;
|
|
1742
|
+
const resSaveAnother =
|
|
1743
|
+
await CustomFetch(
|
|
1744
|
+
saveAnotherUrl,
|
|
1745
|
+
saveAnother.method,
|
|
1746
|
+
processedData
|
|
1747
|
+
);
|
|
1748
|
+
if (resSaveAnother.data.error !== '') {
|
|
1749
|
+
hasError = true;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
if (!hasError) {
|
|
1753
|
+
toast.success(saveAnother.message);
|
|
1754
|
+
} else {
|
|
1755
|
+
saveAnotherFailed = true;
|
|
1756
|
+
}
|
|
1724
1757
|
if (fetchTable) {
|
|
1725
1758
|
const createdItem =
|
|
1726
1759
|
res.data.data || res.data;
|
|
1727
1760
|
fetchTable(createdItem);
|
|
1728
1761
|
}
|
|
1729
1762
|
} else {
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1763
|
+
const saveAnotherUrl = `${
|
|
1764
|
+
saveAnother.url
|
|
1765
|
+
}/${formData[saveAnother.dataKey]}`;
|
|
1766
|
+
const resSaveAnother =
|
|
1767
|
+
await CustomFetch(
|
|
1768
|
+
saveAnotherUrl,
|
|
1769
|
+
saveAnother.method,
|
|
1770
|
+
processedData
|
|
1771
|
+
);
|
|
1772
|
+
|
|
1773
|
+
if (resSaveAnother.data.error === '') {
|
|
1774
|
+
toast.success(saveAnother.message);
|
|
1775
|
+
if (fetchTable) {
|
|
1776
|
+
const createdItem =
|
|
1777
|
+
res.data.data || res.data;
|
|
1778
|
+
fetchTable(createdItem);
|
|
1779
|
+
}
|
|
1780
|
+
} else {
|
|
1781
|
+
saveAnotherFailed = true;
|
|
1782
|
+
if (fetchTable) {
|
|
1783
|
+
const createdItem =
|
|
1784
|
+
res.data.data || res.data;
|
|
1785
|
+
fetchTable(createdItem);
|
|
1786
|
+
}
|
|
1735
1787
|
}
|
|
1736
1788
|
}
|
|
1737
1789
|
} else {
|
|
@@ -2179,6 +2231,24 @@ function Form({
|
|
|
2179
2231
|
|
|
2180
2232
|
useEffect(() => {
|
|
2181
2233
|
formSettings.fields.forEach((field) => {
|
|
2234
|
+
// showIfEmpty: only show field when its own value is empty/null/undefined/[]
|
|
2235
|
+
if (field.showIfEmpty) {
|
|
2236
|
+
const val = formData[field.id];
|
|
2237
|
+
const isEmpty =
|
|
2238
|
+
val === undefined ||
|
|
2239
|
+
val === null ||
|
|
2240
|
+
val === '' ||
|
|
2241
|
+
(Array.isArray(val) && val.length === 0);
|
|
2242
|
+
field.hide = !isEmpty;
|
|
2243
|
+
|
|
2244
|
+
if (updateForm) {
|
|
2245
|
+
updateForm((prevState) => ({
|
|
2246
|
+
...prevState,
|
|
2247
|
+
fields: [...formSettings.fields],
|
|
2248
|
+
}));
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2182
2252
|
const showConditions = field.show || [];
|
|
2183
2253
|
|
|
2184
2254
|
showConditions.forEach((showObject) => {
|