@skalfa/skalfa-component 1.0.0 → 1.0.3
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.d.ts +1 -1
- package/dist/breadcrumb/Breadcrumb.component.d.ts +1 -1
- package/dist/button/Button.component.d.ts +1 -1
- package/dist/card/AlertCard.component.d.ts +1 -1
- package/dist/card/Card.component.d.ts +1 -1
- package/dist/card/DashboardCard.component.d.ts +1 -1
- package/dist/card/GalleryCard.component.d.ts +1 -1
- package/dist/card/ProductCard.component.d.ts +1 -1
- package/dist/card/ProfileCard.component.d.ts +1 -1
- package/dist/carousel/Carousel.component.d.ts +1 -1
- package/dist/chip/Chip.component.d.ts +1 -1
- package/dist/index.js +175 -56
- package/dist/input/Checkbox.component.d.ts +1 -1
- package/dist/input/Input.component.d.ts +1 -1
- package/dist/input/InputCheckbox.component.d.ts +1 -1
- package/dist/input/InputCheckbox.component.js +2 -2
- package/dist/input/InputCurrency.component.d.ts +1 -1
- package/dist/input/InputDate.component.d.ts +1 -1
- package/dist/input/InputDate.component.js +9 -7
- package/dist/input/InputDatetime.component.d.ts +1 -1
- package/dist/input/InputDatetime.component.js +13 -8
- package/dist/input/InputDocument.component.d.ts +1 -1
- package/dist/input/InputDocument.component.js +6 -4
- package/dist/input/InputImage.component.js +5 -3
- package/dist/input/InputMap.component.d.ts +1 -1
- package/dist/input/InputMap.component.js +5 -3
- package/dist/input/InputNumber.component.d.ts +1 -1
- package/dist/input/InputPassword.component.d.ts +1 -1
- package/dist/input/InputRadio.component.d.ts +1 -1
- package/dist/input/InputRadio.component.js +2 -2
- package/dist/input/InputTime.component.d.ts +1 -1
- package/dist/input/InputTime.component.js +5 -3
- package/dist/input/InputValues.component.d.ts +1 -1
- package/dist/input/Radio.component.d.ts +1 -1
- package/dist/input/Select.component.d.ts +1 -1
- package/dist/modal/FloatingPage.component.d.ts +1 -1
- package/dist/modal/FloatingPage.component.js +2 -2
- package/dist/modal/Modal.component.d.ts +1 -1
- package/dist/modal/Modal.component.js +2 -2
- package/dist/modal/ModalConfirm.component.d.ts +2 -2
- package/dist/modal/ModalConfirm.component.js +5 -3
- package/dist/modal/Toast.component.d.ts +1 -1
- package/dist/modal/Toast.component.js +2 -2
- package/dist/nav/Bottombar.component.d.ts +1 -1
- package/dist/nav/Footer.component.d.ts +1 -1
- package/dist/nav/Headbar.component.d.ts +4 -11
- package/dist/nav/Headbar.component.js +3 -22
- package/dist/nav/Navbar.component.d.ts +1 -1
- package/dist/nav/Navbar.component.js +2 -2
- package/dist/nav/Sidebar.component.d.ts +2 -2
- package/dist/nav/Tabbar.component.d.ts +1 -1
- package/dist/nav/Wizard.component.d.ts +1 -1
- package/dist/supervision/FormSupervision.component.d.ts +14 -2
- package/dist/supervision/FormSupervision.component.js +32 -17
- package/dist/supervision/TableSupervision.component.d.ts +7 -2
- package/dist/supervision/TableSupervision.component.js +25 -19
- package/dist/table/ControlBar.component.d.ts +2 -2
- package/dist/table/ControlBar.component.js +20 -14
- package/dist/table/FilterComponent.d.ts +2 -2
- package/dist/table/FilterComponent.js +24 -17
- package/dist/table/Pagination.component.d.ts +1 -1
- package/dist/table/Pagination.component.js +4 -3
- package/dist/table/Table.component.d.ts +4 -2
- package/dist/table/Table.component.js +11 -7
- package/dist/typography/TypographyArticle.component.d.ts +1 -1
- package/dist/typography/TypographyColumn.component.d.ts +1 -1
- package/dist/typography/TypographyContent.component.d.ts +1 -1
- package/dist/typography/TypographyTips.component.d.ts +1 -1
- package/dist/wrap/Image.component.d.ts +1 -1
- package/dist/wrap/ScrollContainer.component.d.ts +1 -1
- package/dist/wrap/ShortcutProvider.d.ts +1 -1
- package/dist/wrap/ShortcutProvider.js +2 -2
- package/dist/wrap/Swipe.component.d.ts +1 -1
- package/package.json +4 -3
- package/dist/src/accordion/Accordion.component.d.ts +0 -13
- package/dist/src/accordion/Accordion.component.js +0 -25
- package/dist/src/breadcrumb/Breadcrumb.component.d.ts +0 -14
- package/dist/src/breadcrumb/Breadcrumb.component.js +0 -21
- package/dist/src/button/Button.component.d.ts +0 -21
- package/dist/src/button/Button.component.js +0 -19
- package/dist/src/card/AlertCard.component.d.ts +0 -11
- package/dist/src/card/AlertCard.component.js +0 -9
- package/dist/src/card/Card.component.d.ts +0 -5
- package/dist/src/card/Card.component.js +0 -9
- package/dist/src/card/DashboardCard.component.d.ts +0 -9
- package/dist/src/card/DashboardCard.component.js +0 -13
- package/dist/src/card/GalleryCard.component.d.ts +0 -7
- package/dist/src/card/GalleryCard.component.js +0 -13
- package/dist/src/card/ProductCard.component.d.ts +0 -9
- package/dist/src/card/ProductCard.component.js +0 -13
- package/dist/src/card/ProfileCard.component.d.ts +0 -10
- package/dist/src/card/ProfileCard.component.js +0 -13
- package/dist/src/carousel/Carousel.component.d.ts +0 -13
- package/dist/src/carousel/Carousel.component.js +0 -37
- package/dist/src/chip/Chip.component.d.ts +0 -6
- package/dist/src/chip/Chip.component.js +0 -12
- package/dist/src/index.d.ts +0 -13
- package/dist/src/index.js +0 -29
- package/dist/src/input/Checkbox.component.d.ts +0 -13
- package/dist/src/input/Checkbox.component.js +0 -23
- package/dist/src/input/Input.component.d.ts +0 -23
- package/dist/src/input/Input.component.js +0 -134
- package/dist/src/input/InputCheckbox.component.d.ts +0 -27
- package/dist/src/input/InputCheckbox.component.js +0 -53
- package/dist/src/input/InputCurrency.component.d.ts +0 -21
- package/dist/src/input/InputCurrency.component.js +0 -30
- package/dist/src/input/InputDate.component.d.ts +0 -24
- package/dist/src/input/InputDate.component.js +0 -107
- package/dist/src/input/InputDatetime.component.d.ts +0 -17
- package/dist/src/input/InputDatetime.component.js +0 -75
- package/dist/src/input/InputDocument.component.d.ts +0 -22
- package/dist/src/input/InputDocument.component.js +0 -88
- package/dist/src/input/InputImage.component.d.ts +0 -23
- package/dist/src/input/InputImage.component.js +0 -260
- package/dist/src/input/InputMap.component.d.ts +0 -25
- package/dist/src/input/InputMap.component.js +0 -101
- package/dist/src/input/InputNumber.component.d.ts +0 -19
- package/dist/src/input/InputNumber.component.js +0 -40
- package/dist/src/input/InputOtp.component.d.ts +0 -14
- package/dist/src/input/InputOtp.component.js +0 -65
- package/dist/src/input/InputPassword.component.d.ts +0 -17
- package/dist/src/input/InputPassword.component.js +0 -59
- package/dist/src/input/InputRadio.component.d.ts +0 -27
- package/dist/src/input/InputRadio.component.js +0 -56
- package/dist/src/input/InputTime.component.d.ts +0 -23
- package/dist/src/input/InputTime.component.js +0 -73
- package/dist/src/input/InputValues.component.d.ts +0 -9
- package/dist/src/input/InputValues.component.js +0 -19
- package/dist/src/input/Radio.component.d.ts +0 -12
- package/dist/src/input/Radio.component.js +0 -22
- package/dist/src/input/Select.component.d.ts +0 -47
- package/dist/src/input/Select.component.js +0 -275
- package/dist/src/modal/BottomSheet.component.d.ts +0 -12
- package/dist/src/modal/BottomSheet.component.js +0 -161
- package/dist/src/modal/FloatingPage.component.d.ts +0 -12
- package/dist/src/modal/FloatingPage.component.js +0 -27
- package/dist/src/modal/Modal.component.d.ts +0 -12
- package/dist/src/modal/Modal.component.js +0 -27
- package/dist/src/modal/ModalConfirm.component.d.ts +0 -26
- package/dist/src/modal/ModalConfirm.component.js +0 -68
- package/dist/src/modal/Toast.component.d.ts +0 -11
- package/dist/src/modal/Toast.component.js +0 -58
- package/dist/src/nav/Bottombar.component.d.ts +0 -12
- package/dist/src/nav/Bottombar.component.js +0 -32
- package/dist/src/nav/Footer.component.d.ts +0 -37
- package/dist/src/nav/Footer.component.js +0 -49
- package/dist/src/nav/Headbar.component.d.ts +0 -14
- package/dist/src/nav/Headbar.component.js +0 -32
- package/dist/src/nav/Navbar.component.d.ts +0 -22
- package/dist/src/nav/Navbar.component.js +0 -26
- package/dist/src/nav/Sidebar.component.d.ts +0 -33
- package/dist/src/nav/Sidebar.component.js +0 -87
- package/dist/src/nav/Tabbar.component.d.ts +0 -13
- package/dist/src/nav/Tabbar.component.js +0 -17
- package/dist/src/nav/Wizard.component.d.ts +0 -9
- package/dist/src/nav/Wizard.component.js +0 -24
- package/dist/src/supervision/FormSupervision.component.d.ts +0 -93
- package/dist/src/supervision/FormSupervision.component.js +0 -168
- package/dist/src/supervision/TableSupervision.component.d.ts +0 -78
- package/dist/src/supervision/TableSupervision.component.js +0 -273
- package/dist/src/table/ControlBar.component.d.ts +0 -34
- package/dist/src/table/ControlBar.component.js +0 -205
- package/dist/src/table/FilterComponent.d.ts +0 -45
- package/dist/src/table/FilterComponent.js +0 -132
- package/dist/src/table/Pagination.component.d.ts +0 -8
- package/dist/src/table/Pagination.component.js +0 -32
- package/dist/src/table/Table.component.d.ts +0 -61
- package/dist/src/table/Table.component.js +0 -101
- package/dist/src/typography/TypographyArticle.component.d.ts +0 -8
- package/dist/src/typography/TypographyArticle.component.js +0 -7
- package/dist/src/typography/TypographyColumn.component.d.ts +0 -6
- package/dist/src/typography/TypographyColumn.component.js +0 -7
- package/dist/src/typography/TypographyContent.component.d.ts +0 -6
- package/dist/src/typography/TypographyContent.component.js +0 -7
- package/dist/src/typography/TypographyTips.component.d.ts +0 -6
- package/dist/src/typography/TypographyTips.component.js +0 -7
- package/dist/src/wrap/Draggable.component.d.ts +0 -34
- package/dist/src/wrap/Draggable.component.js +0 -214
- package/dist/src/wrap/Image.component.d.ts +0 -2
- package/dist/src/wrap/Image.component.js +0 -13
- package/dist/src/wrap/OutsideClick.component.d.ts +0 -6
- package/dist/src/wrap/OutsideClick.component.js +0 -34
- package/dist/src/wrap/ScrollContainer.component.d.ts +0 -10
- package/dist/src/wrap/ScrollContainer.component.js +0 -54
- package/dist/src/wrap/ShortcutProvider.d.ts +0 -1
- package/dist/src/wrap/ShortcutProvider.js +0 -42
- package/dist/src/wrap/Swipe.component.d.ts +0 -14
- package/dist/src/wrap/Swipe.component.js +0 -61
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.FormSupervisionComponent = FormSupervisionComponent;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
8
|
-
const _utils_1 = require("@utils");
|
|
9
|
-
const _components_1 = require("@components");
|
|
10
|
-
function FormSupervisionComponent({ title, fields, submitControl, confirmation, defaultValue, onSuccess, onError, footerControl, payload, className = "", }) {
|
|
11
|
-
const [modal, setModal] = (0, react_1.useState)(false);
|
|
12
|
-
const [fresh, setFresh] = (0, react_1.useState)(true);
|
|
13
|
-
const [mapGroups, setMapGroups] = (0, react_1.useState)({});
|
|
14
|
-
const [watchState, setWatchState] = (0, react_1.useState)({});
|
|
15
|
-
const watchRef = (0, react_1.useRef)({});
|
|
16
|
-
const { formControl, setRegister, unregister, unregisterPrefix, values, setValues, errors, setErrors, setDefaultValues, submit, loading, confirm } = (0, _utils_1.useForm)({
|
|
17
|
-
...submitControl,
|
|
18
|
-
payload,
|
|
19
|
-
confirmation,
|
|
20
|
-
onSuccess: (data) => {
|
|
21
|
-
onSuccess?.(data);
|
|
22
|
-
setModal("success");
|
|
23
|
-
resetFresh();
|
|
24
|
-
},
|
|
25
|
-
onFailed: (code) => {
|
|
26
|
-
onError?.(code);
|
|
27
|
-
if (code == 422)
|
|
28
|
-
confirm.onClose();
|
|
29
|
-
else
|
|
30
|
-
setModal("failed");
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
const resetFresh = () => {
|
|
34
|
-
setFresh(false);
|
|
35
|
-
setTimeout(() => setFresh(true), 300);
|
|
36
|
-
};
|
|
37
|
-
(0, react_1.useEffect)(() => {
|
|
38
|
-
resetFresh();
|
|
39
|
-
}, [fields]);
|
|
40
|
-
(0, react_1.useEffect)(() => {
|
|
41
|
-
if (defaultValue)
|
|
42
|
-
setDefaultValues(defaultValue);
|
|
43
|
-
else {
|
|
44
|
-
setDefaultValues(null);
|
|
45
|
-
resetFresh();
|
|
46
|
-
}
|
|
47
|
-
}, [defaultValue]);
|
|
48
|
-
// ==============================>
|
|
49
|
-
// ## Watch: collect watchers from fields
|
|
50
|
-
// ==============================>
|
|
51
|
-
const collectWatchers = (fieldList, prefix) => {
|
|
52
|
-
const result = [];
|
|
53
|
-
for (const f of fieldList) {
|
|
54
|
-
const inputType = f.type || "default";
|
|
55
|
-
const name = prefix ? `${prefix}.${f.construction?.name}` : f.construction?.name || "";
|
|
56
|
-
if (inputType === "cluster") {
|
|
57
|
-
const cluster = f.construction;
|
|
58
|
-
const groupKey = prefix ? `${prefix}.${cluster.name}` : cluster.name;
|
|
59
|
-
const group = mapGroups[groupKey] || [0];
|
|
60
|
-
for (const gIndex of group) {
|
|
61
|
-
result.push(...collectWatchers(cluster.fields, `${cluster.name}[${gIndex}]`));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (f.watch) {
|
|
65
|
-
result.push({ name, watch: f.watch, construction: f.construction });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
// ==============================>
|
|
71
|
-
// ## Watch: execute watchers on value change
|
|
72
|
-
// ==============================>
|
|
73
|
-
(0, react_1.useEffect)(() => {
|
|
74
|
-
const watchers = collectWatchers(fields);
|
|
75
|
-
if (watchers.length === 0) {
|
|
76
|
-
if (Object.keys(watchRef.current).length > 0) {
|
|
77
|
-
watchRef.current = {};
|
|
78
|
-
setWatchState({});
|
|
79
|
-
}
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const valMap = values.reduce((acc, v) => { acc[v.name] = v.value; return acc; }, {});
|
|
83
|
-
const nextState = {};
|
|
84
|
-
const valueUpdates = [];
|
|
85
|
-
for (const { name, watch, construction } of watchers) {
|
|
86
|
-
const prev = watchRef.current[name] || {};
|
|
87
|
-
const action = watch({ values: valMap, self: name, prev });
|
|
88
|
-
if (!action)
|
|
89
|
-
continue;
|
|
90
|
-
nextState[name] = action;
|
|
91
|
-
if (action.hidden && !prev.hidden)
|
|
92
|
-
unregister(name);
|
|
93
|
-
if (action.required !== prev.required) {
|
|
94
|
-
const baseValidations = Array.isArray(construction?.validations) ? [...construction.validations] : [];
|
|
95
|
-
const newValidations = action.required ? (baseValidations.includes("required") ? baseValidations : [...baseValidations, "required"]) : baseValidations.filter((v) => v !== "required");
|
|
96
|
-
setRegister({ name, validations: newValidations });
|
|
97
|
-
}
|
|
98
|
-
if (action.reset) {
|
|
99
|
-
const cur = valMap[name];
|
|
100
|
-
if (cur != null && cur !== "")
|
|
101
|
-
valueUpdates.push({ name, value: "" });
|
|
102
|
-
}
|
|
103
|
-
else if (action.value !== undefined && action.value !== valMap[name]) {
|
|
104
|
-
valueUpdates.push({ name, value: action.value });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (JSON.stringify(watchRef.current) !== JSON.stringify(nextState)) {
|
|
108
|
-
watchRef.current = nextState;
|
|
109
|
-
setWatchState(nextState);
|
|
110
|
-
}
|
|
111
|
-
if (valueUpdates.length > 0) {
|
|
112
|
-
const merged = [...values];
|
|
113
|
-
for (const upd of valueUpdates) {
|
|
114
|
-
const idx = merged.findIndex(v => v.name === upd.name);
|
|
115
|
-
if (idx >= 0)
|
|
116
|
-
merged[idx] = upd;
|
|
117
|
-
else
|
|
118
|
-
merged.push(upd);
|
|
119
|
-
}
|
|
120
|
-
setValues(merged);
|
|
121
|
-
}
|
|
122
|
-
}, [values, fields, mapGroups]);
|
|
123
|
-
const generateColClass = (col) => String(col).split(" ").map((c) => (c.includes(":") ? `${c.replace(":", ":col-span-")}` : `col-span-${c}`)).join(" ");
|
|
124
|
-
const inputMap = {
|
|
125
|
-
default: _components_1.InputComponent,
|
|
126
|
-
check: _components_1.InputCheckboxComponent,
|
|
127
|
-
currency: _components_1.InputCurrencyComponent,
|
|
128
|
-
date: _components_1.InputDateComponent,
|
|
129
|
-
datetime: _components_1.InputDatetimeComponent,
|
|
130
|
-
time: _components_1.InputTimeComponent,
|
|
131
|
-
number: _components_1.InputNumberComponent,
|
|
132
|
-
radio: _components_1.InputRadioComponent,
|
|
133
|
-
select: _components_1.SelectComponent,
|
|
134
|
-
"enter-password": _components_1.InputPasswordComponent,
|
|
135
|
-
otp: _components_1.InputOtpComponent,
|
|
136
|
-
image: _components_1.InputImageComponent,
|
|
137
|
-
map: _components_1.InputMapComponent,
|
|
138
|
-
cluster: () => null,
|
|
139
|
-
custom: () => null,
|
|
140
|
-
};
|
|
141
|
-
const renderInput = (form, key, prefix) => {
|
|
142
|
-
const inputType = form.type || "default";
|
|
143
|
-
const name = prefix ? `${prefix}.${form.construction?.name}` : form.construction?.name || "input_name";
|
|
144
|
-
if (form?.onHide?.(values))
|
|
145
|
-
return null;
|
|
146
|
-
const ws = watchState[name];
|
|
147
|
-
if (ws?.hidden)
|
|
148
|
-
return null;
|
|
149
|
-
if (inputType === "cluster") {
|
|
150
|
-
const { name: mapName, fields: innerForms, label, tip, wrap, className, min = 0 } = form.construction;
|
|
151
|
-
const groupKey = prefix ? `${prefix}.${mapName}` : mapName;
|
|
152
|
-
const group = mapGroups[groupKey] || Array.from({ length: Math.max(min, 1) }, (_, i) => i);
|
|
153
|
-
const addGroup = () => setMapGroups((prev) => ({ ...prev, [groupKey]: [...group, group.length > 0 ? Math.max(...group) + 1 : 0] }));
|
|
154
|
-
const removeGroup = (gIndex) => {
|
|
155
|
-
setMapGroups((prev) => ({ ...prev, [groupKey]: group.filter((g) => g !== gIndex) }));
|
|
156
|
-
unregisterPrefix(`${groupKey}[${gIndex}]`);
|
|
157
|
-
};
|
|
158
|
-
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)("form-supervision-cluster-item", wrap && "form-supervision-cluster-item-wrapped", className), children: [label && (0, jsx_runtime_1.jsxs)("p", { className: "input-label", children: [label, " ", gIndex + 1] }), tip && (0, jsx_runtime_1.jsx)("small", { className: "input-tip", children: tip }), (label || tip) && (0, jsx_runtime_1.jsx)("div", { className: "mb-2" }), (0, jsx_runtime_1.jsx)("div", { className: "form-supervision-cluster-grid", children: innerForms.map((inner, i) => renderInput(inner, i, `${mapName}[${gIndex}]`)) }), group.length > min && ((0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faTimes, paint: "danger", variant: "outline", size: "xs", className: (0, _utils_1.cn)("form-supervision-cluster-remove-btn", wrap && "form-supervision-cluster-remove-btn-wrapped"), onClick: () => removeGroup(gIndex) }))] }, gIndex))), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, label: `Tambah ${label || mapName}`, variant: "outline", size: "sm", onClick: addGroup }) })] }, key));
|
|
159
|
-
}
|
|
160
|
-
if (inputType === "custom") {
|
|
161
|
-
const customRender = form.construction;
|
|
162
|
-
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));
|
|
163
|
-
}
|
|
164
|
-
const Component = inputMap[inputType] || _components_1.InputComponent;
|
|
165
|
-
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), disabled: ws?.disabled, readOnly: ws?.readonly }) }, key));
|
|
166
|
-
};
|
|
167
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && (0, jsx_runtime_1.jsx)("h4", { className: (0, _utils_1.cn)("form-supervision-title", (0, _utils_1.pcn)(className, "title")), children: title }), (0, jsx_runtime_1.jsxs)("form", { className: (0, _utils_1.cn)("form-supervision-base", (0, _utils_1.pcn)(className, "base")), onSubmit: submit, children: [fresh && fields.map((f, i) => renderInput(f, i)), (0, jsx_runtime_1.jsx)("div", { className: "col-span-12", children: footerControl?.({ loading }) || ((0, jsx_runtime_1.jsx)("div", { className: "form-supervision-footer", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { type: "submit", label: "Simpan", icon: free_solid_svg_icons_1.faSave, loading: loading, className: (0, _utils_1.pcn)(className, "submit") }) })) })] }), (0, jsx_runtime_1.jsx)(_components_1.ModalConfirmComponent, { show: confirm.show, onClose: () => confirm.onClose(), icon: free_solid_svg_icons_1.faQuestionCircle, title: "Yakin", submitControl: { onSubmit: () => confirm?.onConfirm(), paint: "primary" }, children: (0, jsx_runtime_1.jsx)("p", { className: "form-supervision-confirm-text", children: "Yakin semua data sudah benar?" }) }), (0, jsx_runtime_1.jsx)(_components_1.ToastComponent, { show: modal == "failed", onClose: () => setModal(false), title: "Gagal", className: "form-supervision-toast-error header::text-danger", children: (0, jsx_runtime_1.jsx)("p", { className: "form-supervision-toast-text", children: "Data gagal disimpan, cek data dan koneksi internet lalu coba kembali!" }) }), (0, jsx_runtime_1.jsx)(_components_1.ToastComponent, { show: modal == "success", onClose: () => setModal(false), title: "Berhasil", className: "form-supervision-toast-success header::text-success", children: (0, jsx_runtime_1.jsx)("p", { className: "form-supervision-toast-text", children: "Data berhasil disimpan!" }) })] }));
|
|
168
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { conversion, FetchControlType, ShortcutHandler, UseResourceProps } from "@utils";
|
|
3
|
-
import { FloatingPageProps, FormType, ButtonProps, ModalConfirmProps, TableProps, ControlBarOptionType } from "@components";
|
|
4
|
-
export interface TableSupervisionColumnProps {
|
|
5
|
-
selector: string;
|
|
6
|
-
label?: string;
|
|
7
|
-
width?: string;
|
|
8
|
-
sortable?: boolean;
|
|
9
|
-
searchable?: boolean;
|
|
10
|
-
filterable?: boolean | {
|
|
11
|
-
type: "text" | "number" | "currency" | "date";
|
|
12
|
-
} | {
|
|
13
|
-
type: "select";
|
|
14
|
-
options: {
|
|
15
|
-
label: string;
|
|
16
|
-
value: any;
|
|
17
|
-
}[];
|
|
18
|
-
};
|
|
19
|
-
accessCode?: string;
|
|
20
|
-
item?: (data: any) => string | ReactNode;
|
|
21
|
-
tip?: string | ((data: any) => string);
|
|
22
|
-
exportable?: boolean | "default" | "optional" | "hidden";
|
|
23
|
-
importable?: boolean;
|
|
24
|
-
}
|
|
25
|
-
export interface TableSupervisionFormProps {
|
|
26
|
-
fields: string[] | (FormType & {
|
|
27
|
-
visibility?: "*" | "create" | "update";
|
|
28
|
-
})[];
|
|
29
|
-
defaultValue?: (item: Record<string, any> | null) => Promise<Record<string, any>> | Record<string, any>;
|
|
30
|
-
payload?: (values: any) => Promise<Record<string, any>> | object;
|
|
31
|
-
modalControl?: Omit<FloatingPageProps, "show" | "onClose" | "children">;
|
|
32
|
-
contentType?: "application/json" | "multipart/form-data";
|
|
33
|
-
}
|
|
34
|
-
export type TableSupervisionDetailProps = boolean | (string | {
|
|
35
|
-
label: string;
|
|
36
|
-
item: string | ((data: Record<string, any>) => ReactNode);
|
|
37
|
-
conversion?: keyof typeof conversion;
|
|
38
|
-
} | ((data: Record<string, any>) => ReactNode))[] | ((data: Record<string, any>) => void) | {
|
|
39
|
-
modal?: Omit<FloatingPageProps, "show" | "onClose" | "children">;
|
|
40
|
-
content?: boolean | (string | {
|
|
41
|
-
label: string;
|
|
42
|
-
item: string | ((data: Record<string, any>) => ReactNode);
|
|
43
|
-
conversion?: keyof typeof conversion;
|
|
44
|
-
} | ((data: Record<string, any>) => ReactNode))[] | ((data: Record<string, any>) => ReactNode);
|
|
45
|
-
action?: (data: Record<string, any>) => void;
|
|
46
|
-
};
|
|
47
|
-
export type TableSupervisionProps = {
|
|
48
|
-
fetchControl: UseResourceProps;
|
|
49
|
-
title?: string;
|
|
50
|
-
id?: string;
|
|
51
|
-
accessCode?: number;
|
|
52
|
-
urlParam?: boolean | {
|
|
53
|
-
compressed?: boolean;
|
|
54
|
-
};
|
|
55
|
-
columnControl?: string[] | TableSupervisionColumnProps[];
|
|
56
|
-
formControl?: TableSupervisionFormProps;
|
|
57
|
-
detailControl?: TableSupervisionDetailProps;
|
|
58
|
-
actionControl?: boolean | ('EDIT' | 'DELETE' | {
|
|
59
|
-
label: string;
|
|
60
|
-
modal?: Omit<ModalConfirmProps, "show" | "onClose">;
|
|
61
|
-
button?: ButtonProps;
|
|
62
|
-
shortcut?: {
|
|
63
|
-
key: string;
|
|
64
|
-
description: string;
|
|
65
|
-
};
|
|
66
|
-
} | ((row: Record<string, any>, setModal: (type: "EDIT" | "DELETE") => void, setDataSelected?: () => void, setShortcut?: (key: string, handler: ShortcutHandler, description?: string) => void) => ReactNode))[];
|
|
67
|
-
block?: boolean;
|
|
68
|
-
noIndex?: boolean;
|
|
69
|
-
actionBulkingControl?: TableProps["actionBulking"];
|
|
70
|
-
controlBar?: (ControlBarOptionType | "CREATE" | "IMPORT" | "EXPORT" | "PRINT")[];
|
|
71
|
-
responsiveControl?: {
|
|
72
|
-
mobile?: TableProps["responsiveControl"] extends {
|
|
73
|
-
mobile?: infer M;
|
|
74
|
-
} ? M | boolean : boolean;
|
|
75
|
-
};
|
|
76
|
-
importControl?: FetchControlType;
|
|
77
|
-
};
|
|
78
|
-
export declare function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam, importControl, }: TableSupervisionProps): import("react").JSX.Element;
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TableSupervisionComponent = TableSupervisionComponent;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const free_regular_svg_icons_1 = require("@fortawesome/free-regular-svg-icons");
|
|
8
|
-
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
9
|
-
const _utils_1 = require("@utils");
|
|
10
|
-
const _contexts_1 = require("@contexts");
|
|
11
|
-
const _components_1 = require("@components");
|
|
12
|
-
const ExportExcel = _utils_1.registry.get("ExportExcel");
|
|
13
|
-
const ImportExcel = _utils_1.registry.get("ImportExcel");
|
|
14
|
-
function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam, importControl, }) {
|
|
15
|
-
const { tableKey, tableControl, data, selected, setSelected, checks, setChecks, reset, focus } = (0, _utils_1.useTable)(fetchControl, id, title, (urlParam || true));
|
|
16
|
-
const { setToggle, toggle } = (0, _contexts_1.useToggleContext)();
|
|
17
|
-
const { isSm } = (0, _utils_1.useResponsive)();
|
|
18
|
-
const isDetailControlObject = detailControl && typeof detailControl === "object" && !Array.isArray(detailControl);
|
|
19
|
-
const detailAction = isDetailControlObject
|
|
20
|
-
? detailControl?.action
|
|
21
|
-
: (typeof detailControl === "function" ? detailControl : undefined);
|
|
22
|
-
const detailContent = isDetailControlObject
|
|
23
|
-
? detailControl?.content
|
|
24
|
-
: (typeof detailControl === "function" ? undefined : detailControl);
|
|
25
|
-
const detailModalProps = isDetailControlObject
|
|
26
|
-
? detailControl?.modal
|
|
27
|
-
: undefined;
|
|
28
|
-
const toggleKey = (0, react_1.useMemo)(() => _utils_1.conversion.strSnake(tableKey).toUpperCase(), [tableKey]);
|
|
29
|
-
// ============================
|
|
30
|
-
// ## Shortcut register
|
|
31
|
-
// ============================
|
|
32
|
-
(0, react_1.useEffect)(() => {
|
|
33
|
-
if (!isSm) {
|
|
34
|
-
if (controlBar == undefined || controlBar?.includes("CREATE")) {
|
|
35
|
-
_utils_1.shortcut.register("alt+n", () => {
|
|
36
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
37
|
-
setSelected(null);
|
|
38
|
-
}, "Tambah Data Baru");
|
|
39
|
-
}
|
|
40
|
-
if (controlBar?.includes("IMPORT")) {
|
|
41
|
-
_utils_1.shortcut.register("alt+i", () => {
|
|
42
|
-
setToggle(`MODAL_IMPORT_${toggleKey}`);
|
|
43
|
-
}, "Import Data Dari Excel");
|
|
44
|
-
}
|
|
45
|
-
if (controlBar?.includes("EXPORT")) {
|
|
46
|
-
_utils_1.shortcut.register("alt+e", () => {
|
|
47
|
-
setToggle(`MODAL_EXPORT_${toggleKey}`);
|
|
48
|
-
}, "Export Data Ke Excel");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return () => {
|
|
52
|
-
if (!isSm) {
|
|
53
|
-
_utils_1.shortcut.unregister("alt+n");
|
|
54
|
-
_utils_1.shortcut.unregister("alt+i");
|
|
55
|
-
_utils_1.shortcut.unregister("alt+e");
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}, [controlBar, isSm]);
|
|
59
|
-
(0, react_1.useEffect)(() => {
|
|
60
|
-
if (actionControl && Array.isArray(actionControl) && selected) {
|
|
61
|
-
actionControl.filter((ac) => typeof ac == "object")?.forEach((ac) => {
|
|
62
|
-
if (typeof ac == "object" && ac?.shortcut) {
|
|
63
|
-
_utils_1.shortcut.register(ac.shortcut.key, () => {
|
|
64
|
-
setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`);
|
|
65
|
-
}, ac.shortcut.description);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return () => {
|
|
70
|
-
if (actionControl && Array.isArray(actionControl)) {
|
|
71
|
-
actionControl.filter((ac) => typeof ac == "object")?.forEach((ac) => {
|
|
72
|
-
if (typeof ac == "object" && ac?.shortcut) {
|
|
73
|
-
_utils_1.shortcut.unregister(ac.shortcut.key);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}, [actionControl, selected]);
|
|
79
|
-
const columns = (0, react_1.useMemo)(() => {
|
|
80
|
-
return columnControl ? columnControl.map((col) => {
|
|
81
|
-
if (typeof col == "string") {
|
|
82
|
-
return {
|
|
83
|
-
selector: col,
|
|
84
|
-
label: col,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
return { ...col };
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
: data?.columns || data?.data?.at(0) ? Object.keys(data.data[0]).map((col) => {
|
|
92
|
-
return {
|
|
93
|
-
selector: col,
|
|
94
|
-
label: col,
|
|
95
|
-
};
|
|
96
|
-
})
|
|
97
|
-
: [];
|
|
98
|
-
}, [columnControl, data]);
|
|
99
|
-
const renderTableAction = (actions, item, options) => {
|
|
100
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("table-supervision-action-list", options?.className), children: (Array.isArray(actions) ? actions : (actions || actions == undefined) ? ['EDIT', "DELETE"] : [])?.map((action, key) => {
|
|
101
|
-
if (action == "EDIT") {
|
|
102
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faEdit, label: "Ubah", variant: "outline", paint: "warning", size: options?.size || "xs", rounded: true, onClick: () => {
|
|
103
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
104
|
-
item && setSelected?.(item);
|
|
105
|
-
} }, key));
|
|
106
|
-
}
|
|
107
|
-
if (action == "DELETE") {
|
|
108
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faTrash, label: "Hapus", variant: "outline", paint: "danger", size: options?.size || "xs", rounded: true, onClick: () => {
|
|
109
|
-
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
110
|
-
item && setSelected?.(item);
|
|
111
|
-
} }, key));
|
|
112
|
-
}
|
|
113
|
-
if (typeof action == "object") {
|
|
114
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { label: action.label, variant: "outline", paint: "primary", size: options?.size || "xs", rounded: true, onClick: () => {
|
|
115
|
-
setToggle(`MODAL_${_utils_1.conversion.strSnake(action.label).toUpperCase()}_${toggleKey}`);
|
|
116
|
-
item && setSelected?.(item);
|
|
117
|
-
}, ...action.button }, key));
|
|
118
|
-
}
|
|
119
|
-
if (typeof action == "function") {
|
|
120
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: action(item || {}, (type) => {
|
|
121
|
-
setToggle(`MODAL_${type}_${toggleKey}`);
|
|
122
|
-
item && setSelected?.(item);
|
|
123
|
-
}, () => item && setSelected?.(item)) }, key));
|
|
124
|
-
}
|
|
125
|
-
}) }) }));
|
|
126
|
-
};
|
|
127
|
-
// ============================
|
|
128
|
-
// ## Render detail page
|
|
129
|
-
// ============================
|
|
130
|
-
const detailPage = (0, react_1.useMemo)(() => {
|
|
131
|
-
if (detailContent === false || detailContent === undefined)
|
|
132
|
-
return null;
|
|
133
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "table-supervision-detail-container", children: (0, jsx_runtime_1.jsx)("div", { className: "table-supervision-detail-body", children: !!selected && (typeof detailContent === "object" && Array.isArray(detailContent) ? detailContent?.map((column, key) => {
|
|
134
|
-
if (typeof column === "string") {
|
|
135
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.TypographyColumnComponent, { title: columns?.find((c) => c.selector == column)?.label, content: selected[column] }, key));
|
|
136
|
-
}
|
|
137
|
-
else if (typeof column === "object" && column !== null) {
|
|
138
|
-
const colObj = column;
|
|
139
|
-
const rawContent = typeof colObj.item === "string" ? selected[colObj.item] : colObj.item(selected);
|
|
140
|
-
const conversionKey = colObj.conversion;
|
|
141
|
-
const content = conversionKey && _utils_1.conversion[conversionKey] ? _utils_1.conversion[conversionKey](rawContent) : rawContent;
|
|
142
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.TypographyColumnComponent, { title: colObj.label, content: content }, key));
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
return column?.(selected);
|
|
146
|
-
}
|
|
147
|
-
}) : typeof detailContent === "function" ? detailContent(selected) : columns?.map((column, key) => ((0, jsx_runtime_1.jsx)(_components_1.TypographyColumnComponent, { title: column.label, content: selected[column.selector] }, key)))) }) }));
|
|
148
|
-
}, [selected, detailContent, columns]);
|
|
149
|
-
// ============================
|
|
150
|
-
// ## Form preparation
|
|
151
|
-
// ============================
|
|
152
|
-
const fields = (0, react_1.useMemo)(() => {
|
|
153
|
-
return formControl?.fields?.length ? formControl?.fields.map((form) => {
|
|
154
|
-
return typeof form === "string" ? {
|
|
155
|
-
label: form,
|
|
156
|
-
name: _utils_1.conversion.strSnake(form),
|
|
157
|
-
type: "text",
|
|
158
|
-
visibility: "*"
|
|
159
|
-
} : {
|
|
160
|
-
...form,
|
|
161
|
-
visibility: form.visibility || "*"
|
|
162
|
-
};
|
|
163
|
-
}) : [];
|
|
164
|
-
}, [formControl]);
|
|
165
|
-
const formPage = (0, react_1.useMemo)(() => {
|
|
166
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.FormSupervisionComponent, { fields: fields, defaultValue: formControl?.defaultValue, payload: formControl?.payload, submitControl: fetchControl, onSuccess: () => {
|
|
167
|
-
setToggle(`MODAL_FORM_${toggleKey}`, false);
|
|
168
|
-
reset();
|
|
169
|
-
} }));
|
|
170
|
-
}, [selected, fields]);
|
|
171
|
-
const dataTables = (0, react_1.useMemo)(() => {
|
|
172
|
-
return data?.data?.map((item) => {
|
|
173
|
-
return {
|
|
174
|
-
...item,
|
|
175
|
-
action: renderTableAction(actionControl, item)
|
|
176
|
-
};
|
|
177
|
-
}) || [];
|
|
178
|
-
}, [actionControl, data]);
|
|
179
|
-
(0, react_1.useEffect)(() => {
|
|
180
|
-
if (toggle[`REFRESH_${toggleKey}`] != undefined)
|
|
181
|
-
reset();
|
|
182
|
-
}, [toggle[`REFRESH_${toggleKey}`]]);
|
|
183
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)("div", { children: "Loading..." }), children: [title && (0, jsx_runtime_1.jsx)("h1", { className: "table-supervision-title", children: title }), (0, jsx_runtime_1.jsx)(_components_1.TableComponent, { id: tableKey, controlBar: controlBar?.map((cb) => {
|
|
184
|
-
if (cb == "CREATE") {
|
|
185
|
-
if (isSm)
|
|
186
|
-
return;
|
|
187
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-create-wrapper", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, label: "Tambah Data", size: "sm", onClick: () => {
|
|
188
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
189
|
-
setSelected(null);
|
|
190
|
-
} }) }, "button-add"));
|
|
191
|
-
}
|
|
192
|
-
if (cb == "IMPORT") {
|
|
193
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faFileExcel, label: "Import", variant: "outline", className: "table-supervision-control-button", onClick: () => setToggle(`MODAL_IMPORT_${toggleKey}`), size: "sm" }) }, "import"));
|
|
194
|
-
}
|
|
195
|
-
if (cb == "EXPORT") {
|
|
196
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faFileExcel, label: "Export", variant: "outline", className: "table-supervision-control-button", onClick: () => setToggle(`MODAL_EXPORT_${toggleKey}`), size: "sm" }) }, "export-excel"));
|
|
197
|
-
}
|
|
198
|
-
if (cb == "PRINT") {
|
|
199
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faFilePdf, label: "Cetak", variant: "outline", className: "table-supervision-control-button", onClick: () => setToggle(`MODAL_PRINT_${toggleKey}`), size: "sm" }) }, "export-pdf"));
|
|
200
|
-
}
|
|
201
|
-
return cb;
|
|
202
|
-
}) || [
|
|
203
|
-
...(!isSm ? [
|
|
204
|
-
(0, jsx_runtime_1.jsx)("div", { className: "control-bar-create-wrapper", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, label: "Tambah Data", size: "sm", onClick: () => {
|
|
205
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
206
|
-
setSelected(null);
|
|
207
|
-
} }) }, "button-add")
|
|
208
|
-
] : []),
|
|
209
|
-
"SEARCH",
|
|
210
|
-
...(columns?.filter((c) => !!c.filterable)?.length ? ["FILTER"] : []),
|
|
211
|
-
...(columns?.filter((c) => !!c.sortable)?.length ? ["SORT"] : []),
|
|
212
|
-
"SELECTABLE", "REFRESH",
|
|
213
|
-
], columns: columns, data: dataTables, onRowClick: detailAction ? detailAction : (detailContent !== false && detailContent !== undefined) ? (e) => {
|
|
214
|
-
setToggle(`MODAL_SHOW_${toggleKey}`);
|
|
215
|
-
setSelected(e);
|
|
216
|
-
} : undefined, actionBulking: actionBulkingControl, checks: checks || [], onChangeChecks: (e) => setChecks(e), block: block, focus: focus, noIndex: noIndex, responsiveControl: responsiveControl ? {
|
|
217
|
-
mobile: responsiveControl?.mobile == true ? {
|
|
218
|
-
leftActionControl: (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('EDIT') ? {
|
|
219
|
-
icon: free_solid_svg_icons_1.faEdit,
|
|
220
|
-
onAction: (item) => {
|
|
221
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
222
|
-
item && setSelected?.(item);
|
|
223
|
-
}
|
|
224
|
-
} : undefined,
|
|
225
|
-
rightActionControl: (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('DELETE') ? {
|
|
226
|
-
icon: free_solid_svg_icons_1.faTrash,
|
|
227
|
-
onAction: (item) => {
|
|
228
|
-
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
229
|
-
item && setSelected?.(item);
|
|
230
|
-
}
|
|
231
|
-
} : undefined
|
|
232
|
-
} : responsiveControl?.mobile || undefined,
|
|
233
|
-
} : undefined, ...tableControl }), (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, className: "table-supervision-mobile-add-btn", size: "lg", rounded: true, onClick: () => {
|
|
234
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
235
|
-
setSelected(null);
|
|
236
|
-
} }), (detailContent !== false && detailContent !== undefined) && (isSm ? ((0, jsx_runtime_1.jsx)(_components_1.BottomSheetComponent, { show: !!toggle[`MODAL_SHOW_${toggleKey}`], onClose: () => setToggle(`MODAL_SHOW_${toggleKey}`, false), className: "table-supervision-modal", footer: renderTableAction(actionControl, undefined, { className: isSm ? "justify-end p-2 bg-background" : "justify-end", size: isSm ? "sm" : "md" }), size: "98vh", ...detailModalProps, children: detailPage })) : ((0, jsx_runtime_1.jsx)(_components_1.FloatingPageComponent, { show: !!toggle[`MODAL_SHOW_${toggleKey}`], onClose: () => setToggle(`MODAL_SHOW_${toggleKey}`, false), title: "Detail", className: "table-supervision-modal", footer: renderTableAction(actionControl, undefined, { className: isSm ? "justify-end p-2 bg-background" : "justify-end", size: isSm ? "sm" : "md" }), ...detailModalProps, children: detailPage }))), isSm ? ((0, jsx_runtime_1.jsx)(_components_1.BottomSheetComponent, { show: !!toggle[`MODAL_FORM_${toggleKey}`], onClose: () => setToggle(`MODAL_FORM_${toggleKey}`, false), className: (0, _utils_1.cn)("table-supervision-modal", formControl?.modalControl?.className), size: "98vh", children: (0, jsx_runtime_1.jsx)("div", { className: "table-supervision-form-mobile-container", children: formPage }) })) : ((0, jsx_runtime_1.jsx)(_components_1.FloatingPageComponent, { show: !!toggle[`MODAL_FORM_${toggleKey}`], onClose: () => setToggle(`MODAL_FORM_${toggleKey}`, false), title: !!selected ? "Ubah Data" : "Tambah Data", className: (0, _utils_1.cn)("table-supervision-modal", formControl?.modalControl?.className), children: (0, jsx_runtime_1.jsx)("div", { className: "table-supervision-form-container", children: formPage }) })), ExportExcel && ((0, jsx_runtime_1.jsx)(_components_1.FloatingPageComponent, { show: !!toggle[`MODAL_EXPORT_${toggleKey}`], onClose: () => setToggle(`MODAL_EXPORT_${toggleKey}`, false), title: "Export Ke Excel", className: "table-supervision-large-modal", children: (0, jsx_runtime_1.jsx)(ExportExcel, { fetchControl: fetchControl, filename: "Export - " + title, columnControl: columns?.map((cc) => ({
|
|
237
|
-
label: cc.label || "",
|
|
238
|
-
selector: cc.selector || "",
|
|
239
|
-
status: cc.exportable === false ? "hidden" : cc.exportable === true ? "default" : typeof cc.exportable === "string" ? cc.exportable : undefined,
|
|
240
|
-
})) }) })), ImportExcel && ((0, jsx_runtime_1.jsx)(_components_1.FloatingPageComponent, { show: !!toggle[`MODAL_IMPORT_${toggleKey}`], onClose: () => setToggle(`MODAL_IMPORT_${toggleKey}`, false), title: "Import Dari Excel", className: "table-supervision-large-modal", children: (0, jsx_runtime_1.jsx)(ImportExcel, { submitControl: importControl, fetchControl: fetchControl.path ? {
|
|
241
|
-
path: fetchControl.path,
|
|
242
|
-
} : undefined, columnControl: columns?.filter((cc) => cc.importable !== false).map((cc) => ({
|
|
243
|
-
label: cc.label || "",
|
|
244
|
-
selector: cc.selector || "",
|
|
245
|
-
})) }) })), (0, jsx_runtime_1.jsx)(_components_1.ModalConfirmComponent, { show: !!toggle[`MODAL_DELETE_${toggleKey}`], onClose: () => setToggle(`MODAL_DELETE_${toggleKey}`, false), icon: free_regular_svg_icons_1.faQuestionCircle, title: `Menghapus Data?`, submitControl: {
|
|
246
|
-
onSubmit: {
|
|
247
|
-
...(fetchControl.path
|
|
248
|
-
? { path: `${fetchControl.path}/${selected?.id || ""}` }
|
|
249
|
-
: fetchControl.url ? { url: `${fetchControl.url}/${selected?.id || ""}` }
|
|
250
|
-
: { idb: { ...fetchControl?.idb, id: selected?.id || "" } }),
|
|
251
|
-
method: "DELETE",
|
|
252
|
-
},
|
|
253
|
-
onSuccess: () => {
|
|
254
|
-
reset();
|
|
255
|
-
setToggle(`MODAL_DELETE_${toggleKey}`, false);
|
|
256
|
-
},
|
|
257
|
-
}, children: columns?.at(0)?.selector && selected ? ((0, jsx_runtime_1.jsxs)("p", { className: "table-supervision-confirm-text", children: ["Yakin menghapus ", (0, jsx_runtime_1.jsxs)("span", { className: "table-supervision-confirm-item-name", children: ["\"", selected[columns?.at(0)?.selector || ""], "\""] }), "?"] })) : ((0, jsx_runtime_1.jsx)("p", { className: "table-supervision-confirm-text", children: "Yakin yang dihapus sudah benar?" })) }), actionControl && Array.isArray(actionControl) && actionControl.filter((ac) => typeof ac == "object")?.map((ac, acKey) => {
|
|
258
|
-
const submitControl = ac.modal?.submitControl?.onSubmit;
|
|
259
|
-
return ((0, jsx_runtime_1.jsx)(_components_1.ModalConfirmComponent, { show: !!toggle[`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`], onClose: () => setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`, false), icon: free_regular_svg_icons_1.faQuestionCircle, title: `${ac.label} Data?`, submitControl: {
|
|
260
|
-
onSubmit: {
|
|
261
|
-
...(submitControl?.path
|
|
262
|
-
? { path: `${submitControl.path}/${selected?.id || ""}` }
|
|
263
|
-
: submitControl?.url ? { url: `${submitControl.url}/${selected?.id || ""}` }
|
|
264
|
-
: { idb: { ...submitControl?.idb, id: selected?.id || "" } }),
|
|
265
|
-
...ac.modal?.submitControl?.onSubmit,
|
|
266
|
-
},
|
|
267
|
-
onSuccess: () => {
|
|
268
|
-
reset();
|
|
269
|
-
setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`, false);
|
|
270
|
-
},
|
|
271
|
-
}, ...ac.modal, children: columns?.at(0)?.selector && selected ? ((0, jsx_runtime_1.jsxs)("p", { className: "table-supervision-confirm-text", children: ["Yakin melakukan aksi untuk data ", (0, jsx_runtime_1.jsxs)("span", { className: "table-supervision-confirm-item-name", children: ["\"", selected[columns?.at(0)?.selector || ""], "\""] }), "?"] })) : ((0, jsx_runtime_1.jsx)("p", { className: "table-supervision-confirm-text", children: "Yakin aksi yang dilakukan sudah benar?" })) }, acKey));
|
|
272
|
-
})] }) }));
|
|
273
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ApiFilterType } from '@utils';
|
|
3
|
-
import { FilterColumnOption } from '@components';
|
|
4
|
-
export type ControlBarOptionType = "SEARCH" | "SEARCHABLE" | "FILTER" | "SELECTABLE" | "REFRESH" | ReactNode;
|
|
5
|
-
export interface ControlBarProps {
|
|
6
|
-
id?: string;
|
|
7
|
-
options?: ControlBarOptionType[];
|
|
8
|
-
className?: string;
|
|
9
|
-
search?: string;
|
|
10
|
-
onSearch?: (searchable: string) => void;
|
|
11
|
-
searchableOptions?: {
|
|
12
|
-
label: string | ReactNode;
|
|
13
|
-
selector: string;
|
|
14
|
-
}[];
|
|
15
|
-
searchable?: string[];
|
|
16
|
-
onSearchable?: (searchable: string[]) => void;
|
|
17
|
-
selectableOptions?: {
|
|
18
|
-
label: string | ReactNode;
|
|
19
|
-
selector: string;
|
|
20
|
-
}[];
|
|
21
|
-
selectable?: string[];
|
|
22
|
-
onSelectable?: (searchable: string[]) => void;
|
|
23
|
-
sortableOptions?: {
|
|
24
|
-
label: string | ReactNode;
|
|
25
|
-
selector: string;
|
|
26
|
-
}[];
|
|
27
|
-
sort?: string[];
|
|
28
|
-
onSort?: (sort: string[]) => void;
|
|
29
|
-
filterableColumns?: FilterColumnOption[];
|
|
30
|
-
onFilter?: (filters: ApiFilterType[]) => void;
|
|
31
|
-
filter?: ApiFilterType[];
|
|
32
|
-
onRefresh?: () => void;
|
|
33
|
-
}
|
|
34
|
-
export declare function ControlBarComponent({ id, options, className, search, onSearch, searchableOptions, searchable, onSearchable, selectableOptions, selectable, onSelectable, sortableOptions, sort, onSort, filterableColumns, onFilter, filter, onRefresh }: ControlBarProps): import("react").JSX.Element;
|