@visns-studio/visns-components 4.8.14 → 4.9.0

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
@@ -75,7 +75,7 @@
75
75
  "react-dom": "^17.0.0 || ^18.0.0"
76
76
  },
77
77
  "name": "@visns-studio/visns-components",
78
- "version": "4.8.14",
78
+ "version": "4.9.0",
79
79
  "description": "Various packages to assist in the development of our Custom Applications.",
80
80
  "main": "src/index.js",
81
81
  "files": [
@@ -854,7 +854,7 @@ function Form({
854
854
 
855
855
  if (data[item] === undefined) {
856
856
  if (field && field.hasOwnProperty('relation')) {
857
- let tempRes = data[field.relation];
857
+ let tempRes = data[field.relation] || null;
858
858
 
859
859
  if (
860
860
  [
@@ -877,8 +877,8 @@ function Form({
877
877
  ? field.relation_from
878
878
  : field.id;
879
879
  tempRes = Array.isArray(tempRes)
880
- ? tempRes[0][relationFrom]
881
- : tempRes[relationFrom];
880
+ ? tempRes[0]?.[relationFrom] || ''
881
+ : tempRes?.[relationFrom] || '';
882
882
  } else {
883
883
  tempRes = '';
884
884
  }
@@ -902,7 +902,10 @@ function Form({
902
902
  ? field.relation.length
903
903
  : 1;
904
904
  for (let i = 0; i < relationLength; i++) {
905
- tempObj = tempObj[field.relation[i]];
905
+ tempObj = tempObj?.[field.relation[i]] || null;
906
+
907
+ // If tempObj becomes null, break out of the loop
908
+ if (!tempObj) break;
906
909
  }
907
910
 
908
911
  if (tempObj !== undefined && tempObj !== null) {
@@ -937,7 +940,10 @@ function Form({
937
940
  ? field.relation.length
938
941
  : 1;
939
942
  for (let i = 0; i < relationLength; i++) {
940
- tempObj = tempObj[field.relation[i]];
943
+ tempObj = tempObj?.[field.relation[i]] || null;
944
+
945
+ // If tempObj becomes null, break out of the loop
946
+ if (!tempObj) break;
941
947
  }
942
948
 
943
949
  if (tempObj !== undefined && tempObj !== null) {
@@ -961,7 +967,8 @@ function Form({
961
967
  let tempObj = data;
962
968
  let tempRes = '';
963
969
 
964
- tempRes = tempObj[field.parent][field.id];
970
+ // Safe check for tempObj and field.parent
971
+ tempRes = tempObj?.[field.parent]?.[field.id] || '';
965
972
 
966
973
  updatedFormData[field.parent][field.id] = tempRes;
967
974
  }
@@ -972,7 +979,10 @@ function Form({
972
979
  let value = data;
973
980
 
974
981
  for (let key of keys) {
975
- value = value[key];
982
+ value = value?.[key] || null;
983
+
984
+ // If value becomes null, break out of the loop
985
+ if (!value) break;
976
986
  }
977
987
 
978
988
  updatedFormData[item] = value;
@@ -1012,13 +1022,13 @@ function Form({
1012
1022
  let relationFound = false;
1013
1023
 
1014
1024
  for (let i = 0; i < relationLength; i++) {
1015
- if (tempObj[field.relation[i]]) {
1025
+ if (tempObj?.[field.relation[i]]) {
1016
1026
  relationFound = true;
1017
1027
  tempObj = tempObj[field.relation[i]];
1018
1028
  }
1019
1029
  }
1020
1030
 
1021
- if (relationFound === false) {
1031
+ if (!relationFound) {
1022
1032
  tempObj = {};
1023
1033
  }
1024
1034
 
@@ -1063,6 +1073,7 @@ function Form({
1063
1073
 
1064
1074
  setFetchTrigger(!fetchTrigger);
1065
1075
  } catch (error) {
1076
+ console.info(error);
1066
1077
  toast.error('Failed to fetch data:', error);
1067
1078
  }
1068
1079
  } else {
@@ -5,6 +5,7 @@ import { Outlet } from 'react-router-dom';
5
5
  import { toast } from 'react-toastify';
6
6
  import { saveAs } from 'file-saver';
7
7
  import _ from 'lodash';
8
+ import moment from 'moment';
8
9
 
9
10
  import CustomFetch from '../Fetch';
10
11
  import Download from '../Download';