@visns-studio/visns-components 5.12.4 → 5.12.5

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
@@ -87,7 +87,7 @@
87
87
  "react-dom": "^17.0.0 || ^18.0.0"
88
88
  },
89
89
  "name": "@visns-studio/visns-components",
90
- "version": "5.12.4",
90
+ "version": "5.12.5",
91
91
  "description": "Various packages to assist in the development of our Custom Applications.",
92
92
  "main": "src/index.js",
93
93
  "files": [
@@ -25,14 +25,7 @@ const StagePopupModal = ({
25
25
 
26
26
  // Re-render form fields when fieldOptions change
27
27
  useEffect(() => {
28
- console.log('[StagePopupModal] useEffect triggered:', {
29
- show,
30
- loading,
31
- fieldOptionsKeys: Object.keys(fieldOptions),
32
- fieldOptions
33
- });
34
28
  if (show && !loading && Object.keys(fieldOptions).length > 0) {
35
- console.log('[StagePopupModal] Re-rendering form fields after fieldOptions update');
36
29
  renderFormFields();
37
30
  }
38
31
  }, [fieldOptions, loading, formData, validationErrors, show]);
@@ -64,14 +57,11 @@ const StagePopupModal = ({
64
57
  });
65
58
 
66
59
  const response = await CustomFetch(url, 'POST');
67
- console.log(`[StagePopupModal] Response for ${field.id}:`, response);
68
- console.log(`[StagePopupModal] Response.data:`, response.data);
69
60
 
70
61
  if (response.data && !response.data.error) {
71
62
  // Handle both nested (response.data.data) and direct (response.data) array formats
72
63
  const optionsData = Array.isArray(response.data.data) ? response.data.data :
73
64
  Array.isArray(response.data) ? response.data : [];
74
- console.log(`[StagePopupModal] Processed options for ${field.id}:`, optionsData);
75
65
  options[field.id] = optionsData;
76
66
  }
77
67
  } catch (error) {
@@ -81,9 +71,6 @@ const StagePopupModal = ({
81
71
  }
82
72
  }
83
73
 
84
- console.log(`[StagePopupModal] Final options object:`, options);
85
- console.log(`[StagePopupModal] Setting fieldOptions state:`, options);
86
-
87
74
  setFormData(initialData);
88
75
  setFieldOptions(options);
89
76
  setLoading(false);
@@ -106,15 +93,24 @@ const StagePopupModal = ({
106
93
 
107
94
  const validateForm = () => {
108
95
  const errors = {};
96
+ const fieldsContainer = document.getElementById('stage-popup-fields');
109
97
 
110
98
  popupConfig.fields?.forEach(field => {
111
- if (field.required && (!formData[field.id] || formData[field.id] === '')) {
99
+ let value = formData[field.id];
100
+
101
+ // Get current value from DOM if available
102
+ if (fieldsContainer) {
103
+ const input = fieldsContainer.querySelector(`[data-field-id="${field.id}"]`);
104
+ if (input) {
105
+ value = input.value;
106
+ }
107
+ }
108
+
109
+ if (field.required && (!value || value === '')) {
112
110
  errors[field.id] = `${field.label} is required`;
113
111
  }
114
112
 
115
113
  if (field.validation) {
116
- const value = formData[field.id];
117
-
118
114
  if (field.validation.minLength && value && value.length < field.validation.minLength) {
119
115
  errors[field.id] = `${field.label} must be at least ${field.validation.minLength} characters`;
120
116
  }
@@ -135,13 +131,24 @@ const StagePopupModal = ({
135
131
  }
136
132
 
137
133
  const dataToSend = {};
134
+ const fieldsContainer = document.getElementById('stage-popup-fields');
138
135
 
139
136
  // Only include fields specified in saveFields, or all fields if not specified
140
137
  const fieldsToSave = popupConfig.saveFields || popupConfig.fields?.map(f => f.id) || [];
141
138
 
142
139
  fieldsToSave.forEach(fieldId => {
143
- if (formData[fieldId] !== undefined) {
144
- dataToSend[fieldId] = formData[fieldId];
140
+ let value = formData[fieldId];
141
+
142
+ // Get current value from DOM if available
143
+ if (fieldsContainer) {
144
+ const input = fieldsContainer.querySelector(`[data-field-id="${fieldId}"]`);
145
+ if (input) {
146
+ value = input.value;
147
+ }
148
+ }
149
+
150
+ if (value !== undefined && value !== '') {
151
+ dataToSend[fieldId] = value;
145
152
  }
146
153
  });
147
154
 
@@ -168,14 +175,11 @@ const StagePopupModal = ({
168
175
  disabled={loading}
169
176
  >
170
177
  <option value="">-- Select {field.label} --</option>
171
- {(() => {
172
- console.log(`[StagePopupModal] Rendering JSX options for ${field.id}:`, fieldOptions[field.id]);
173
- return (fieldOptions[field.id] || []).map(option => (
174
- <option key={option.id || option.value} value={option.id || option.value}>
175
- {option.label || option.name || option.text}
176
- </option>
177
- ));
178
- })()}
178
+ {(fieldOptions[field.id] || []).map(option => (
179
+ <option key={option.id || option.value} value={option.id || option.value}>
180
+ {option.label || option.name || option.text}
181
+ </option>
182
+ ))}
179
183
  </select>
180
184
  {hasError && <span className={styles.errorText}>{validationErrors[field.id]}</span>}
181
185
  </div>
@@ -303,13 +307,12 @@ const StagePopupModal = ({
303
307
  onCancel();
304
308
  }
305
309
  });
306
- } else if (popupConfig.type === 'form') {
307
- // Custom form dialog
310
+ } else if (popupConfig.type === 'form' && !loading) {
311
+ // Custom form dialog - only show when not loading
308
312
  const formHTML = `
309
313
  <div class="${styles.stagePopupForm}">
310
314
  ${popupConfig.message ? `<p class="${styles.message}">${popupConfig.message}</p>` : ''}
311
315
  <div id="stage-popup-fields" class="${styles.fields}">
312
- ${loading ? '<div class="' + styles.loading + '">Loading...</div>' : ''}
313
316
  </div>
314
317
  </div>
315
318
  `;
@@ -330,6 +333,9 @@ const StagePopupModal = ({
330
333
  renderFormFields();
331
334
  },
332
335
  preConfirm: () => {
336
+ // Update form data from DOM before validation
337
+ updateFormDataFromDOM();
338
+
333
339
  if (!validateForm()) {
334
340
  Swal.showValidationMessage('Please correct the errors below');
335
341
  return false;
@@ -347,28 +353,36 @@ const StagePopupModal = ({
347
353
  }
348
354
  }, [show, popupConfig, loading, formData, fieldOptions]);
349
355
 
356
+ const updateFormDataFromDOM = () => {
357
+ const fieldsContainer = document.getElementById('stage-popup-fields');
358
+ if (!fieldsContainer) return;
359
+
360
+ const newFormData = { ...formData };
361
+
362
+ popupConfig.fields?.forEach(field => {
363
+ const input = fieldsContainer.querySelector(`[data-field-id="${field.id}"]`);
364
+ if (input) {
365
+ newFormData[field.id] = input.value;
366
+ }
367
+ });
368
+
369
+ setFormData(newFormData);
370
+ };
371
+
350
372
  const renderFormFields = () => {
351
- console.log('[StagePopupModal] renderFormFields called');
352
373
  const fieldsContainer = document.getElementById('stage-popup-fields');
353
- console.log('[StagePopupModal] fieldsContainer:', fieldsContainer);
354
- console.log('[StagePopupModal] loading:', loading);
355
374
 
356
375
  if (!fieldsContainer || loading) {
357
- console.log('[StagePopupModal] Early return - no container or loading');
358
376
  return;
359
377
  }
360
378
 
361
- console.log('[StagePopupModal] Clearing container and rendering fields');
362
379
  fieldsContainer.innerHTML = '';
363
380
 
364
- console.log('[StagePopupModal] popupConfig.fields:', popupConfig.fields);
365
381
  popupConfig.fields?.forEach(field => {
366
- console.log(`[StagePopupModal] Processing field: ${field.id}, type: ${field.type}`);
367
382
  const fieldElement = document.createElement('div');
368
383
  fieldElement.className = styles.fieldWrapper;
369
384
 
370
385
  const fieldHTML = renderFieldHTML(field);
371
- console.log(`[StagePopupModal] Generated HTML for ${field.id}:`, fieldHTML);
372
386
  fieldElement.innerHTML = fieldHTML;
373
387
 
374
388
  fieldsContainer.appendChild(fieldElement);
@@ -379,6 +393,9 @@ const StagePopupModal = ({
379
393
  input.addEventListener('change', (e) => {
380
394
  handleFieldChange(field.id, e.target.value);
381
395
  });
396
+ input.addEventListener('input', (e) => {
397
+ handleFieldChange(field.id, e.target.value);
398
+ });
382
399
  }
383
400
  });
384
401
  };
@@ -390,7 +407,6 @@ const StagePopupModal = ({
390
407
 
391
408
  switch (field.type) {
392
409
  case 'select':
393
- console.log(`[StagePopupModal] Rendering HTML options for ${field.id}:`, fieldOptions[field.id]);
394
410
  const options = (fieldOptions[field.id] || []).map(option =>
395
411
  `<option value="${option.id || option.value}" ${value === (option.id || option.value) ? 'selected' : ''}>
396
412
  ${option.label || option.name || option.text}
@@ -399,7 +415,7 @@ const StagePopupModal = ({
399
415
 
400
416
  return `
401
417
  <label class="${styles.label}">${field.label}${requiredStar}</label>
402
- <select class="${styles.select}" data-field-id="${field.id}">
418
+ <select class="${styles.select}" data-field-id="${field.id}" ${loading ? 'disabled' : ''}>
403
419
  <option value="">-- Select ${field.label} --</option>
404
420
  ${options}
405
421
  </select>