@skalfa/skalfa-component 1.0.7 → 1.0.9
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 +87 -0
- package/src/breadcrumb/Breadcrumb.component.tsx +79 -0
- package/src/button/Button.component.tsx +89 -0
- package/src/card/AlertCard.component.tsx +69 -0
- package/src/card/Card.component.tsx +25 -0
- package/src/card/DashboardCard.component.tsx +44 -0
- package/src/card/GalleryCard.component.tsx +50 -0
- package/src/card/ProductCard.component.tsx +65 -0
- package/src/card/ProfileCard.component.tsx +71 -0
- package/src/carousel/Carousel.component.tsx +111 -0
- package/src/chip/Chip.component.tsx +38 -0
- package/src/contexts-mock.ts +6 -0
- package/src/index.ts +70 -0
- package/src/input/Checkbox.component.tsx +102 -0
- package/src/input/Input.component.tsx +334 -0
- package/src/input/InputCheckbox.component.tsx +174 -0
- package/src/input/InputCurrency.component.tsx +165 -0
- package/src/input/InputDate.component.tsx +355 -0
- package/src/input/InputDatetime.component.tsx +267 -0
- package/src/input/InputDocument.component.tsx +360 -0
- package/src/input/InputImage.component.tsx +534 -0
- package/src/input/InputNumber.component.tsx +193 -0
- package/src/input/InputOtp.component.tsx +169 -0
- package/src/input/InputPassword.component.tsx +245 -0
- package/src/input/InputRadio.component.tsx +174 -0
- package/src/input/InputTime.component.tsx +280 -0
- package/src/input/InputValues.component.tsx +70 -0
- package/src/input/Radio.component.tsx +98 -0
- package/src/input/Select.component.tsx +557 -0
- package/src/modal/BottomSheet.component.tsx +246 -0
- package/src/modal/FloatingPage.component.tsx +133 -0
- package/src/modal/Modal.component.tsx +94 -0
- package/src/modal/ModalConfirm.component.tsx +204 -0
- package/src/modal/Toast.component.tsx +124 -0
- package/src/nav/Bottombar.component.tsx +71 -0
- package/src/nav/Footer.component.tsx +176 -0
- package/src/nav/Headbar.component.tsx +33 -0
- package/src/nav/Navbar.component.tsx +137 -0
- package/src/nav/Sidebar.component.tsx +307 -0
- package/src/nav/Tabbar.component.tsx +61 -0
- package/src/nav/Wizard.component.tsx +80 -0
- package/src/supervision/FormSupervision.component.tsx +404 -0
- package/src/supervision/TableSupervision.component.tsx +653 -0
- package/src/table/ControlBar.component.tsx +501 -0
- package/src/table/FilterComponent.tsx +517 -0
- package/src/table/Pagination.component.tsx +152 -0
- package/src/table/Table.component.tsx +436 -0
- package/src/typography/TypographyArticle.component.tsx +26 -0
- package/src/typography/TypographyColumn.component.tsx +20 -0
- package/src/typography/TypographyContent.component.tsx +20 -0
- package/src/typography/TypographyTips.component.tsx +20 -0
- package/src/wrap/Draggable.component.tsx +303 -0
- package/src/wrap/Image.component.tsx +10 -0
- package/src/wrap/OutsideClick.component.tsx +48 -0
- package/src/wrap/ScrollContainer.component.tsx +107 -0
- package/src/wrap/ShortcutProvider.tsx +57 -0
- package/src/wrap/Swipe.component.tsx +121 -0
|
@@ -4,87 +4,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.TableSupervisionComponent = TableSupervisionComponent;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
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
7
|
const _utils_1 = require("@utils");
|
|
10
8
|
const _contexts_1 = require("@contexts");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const Table_component_1 = require("../table/Table.component");
|
|
14
|
-
const FormSupervision_component_1 = require("./FormSupervision.component");
|
|
15
|
-
const ModalConfirm_component_1 = require("../modal/ModalConfirm.component");
|
|
16
|
-
const TypographyColumn_component_1 = require("../typography/TypographyColumn.component");
|
|
17
|
-
const BottomSheet_component_1 = require("../modal/BottomSheet.component");
|
|
9
|
+
const __1 = require("../");
|
|
10
|
+
const skalfa_lang_1 = require("@skalfa/skalfa-lang");
|
|
18
11
|
const ExportExcel = _utils_1.registry.get("ExportExcel");
|
|
19
12
|
const ImportExcel = _utils_1.registry.get("ImportExcel");
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
;
|
|
14
|
+
;
|
|
15
|
+
function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, onRowClick, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam, }) {
|
|
16
|
+
const l = (0, skalfa_lang_1.useLang)();
|
|
17
|
+
const { tableKey, tableControl, data, selected, setSelected, checks, setChecks, reset, focus, setFocus } = (0, _utils_1.useTable)(fetchControl, id, title, (urlParam || true));
|
|
22
18
|
const { setToggle, toggle } = (0, _contexts_1.useToggleContext)();
|
|
23
19
|
const { isSm } = (0, _utils_1.useResponsive)();
|
|
24
|
-
const isDetailControlObject = detailControl && typeof detailControl === "object" && !Array.isArray(detailControl);
|
|
25
|
-
const detailAction = isDetailControlObject
|
|
26
|
-
? detailControl?.action
|
|
27
|
-
: (typeof detailControl === "function" ? detailControl : undefined);
|
|
28
|
-
const detailContent = isDetailControlObject
|
|
29
|
-
? detailControl?.content
|
|
30
|
-
: (typeof detailControl === "function" ? undefined : detailControl);
|
|
31
|
-
const detailModalProps = isDetailControlObject
|
|
32
|
-
? detailControl?.modal
|
|
33
|
-
: undefined;
|
|
34
20
|
const toggleKey = (0, react_1.useMemo)(() => _utils_1.conversion.strSnake(tableKey).toUpperCase(), [tableKey]);
|
|
35
|
-
// ============================
|
|
36
|
-
// ## Shortcut register
|
|
37
|
-
// ============================
|
|
38
21
|
(0, react_1.useEffect)(() => {
|
|
39
|
-
if (!
|
|
40
|
-
|
|
41
|
-
|
|
22
|
+
if (data?.data?.length && !toggle[`MODAL_DELETE_${toggleKey}`] && !toggle[`MODAL_DELETE_${toggleKey}`] && !toggle[`MODAL_SHOW_${toggleKey}`]) {
|
|
23
|
+
_utils_1.shortcut.register("arrowdown", () => {
|
|
24
|
+
const max = data?.data?.length - 1;
|
|
25
|
+
setFocus(focus == null ? 0 : focus >= max ? max : (focus + 1));
|
|
26
|
+
}, "Pilih data kebawah");
|
|
27
|
+
_utils_1.shortcut.register("arrowup", () => {
|
|
28
|
+
setFocus(focus == null ? 0 : focus <= 0 ? 0 : (focus - 1));
|
|
29
|
+
}, "Pilih data keatas");
|
|
30
|
+
if (focus != null) {
|
|
31
|
+
_utils_1.shortcut.register("delete", () => {
|
|
32
|
+
setSelected(data?.data?.at(focus));
|
|
33
|
+
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
34
|
+
}, "Delete data yang dipilih");
|
|
35
|
+
_utils_1.shortcut.register(" ", () => {
|
|
36
|
+
setSelected(data?.data?.at(focus));
|
|
42
37
|
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (controlBar?.includes("EXPORT")) {
|
|
52
|
-
_utils_1.shortcut.register("alt+e", () => {
|
|
53
|
-
setToggle(`MODAL_EXPORT_${toggleKey}`);
|
|
54
|
-
}, "Export Data Ke Excel");
|
|
38
|
+
}, "Edit data yang dipilih");
|
|
39
|
+
_utils_1.shortcut.register("enter", () => {
|
|
40
|
+
setSelected(data?.data?.at(focus));
|
|
41
|
+
setToggle(`MODAL_SHOW_${toggleKey}`);
|
|
42
|
+
}, "Detail data yang dipilih");
|
|
43
|
+
_utils_1.shortcut.register("escape", () => {
|
|
44
|
+
setFocus(null);
|
|
45
|
+
}, "Kembali");
|
|
55
46
|
}
|
|
56
47
|
}
|
|
57
48
|
return () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
_utils_1.shortcut.unregister("arrowdown");
|
|
50
|
+
_utils_1.shortcut.unregister("arrowup");
|
|
51
|
+
_utils_1.shortcut.unregister("delete");
|
|
52
|
+
_utils_1.shortcut.unregister(" ");
|
|
53
|
+
_utils_1.shortcut.unregister("enter");
|
|
54
|
+
_utils_1.shortcut.unregister("escape");
|
|
63
55
|
};
|
|
64
|
-
}, [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (typeof ac == "object" && ac?.shortcut) {
|
|
69
|
-
_utils_1.shortcut.register(ac.shortcut.key, () => {
|
|
70
|
-
setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`);
|
|
71
|
-
}, ac.shortcut.description);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return () => {
|
|
76
|
-
if (actionControl && Array.isArray(actionControl)) {
|
|
77
|
-
actionControl.filter((ac) => typeof ac == "object")?.forEach((ac) => {
|
|
78
|
-
if (typeof ac == "object" && ac?.shortcut) {
|
|
79
|
-
_utils_1.shortcut.unregister(ac.shortcut.key);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}, [actionControl, selected]);
|
|
56
|
+
}, [data?.data, actionControl, focus, toggle[`MODAL_DELETE_${toggleKey}`], toggle[`MODAL_DELETE_${toggleKey}`], toggle[`MODAL_SHOW_${toggleKey}`]]);
|
|
57
|
+
// ============================
|
|
58
|
+
// ## Column preparation
|
|
59
|
+
// ============================
|
|
85
60
|
const columns = (0, react_1.useMemo)(() => {
|
|
86
|
-
return columnControl ? columnControl.map((col) => {
|
|
87
|
-
if (typeof col
|
|
61
|
+
return columnControl?.length ? columnControl.map((col) => {
|
|
62
|
+
if (typeof col === "string") {
|
|
88
63
|
return {
|
|
89
64
|
selector: col,
|
|
90
65
|
label: col,
|
|
@@ -103,177 +78,216 @@ function TableSupervisionComponent({ title, id, fetchControl, columnControl, for
|
|
|
103
78
|
: [];
|
|
104
79
|
}, [columnControl, data]);
|
|
105
80
|
const renderTableAction = (actions, item, options) => {
|
|
106
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("flex items-center gap-2", options?.className), children: (Array.isArray(actions) ? actions : (actions || actions == undefined) ? ['EDIT', "DELETE"] : [])?.map((action, key) => {
|
|
107
82
|
if (action == "EDIT") {
|
|
108
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
83
|
+
return ((0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/edit", label: l.base.edit ? l.base.edit() : "Edit", variant: "outline", paint: "warning", size: options?.size || "xs", rounded: true, onClick: () => {
|
|
109
84
|
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
110
85
|
item && setSelected?.(item);
|
|
111
86
|
} }, key));
|
|
112
87
|
}
|
|
113
88
|
if (action == "DELETE") {
|
|
114
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
89
|
+
return ((0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/trash", label: l.base.delete ? l.base.delete() : "Delete", variant: "outline", paint: "danger", size: options?.size || "xs", rounded: true, onClick: () => {
|
|
115
90
|
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
116
91
|
item && setSelected?.(item);
|
|
117
92
|
} }, key));
|
|
118
93
|
}
|
|
119
94
|
if (typeof action == "object") {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
95
|
+
(0, jsx_runtime_1.jsx)(__1.ButtonComponent, { label: action?.button?.label || action?.label, variant: action?.button?.variant || "outline", paint: action?.button?.paint || "primary", size: action?.button?.size || options?.size || "xs", rounded: action?.button?.rounded || true, onClick: () => {
|
|
96
|
+
if (action?.button?.onClick) {
|
|
97
|
+
action?.button?.onClick(item);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
setToggle(`MODAL_${_utils_1.conversion.strSnake(action?.label).toUpperCase()}_${toggleKey}`);
|
|
101
|
+
item && setSelected?.(item);
|
|
102
|
+
}
|
|
103
|
+
}, ...action.button }, `action-object-${key}`);
|
|
124
104
|
}
|
|
125
105
|
if (typeof action == "function") {
|
|
126
|
-
return ((0, jsx_runtime_1.jsx)("
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
106
|
+
return ((0, jsx_runtime_1.jsx)("span", { children: action(item || {}, (type) => {
|
|
107
|
+
if (type == "EDIT") {
|
|
108
|
+
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
109
|
+
item && setSelected?.(item);
|
|
110
|
+
}
|
|
111
|
+
if (type == "DELETE") {
|
|
112
|
+
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
113
|
+
item && setSelected?.(item);
|
|
114
|
+
}
|
|
115
|
+
}, () => item && setSelected?.(item), () => { }, options?.size) }, `action-fn-${key}`));
|
|
130
116
|
}
|
|
117
|
+
return (0, jsx_runtime_1.jsx)("span", {}, `action-default-${key}`);
|
|
131
118
|
}) }) }));
|
|
132
119
|
};
|
|
133
120
|
// ============================
|
|
121
|
+
// ## Data table preparation
|
|
122
|
+
// ============================
|
|
123
|
+
const dataTables = (0, react_1.useMemo)(() => {
|
|
124
|
+
return data?.data?.map((row) => {
|
|
125
|
+
return {
|
|
126
|
+
...row,
|
|
127
|
+
action: renderTableAction(actionControl, row),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}, [actionControl, data]);
|
|
131
|
+
// ============================
|
|
134
132
|
// ## Render detail page
|
|
135
133
|
// ============================
|
|
136
134
|
const detailPage = (0, react_1.useMemo)(() => {
|
|
137
|
-
if (
|
|
135
|
+
if (!toggle[`MODAL_SHOW_${toggleKey}`])
|
|
138
136
|
return null;
|
|
139
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "
|
|
137
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("flex flex-col gap-y-4"), children: !!selected && (typeof detailControl === "object" && detailControl?.length ? detailControl?.map((column, key) => {
|
|
140
138
|
if (typeof column === "string") {
|
|
141
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
139
|
+
return ((0, jsx_runtime_1.jsx)(__1.TypographyColumnComponent, { title: columns?.find((c) => c.selector == column)?.label, content: selected[column] }, key));
|
|
142
140
|
}
|
|
143
|
-
else if (typeof column === "object"
|
|
144
|
-
|
|
145
|
-
const rawContent = typeof colObj.item === "string" ? selected[colObj.item] : colObj.item(selected);
|
|
146
|
-
const conversionKey = colObj.conversion;
|
|
147
|
-
const content = conversionKey && _utils_1.conversion[conversionKey] ? _utils_1.conversion[conversionKey](rawContent) : rawContent;
|
|
148
|
-
return ((0, jsx_runtime_1.jsx)(TypographyColumn_component_1.TypographyColumnComponent, { title: colObj.label, content: content }, key));
|
|
141
|
+
else if (typeof column === "object") {
|
|
142
|
+
return ((0, jsx_runtime_1.jsx)(__1.TypographyColumnComponent, { title: column?.label, content: typeof column?.item === "string" ? selected[column?.item] : column?.item(selected) }, key));
|
|
149
143
|
}
|
|
150
144
|
else {
|
|
151
145
|
return column?.(selected);
|
|
152
146
|
}
|
|
153
|
-
}) : typeof
|
|
154
|
-
}, [selected,
|
|
147
|
+
}) : typeof detailControl == "function" ? detailControl(selected) : columns?.map((column, key) => ((0, jsx_runtime_1.jsx)(__1.TypographyColumnComponent, { title: column.label, content: selected[column.selector] }, key)))) }) }));
|
|
148
|
+
}, [selected, detailControl]);
|
|
155
149
|
// ============================
|
|
156
150
|
// ## Form preparation
|
|
157
151
|
// ============================
|
|
158
152
|
const fields = (0, react_1.useMemo)(() => {
|
|
159
153
|
return formControl?.fields?.length ? formControl?.fields.map((form) => {
|
|
160
154
|
return typeof form === "string" ? {
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
col: 12,
|
|
156
|
+
type: "text",
|
|
157
|
+
construction: {
|
|
158
|
+
name: form,
|
|
159
|
+
label: form,
|
|
160
|
+
},
|
|
161
|
+
} : { ...form };
|
|
162
|
+
}) : data?.forms || data?.columns || columnControl?.map((col) => {
|
|
163
|
+
return {
|
|
164
|
+
col: 12,
|
|
163
165
|
type: "text",
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
construction: {
|
|
167
|
+
name: typeof col == "string" ? col : col?.selector,
|
|
168
|
+
label: typeof col == "string" ? col : col?.label,
|
|
169
|
+
placeholder: `Masukkan ${typeof col == "string" ? col : col?.label}...`,
|
|
170
|
+
},
|
|
168
171
|
};
|
|
169
|
-
})
|
|
170
|
-
}, [formControl]);
|
|
171
|
-
const formPage = (0, react_1.useMemo)(() => {
|
|
172
|
-
return ((0, jsx_runtime_1.jsx)(FormSupervision_component_1.FormSupervisionComponent, { fields: fields, defaultValue: formControl?.defaultValue, payload: formControl?.payload, submitControl: fetchControl, onSuccess: () => {
|
|
173
|
-
setToggle(`MODAL_FORM_${toggleKey}`, false);
|
|
174
|
-
reset();
|
|
175
|
-
} }));
|
|
176
|
-
}, [selected, fields]);
|
|
177
|
-
const dataTables = (0, react_1.useMemo)(() => {
|
|
178
|
-
return data?.data?.map((item) => {
|
|
172
|
+
}) || (data?.data?.at(0) ? Object.keys(data.data[0]).map((col) => {
|
|
179
173
|
return {
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
col: 12,
|
|
175
|
+
type: "text",
|
|
176
|
+
construction: {
|
|
177
|
+
name: col,
|
|
178
|
+
label: col,
|
|
179
|
+
placeholder: `Masukkan ${col}...`,
|
|
180
|
+
},
|
|
182
181
|
};
|
|
183
|
-
})
|
|
184
|
-
|
|
182
|
+
})
|
|
183
|
+
: []);
|
|
184
|
+
}, [formControl, data]);
|
|
185
|
+
// ============================
|
|
186
|
+
// ## Render form page
|
|
187
|
+
// ============================
|
|
188
|
+
const formPage = (0, react_1.useMemo)(async () => {
|
|
189
|
+
return ((0, jsx_runtime_1.jsx)(__1.FormSupervisionComponent, { submitControl: fetchControl.path ? {
|
|
190
|
+
path: `${fetchControl.path}/${selected?.id || ""}`,
|
|
191
|
+
method: !selected?.id ? "POST" : "PUT",
|
|
192
|
+
} : fetchControl.url ? {
|
|
193
|
+
url: `${fetchControl.url}/${selected?.id || ""}`,
|
|
194
|
+
method: !selected?.id ? "POST" : "PUT",
|
|
195
|
+
} : { idb: fetchControl?.idb }, fields: fields?.filter((f) => f.visibility ? !selected?.id ? ["*", "create"]?.includes(f.visibility) : ["*", "update"]?.includes(f.visibility) : true), defaultValue: formControl?.defaultValue ? await formControl?.defaultValue(selected || null) : selected, payload: formControl?.payload, onSuccess: () => {
|
|
196
|
+
reset();
|
|
197
|
+
setTimeout(() => { setToggle(`MODAL_FORM_${toggleKey}`, false); }, 900);
|
|
198
|
+
} }));
|
|
199
|
+
}, [selected, fetchControl, formControl]);
|
|
185
200
|
(0, react_1.useEffect)(() => {
|
|
186
201
|
if (toggle[`REFRESH_${toggleKey}`] != undefined)
|
|
187
202
|
reset();
|
|
188
203
|
}, [toggle[`REFRESH_${toggleKey}`]]);
|
|
189
|
-
return ((0, jsx_runtime_1.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
195
|
-
setSelected(null);
|
|
196
|
-
} }) }, "button-add"));
|
|
197
|
-
}
|
|
198
|
-
if (cb == "IMPORT") {
|
|
199
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(Button_component_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"));
|
|
200
|
-
}
|
|
201
|
-
if (cb == "EXPORT") {
|
|
202
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(Button_component_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"));
|
|
203
|
-
}
|
|
204
|
-
if (cb == "PRINT") {
|
|
205
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "control-bar-button-wrapper", children: (0, jsx_runtime_1.jsx)(Button_component_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"));
|
|
206
|
-
}
|
|
207
|
-
return cb;
|
|
208
|
-
}) || [
|
|
209
|
-
...(!isSm ? [
|
|
210
|
-
(0, jsx_runtime_1.jsx)("div", { className: "control-bar-create-wrapper", children: (0, jsx_runtime_1.jsx)(Button_component_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, label: "Tambah Data", size: "sm", onClick: () => {
|
|
211
|
-
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
212
|
-
setSelected(null);
|
|
213
|
-
} }) }, "button-add")
|
|
214
|
-
] : []),
|
|
215
|
-
"SEARCH",
|
|
216
|
-
...(columns?.filter((c) => !!c.filterable)?.length ? ["FILTER"] : []),
|
|
217
|
-
...(columns?.filter((c) => !!c.sortable)?.length ? ["SORT"] : []),
|
|
218
|
-
"SELECTABLE", "REFRESH",
|
|
219
|
-
], columns: columns, data: dataTables, onRowClick: detailAction ? detailAction : (detailContent !== false && detailContent !== undefined) ? (e) => {
|
|
220
|
-
setToggle(`MODAL_SHOW_${toggleKey}`);
|
|
221
|
-
setSelected(e);
|
|
222
|
-
} : undefined, actionBulking: actionBulkingControl, checks: checks || [], onChangeChecks: (e) => setChecks(e), block: block, focus: focus, noIndex: noIndex, responsiveControl: responsiveControl ? {
|
|
223
|
-
mobile: responsiveControl?.mobile == true ? {
|
|
224
|
-
leftActionControl: (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('EDIT') ? {
|
|
225
|
-
icon: free_solid_svg_icons_1.faEdit,
|
|
226
|
-
onAction: (item) => {
|
|
204
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && (0, jsx_runtime_1.jsx)("h1", { className: "text-lg lg:text-xl font-bold mb-2 lg:mb-4", children: title }), (0, jsx_runtime_1.jsx)(__1.TableComponent, { id: tableKey, controlBar: controlBar?.map((cb) => {
|
|
205
|
+
if (cb == "CREATE") {
|
|
206
|
+
if (isSm)
|
|
207
|
+
return;
|
|
208
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "pl-1.5 pr-3 mr-2 border-r", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/plus", label: "Tambah Data", size: "sm", onClick: () => {
|
|
227
209
|
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} :
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
210
|
+
setSelected(null);
|
|
211
|
+
} }) }, "button-add"));
|
|
212
|
+
}
|
|
213
|
+
if (cb == "IMPORT") {
|
|
214
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "px-1.5 rounded-md relative", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/file-excel", label: "Import", variant: "outline", className: "!text-foreground", onClick: () => setToggle(`MODAL_IMPORT_${toggleKey}`), size: "sm" }) }, "import"));
|
|
215
|
+
}
|
|
216
|
+
if (cb == "EXPORT") {
|
|
217
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "px-1.5 rounded-md relative", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/file-excel", label: "Export", variant: "outline", className: "!text-foreground", onClick: () => setToggle(`MODAL_EXPORT_${toggleKey}`), size: "sm" }) }, "export-excel"));
|
|
218
|
+
}
|
|
219
|
+
if (cb == "PRINT") {
|
|
220
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "px-1.5 rounded-md relative", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/file-pdf", label: "Cetak", variant: "outline", className: "!text-foreground", onClick: () => setToggle(`MODAL_PRINT_${toggleKey}`), size: "sm" }) }, "export-pdf"));
|
|
221
|
+
}
|
|
222
|
+
return cb;
|
|
223
|
+
}) || [
|
|
224
|
+
...(!isSm ? [
|
|
225
|
+
(0, jsx_runtime_1.jsx)("div", { className: "pl-1.5 pr-3 mr-2 border-r", children: (0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/plus", label: "Tambah Data", size: "sm", onClick: () => {
|
|
226
|
+
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
227
|
+
setSelected(null);
|
|
228
|
+
} }) }, "button-add")
|
|
229
|
+
] : []),
|
|
230
|
+
"SEARCH",
|
|
231
|
+
...(columns?.filter((c) => !!c.filterable)?.length ? ["FILTER"] : []),
|
|
232
|
+
...(columns?.filter((c) => !!c.sortable)?.length ? ["SORT"] : []),
|
|
233
|
+
"SELECTABLE", "REFRESH",
|
|
234
|
+
], columns: columns, data: dataTables, onRowClick: onRowClick ? onRowClick : detailControl != false ? (e) => {
|
|
235
|
+
setToggle(`MODAL_SHOW_${toggleKey}`);
|
|
236
|
+
setSelected(e);
|
|
237
|
+
} : undefined, actionBulking: actionBulkingControl, checks: checks || [], onChangeChecks: (e) => setChecks(e), block: block, focus: focus, noIndex: noIndex, responsiveControl: responsiveControl ? {
|
|
238
|
+
mobile: responsiveControl?.mobile ? {
|
|
239
|
+
...(typeof responsiveControl.mobile === 'object' ? responsiveControl.mobile : {}),
|
|
240
|
+
leftActionControl: (typeof responsiveControl.mobile === 'object' && responsiveControl.mobile.leftActionControl !== undefined) ? responsiveControl.mobile.leftActionControl : (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('EDIT') ? {
|
|
241
|
+
icon: "solid/edit",
|
|
242
|
+
onAction: (item) => {
|
|
243
|
+
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
244
|
+
item && setSelected?.(item);
|
|
245
|
+
}
|
|
246
|
+
} : undefined,
|
|
247
|
+
rightActionControl: (typeof responsiveControl.mobile === 'object' && responsiveControl.mobile.rightActionControl !== undefined) ? responsiveControl.mobile.rightActionControl : (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('DELETE') ? {
|
|
248
|
+
icon: "solid/trash",
|
|
249
|
+
onAction: (item) => {
|
|
250
|
+
setToggle(`MODAL_DELETE_${toggleKey}`);
|
|
251
|
+
item && setSelected?.(item);
|
|
252
|
+
}
|
|
253
|
+
} : undefined
|
|
254
|
+
} : undefined,
|
|
255
|
+
} : undefined, ...tableControl }), controlBar?.find((cb) => cb == "CREATE") && ((0, jsx_runtime_1.jsx)(__1.ButtonComponent, { icon: "solid/plus", className: "fixed bottom-24 right-4 w-14 h-14 z-20 md:hidden", size: "lg", rounded: true, onClick: () => {
|
|
256
|
+
setToggle(`MODAL_FORM_${toggleKey}`);
|
|
257
|
+
setSelected(null);
|
|
258
|
+
} })), (0, jsx_runtime_1.jsx)(__1.FloatingPageComponent, { show: !!toggle[`MODAL_SHOW_${toggleKey}`], onClose: () => setToggle(`MODAL_SHOW_${toggleKey}`, false), title: "Detail", className: "bg-background", footer: renderTableAction(actionControl, undefined, { className: isSm ? "justify-end p-2 bg-background" : "justify-end", size: isSm ? "sm" : "md" }), children: detailPage }), (0, jsx_runtime_1.jsx)(__1.FloatingPageComponent, { show: !!toggle[`MODAL_FORM_${toggleKey}`], onClose: () => setToggle(`MODAL_FORM_${toggleKey}`, false), title: !!selected ? "Ubah Data" : "Tambah Data", className: (0, _utils_1.cn)("bg-white", formControl?.modalControl?.className), children: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: formPage }) }), (0, jsx_runtime_1.jsx)(__1.FloatingPageComponent, { show: !!toggle[`MODAL_EXPORT_${toggleKey}`], onClose: () => setToggle(`MODAL_EXPORT_${toggleKey}`, false), title: "Export Ke Excel", className: "bg-white md:w-[1200px] max-w-[1200px]", children: (0, jsx_runtime_1.jsx)(ExportExcel, { fetchControl: fetchControl, filename: "Export - " + title, columnControl: columns?.map((cc) => ({
|
|
259
|
+
label: cc.label || "",
|
|
260
|
+
selector: cc.selector || "",
|
|
261
|
+
})) }) }), (0, jsx_runtime_1.jsx)(__1.FloatingPageComponent, { show: !!toggle[`MODAL_IMPORT_${toggleKey}`], onClose: () => setToggle(`MODAL_IMPORT_${toggleKey}`, false), title: "Import Dari Excel", className: "bg-white md:w-[1200px] max-w-[1200px]", children: (0, jsx_runtime_1.jsx)(ImportExcel, { submitControl: { path: fetchControl?.path + "/import" }, columnControl: columns?.map((cc) => ({
|
|
262
|
+
label: cc.label || "",
|
|
263
|
+
selector: cc.selector || "",
|
|
264
|
+
})) }) }), (0, jsx_runtime_1.jsx)(__1.ModalConfirmComponent, { show: !!toggle[`MODAL_DELETE_${toggleKey}`], onClose: () => setToggle(`MODAL_DELETE_${toggleKey}`, false), title: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Menghapus Data ", (0, jsx_runtime_1.jsxs)("span", { className: "font-semibold", children: ["\"", selected?.[columns?.at(0)?.selector || ""], "\""] }), " ?"] }), submitControl: {
|
|
265
|
+
onSubmit: {
|
|
266
|
+
...(fetchControl.path
|
|
267
|
+
? { path: `${fetchControl.path}/${selected?.id || ""}` }
|
|
268
|
+
: fetchControl.url ? { url: `${fetchControl.url}/${selected?.id || ""}` }
|
|
269
|
+
: { idb: { ...fetchControl?.idb, id: selected?.id || "" } }),
|
|
270
|
+
method: "DELETE",
|
|
271
|
+
},
|
|
272
|
+
onSuccess: () => {
|
|
273
|
+
reset();
|
|
274
|
+
setTimeout(() => { setToggle(`MODAL_DELETE_${toggleKey}`, false); }, 900);
|
|
275
|
+
},
|
|
276
|
+
} }), actionControl && Array.isArray(actionControl) && actionControl.filter((ac) => typeof ac == "object")?.map((ac, acKey) => {
|
|
277
|
+
const submitControl = ac.modal?.submitControl?.onSubmit;
|
|
278
|
+
return ((0, jsx_runtime_1.jsx)(__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), title: ac?.modal?.title || ac.label, submitControl: {
|
|
252
279
|
onSubmit: {
|
|
253
|
-
...(
|
|
254
|
-
? { path: `${
|
|
255
|
-
:
|
|
256
|
-
|
|
257
|
-
method: "DELETE",
|
|
280
|
+
...(submitControl?.path
|
|
281
|
+
? { path: `${submitControl?.path}/${selected?.id || ""}` }
|
|
282
|
+
: { url: `${submitControl?.url}/${selected?.id || ""}` }),
|
|
283
|
+
method: submitControl?.method || "POST",
|
|
258
284
|
},
|
|
259
285
|
onSuccess: () => {
|
|
260
286
|
reset();
|
|
261
|
-
setToggle(`
|
|
287
|
+
setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${_utils_1.conversion.strSnake(tableKey).toUpperCase()}`, false);
|
|
288
|
+
setSelected(null);
|
|
289
|
+
ac.modal?.submitControl?.onSuccess?.();
|
|
262
290
|
},
|
|
263
|
-
}, children:
|
|
264
|
-
|
|
265
|
-
return ((0, jsx_runtime_1.jsx)(ModalConfirm_component_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: {
|
|
266
|
-
onSubmit: {
|
|
267
|
-
...(submitControl?.path
|
|
268
|
-
? { path: `${submitControl.path}/${selected?.id || ""}` }
|
|
269
|
-
: submitControl?.url ? { url: `${submitControl.url}/${selected?.id || ""}` }
|
|
270
|
-
: { idb: { ...submitControl?.idb, id: selected?.id || "" } }),
|
|
271
|
-
...ac.modal?.submitControl?.onSubmit,
|
|
272
|
-
},
|
|
273
|
-
onSuccess: () => {
|
|
274
|
-
reset();
|
|
275
|
-
setToggle(`MODAL_${_utils_1.conversion.strSnake(ac.label).toUpperCase()}_${toggleKey}`, false);
|
|
276
|
-
},
|
|
277
|
-
}, ...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));
|
|
278
|
-
})] }) }));
|
|
291
|
+
}, children: ac.modal?.children }, acKey));
|
|
292
|
+
})] }));
|
|
279
293
|
}
|