@visns-studio/visns-components 4.2.1 → 4.2.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Link, useParams } from 'react-router-dom';
|
|
3
3
|
import moment from 'moment';
|
|
4
4
|
import parse from 'html-react-parser';
|
|
@@ -23,6 +23,7 @@ import { toast } from 'react-toastify';
|
|
|
23
23
|
|
|
24
24
|
function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
25
25
|
const gridRef = useRef(null);
|
|
26
|
+
const currentConfigRef = useRef(null);
|
|
26
27
|
const routeParams = useParams();
|
|
27
28
|
|
|
28
29
|
const { filters, page, stages, tabs } = setting;
|
|
@@ -34,8 +35,10 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
34
35
|
/** General States */
|
|
35
36
|
const [activeStage, setActiveStage] = useState('');
|
|
36
37
|
const [config, setConfig] = useState({});
|
|
38
|
+
const [currentConfig, setCurrentConfig] = useState({});
|
|
37
39
|
const [data, setData] = useState({});
|
|
38
40
|
const [dataReload, setDataReload] = useState(0);
|
|
41
|
+
const [rowsSelected, setRowsSelected] = useState({});
|
|
39
42
|
const [subnav, setSubnav] = useState([]);
|
|
40
43
|
const [total, setTotal] = useState(0);
|
|
41
44
|
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
|
|
@@ -79,6 +82,31 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
84
|
|
|
85
|
+
const handleCheckboxUpdate = async () => {
|
|
86
|
+
try {
|
|
87
|
+
if (currentConfigRef.current.functions.checkboxUpdate) {
|
|
88
|
+
const { data, method, message, url } =
|
|
89
|
+
currentConfigRef.current.functions.checkboxUpdate;
|
|
90
|
+
if (!Object.keys(rowsSelected).length) {
|
|
91
|
+
toast.warning(message.warning);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const res = await CustomFetch(url, method, {
|
|
95
|
+
...data,
|
|
96
|
+
rows: rowsSelected,
|
|
97
|
+
});
|
|
98
|
+
if (res.data.error === '') {
|
|
99
|
+
toast.success(message.success);
|
|
100
|
+
gridRef.current.reload();
|
|
101
|
+
} else {
|
|
102
|
+
toast.error(message.error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error(error);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
82
110
|
const handleReload = () => {
|
|
83
111
|
const min = 0;
|
|
84
112
|
const max = 999999999;
|
|
@@ -281,6 +309,7 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
281
309
|
|
|
282
310
|
if (activeTab) {
|
|
283
311
|
const activeTabConfig = tabs.find((t) => t.id === activeTab.id);
|
|
312
|
+
currentConfigRef.current = activeTabConfig;
|
|
284
313
|
|
|
285
314
|
if (activeTabConfig && activeTabConfig.type) {
|
|
286
315
|
switch (activeTabConfig.type) {
|
|
@@ -967,6 +996,22 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
967
996
|
/>
|
|
968
997
|
</div>
|
|
969
998
|
</div>
|
|
999
|
+
|
|
1000
|
+
{activeTabConfig.functions
|
|
1001
|
+
?.checkboxUpdate && (
|
|
1002
|
+
<div className="polActions">
|
|
1003
|
+
<button
|
|
1004
|
+
className="btn"
|
|
1005
|
+
onClick={
|
|
1006
|
+
handleCheckboxUpdate
|
|
1007
|
+
}
|
|
1008
|
+
>
|
|
1009
|
+
{activeTabConfig.functions
|
|
1010
|
+
.checkboxUpdate.label ||
|
|
1011
|
+
'Update'}
|
|
1012
|
+
</button>
|
|
1013
|
+
</div>
|
|
1014
|
+
)}
|
|
970
1015
|
</>
|
|
971
1016
|
);
|
|
972
1017
|
} else {
|
|
@@ -1085,6 +1130,16 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
1085
1130
|
form: updatedForm,
|
|
1086
1131
|
columns: activeTabConfig.columns,
|
|
1087
1132
|
settings: activeTabConfig.settings,
|
|
1133
|
+
...(activeTabConfig.tableSetting && {
|
|
1134
|
+
tableSetting:
|
|
1135
|
+
activeTabConfig.tableSetting,
|
|
1136
|
+
}),
|
|
1137
|
+
...(activeTabConfig.functions && {
|
|
1138
|
+
functions: activeTabConfig.functions,
|
|
1139
|
+
}),
|
|
1140
|
+
...(setRowsSelected && {
|
|
1141
|
+
setRowsSelected: setRowsSelected,
|
|
1142
|
+
}),
|
|
1088
1143
|
});
|
|
1089
1144
|
}
|
|
1090
1145
|
break;
|
package/package.json
CHANGED