@visns-studio/visns-components 5.2.16 → 5.3.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
@@ -78,7 +78,7 @@
78
78
  "react-dom": "^17.0.0 || ^18.0.0"
79
79
  },
80
80
  "name": "@visns-studio/visns-components",
81
- "version": "5.2.16",
81
+ "version": "5.3.0",
82
82
  "description": "Various packages to assist in the development of our Custom Applications.",
83
83
  "main": "src/index.js",
84
84
  "files": [
@@ -51,6 +51,7 @@ function Field({
51
51
  inputClass,
52
52
  mapbox,
53
53
  onChange,
54
+ onChangeCanvas,
54
55
  onChangeCheckbox,
55
56
  onChangeCheckboxManual,
56
57
  onChangeColour,
@@ -199,6 +200,13 @@ function Field({
199
200
  setFormItemClass(`${styles.formItem} ${styles.halfItem}`);
200
201
  break;
201
202
  }
203
+
204
+ if (settings.type === 'canvas') {
205
+ const canvasType = SketchConfig.canvasTypes.find(
206
+ (a) => a.id === settings.canvasType
207
+ );
208
+ setCanvasUrl(canvasType.url);
209
+ }
202
210
  }, [settings, counter]);
203
211
 
204
212
  const fetchChildDropdownData = (s, v) => {
@@ -316,6 +324,7 @@ function Field({
316
324
  [
317
325
  'address',
318
326
  'async-dropdown-ajax',
327
+ 'canvas',
319
328
  'checkbox',
320
329
  'colour',
321
330
  'copytoclipboard',
@@ -432,6 +441,19 @@ function Field({
432
441
  />
433
442
  </div>
434
443
  );
444
+ case 'canvas':
445
+ return canvasUrl ? (
446
+ <div
447
+ onClick={() => setCanvasPopupOpen(true)}
448
+ style={{ cursor: 'pointer' }}
449
+ >
450
+ <img
451
+ src={settings.imageData || canvasUrl}
452
+ width="200"
453
+ alt="Canvas Preview"
454
+ />
455
+ </div>
456
+ ) : null;
435
457
  case 'checkbox':
436
458
  return (
437
459
  <div
@@ -1666,6 +1688,7 @@ function Field({
1666
1688
  ![
1667
1689
  'address',
1668
1690
  'async-dropdown-ajax',
1691
+ 'canvas',
1669
1692
  'checkbox',
1670
1693
  'colour',
1671
1694
  'copytoclipboard',
@@ -151,6 +151,8 @@ function Form({
151
151
  }
152
152
  };
153
153
 
154
+ const handleChangeCanvas = (id, value) => {};
155
+
154
156
  const handleChangeCheckbox = (e) => {
155
157
  const { checked, name, value } = e.target;
156
158
 
@@ -1291,6 +1293,7 @@ function Form({
1291
1293
  }
1292
1294
  mapbox={mapbox}
1293
1295
  onChange={handleChange}
1296
+ onChangeCanvas={handleChangeCanvas}
1294
1297
  onChangeCheckbox={handleChangeCheckbox}
1295
1298
  onChangeCheckboxManual={
1296
1299
  handleChangeCheckboxManual
@@ -1442,6 +1445,7 @@ function Form({
1442
1445
  }
1443
1446
  mapbox={mapbox}
1444
1447
  onChange={handleChange}
1448
+ onChangeCanvas={handleChangeCanvas}
1445
1449
  onChangeCheckbox={
1446
1450
  handleChangeCheckbox
1447
1451
  }
@@ -31,6 +31,8 @@ const updateField = (fields, name, value) => {
31
31
 
32
32
  const renderValue = (field, data) => {
33
33
  switch (field.type) {
34
+ case 'canvas':
35
+ return field.value || '';
34
36
  case 'datetime':
35
37
  case 'date':
36
38
  return field.value && moment(field.value).isValid()
@@ -103,6 +105,7 @@ const GenericDynamic = ({
103
105
  }) => {
104
106
  const [activeForm, setActiveForm] = useState({});
105
107
  const [activeFormKey, setActiveFormKey] = useState(0);
108
+ const [canvasSaveCounter, setCanvasSaveCounter] = useState(0);
106
109
 
107
110
  const handleChange = (e) => {
108
111
  const {
@@ -174,6 +177,35 @@ const GenericDynamic = ({
174
177
  }
175
178
  };
176
179
 
180
+ const handleChangeCanvas = (fieldSetting, value, imageData) => {
181
+ // Check if activeForm has keys
182
+ if (activeForm && typeof activeForm === 'object') {
183
+ // Iterate over the keys in activeForm to find the matching id
184
+ for (const key in activeForm) {
185
+ if (activeForm[key].id === fieldSetting.id) {
186
+ // If a matching id is found, update the corresponding field
187
+ setActiveForm((prevState) => ({
188
+ ...prevState,
189
+ [key]: {
190
+ ...prevState[key],
191
+ value, // Update the value for the matching id
192
+ imageData,
193
+ },
194
+ }));
195
+
196
+ setCanvasSaveCounter((prevState) => prevState + 1);
197
+ return; // Exit after updating to prevent further iterations
198
+ }
199
+ }
200
+ }
201
+ };
202
+
203
+ useEffect(() => {
204
+ if (canvasSaveCounter > 0) {
205
+ handleSaveForm(false);
206
+ }
207
+ }, [canvasSaveCounter]);
208
+
177
209
  const handleChangeCheckbox = (e) => {
178
210
  const { checked, name, value } = e.target;
179
211
 
@@ -473,7 +505,47 @@ const GenericDynamic = ({
473
505
  }
474
506
  };
475
507
 
476
- const handleDownloadForm = async (item, label, data) => {
508
+ const handleDownloadForm = async (item, label, data, debug = false) => {
509
+ if (debug) {
510
+ // Open the form in a new tab by sending a POST request
511
+ const form = document.createElement('form');
512
+ form.method = 'POST';
513
+ form.action = setting.download;
514
+ form.target = '_blank'; // Open in new tab
515
+
516
+ // Append CSRF token if needed (for Laravel)
517
+ const csrfToken = document
518
+ .querySelector('meta[name="csrf-token"]')
519
+ ?.getAttribute('content');
520
+ if (csrfToken) {
521
+ const csrfInput = document.createElement('input');
522
+ csrfInput.type = 'hidden';
523
+ csrfInput.name = '_token';
524
+ csrfInput.value = csrfToken;
525
+ form.appendChild(csrfInput);
526
+ }
527
+
528
+ // Append the required data
529
+ const appendHiddenField = (name, value) => {
530
+ const input = document.createElement('input');
531
+ input.type = 'hidden';
532
+ input.name = name;
533
+ input.value = JSON.stringify(value);
534
+ form.appendChild(input);
535
+ };
536
+
537
+ appendHiddenField('data', item);
538
+ appendHiddenField('dynamicData', data);
539
+ appendHiddenField('label', label);
540
+ appendHiddenField('debug', true);
541
+
542
+ document.body.appendChild(form);
543
+ form.submit();
544
+ document.body.removeChild(form);
545
+
546
+ return;
547
+ }
548
+
477
549
  const toastId = toast.loading('Downloading form...');
478
550
 
479
551
  try {
@@ -665,8 +737,6 @@ const GenericDynamic = ({
665
737
  }
666
738
  }
667
739
  }
668
-
669
- console.info(activeForm);
670
740
  }, [activeForm]);
671
741
 
672
742
  const shouldDisplayFormList = (data, type) => {
@@ -725,6 +795,9 @@ const GenericDynamic = ({
725
795
  onChange={
726
796
  handleChange
727
797
  }
798
+ onChangeCanvas={
799
+ handleChangeCanvas
800
+ }
728
801
  onChangeCheckbox={
729
802
  handleChangeCheckbox
730
803
  }
@@ -773,6 +846,9 @@ const GenericDynamic = ({
773
846
  originalData
774
847
  )}
775
848
  onChange={handleChange}
849
+ onChangeCanvas={
850
+ handleChangeCanvas
851
+ }
776
852
  onChangeCheckbox={
777
853
  handleChangeCheckbox
778
854
  }
@@ -879,7 +955,8 @@ const GenericDynamic = ({
879
955
  handleDownloadForm(
880
956
  item,
881
957
  label,
882
- originalData
958
+ originalData,
959
+ true
883
960
  )
884
961
  }
885
962
  >