@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.
Files changed (107) hide show
  1. package/dist/accordion/Accordion.component.js +2 -3
  2. package/dist/breadcrumb/Breadcrumb.component.js +2 -3
  3. package/dist/button/Button.component.d.ts +2 -1
  4. package/dist/button/Button.component.js +2 -2
  5. package/dist/carousel/Carousel.component.js +2 -3
  6. package/dist/chip/Chip.component.js +2 -3
  7. package/dist/contexts-mock.d.ts +2 -0
  8. package/dist/contexts-mock.js +10 -0
  9. package/dist/input/Checkbox.component.js +2 -3
  10. package/dist/input/Input.component.d.ts +3 -2
  11. package/dist/input/Input.component.js +3 -3
  12. package/dist/input/InputCheckbox.component.js +1 -1
  13. package/dist/input/InputCurrency.component.d.ts +3 -2
  14. package/dist/input/InputCurrency.component.js +3 -3
  15. package/dist/input/InputDate.component.js +4 -5
  16. package/dist/input/InputDatetime.component.d.ts +3 -2
  17. package/dist/input/InputDatetime.component.js +3 -3
  18. package/dist/input/InputDocument.component.js +7 -8
  19. package/dist/input/InputImage.component.js +3 -4
  20. package/dist/input/InputNumber.component.js +3 -4
  21. package/dist/input/InputPassword.component.js +3 -3
  22. package/dist/input/InputRadio.component.js +1 -1
  23. package/dist/input/InputTime.component.js +3 -3
  24. package/dist/input/InputValues.component.js +3 -4
  25. package/dist/input/Select.component.js +6 -7
  26. package/dist/modal/FloatingPage.component.d.ts +3 -1
  27. package/dist/modal/FloatingPage.component.js +7 -3
  28. package/dist/modal/Modal.component.js +1 -2
  29. package/dist/modal/ModalConfirm.component.d.ts +2 -2
  30. package/dist/modal/ModalConfirm.component.js +14 -12
  31. package/dist/modal/Toast.component.js +1 -2
  32. package/dist/nav/Bottombar.component.d.ts +2 -2
  33. package/dist/nav/Bottombar.component.js +7 -8
  34. package/dist/nav/Footer.component.d.ts +2 -2
  35. package/dist/nav/Footer.component.js +6 -7
  36. package/dist/nav/Headbar.component.js +2 -3
  37. package/dist/nav/Navbar.component.d.ts +2 -2
  38. package/dist/nav/Navbar.component.js +3 -4
  39. package/dist/nav/Sidebar.component.d.ts +3 -7
  40. package/dist/nav/Sidebar.component.js +14 -17
  41. package/dist/supervision/FormSupervision.component.d.ts +4 -29
  42. package/dist/supervision/FormSupervision.component.js +84 -136
  43. package/dist/supervision/TableSupervision.component.d.ts +17 -26
  44. package/dist/supervision/TableSupervision.component.js +207 -193
  45. package/dist/table/ControlBar.component.js +15 -16
  46. package/dist/table/FilterComponent.js +4 -6
  47. package/dist/table/Pagination.component.js +2 -3
  48. package/dist/table/Table.component.js +3 -4
  49. package/dist/wrap/Swipe.component.js +2 -2
  50. package/package.json +18 -10
  51. package/src/accordion/Accordion.component.tsx +87 -0
  52. package/src/breadcrumb/Breadcrumb.component.tsx +79 -0
  53. package/src/button/Button.component.tsx +89 -0
  54. package/src/card/AlertCard.component.tsx +69 -0
  55. package/src/card/Card.component.tsx +25 -0
  56. package/src/card/DashboardCard.component.tsx +44 -0
  57. package/src/card/GalleryCard.component.tsx +50 -0
  58. package/src/card/ProductCard.component.tsx +65 -0
  59. package/src/card/ProfileCard.component.tsx +71 -0
  60. package/src/carousel/Carousel.component.tsx +111 -0
  61. package/src/chip/Chip.component.tsx +38 -0
  62. package/src/contexts-mock.ts +6 -0
  63. package/src/index.ts +70 -0
  64. package/src/input/Checkbox.component.tsx +102 -0
  65. package/src/input/Input.component.tsx +334 -0
  66. package/src/input/InputCheckbox.component.tsx +174 -0
  67. package/src/input/InputCurrency.component.tsx +165 -0
  68. package/src/input/InputDate.component.tsx +355 -0
  69. package/src/input/InputDatetime.component.tsx +267 -0
  70. package/src/input/InputDocument.component.tsx +360 -0
  71. package/src/input/InputImage.component.tsx +534 -0
  72. package/src/input/InputNumber.component.tsx +193 -0
  73. package/src/input/InputOtp.component.tsx +169 -0
  74. package/src/input/InputPassword.component.tsx +245 -0
  75. package/src/input/InputRadio.component.tsx +174 -0
  76. package/src/input/InputTime.component.tsx +280 -0
  77. package/src/input/InputValues.component.tsx +70 -0
  78. package/src/input/Radio.component.tsx +98 -0
  79. package/src/input/Select.component.tsx +557 -0
  80. package/src/modal/BottomSheet.component.tsx +246 -0
  81. package/src/modal/FloatingPage.component.tsx +133 -0
  82. package/src/modal/Modal.component.tsx +94 -0
  83. package/src/modal/ModalConfirm.component.tsx +204 -0
  84. package/src/modal/Toast.component.tsx +124 -0
  85. package/src/nav/Bottombar.component.tsx +71 -0
  86. package/src/nav/Footer.component.tsx +176 -0
  87. package/src/nav/Headbar.component.tsx +33 -0
  88. package/src/nav/Navbar.component.tsx +137 -0
  89. package/src/nav/Sidebar.component.tsx +307 -0
  90. package/src/nav/Tabbar.component.tsx +61 -0
  91. package/src/nav/Wizard.component.tsx +80 -0
  92. package/src/supervision/FormSupervision.component.tsx +404 -0
  93. package/src/supervision/TableSupervision.component.tsx +653 -0
  94. package/src/table/ControlBar.component.tsx +501 -0
  95. package/src/table/FilterComponent.tsx +517 -0
  96. package/src/table/Pagination.component.tsx +152 -0
  97. package/src/table/Table.component.tsx +436 -0
  98. package/src/typography/TypographyArticle.component.tsx +26 -0
  99. package/src/typography/TypographyColumn.component.tsx +20 -0
  100. package/src/typography/TypographyContent.component.tsx +20 -0
  101. package/src/typography/TypographyTips.component.tsx +20 -0
  102. package/src/wrap/Draggable.component.tsx +303 -0
  103. package/src/wrap/Image.component.tsx +10 -0
  104. package/src/wrap/OutsideClick.component.tsx +48 -0
  105. package/src/wrap/ScrollContainer.component.tsx +107 -0
  106. package/src/wrap/ShortcutProvider.tsx +57 -0
  107. 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 FloatingPage_component_1 = require("../modal/FloatingPage.component");
12
- const Button_component_1 = require("../button/Button.component");
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
- function TableSupervisionComponent({ title, id, fetchControl, columnControl, formControl, detailControl, actionControl, actionBulkingControl, block, controlBar, noIndex, responsiveControl, urlParam, importControl, }) {
21
- const { tableKey, tableControl, data, selected, setSelected, checks, setChecks, reset, focus } = (0, _utils_1.useTable)(fetchControl, id, title, (urlParam || true));
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 (!isSm) {
40
- if (controlBar == undefined || controlBar?.includes("CREATE")) {
41
- _utils_1.shortcut.register("alt+n", () => {
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
- setSelected(null);
44
- }, "Tambah Data Baru");
45
- }
46
- if (controlBar?.includes("IMPORT")) {
47
- _utils_1.shortcut.register("alt+i", () => {
48
- setToggle(`MODAL_IMPORT_${toggleKey}`);
49
- }, "Import Data Dari Excel");
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
- if (!isSm) {
59
- _utils_1.shortcut.unregister("alt+n");
60
- _utils_1.shortcut.unregister("alt+i");
61
- _utils_1.shortcut.unregister("alt+e");
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
- }, [controlBar, isSm]);
65
- (0, react_1.useEffect)(() => {
66
- if (actionControl && Array.isArray(actionControl) && selected) {
67
- actionControl.filter((ac) => typeof ac == "object")?.forEach((ac) => {
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 == "string") {
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)("table-supervision-action-list", options?.className), children: (Array.isArray(actions) ? actions : (actions || actions == undefined) ? ['EDIT', "DELETE"] : [])?.map((action, key) => {
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)(Button_component_1.ButtonComponent, { icon: free_solid_svg_icons_1.faEdit, label: "Ubah", variant: "outline", paint: "warning", size: options?.size || "xs", rounded: true, onClick: () => {
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)(Button_component_1.ButtonComponent, { icon: free_solid_svg_icons_1.faTrash, label: "Hapus", variant: "outline", paint: "danger", size: options?.size || "xs", rounded: true, onClick: () => {
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
- return ((0, jsx_runtime_1.jsx)(Button_component_1.ButtonComponent, { label: action.label, variant: "outline", paint: "primary", size: options?.size || "xs", rounded: true, onClick: () => {
121
- setToggle(`MODAL_${_utils_1.conversion.strSnake(action.label).toUpperCase()}_${toggleKey}`);
122
- item && setSelected?.(item);
123
- }, ...action.button }, key));
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)("div", { children: action(item || {}, (type) => {
127
- setToggle(`MODAL_${type}_${toggleKey}`);
128
- item && setSelected?.(item);
129
- }, () => item && setSelected?.(item)) }, key));
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 (detailContent === false || detailContent === undefined)
135
+ if (!toggle[`MODAL_SHOW_${toggleKey}`])
138
136
  return null;
139
- 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) => {
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)(TypographyColumn_component_1.TypographyColumnComponent, { title: columns?.find((c) => c.selector == column)?.label, content: selected[column] }, key));
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" && column !== null) {
144
- const colObj = column;
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 detailContent === "function" ? detailContent(selected) : columns?.map((column, key) => ((0, jsx_runtime_1.jsx)(TypographyColumn_component_1.TypographyColumnComponent, { title: column.label, content: selected[column.selector] }, key)))) }) }));
154
- }, [selected, detailContent, columns]);
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
- label: form,
162
- name: _utils_1.conversion.strSnake(form),
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
- visibility: "*"
165
- } : {
166
- ...form,
167
- visibility: form.visibility || "*"
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
- ...item,
181
- action: renderTableAction(actionControl, item)
174
+ col: 12,
175
+ type: "text",
176
+ construction: {
177
+ name: col,
178
+ label: col,
179
+ placeholder: `Masukkan ${col}...`,
180
+ },
182
181
  };
183
- }) || [];
184
- }, [actionControl, data]);
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.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)(Table_component_1.TableComponent, { id: tableKey, controlBar: controlBar?.map((cb) => {
190
- if (cb == "CREATE") {
191
- if (isSm)
192
- return;
193
- return ((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: () => {
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
- item && setSelected?.(item);
229
- }
230
- } : undefined,
231
- rightActionControl: (Array.isArray(actionControl) ? actionControl : (actionControl || actionControl == undefined) ? ['EDIT', "DELETE"] : []).includes('DELETE') ? {
232
- icon: free_solid_svg_icons_1.faTrash,
233
- onAction: (item) => {
234
- setToggle(`MODAL_DELETE_${toggleKey}`);
235
- item && setSelected?.(item);
236
- }
237
- } : undefined
238
- } : responsiveControl?.mobile || undefined,
239
- } : undefined, ...tableControl }), (0, jsx_runtime_1.jsx)(Button_component_1.ButtonComponent, { icon: free_solid_svg_icons_1.faPlus, className: "table-supervision-mobile-add-btn", size: "lg", rounded: true, onClick: () => {
240
- setToggle(`MODAL_FORM_${toggleKey}`);
241
- setSelected(null);
242
- } }), (detailContent !== false && detailContent !== undefined) && (isSm ? ((0, jsx_runtime_1.jsx)(BottomSheet_component_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)(FloatingPage_component_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)(BottomSheet_component_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)(FloatingPage_component_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)(FloatingPage_component_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) => ({
243
- label: cc.label || "",
244
- selector: cc.selector || "",
245
- status: cc.exportable === false ? "hidden" : cc.exportable === true ? "default" : typeof cc.exportable === "string" ? cc.exportable : undefined,
246
- })) }) })), ImportExcel && ((0, jsx_runtime_1.jsx)(FloatingPage_component_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 ? {
247
- path: fetchControl.path,
248
- } : undefined, columnControl: columns?.filter((cc) => cc.importable !== false).map((cc) => ({
249
- label: cc.label || "",
250
- selector: cc.selector || "",
251
- })) }) })), (0, jsx_runtime_1.jsx)(ModalConfirm_component_1.ModalConfirmComponent, { show: !!toggle[`MODAL_DELETE_${toggleKey}`], onClose: () => setToggle(`MODAL_DELETE_${toggleKey}`, false), icon: free_regular_svg_icons_1.faQuestionCircle, title: `Menghapus Data?`, submitControl: {
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
- ...(fetchControl.path
254
- ? { path: `${fetchControl.path}/${selected?.id || ""}` }
255
- : fetchControl.url ? { url: `${fetchControl.url}/${selected?.id || ""}` }
256
- : { idb: { ...fetchControl?.idb, id: selected?.id || "" } }),
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(`MODAL_DELETE_${toggleKey}`, false);
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: 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) => {
264
- const submitControl = ac.modal?.submitControl?.onSubmit;
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
  }