@visns-studio/visns-components 4.10.46 → 4.10.47

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 CHANGED
@@ -77,7 +77,7 @@
77
77
  "react-dom": "^17.0.0 || ^18.0.0"
78
78
  },
79
79
  "name": "@visns-studio/visns-components",
80
- "version": "4.10.46",
80
+ "version": "4.10.47",
81
81
  "description": "Various packages to assist in the development of our Custom Applications.",
82
82
  "main": "src/index.js",
83
83
  "files": [
@@ -710,87 +710,55 @@ function Form({
710
710
  });
711
711
  }
712
712
 
713
- if (Array.isArray(formData[fileKey])) {
714
- if (fileUpload && formData[fileKey]) {
715
- const uploadPromises = formData[fileKey].map(
716
- async (file) => {
717
- const toastId = toast.info(
718
- `Uploading ${file.name}`,
719
- {
720
- progress: 0,
721
- autoClose: false,
722
- }
723
- );
724
-
725
- const fileRes = await Vapor.store(file, {
726
- progress: (progress) => {
727
- setUploadProgress(progress * 100);
728
- toast.update(toastId, {
729
- progress,
730
- });
731
- },
732
- });
733
-
734
- toast.update(toastId, {
735
- render: `${file.name} uploaded successfully!`,
736
- type: 'success',
737
- autoClose: 3000,
738
- });
713
+ const files = Array.isArray(formData[fileKey])
714
+ ? formData[fileKey]
715
+ : [formData[fileKey]];
739
716
 
740
- return {
741
- uuid: fileRes.uuid,
742
- key: fileRes.key,
743
- bucket: fileRes.bucket,
744
- filename: file.name,
745
- filesize: file.size,
746
- extension: fileRes.extension,
747
- file_relationship: fileKey,
748
- fileable_field:
749
- fileFieldSetting.fileable_field,
750
- };
751
- }
752
- );
753
-
754
- formData['uploadedFiles'] = await Promise.all(
755
- uploadPromises
756
- );
757
- } else {
717
+ if (fileUpload && files.length > 0) {
718
+ const uploadPromises = files.map(async (file) => {
758
719
  const toastId = toast.info(
759
- `Uploading ${formData[fileKey].name}`,
720
+ `Uploading ${file.name}`,
760
721
  {
761
722
  progress: 0,
762
723
  autoClose: false,
763
724
  }
764
725
  );
765
726
 
766
- const fileRes = await Vapor.store(
767
- formData[fileKey],
768
- {
769
- progress: (progress) => {
770
- setUploadProgress(progress * 100);
771
- toast.update(toastId, {
772
- progress,
773
- });
774
- },
775
- }
776
- );
727
+ const fileRes = await Vapor.store(file, {
728
+ progress: (progress) => {
729
+ setUploadProgress(progress * 100);
730
+ toast.update(toastId, { progress });
731
+ },
732
+ });
777
733
 
778
734
  toast.update(toastId, {
779
- render: `${formData[fileKey].name} uploaded successfully!`,
735
+ render: `${file.name} uploaded successfully!`,
780
736
  type: 'success',
781
737
  autoClose: 3000,
782
738
  });
783
739
 
784
- formData['uuid'] = fileRes.uuid;
785
- formData['key'] = fileRes.key;
786
- formData['bucket'] = fileRes.bucket;
787
- formData['filename'] = formData[fileKey].name;
788
- formData['filesize'] = formData[fileKey].size;
789
- formData['extension'] = fileRes.extension;
790
- formData['file_relationship'] = fileKey;
791
- formData['fileable_field'] =
792
- fileFieldSetting.fileable_field;
793
- }
740
+ return {
741
+ uuid: fileRes.uuid,
742
+ key: fileRes.key,
743
+ bucket: fileRes.bucket,
744
+ filename: file.name,
745
+ filesize: file.size,
746
+ extension: fileRes.extension,
747
+ file_relationship: fileKey,
748
+ fileable_field:
749
+ fileFieldSetting.fileable_field ||
750
+ fileFieldSetting.id,
751
+ };
752
+ });
753
+
754
+ // Wait for all uploads to complete
755
+ const uploadedFiles = await Promise.all(uploadPromises);
756
+
757
+ // If there are multiple files, store them as an array, otherwise as a single object
758
+ formData['uploadedFiles'] =
759
+ uploadedFiles.length > 1
760
+ ? uploadedFiles
761
+ : uploadedFiles[0];
794
762
  }
795
763
 
796
764
  // Transform keys with dots into nested objects
@@ -805,8 +773,6 @@ function Form({
805
773
  return acc;
806
774
  }, {});
807
775
 
808
- console.info('Payload:', payload);
809
-
810
776
  const res = await CustomFetch(url, method, payload);
811
777
 
812
778
  if (res.data.error === '') {