@visns-studio/visns-components 3.6.6 → 3.6.8
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.
|
@@ -74,6 +74,7 @@ const GenericDynamic = ({
|
|
|
74
74
|
primaryKey,
|
|
75
75
|
setData,
|
|
76
76
|
setting,
|
|
77
|
+
templateStatus = true,
|
|
77
78
|
type,
|
|
78
79
|
}) => {
|
|
79
80
|
const toastId = useRef(null);
|
|
@@ -266,13 +267,14 @@ const GenericDynamic = ({
|
|
|
266
267
|
}
|
|
267
268
|
};
|
|
268
269
|
|
|
269
|
-
const handleDownloadForm = async (item,
|
|
270
|
+
const handleDownloadForm = async (item, label, data) => {
|
|
270
271
|
// Show loading toast and keep its ID
|
|
271
272
|
const toastId = toast.loading('Downloading form...');
|
|
272
273
|
|
|
273
274
|
try {
|
|
274
275
|
const res = await Download(setting.download, 'POST', {
|
|
275
276
|
data: item,
|
|
277
|
+
dynamicData: data,
|
|
276
278
|
label: label,
|
|
277
279
|
});
|
|
278
280
|
|
|
@@ -359,6 +361,7 @@ const GenericDynamic = ({
|
|
|
359
361
|
Object.entries(activeForm).forEach(([key, field]) => {
|
|
360
362
|
if (
|
|
361
363
|
field.required === true &&
|
|
364
|
+
field.type !== 'dynamicdata' &&
|
|
362
365
|
(field.value === null || field.value === '')
|
|
363
366
|
) {
|
|
364
367
|
error += `<p>${field.label} is required</p>`;
|
|
@@ -366,7 +369,6 @@ const GenericDynamic = ({
|
|
|
366
369
|
});
|
|
367
370
|
|
|
368
371
|
if (error === '') {
|
|
369
|
-
console.info(setting);
|
|
370
372
|
const res = await CustomFetch(setting.save, 'POST', {
|
|
371
373
|
[primaryKey]: data.id,
|
|
372
374
|
form_data: {
|
|
@@ -391,28 +393,30 @@ const GenericDynamic = ({
|
|
|
391
393
|
useEffect(() => {
|
|
392
394
|
if (data[type] && data[type].length > 0) {
|
|
393
395
|
if (multiple) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
396
|
+
if (templateStatus) {
|
|
397
|
+
// Retrieve the last form of the specified type
|
|
398
|
+
let lastForm = data[type][data[type].length - 1];
|
|
399
|
+
|
|
400
|
+
if (lastForm && typeof lastForm === 'object') {
|
|
401
|
+
Object.entries(lastForm).forEach(([key, field]) => {
|
|
402
|
+
if (field && field.required) {
|
|
403
|
+
if (
|
|
404
|
+
field.required === 'yes' ||
|
|
405
|
+
field.required === 'no'
|
|
406
|
+
) {
|
|
407
|
+
lastForm[key].required =
|
|
408
|
+
field.required === 'yes';
|
|
409
|
+
}
|
|
406
410
|
}
|
|
407
|
-
}
|
|
408
|
-
});
|
|
411
|
+
});
|
|
409
412
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
+
// Update the active form with the modified lastForm
|
|
414
|
+
setActiveForm(lastForm);
|
|
415
|
+
setActiveFormKey(data[type].length - 1);
|
|
416
|
+
}
|
|
413
417
|
}
|
|
414
418
|
} else {
|
|
415
|
-
if (activeForm.length === 0) {
|
|
419
|
+
if (activeForm.length === 0 && templateStatus) {
|
|
416
420
|
setActiveForm(data[type]);
|
|
417
421
|
setActiveFormKey(0);
|
|
418
422
|
}
|
|
@@ -423,10 +427,6 @@ const GenericDynamic = ({
|
|
|
423
427
|
}
|
|
424
428
|
}, [data, type]);
|
|
425
429
|
|
|
426
|
-
useEffect(() => {
|
|
427
|
-
console.info(activeForm);
|
|
428
|
-
}, [activeForm]);
|
|
429
|
-
|
|
430
430
|
return (
|
|
431
431
|
<>
|
|
432
432
|
<div className="formSplit">
|
|
@@ -442,6 +442,7 @@ const GenericDynamic = ({
|
|
|
442
442
|
<thead>
|
|
443
443
|
<tr className="grid-headers">
|
|
444
444
|
<th>ID</th>
|
|
445
|
+
<th>Form</th>
|
|
445
446
|
<th>Created By</th>
|
|
446
447
|
<th>Created At</th>
|
|
447
448
|
<th>Updated By</th>
|
|
@@ -468,7 +469,8 @@ const GenericDynamic = ({
|
|
|
468
469
|
);
|
|
469
470
|
}}
|
|
470
471
|
>
|
|
471
|
-
<td>
|
|
472
|
+
<td>{item.id}</td>
|
|
473
|
+
<td>{item.form_label}</td>
|
|
472
474
|
<td>{item.created_by}</td>
|
|
473
475
|
<td>
|
|
474
476
|
{item.created_at
|
|
@@ -498,7 +500,8 @@ const GenericDynamic = ({
|
|
|
498
500
|
onClick={() =>
|
|
499
501
|
handleDownloadForm(
|
|
500
502
|
item,
|
|
501
|
-
|
|
503
|
+
label,
|
|
504
|
+
data
|
|
502
505
|
)
|
|
503
506
|
}
|
|
504
507
|
>
|
|
@@ -646,7 +649,7 @@ const GenericDynamic = ({
|
|
|
646
649
|
)}
|
|
647
650
|
</div>
|
|
648
651
|
<div className="polActions">
|
|
649
|
-
{multiple && (
|
|
652
|
+
{multiple && templateStatus && (
|
|
650
653
|
<button className="btn" onClick={handleAddNewForm}>
|
|
651
654
|
Add New Form
|
|
652
655
|
</button>
|
package/package.json
CHANGED