@skalfa/skalfa-component 1.0.0
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/accordion/Accordion.component.d.ts +13 -0
- package/dist/accordion/Accordion.component.js +25 -0
- package/dist/breadcrumb/Breadcrumb.component.d.ts +14 -0
- package/dist/breadcrumb/Breadcrumb.component.js +21 -0
- package/dist/button/Button.component.d.ts +21 -0
- package/dist/button/Button.component.js +19 -0
- package/dist/card/AlertCard.component.d.ts +11 -0
- package/dist/card/AlertCard.component.js +9 -0
- package/dist/card/Card.component.d.ts +5 -0
- package/dist/card/Card.component.js +9 -0
- package/dist/card/DashboardCard.component.d.ts +9 -0
- package/dist/card/DashboardCard.component.js +13 -0
- package/dist/card/GalleryCard.component.d.ts +7 -0
- package/dist/card/GalleryCard.component.js +13 -0
- package/dist/card/ProductCard.component.d.ts +9 -0
- package/dist/card/ProductCard.component.js +13 -0
- package/dist/card/ProfileCard.component.d.ts +10 -0
- package/dist/card/ProfileCard.component.js +13 -0
- package/dist/carousel/Carousel.component.d.ts +13 -0
- package/dist/carousel/Carousel.component.js +37 -0
- package/dist/chip/Chip.component.d.ts +6 -0
- package/dist/chip/Chip.component.js +12 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +85 -0
- package/dist/input/Checkbox.component.d.ts +13 -0
- package/dist/input/Checkbox.component.js +23 -0
- package/dist/input/Input.component.d.ts +23 -0
- package/dist/input/Input.component.js +134 -0
- package/dist/input/InputCheckbox.component.d.ts +27 -0
- package/dist/input/InputCheckbox.component.js +53 -0
- package/dist/input/InputCurrency.component.d.ts +21 -0
- package/dist/input/InputCurrency.component.js +30 -0
- package/dist/input/InputDate.component.d.ts +24 -0
- package/dist/input/InputDate.component.js +107 -0
- package/dist/input/InputDatetime.component.d.ts +17 -0
- package/dist/input/InputDatetime.component.js +75 -0
- package/dist/input/InputDocument.component.d.ts +22 -0
- package/dist/input/InputDocument.component.js +88 -0
- package/dist/input/InputImage.component.d.ts +23 -0
- package/dist/input/InputImage.component.js +260 -0
- package/dist/input/InputMap.component.d.ts +25 -0
- package/dist/input/InputMap.component.js +103 -0
- package/dist/input/InputNumber.component.d.ts +19 -0
- package/dist/input/InputNumber.component.js +40 -0
- package/dist/input/InputOtp.component.d.ts +14 -0
- package/dist/input/InputOtp.component.js +65 -0
- package/dist/input/InputPassword.component.d.ts +17 -0
- package/dist/input/InputPassword.component.js +59 -0
- package/dist/input/InputRadio.component.d.ts +27 -0
- package/dist/input/InputRadio.component.js +56 -0
- package/dist/input/InputTime.component.d.ts +23 -0
- package/dist/input/InputTime.component.js +73 -0
- package/dist/input/InputValues.component.d.ts +9 -0
- package/dist/input/InputValues.component.js +19 -0
- package/dist/input/Radio.component.d.ts +12 -0
- package/dist/input/Radio.component.js +22 -0
- package/dist/input/Select.component.d.ts +47 -0
- package/dist/input/Select.component.js +275 -0
- package/dist/modal/BottomSheet.component.d.ts +12 -0
- package/dist/modal/BottomSheet.component.js +161 -0
- package/dist/modal/FloatingPage.component.d.ts +12 -0
- package/dist/modal/FloatingPage.component.js +27 -0
- package/dist/modal/Modal.component.d.ts +12 -0
- package/dist/modal/Modal.component.js +27 -0
- package/dist/modal/ModalConfirm.component.d.ts +26 -0
- package/dist/modal/ModalConfirm.component.js +68 -0
- package/dist/modal/Toast.component.d.ts +11 -0
- package/dist/modal/Toast.component.js +58 -0
- package/dist/nav/Bottombar.component.d.ts +12 -0
- package/dist/nav/Bottombar.component.js +32 -0
- package/dist/nav/Footer.component.d.ts +37 -0
- package/dist/nav/Footer.component.js +49 -0
- package/dist/nav/Headbar.component.d.ts +14 -0
- package/dist/nav/Headbar.component.js +32 -0
- package/dist/nav/Navbar.component.d.ts +22 -0
- package/dist/nav/Navbar.component.js +26 -0
- package/dist/nav/Sidebar.component.d.ts +33 -0
- package/dist/nav/Sidebar.component.js +87 -0
- package/dist/nav/Tabbar.component.d.ts +13 -0
- package/dist/nav/Tabbar.component.js +17 -0
- package/dist/nav/Wizard.component.d.ts +9 -0
- package/dist/nav/Wizard.component.js +24 -0
- package/dist/src/accordion/Accordion.component.d.ts +13 -0
- package/dist/src/accordion/Accordion.component.js +25 -0
- package/dist/src/breadcrumb/Breadcrumb.component.d.ts +14 -0
- package/dist/src/breadcrumb/Breadcrumb.component.js +21 -0
- package/dist/src/button/Button.component.d.ts +21 -0
- package/dist/src/button/Button.component.js +19 -0
- package/dist/src/card/AlertCard.component.d.ts +11 -0
- package/dist/src/card/AlertCard.component.js +9 -0
- package/dist/src/card/Card.component.d.ts +5 -0
- package/dist/src/card/Card.component.js +9 -0
- package/dist/src/card/DashboardCard.component.d.ts +9 -0
- package/dist/src/card/DashboardCard.component.js +13 -0
- package/dist/src/card/GalleryCard.component.d.ts +7 -0
- package/dist/src/card/GalleryCard.component.js +13 -0
- package/dist/src/card/ProductCard.component.d.ts +9 -0
- package/dist/src/card/ProductCard.component.js +13 -0
- package/dist/src/card/ProfileCard.component.d.ts +10 -0
- package/dist/src/card/ProfileCard.component.js +13 -0
- package/dist/src/carousel/Carousel.component.d.ts +13 -0
- package/dist/src/carousel/Carousel.component.js +37 -0
- package/dist/src/chip/Chip.component.d.ts +6 -0
- package/dist/src/chip/Chip.component.js +12 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +29 -0
- package/dist/src/input/Checkbox.component.d.ts +13 -0
- package/dist/src/input/Checkbox.component.js +23 -0
- package/dist/src/input/Input.component.d.ts +23 -0
- package/dist/src/input/Input.component.js +134 -0
- package/dist/src/input/InputCheckbox.component.d.ts +27 -0
- package/dist/src/input/InputCheckbox.component.js +53 -0
- package/dist/src/input/InputCurrency.component.d.ts +21 -0
- package/dist/src/input/InputCurrency.component.js +30 -0
- package/dist/src/input/InputDate.component.d.ts +24 -0
- package/dist/src/input/InputDate.component.js +107 -0
- package/dist/src/input/InputDatetime.component.d.ts +17 -0
- package/dist/src/input/InputDatetime.component.js +75 -0
- package/dist/src/input/InputDocument.component.d.ts +22 -0
- package/dist/src/input/InputDocument.component.js +88 -0
- package/dist/src/input/InputImage.component.d.ts +23 -0
- package/dist/src/input/InputImage.component.js +260 -0
- package/dist/src/input/InputMap.component.d.ts +25 -0
- package/dist/src/input/InputMap.component.js +101 -0
- package/dist/src/input/InputNumber.component.d.ts +19 -0
- package/dist/src/input/InputNumber.component.js +40 -0
- package/dist/src/input/InputOtp.component.d.ts +14 -0
- package/dist/src/input/InputOtp.component.js +65 -0
- package/dist/src/input/InputPassword.component.d.ts +17 -0
- package/dist/src/input/InputPassword.component.js +59 -0
- package/dist/src/input/InputRadio.component.d.ts +27 -0
- package/dist/src/input/InputRadio.component.js +56 -0
- package/dist/src/input/InputTime.component.d.ts +23 -0
- package/dist/src/input/InputTime.component.js +73 -0
- package/dist/src/input/InputValues.component.d.ts +9 -0
- package/dist/src/input/InputValues.component.js +19 -0
- package/dist/src/input/Radio.component.d.ts +12 -0
- package/dist/src/input/Radio.component.js +22 -0
- package/dist/src/input/Select.component.d.ts +47 -0
- package/dist/src/input/Select.component.js +275 -0
- package/dist/src/modal/BottomSheet.component.d.ts +12 -0
- package/dist/src/modal/BottomSheet.component.js +161 -0
- package/dist/src/modal/FloatingPage.component.d.ts +12 -0
- package/dist/src/modal/FloatingPage.component.js +27 -0
- package/dist/src/modal/Modal.component.d.ts +12 -0
- package/dist/src/modal/Modal.component.js +27 -0
- package/dist/src/modal/ModalConfirm.component.d.ts +26 -0
- package/dist/src/modal/ModalConfirm.component.js +68 -0
- package/dist/src/modal/Toast.component.d.ts +11 -0
- package/dist/src/modal/Toast.component.js +58 -0
- package/dist/src/nav/Bottombar.component.d.ts +12 -0
- package/dist/src/nav/Bottombar.component.js +32 -0
- package/dist/src/nav/Footer.component.d.ts +37 -0
- package/dist/src/nav/Footer.component.js +49 -0
- package/dist/src/nav/Headbar.component.d.ts +14 -0
- package/dist/src/nav/Headbar.component.js +32 -0
- package/dist/src/nav/Navbar.component.d.ts +22 -0
- package/dist/src/nav/Navbar.component.js +26 -0
- package/dist/src/nav/Sidebar.component.d.ts +33 -0
- package/dist/src/nav/Sidebar.component.js +87 -0
- package/dist/src/nav/Tabbar.component.d.ts +13 -0
- package/dist/src/nav/Tabbar.component.js +17 -0
- package/dist/src/nav/Wizard.component.d.ts +9 -0
- package/dist/src/nav/Wizard.component.js +24 -0
- package/dist/src/supervision/FormSupervision.component.d.ts +93 -0
- package/dist/src/supervision/FormSupervision.component.js +168 -0
- package/dist/src/supervision/TableSupervision.component.d.ts +78 -0
- package/dist/src/supervision/TableSupervision.component.js +273 -0
- package/dist/src/table/ControlBar.component.d.ts +34 -0
- package/dist/src/table/ControlBar.component.js +205 -0
- package/dist/src/table/FilterComponent.d.ts +45 -0
- package/dist/src/table/FilterComponent.js +132 -0
- package/dist/src/table/Pagination.component.d.ts +8 -0
- package/dist/src/table/Pagination.component.js +32 -0
- package/dist/src/table/Table.component.d.ts +61 -0
- package/dist/src/table/Table.component.js +101 -0
- package/dist/src/typography/TypographyArticle.component.d.ts +8 -0
- package/dist/src/typography/TypographyArticle.component.js +7 -0
- package/dist/src/typography/TypographyColumn.component.d.ts +6 -0
- package/dist/src/typography/TypographyColumn.component.js +7 -0
- package/dist/src/typography/TypographyContent.component.d.ts +6 -0
- package/dist/src/typography/TypographyContent.component.js +7 -0
- package/dist/src/typography/TypographyTips.component.d.ts +6 -0
- package/dist/src/typography/TypographyTips.component.js +7 -0
- package/dist/src/wrap/Draggable.component.d.ts +34 -0
- package/dist/src/wrap/Draggable.component.js +214 -0
- package/dist/src/wrap/Image.component.d.ts +2 -0
- package/dist/src/wrap/Image.component.js +13 -0
- package/dist/src/wrap/OutsideClick.component.d.ts +6 -0
- package/dist/src/wrap/OutsideClick.component.js +34 -0
- package/dist/src/wrap/ScrollContainer.component.d.ts +10 -0
- package/dist/src/wrap/ScrollContainer.component.js +54 -0
- package/dist/src/wrap/ShortcutProvider.d.ts +1 -0
- package/dist/src/wrap/ShortcutProvider.js +42 -0
- package/dist/src/wrap/Swipe.component.d.ts +14 -0
- package/dist/src/wrap/Swipe.component.js +61 -0
- package/dist/supervision/FormSupervision.component.d.ts +93 -0
- package/dist/supervision/FormSupervision.component.js +168 -0
- package/dist/supervision/TableSupervision.component.d.ts +78 -0
- package/dist/supervision/TableSupervision.component.js +273 -0
- package/dist/table/ControlBar.component.d.ts +34 -0
- package/dist/table/ControlBar.component.js +205 -0
- package/dist/table/FilterComponent.d.ts +45 -0
- package/dist/table/FilterComponent.js +132 -0
- package/dist/table/Pagination.component.d.ts +8 -0
- package/dist/table/Pagination.component.js +32 -0
- package/dist/table/Table.component.d.ts +61 -0
- package/dist/table/Table.component.js +101 -0
- package/dist/typography/TypographyArticle.component.d.ts +8 -0
- package/dist/typography/TypographyArticle.component.js +7 -0
- package/dist/typography/TypographyColumn.component.d.ts +6 -0
- package/dist/typography/TypographyColumn.component.js +7 -0
- package/dist/typography/TypographyContent.component.d.ts +6 -0
- package/dist/typography/TypographyContent.component.js +7 -0
- package/dist/typography/TypographyTips.component.d.ts +6 -0
- package/dist/typography/TypographyTips.component.js +7 -0
- package/dist/wrap/Draggable.component.d.ts +1 -0
- package/dist/wrap/Draggable.component.js +214 -0
- package/dist/wrap/Image.component.d.ts +2 -0
- package/dist/wrap/Image.component.js +13 -0
- package/dist/wrap/OutsideClick.component.d.ts +6 -0
- package/dist/wrap/OutsideClick.component.js +34 -0
- package/dist/wrap/ScrollContainer.component.d.ts +10 -0
- package/dist/wrap/ScrollContainer.component.js +54 -0
- package/dist/wrap/ShortcutProvider.d.ts +1 -0
- package/dist/wrap/ShortcutProvider.js +42 -0
- package/dist/wrap/Swipe.component.d.ts +14 -0
- package/dist/wrap/Swipe.component.js +61 -0
- package/package.json +44 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { ApiType, FormErrorType, FormRegisterType, FormValueType, ValidationRules, DBSchema } from "@utils";
|
|
3
|
+
import { InputProps, InputCheckboxProps, InputCurrencyProps, InputDateProps, InputNumberProps, InputRadioProps, SelectProps, InputPasswordProps, InputOtpProps, InputTimeProps, InputImageProps, InputDateTimeProps, InputMapProps } from "@components";
|
|
4
|
+
type formCustomConstructionProps = ({ formControl, values, setValues, setRegister, errors, setErrors, }: {
|
|
5
|
+
formControl: (name: string) => {
|
|
6
|
+
register: (regName: string, regValidations?: ValidationRules | undefined) => void;
|
|
7
|
+
unregister: (regName: string) => void;
|
|
8
|
+
onChange: (e: any) => void;
|
|
9
|
+
value: any;
|
|
10
|
+
invalid: any;
|
|
11
|
+
};
|
|
12
|
+
values: {
|
|
13
|
+
name: string;
|
|
14
|
+
value?: any;
|
|
15
|
+
}[];
|
|
16
|
+
setValues: (values: FormValueType[]) => void;
|
|
17
|
+
errors: FormErrorType[];
|
|
18
|
+
setErrors: (errors: FormErrorType[]) => void;
|
|
19
|
+
setRegister: (registers: FormRegisterType) => void;
|
|
20
|
+
prefixName?: string;
|
|
21
|
+
}) => ReactNode;
|
|
22
|
+
type ClusterConstruction = {
|
|
23
|
+
name: string;
|
|
24
|
+
label: string;
|
|
25
|
+
tip: string;
|
|
26
|
+
fields: FormType[];
|
|
27
|
+
wrap: boolean;
|
|
28
|
+
min?: number;
|
|
29
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
|
|
30
|
+
className: string;
|
|
31
|
+
};
|
|
32
|
+
type ConstructionMap = {
|
|
33
|
+
default: InputProps;
|
|
34
|
+
check: InputCheckboxProps;
|
|
35
|
+
currency: InputCurrencyProps;
|
|
36
|
+
date: InputDateProps;
|
|
37
|
+
datetime: InputDateTimeProps;
|
|
38
|
+
time: InputTimeProps;
|
|
39
|
+
image: InputImageProps;
|
|
40
|
+
cluster: ClusterConstruction;
|
|
41
|
+
number: InputNumberProps;
|
|
42
|
+
radio: InputRadioProps;
|
|
43
|
+
select: SelectProps;
|
|
44
|
+
"enter-password": InputPasswordProps;
|
|
45
|
+
otp: InputOtpProps;
|
|
46
|
+
map: InputMapProps;
|
|
47
|
+
custom: formCustomConstructionProps;
|
|
48
|
+
};
|
|
49
|
+
type TypeKeys = keyof ConstructionMap;
|
|
50
|
+
export type WatchContext = {
|
|
51
|
+
values: Record<string, any>;
|
|
52
|
+
self: string;
|
|
53
|
+
prev: WatchAction;
|
|
54
|
+
};
|
|
55
|
+
export type WatchAction = {
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
hidden?: boolean;
|
|
58
|
+
value?: any;
|
|
59
|
+
required?: boolean;
|
|
60
|
+
readonly?: boolean;
|
|
61
|
+
reset?: boolean;
|
|
62
|
+
};
|
|
63
|
+
export interface FormType<T extends TypeKeys = keyof ConstructionMap> {
|
|
64
|
+
col?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | string;
|
|
65
|
+
className?: string;
|
|
66
|
+
construction?: ConstructionMap[T];
|
|
67
|
+
type?: T;
|
|
68
|
+
onHide?: (values: any) => boolean;
|
|
69
|
+
watch?: (ctx: WatchContext) => WatchAction | undefined;
|
|
70
|
+
}
|
|
71
|
+
export interface formSupervisionProps {
|
|
72
|
+
title?: string;
|
|
73
|
+
fields: FormType[];
|
|
74
|
+
confirmation?: boolean;
|
|
75
|
+
defaultValue?: object | null;
|
|
76
|
+
payload?: (values: any) => Promise<object> | object;
|
|
77
|
+
submitControl: (ApiType & {
|
|
78
|
+
idb?: never;
|
|
79
|
+
}) | {
|
|
80
|
+
idb: {
|
|
81
|
+
store: string;
|
|
82
|
+
schema?: DBSchema;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
footerControl?: ({ loading }: {
|
|
86
|
+
loading: boolean;
|
|
87
|
+
}) => ReactNode;
|
|
88
|
+
onSuccess?: (data: any) => void;
|
|
89
|
+
onError?: (code: number) => void;
|
|
90
|
+
className?: string;
|
|
91
|
+
}
|
|
92
|
+
export declare function FormSupervisionComponent({ title, fields, submitControl, confirmation, defaultValue, onSuccess, onError, footerControl, payload, className, }: formSupervisionProps): React.JSX.Element;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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;
|
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|