@visns-studio/visns-components 5.3.12 → 5.3.13
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.3.
|
|
81
|
+
"version": "5.3.13",
|
|
82
82
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
83
83
|
"main": "src/index.js",
|
|
84
84
|
"files": [
|
|
@@ -72,6 +72,7 @@ function Field({
|
|
|
72
72
|
}) {
|
|
73
73
|
const editorRef = useRef(null);
|
|
74
74
|
const fileImageInputRef = useRef(null);
|
|
75
|
+
const [autoValue, setAutoValue] = useState('');
|
|
75
76
|
const [colorPickerShow, setColorPickerShow] = useState(false);
|
|
76
77
|
const [counter, setCounter] = useState(0);
|
|
77
78
|
const [dataOptions, setDataOptions] = useState([]);
|
|
@@ -117,6 +118,31 @@ function Field({
|
|
|
117
118
|
marginTop: '6px',
|
|
118
119
|
};
|
|
119
120
|
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const fetchAutoValue = async () => {
|
|
123
|
+
if (settings.type === 'text' && settings.url) {
|
|
124
|
+
try {
|
|
125
|
+
const res = await CustomFetch(settings.url, 'POST', {});
|
|
126
|
+
if (res.data) {
|
|
127
|
+
setAutoValue(res.data);
|
|
128
|
+
// Simulate an onChange event to update the form data
|
|
129
|
+
const simulatedEvent = {
|
|
130
|
+
target: {
|
|
131
|
+
dataset: { name: settings.id },
|
|
132
|
+
value: res.data,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
onChange(simulatedEvent);
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error('Error fetching auto value:', error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
fetchAutoValue();
|
|
144
|
+
}, [settings.url, settings.type, settings.id]);
|
|
145
|
+
|
|
120
146
|
useEffect(() => {
|
|
121
147
|
const fetchOptions = () => {
|
|
122
148
|
let filter = {};
|
|
@@ -1669,6 +1695,18 @@ function Field({
|
|
|
1669
1695
|
></textarea>
|
|
1670
1696
|
);
|
|
1671
1697
|
case 'text':
|
|
1698
|
+
return (
|
|
1699
|
+
<input
|
|
1700
|
+
type={settings.type}
|
|
1701
|
+
data-name={settings.id}
|
|
1702
|
+
className={inputClass[settings.id]}
|
|
1703
|
+
placeholder=" "
|
|
1704
|
+
onChange={onChange}
|
|
1705
|
+
value={inputValue || autoValue || ''}
|
|
1706
|
+
readOnly={settings.readOnly ? settings.readOnly : false}
|
|
1707
|
+
autoComplete="off"
|
|
1708
|
+
/>
|
|
1709
|
+
);
|
|
1672
1710
|
case 'password':
|
|
1673
1711
|
return (
|
|
1674
1712
|
<input
|
|
@@ -799,8 +799,43 @@ function Form({
|
|
|
799
799
|
if (closeModal) {
|
|
800
800
|
closeModal();
|
|
801
801
|
if (type === 'saveAnother') {
|
|
802
|
-
|
|
803
|
-
|
|
802
|
+
const { saveAnother } =
|
|
803
|
+
formSettings?.update || {};
|
|
804
|
+
|
|
805
|
+
if (
|
|
806
|
+
saveAnother?.url &&
|
|
807
|
+
saveAnother?.method &&
|
|
808
|
+
saveAnother?.data
|
|
809
|
+
) {
|
|
810
|
+
// Process data object to handle now() timestamps
|
|
811
|
+
const processedData = Object.entries(
|
|
812
|
+
saveAnother.data
|
|
813
|
+
).reduce((acc, [key, value]) => {
|
|
814
|
+
acc[key] =
|
|
815
|
+
value === 'now()'
|
|
816
|
+
? moment().format(
|
|
817
|
+
'YYYY-MM-DD HH:mm:ss'
|
|
818
|
+
) // Format that strtotime() can parse
|
|
819
|
+
: value;
|
|
820
|
+
return acc;
|
|
821
|
+
}, {});
|
|
822
|
+
|
|
823
|
+
const saveAnotherUrl = `${
|
|
824
|
+
saveAnother.url
|
|
825
|
+
}/${formData[saveAnother.dataKey]}`;
|
|
826
|
+
const resSaveAnother = await CustomFetch(
|
|
827
|
+
saveAnotherUrl,
|
|
828
|
+
saveAnother.method,
|
|
829
|
+
processedData
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
if (resSaveAnother.data.error === '') {
|
|
833
|
+
toast.success(saveAnother.message);
|
|
834
|
+
}
|
|
835
|
+
} else {
|
|
836
|
+
fetchData();
|
|
837
|
+
modalOpen('create', 0);
|
|
838
|
+
}
|
|
804
839
|
}
|
|
805
840
|
}
|
|
806
841
|
toast.success(
|
|
@@ -1511,6 +1546,30 @@ function Form({
|
|
|
1511
1546
|
Save & Create Another
|
|
1512
1547
|
</button>
|
|
1513
1548
|
</div>
|
|
1549
|
+
) : formType === 'update' &&
|
|
1550
|
+
formSettings.update?.hasOwnProperty(
|
|
1551
|
+
'saveAnother'
|
|
1552
|
+
) ? (
|
|
1553
|
+
<div
|
|
1554
|
+
className={`${styles.formItem} ${styles.fwItem} ${styles.buttonContainer}`}
|
|
1555
|
+
>
|
|
1556
|
+
<button
|
|
1557
|
+
className={styles.btn}
|
|
1558
|
+
onClick={handleSubmit}
|
|
1559
|
+
data-type="save"
|
|
1560
|
+
>
|
|
1561
|
+
Save & Close
|
|
1562
|
+
</button>
|
|
1563
|
+
<button
|
|
1564
|
+
className={styles.btn}
|
|
1565
|
+
onClick={handleSubmit}
|
|
1566
|
+
data-type="saveAnother"
|
|
1567
|
+
>
|
|
1568
|
+
{formSettings.update.saveAnother
|
|
1569
|
+
.label ||
|
|
1570
|
+
'Save & Create Another'}
|
|
1571
|
+
</button>
|
|
1572
|
+
</div>
|
|
1514
1573
|
) : (
|
|
1515
1574
|
<div
|
|
1516
1575
|
className={`${styles.formItem} ${styles.fwItem} ${styles.lastItem}`}
|