@skalfa/skalfa-component 1.0.8 → 1.0.10
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/dist/accordion/Accordion.component.js +2 -3
- package/dist/breadcrumb/Breadcrumb.component.js +2 -3
- package/dist/button/Button.component.d.ts +2 -1
- package/dist/button/Button.component.js +2 -2
- package/dist/carousel/Carousel.component.js +2 -3
- package/dist/chip/Chip.component.js +2 -3
- package/dist/contexts-mock.d.ts +2 -0
- package/dist/contexts-mock.js +10 -0
- package/dist/input/Checkbox.component.js +2 -3
- package/dist/input/Input.component.d.ts +3 -2
- package/dist/input/Input.component.js +3 -3
- package/dist/input/InputCheckbox.component.js +1 -1
- package/dist/input/InputCurrency.component.d.ts +3 -2
- package/dist/input/InputCurrency.component.js +3 -3
- package/dist/input/InputDate.component.js +4 -5
- package/dist/input/InputDatetime.component.d.ts +3 -2
- package/dist/input/InputDatetime.component.js +3 -3
- package/dist/input/InputDocument.component.js +7 -8
- package/dist/input/InputImage.component.js +3 -4
- package/dist/input/InputNumber.component.js +3 -4
- package/dist/input/InputPassword.component.js +3 -3
- package/dist/input/InputRadio.component.js +1 -1
- package/dist/input/InputTime.component.js +3 -3
- package/dist/input/InputValues.component.js +3 -4
- package/dist/input/Select.component.js +6 -7
- package/dist/modal/FloatingPage.component.d.ts +3 -1
- package/dist/modal/FloatingPage.component.js +7 -3
- package/dist/modal/Modal.component.js +1 -2
- package/dist/modal/ModalConfirm.component.d.ts +2 -2
- package/dist/modal/ModalConfirm.component.js +14 -12
- package/dist/modal/Toast.component.js +1 -2
- package/dist/nav/Bottombar.component.d.ts +2 -2
- package/dist/nav/Bottombar.component.js +7 -8
- package/dist/nav/Footer.component.d.ts +2 -2
- package/dist/nav/Footer.component.js +6 -7
- package/dist/nav/Headbar.component.js +2 -3
- package/dist/nav/Navbar.component.d.ts +2 -2
- package/dist/nav/Navbar.component.js +3 -4
- package/dist/nav/Sidebar.component.d.ts +3 -7
- package/dist/nav/Sidebar.component.js +14 -17
- package/dist/supervision/FormSupervision.component.d.ts +4 -29
- package/dist/supervision/FormSupervision.component.js +84 -136
- package/dist/supervision/TableSupervision.component.d.ts +17 -26
- package/dist/supervision/TableSupervision.component.js +207 -193
- package/dist/table/ControlBar.component.js +15 -16
- package/dist/table/FilterComponent.js +4 -6
- package/dist/table/Pagination.component.js +2 -3
- package/dist/table/Table.component.js +3 -4
- package/dist/wrap/Swipe.component.js +2 -2
- package/package.json +18 -10
- package/src/accordion/Accordion.component.tsx +3 -3
- package/src/breadcrumb/Breadcrumb.component.tsx +4 -4
- package/src/button/Button.component.tsx +3 -3
- package/src/carousel/Carousel.component.tsx +4 -4
- package/src/chip/Chip.component.tsx +3 -4
- package/src/contexts-mock.ts +6 -0
- package/src/input/Checkbox.component.tsx +3 -3
- package/src/input/Input.component.tsx +6 -6
- package/src/input/InputCheckbox.component.tsx +1 -1
- package/src/input/InputCurrency.component.tsx +6 -6
- package/src/input/InputDate.component.tsx +6 -7
- package/src/input/InputDatetime.component.tsx +6 -6
- package/src/input/InputDocument.component.tsx +9 -9
- package/src/input/InputImage.component.tsx +4 -5
- package/src/input/InputNumber.component.tsx +7 -8
- package/src/input/InputPassword.component.tsx +4 -4
- package/src/input/InputRadio.component.tsx +1 -1
- package/src/input/InputTime.component.tsx +4 -4
- package/src/input/InputValues.component.tsx +5 -6
- package/src/input/Select.component.tsx +10 -10
- package/src/modal/FloatingPage.component.tsx +33 -3
- package/src/modal/Modal.component.tsx +1 -2
- package/src/modal/ModalConfirm.component.tsx +34 -49
- package/src/modal/Toast.component.tsx +1 -2
- package/src/nav/Bottombar.component.tsx +9 -10
- package/src/nav/Footer.component.tsx +8 -9
- package/src/nav/Headbar.component.tsx +3 -3
- package/src/nav/Navbar.component.tsx +9 -10
- package/src/nav/Sidebar.component.tsx +55 -46
- package/src/supervision/FormSupervision.component.tsx +203 -224
- package/src/supervision/TableSupervision.component.tsx +420 -455
- package/src/table/ControlBar.component.tsx +16 -16
- package/src/table/FilterComponent.tsx +9 -11
- package/src/table/Pagination.component.tsx +6 -6
- package/src/table/Table.component.tsx +5 -5
- package/src/wrap/Swipe.component.tsx +3 -3
- package/src/types.d.ts +0 -7
|
@@ -4,46 +4,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.FormSupervisionComponent = FormSupervisionComponent;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
8
7
|
const _utils_1 = require("@utils");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const InputOtp_component_1 = require("../input/InputOtp.component");
|
|
15
|
-
const InputPassword_component_1 = require("../input/InputPassword.component");
|
|
16
|
-
const InputRadio_component_1 = require("../input/InputRadio.component");
|
|
17
|
-
const Select_component_1 = require("../input/Select.component");
|
|
18
|
-
const Button_component_1 = require("../button/Button.component");
|
|
19
|
-
const ModalConfirm_component_1 = require("../modal/ModalConfirm.component");
|
|
20
|
-
const Toast_component_1 = require("../modal/Toast.component");
|
|
21
|
-
const InputTime_component_1 = require("../input/InputTime.component");
|
|
22
|
-
const InputImage_component_1 = require("../input/InputImage.component");
|
|
23
|
-
const InputDatetime_component_1 = require("../input/InputDatetime.component");
|
|
24
|
-
function FormSupervisionComponent({ title, fields, submitControl, confirmation, defaultValue, onSuccess, onError, footerControl, payload, className = "", }) {
|
|
8
|
+
const __1 = require("../");
|
|
9
|
+
const skalfa_icon_1 = require("@skalfa/skalfa-icon");
|
|
10
|
+
const skalfa_lang_1 = require("@skalfa/skalfa-lang");
|
|
11
|
+
function FormSupervisionComponent({ title, fields, submitControl, confirmation, defaultValue, onSuccess, onError, footerControl, payload, className = "", successMessage, id, }) {
|
|
12
|
+
const l = (0, skalfa_lang_1.useLang)();
|
|
25
13
|
const [modal, setModal] = (0, react_1.useState)(false);
|
|
26
14
|
const [fresh, setFresh] = (0, react_1.useState)(true);
|
|
27
15
|
const [mapGroups, setMapGroups] = (0, react_1.useState)({});
|
|
28
|
-
const [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
onFailed: (code) => {
|
|
40
|
-
onError?.(code);
|
|
41
|
-
if (code == 422)
|
|
42
|
-
confirm.onClose();
|
|
43
|
-
else
|
|
44
|
-
setModal("failed");
|
|
45
|
-
},
|
|
16
|
+
const [{ formControl, setRegister, values, setValues, errors, setErrors, setDefaultValues, submit, loading, confirm, },] = (0, _utils_1.useForm)(submitControl, payload, confirmation, (data) => {
|
|
17
|
+
onSuccess?.(data);
|
|
18
|
+
setModal("success");
|
|
19
|
+
setTimeout(() => setModal(false), 1000);
|
|
20
|
+
resetFresh();
|
|
21
|
+
}, (code) => {
|
|
22
|
+
onError?.(code);
|
|
23
|
+
if (code == 422)
|
|
24
|
+
confirm.onClose();
|
|
25
|
+
else
|
|
26
|
+
setModal("failed");
|
|
46
27
|
});
|
|
28
|
+
const GroupsFromDefaults = (defaults) => {
|
|
29
|
+
const groups = {};
|
|
30
|
+
Object.keys(defaults).forEach((key) => {
|
|
31
|
+
const match = key.match(/^(.+?)\[(\d+)\]/);
|
|
32
|
+
if (!match)
|
|
33
|
+
return;
|
|
34
|
+
const [, groupKey, indexStr] = match;
|
|
35
|
+
const index = Number(indexStr);
|
|
36
|
+
if (!groups[groupKey]) {
|
|
37
|
+
groups[groupKey] = new Set();
|
|
38
|
+
}
|
|
39
|
+
groups[groupKey].add(index);
|
|
40
|
+
});
|
|
41
|
+
return Object.fromEntries(Object.entries(groups).map(([key, indexSet]) => [
|
|
42
|
+
key,
|
|
43
|
+
Array.from(indexSet)
|
|
44
|
+
.sort((a, b) => a - b)
|
|
45
|
+
.map((_, i) => i),
|
|
46
|
+
]));
|
|
47
|
+
};
|
|
47
48
|
const resetFresh = () => {
|
|
48
49
|
setFresh(false);
|
|
49
50
|
setTimeout(() => setFresh(true), 300);
|
|
@@ -52,102 +53,32 @@ function FormSupervisionComponent({ title, fields, submitControl, confirmation,
|
|
|
52
53
|
resetFresh();
|
|
53
54
|
}, [fields]);
|
|
54
55
|
(0, react_1.useEffect)(() => {
|
|
55
|
-
if (defaultValue)
|
|
56
|
+
if (defaultValue) {
|
|
56
57
|
setDefaultValues(defaultValue);
|
|
58
|
+
const derivedGroups = GroupsFromDefaults(defaultValue);
|
|
59
|
+
setMapGroups(derivedGroups);
|
|
60
|
+
resetFresh();
|
|
61
|
+
}
|
|
57
62
|
else {
|
|
58
63
|
setDefaultValues(null);
|
|
64
|
+
setMapGroups({});
|
|
59
65
|
resetFresh();
|
|
60
66
|
}
|
|
61
67
|
}, [defaultValue]);
|
|
62
|
-
// ==============================>
|
|
63
|
-
// ## Watch: collect watchers from fields
|
|
64
|
-
// ==============================>
|
|
65
|
-
const collectWatchers = (fieldList, prefix) => {
|
|
66
|
-
const result = [];
|
|
67
|
-
for (const f of fieldList) {
|
|
68
|
-
const inputType = f.type || "default";
|
|
69
|
-
const name = prefix ? `${prefix}.${f.construction?.name}` : f.construction?.name || "";
|
|
70
|
-
if (inputType === "cluster") {
|
|
71
|
-
const cluster = f.construction;
|
|
72
|
-
const groupKey = prefix ? `${prefix}.${cluster.name}` : cluster.name;
|
|
73
|
-
const group = mapGroups[groupKey] || [0];
|
|
74
|
-
for (const gIndex of group) {
|
|
75
|
-
result.push(...collectWatchers(cluster.fields, `${cluster.name}[${gIndex}]`));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (f.watch) {
|
|
79
|
-
result.push({ name, watch: f.watch, construction: f.construction });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
// ==============================>
|
|
85
|
-
// ## Watch: execute watchers on value change
|
|
86
|
-
// ==============================>
|
|
87
|
-
(0, react_1.useEffect)(() => {
|
|
88
|
-
const watchers = collectWatchers(fields);
|
|
89
|
-
if (watchers.length === 0) {
|
|
90
|
-
if (Object.keys(watchRef.current).length > 0) {
|
|
91
|
-
watchRef.current = {};
|
|
92
|
-
setWatchState({});
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const valMap = values.reduce((acc, v) => { acc[v.name] = v.value; return acc; }, {});
|
|
97
|
-
const nextState = {};
|
|
98
|
-
const valueUpdates = [];
|
|
99
|
-
for (const { name, watch, construction } of watchers) {
|
|
100
|
-
const prev = watchRef.current[name] || {};
|
|
101
|
-
const action = watch({ values: valMap, self: name, prev });
|
|
102
|
-
if (!action)
|
|
103
|
-
continue;
|
|
104
|
-
nextState[name] = action;
|
|
105
|
-
if (action.hidden && !prev.hidden)
|
|
106
|
-
unregister(name);
|
|
107
|
-
if (action.required !== prev.required) {
|
|
108
|
-
const baseValidations = Array.isArray(construction?.validations) ? [...construction.validations] : [];
|
|
109
|
-
const newValidations = action.required ? (baseValidations.includes("required") ? baseValidations : [...baseValidations, "required"]) : baseValidations.filter((v) => v !== "required");
|
|
110
|
-
setRegister({ name, validations: newValidations });
|
|
111
|
-
}
|
|
112
|
-
if (action.reset) {
|
|
113
|
-
const cur = valMap[name];
|
|
114
|
-
if (cur != null && cur !== "")
|
|
115
|
-
valueUpdates.push({ name, value: "" });
|
|
116
|
-
}
|
|
117
|
-
else if (action.value !== undefined && action.value !== valMap[name]) {
|
|
118
|
-
valueUpdates.push({ name, value: action.value });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (JSON.stringify(watchRef.current) !== JSON.stringify(nextState)) {
|
|
122
|
-
watchRef.current = nextState;
|
|
123
|
-
setWatchState(nextState);
|
|
124
|
-
}
|
|
125
|
-
if (valueUpdates.length > 0) {
|
|
126
|
-
const merged = [...values];
|
|
127
|
-
for (const upd of valueUpdates) {
|
|
128
|
-
const idx = merged.findIndex(v => v.name === upd.name);
|
|
129
|
-
if (idx >= 0)
|
|
130
|
-
merged[idx] = upd;
|
|
131
|
-
else
|
|
132
|
-
merged.push(upd);
|
|
133
|
-
}
|
|
134
|
-
setValues(merged);
|
|
135
|
-
}
|
|
136
|
-
}, [values, fields, mapGroups]);
|
|
137
68
|
const generateColClass = (col) => String(col).split(" ").map((c) => (c.includes(":") ? `${c.replace(":", ":col-span-")}` : `col-span-${c}`)).join(" ");
|
|
138
69
|
const inputMap = {
|
|
139
|
-
default:
|
|
140
|
-
check:
|
|
141
|
-
currency:
|
|
142
|
-
date:
|
|
143
|
-
datetime:
|
|
144
|
-
time:
|
|
145
|
-
number:
|
|
146
|
-
radio:
|
|
147
|
-
select:
|
|
148
|
-
"enter-password":
|
|
149
|
-
otp:
|
|
150
|
-
image:
|
|
70
|
+
default: __1.InputComponent,
|
|
71
|
+
check: __1.InputCheckboxComponent,
|
|
72
|
+
currency: __1.InputCurrencyComponent,
|
|
73
|
+
date: __1.InputDateComponent,
|
|
74
|
+
datetime: __1.InputDatetimeComponent,
|
|
75
|
+
time: __1.InputTimeComponent,
|
|
76
|
+
number: __1.InputNumberComponent,
|
|
77
|
+
radio: __1.InputRadioComponent,
|
|
78
|
+
select: __1.SelectComponent,
|
|
79
|
+
"enter-password": __1.InputPasswordComponent,
|
|
80
|
+
otp: __1.InputOtpComponent,
|
|
81
|
+
image: __1.InputImageComponent,
|
|
151
82
|
cluster: () => null,
|
|
152
83
|
custom: () => null,
|
|
153
84
|
};
|
|
@@ -156,26 +87,43 @@ function FormSupervisionComponent({ title, fields, submitControl, confirmation,
|
|
|
156
87
|
const name = prefix ? `${prefix}.${form.construction?.name}` : form.construction?.name || "input_name";
|
|
157
88
|
if (form?.onHide?.(values))
|
|
158
89
|
return null;
|
|
159
|
-
const ws = watchState[name];
|
|
160
|
-
if (ws?.hidden)
|
|
161
|
-
return null;
|
|
162
90
|
if (inputType === "cluster") {
|
|
163
|
-
const { name: mapName, fields: innerForms, label, tip, wrap, className
|
|
91
|
+
const { name: mapName, fields: innerForms, label, tip, wrap, className } = form.construction;
|
|
164
92
|
const groupKey = prefix ? `${prefix}.${mapName}` : mapName;
|
|
165
|
-
const group = mapGroups[groupKey] ||
|
|
166
|
-
const addGroup = () => setMapGroups((prev) => ({ ...prev, [groupKey]: [...group, group.length
|
|
167
|
-
const removeGroup = (
|
|
168
|
-
|
|
169
|
-
|
|
93
|
+
const group = mapGroups[groupKey] || [0];
|
|
94
|
+
const addGroup = () => setMapGroups((prev) => ({ ...prev, [groupKey]: [...group, group.length] }));
|
|
95
|
+
const removeGroup = (index) => {
|
|
96
|
+
const filteredGroup = group.filter((_, i) => i !== index);
|
|
97
|
+
const newGroup = filteredGroup.map((_, i) => i);
|
|
98
|
+
setMapGroups((prev) => ({ ...prev, [groupKey]: newGroup }));
|
|
99
|
+
let updatedValues = values.filter((v) => {
|
|
100
|
+
const n = String(v?.name || "");
|
|
101
|
+
if (!n)
|
|
102
|
+
return true;
|
|
103
|
+
if (n.startsWith(`${groupKey}[${index}]`) || n.startsWith(`${groupKey}.${index}.`))
|
|
104
|
+
return false;
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
const regex = new RegExp(`${groupKey}\\[(\\d+)\\]`, 'g');
|
|
108
|
+
updatedValues = updatedValues.map((v) => {
|
|
109
|
+
let name = v.name;
|
|
110
|
+
name = name.replace(regex, (match, oldIdx) => {
|
|
111
|
+
const oldIndex = parseInt(oldIdx, 10);
|
|
112
|
+
const newIndex = newGroup.indexOf(oldIndex);
|
|
113
|
+
return newIndex >= 0 ? `${groupKey}[${newIndex}]` : match;
|
|
114
|
+
});
|
|
115
|
+
return { ...v, name };
|
|
116
|
+
});
|
|
117
|
+
setValues(updatedValues);
|
|
170
118
|
};
|
|
171
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("flex flex-col gap-4", generateColClass(form.col || "12")), children: [group.map((gIndex) => ((0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("
|
|
119
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("flex flex-col gap-4", generateColClass(form.col || "12")), children: [group.map((gIndex) => ((0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("relative pr-8", wrap && "p-4 rounded border", className), children: [label && (0, jsx_runtime_1.jsxs)("p", { className: "input-label", children: [label, " ", gIndex + 1] }), tip && (0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-tip"), children: tip }), (label || tip) && (0, jsx_runtime_1.jsx)("div", { className: "mb-2" }), (0, jsx_runtime_1.jsx)("div", { className: "w-full grid grid-cols-12 gap-4", children: innerForms.map((inner, i) => renderInput(inner, i, `${mapName}[${gIndex}]`)) }), (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/times", paint: "danger", variant: "outline", size: "xs", className: (0, _utils_1.cn)("absolute top-10 right-2 translate-x-[50%] -translate-y-[50%]", wrap && "translate-x-0 -translate-y-0 top-1 right-1"), onClick: () => removeGroup(gIndex) })] }, gIndex))), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/plus", label: `Tambah ${label || mapName}`, variant: "outline", size: "sm", onClick: addGroup }) })] }, key));
|
|
172
120
|
}
|
|
173
121
|
if (inputType === "custom") {
|
|
174
122
|
const customRender = form.construction;
|
|
175
123
|
return ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)(form.className, generateColClass(form.col || "12")), children: customRender?.({ formControl, values, setValues, errors, setErrors, setRegister, prefixName: prefix }) }, key));
|
|
176
124
|
}
|
|
177
|
-
const Component = inputMap[inputType] ||
|
|
178
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)(form.className, generateColClass(form.col || "12")), children: (0, jsx_runtime_1.jsx)(Component, { ...form.construction, ...formControl(name)
|
|
125
|
+
const Component = inputMap[inputType] || __1.InputComponent;
|
|
126
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)(form.className, generateColClass(form.col || "12")), children: (0, jsx_runtime_1.jsx)(Component, { ...form.construction, ...formControl(name) }) }, key));
|
|
179
127
|
};
|
|
180
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && (0, jsx_runtime_1.jsx)("h4", { className: (0, _utils_1.cn)("
|
|
128
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && (0, jsx_runtime_1.jsx)("h4", { className: (0, _utils_1.cn)("text-lg font-semibold mb-4", (0, _utils_1.pcn)(className, "title")), children: title }), modal == "success" ? ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center justify-center h-full py-6 transition-all duration-300 animate-intro-down", children: [(0, jsx_runtime_1.jsx)("div", { className: "w-12 h-12 rounded-full bg-blue-50 flex items-center justify-center", children: (0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: "solid/check", className: "text-primary text-2xl" }) }), (0, jsx_runtime_1.jsx)("p", { className: "text-primary text-lg font-semibold mt-4", children: successMessage || "Berhasil disimpan!" })] })) : ((0, jsx_runtime_1.jsx)("form", { id: id, className: (0, _utils_1.cn)("flex flex-col h-full pb-8"), onSubmit: submit, children: (0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("grid grid-cols-12 gap-4 flex-1 content-start", (0, _utils_1.pcn)(className, "base")), children: [fresh && fields.map((f, i) => renderInput(f, i)), !footerControl && ((0, jsx_runtime_1.jsx)("div", { className: "hidden md:block col-span-12", children: (0, jsx_runtime_1.jsx)("div", { className: "flex justify-end mt-4", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { type: "submit", label: l.base?.save ? l.base.save() : "Save", icon: "solid/save", loading: loading, className: (0, _utils_1.pcn)(className, "submit") }) }) })), !footerControl && ((0, jsx_runtime_1.jsx)("div", { className: "md:hidden col-span-12 mt-4", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { label: l.base?.save ? l.base.save() : "Save", icon: "solid/save", type: "submit", loading: loading, block: true, className: (0, _utils_1.pcn)(className, "submit") }) })), footerControl && ((0, jsx_runtime_1.jsx)("div", { className: "col-span-12", children: footerControl?.({ loading }) })), modal == "failed" && ((0, jsx_runtime_1.jsxs)("div", { className: "col-span-12 mt-4 w-full p-4 rounded-sm border border-danger bg-light-danger flex gap-4 items-center", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("div", { className: "w-10 h-10 rounded-full bg-danger/20 flex items-center justify-center", children: (0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: "solid/exclamation-triangle", className: "text-danger text-lg" }) }) }), (0, jsx_runtime_1.jsx)("p", { className: "text-danger text-sm font-semibold", children: "Terjadi Masalah, Coba ulangi lagi!" })] }))] }) })), (0, jsx_runtime_1.jsx)(__1.ModalConfirmComponent, { show: confirm.show, onClose: () => confirm.onClose(), title: l.base?.confirmTitle ? l.base.confirmTitle() : "Yakin", submitControl: { onSubmit: () => confirm?.onConfirm(), paint: "primary" } })] }));
|
|
181
129
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
import { conversion,
|
|
3
|
-
import { FloatingPageProps } from "../
|
|
4
|
-
import { ButtonProps } from "../button/Button.component";
|
|
5
|
-
import { TableProps } from "../table/Table.component";
|
|
6
|
-
import { FormType } from "./FormSupervision.component";
|
|
7
|
-
import { ModalConfirmProps } from "../modal/ModalConfirm.component";
|
|
8
|
-
import { ControlBarOptionType } from "../table/ControlBar.component";
|
|
2
|
+
import { conversion, ShortcutHandler, UseResourceProps } from "@utils";
|
|
3
|
+
import { FloatingPageProps, FormType, ButtonProps, ModalConfirmProps, TableProps, ControlBarOptionType, SwipeActionType, BottomSheetProps } from "../";
|
|
9
4
|
export interface TableSupervisionColumnProps {
|
|
10
5
|
selector: string;
|
|
11
6
|
label?: string;
|
|
@@ -24,8 +19,6 @@ export interface TableSupervisionColumnProps {
|
|
|
24
19
|
accessCode?: string;
|
|
25
20
|
item?: (data: any) => string | ReactNode;
|
|
26
21
|
tip?: string | ((data: any) => string);
|
|
27
|
-
exportable?: boolean | "default" | "optional" | "hidden";
|
|
28
|
-
importable?: boolean;
|
|
29
22
|
}
|
|
30
23
|
export interface TableSupervisionFormProps {
|
|
31
24
|
fields: string[] | (FormType & {
|
|
@@ -33,22 +26,14 @@ export interface TableSupervisionFormProps {
|
|
|
33
26
|
})[];
|
|
34
27
|
defaultValue?: (item: Record<string, any> | null) => Promise<Record<string, any>> | Record<string, any>;
|
|
35
28
|
payload?: (values: any) => Promise<Record<string, any>> | object;
|
|
36
|
-
modalControl?: Omit<FloatingPageProps, "show" | "onClose" | "children">;
|
|
29
|
+
modalControl?: Omit<FloatingPageProps, "show" | "onClose" | "children"> | Omit<BottomSheetProps, "show" | "onClose" | "children">;
|
|
37
30
|
contentType?: "application/json" | "multipart/form-data";
|
|
38
31
|
}
|
|
39
32
|
export type TableSupervisionDetailProps = boolean | (string | {
|
|
40
33
|
label: string;
|
|
41
34
|
item: string | ((data: Record<string, any>) => ReactNode);
|
|
42
35
|
conversion?: keyof typeof conversion;
|
|
43
|
-
} | ((data: Record<string, any>) => ReactNode))[] | ((data: Record<string, any>) =>
|
|
44
|
-
modal?: Omit<FloatingPageProps, "show" | "onClose" | "children">;
|
|
45
|
-
content?: boolean | (string | {
|
|
46
|
-
label: string;
|
|
47
|
-
item: string | ((data: Record<string, any>) => ReactNode);
|
|
48
|
-
conversion?: keyof typeof conversion;
|
|
49
|
-
} | ((data: Record<string, any>) => ReactNode))[] | ((data: Record<string, any>) => ReactNode);
|
|
50
|
-
action?: (data: Record<string, any>) => void;
|
|
51
|
-
};
|
|
36
|
+
} | ((data: Record<string, any>) => ReactNode))[] | ((data: Record<string, any>) => ReactNode);
|
|
52
37
|
export type TableSupervisionProps = {
|
|
53
38
|
fetchControl: UseResourceProps;
|
|
54
39
|
title?: string;
|
|
@@ -57,27 +42,33 @@ export type TableSupervisionProps = {
|
|
|
57
42
|
urlParam?: boolean | {
|
|
58
43
|
compressed?: boolean;
|
|
59
44
|
};
|
|
45
|
+
onRowClick?: (data: Record<string, any>) => void;
|
|
60
46
|
columnControl?: string[] | TableSupervisionColumnProps[];
|
|
61
47
|
formControl?: TableSupervisionFormProps;
|
|
62
48
|
detailControl?: TableSupervisionDetailProps;
|
|
63
49
|
actionControl?: boolean | ('EDIT' | 'DELETE' | {
|
|
64
50
|
label: string;
|
|
65
|
-
modal?:
|
|
51
|
+
modal?: ModalConfirmProps;
|
|
66
52
|
button?: ButtonProps;
|
|
67
53
|
shortcut?: {
|
|
68
54
|
key: string;
|
|
69
55
|
description: string;
|
|
70
56
|
};
|
|
71
|
-
} | ((row:
|
|
57
|
+
} | ((row: object, setModal?: (type: "EDIT" | "DELETE") => void, setDataSelected?: () => void, setShortcut?: (key: string, handler: ShortcutHandler, description?: string) => void, size?: string) => ReactNode))[];
|
|
72
58
|
block?: boolean;
|
|
73
59
|
noIndex?: boolean;
|
|
74
60
|
actionBulkingControl?: TableProps["actionBulking"];
|
|
75
61
|
controlBar?: (ControlBarOptionType | "CREATE" | "IMPORT" | "EXPORT" | "PRINT")[];
|
|
76
62
|
responsiveControl?: {
|
|
77
|
-
mobile?:
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
mobile?: boolean | {
|
|
64
|
+
item?: (item: Record<string, any>, key: number) => ReactNode;
|
|
65
|
+
leftActionControl?: Omit<SwipeActionType, "onAction"> & {
|
|
66
|
+
onAction?: (item: Record<string, any>, key?: number) => void;
|
|
67
|
+
};
|
|
68
|
+
rightActionControl?: Omit<SwipeActionType, "onAction"> & {
|
|
69
|
+
onAction?: (item: Record<string, any>, key?: number) => void;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
80
72
|
};
|
|
81
|
-
importControl?: FetchControlType;
|
|
82
73
|
};
|
|
83
|
-
export declare function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam,
|
|
74
|
+
export declare function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, onRowClick, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam, }: TableSupervisionProps): import("@types/react").JSX.Element;
|