@knovator/pagecreator-admin 1.2.9 → 1.3.1
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/index.cjs +7878 -0
- package/index.css +2 -0
- package/index.js +7864 -0
- package/package.json +42 -38
- package/src/{index.ts → index.d.ts} +0 -1
- package/src/lib/api/index.d.ts +10 -0
- package/src/lib/api/list.d.ts +56 -0
- package/src/lib/components/Page/AddButton/AddButton.d.ts +3 -0
- package/src/lib/components/Page/AddButton/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/Form/PageForm.d.ts +4 -0
- package/src/lib/components/Page/Form/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/Page/Page.d.ts +13 -0
- package/src/lib/components/Page/Page/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +4 -0
- package/src/lib/components/Page/PageFormActions/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +4 -0
- package/src/lib/components/Page/PageFormWrapper/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/Pagination/PagePagination.d.ts +3 -0
- package/src/lib/components/Page/Pagination/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/Search/PageSearch.d.ts +3 -0
- package/src/lib/components/Page/Search/{index.tsx → index.d.ts} +0 -1
- package/src/lib/components/Page/Table/PageTable.d.ts +4 -0
- package/src/lib/components/Page/Table/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Page/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/AddButton/AddButton.d.ts +3 -0
- package/src/lib/components/Widget/AddButton/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +4 -0
- package/src/lib/components/Widget/Form/Tabs/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/Form/WidgetForm.d.ts +4 -0
- package/src/lib/components/Widget/Form/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +3 -0
- package/src/lib/components/Widget/Pagination/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/Search/WidgetSearch.d.ts +3 -0
- package/src/lib/components/Widget/Search/{index.tsx → index.d.ts} +0 -1
- package/src/lib/components/Widget/Table/WidgetTable.d.ts +4 -0
- package/src/lib/components/Widget/Table/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/Widget/Widget.d.ts +13 -0
- package/src/lib/components/Widget/Widget/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +4 -0
- package/src/lib/components/Widget/WidgetFormActions/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +4 -0
- package/src/lib/components/Widget/WidgetFormWrapper/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/Widget/{index.tsx → index.d.ts} +0 -1
- package/src/lib/components/common/Accordian/Accordian.d.ts +13 -0
- package/src/lib/components/common/Accordian/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/Button/Button.d.ts +4 -0
- package/src/lib/components/common/Button/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +4 -0
- package/src/lib/components/common/ConfirmPopover/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +4 -0
- package/src/lib/components/common/DNDItemsList/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +4 -0
- package/src/lib/components/common/DeleteModal/index.d.ts +2 -0
- package/src/lib/components/common/Drawer/Drawer.d.ts +9 -0
- package/src/lib/components/common/Drawer/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/Form/Form.d.ts +15 -0
- package/src/lib/components/common/Form/SimpleForm.d.ts +18 -0
- package/src/lib/components/common/Form/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/FormActions/FormActions.d.ts +10 -0
- package/src/lib/components/common/FormActions/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +4 -0
- package/src/lib/components/common/ImageUpload/index.d.ts +2 -0
- package/src/lib/components/common/Input/Checkbox.d.ts +4 -0
- package/src/lib/components/common/Input/Input.d.ts +4 -0
- package/src/lib/components/common/Input/ReactSelect.d.ts +4 -0
- package/src/lib/components/common/Input/Select.d.ts +4 -0
- package/src/lib/components/common/Input/SrcSet.d.ts +4 -0
- package/src/lib/components/common/Input/index.d.ts +12 -0
- package/src/lib/components/common/Modal/Modal.d.ts +8 -0
- package/src/lib/components/common/Modal/index.d.ts +2 -0
- package/src/lib/components/common/Pagination/Pagination.d.ts +4 -0
- package/src/lib/components/common/Pagination/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/Table/Table.d.ts +4 -0
- package/src/lib/components/common/Table/{index.ts → index.d.ts} +0 -1
- package/src/lib/components/common/Toggle/Toggle.d.ts +4 -0
- package/src/lib/components/common/Toggle/{index.ts → index.d.ts} +0 -1
- package/src/lib/constants/common.d.ts +122 -0
- package/src/lib/context/PageContext.d.ts +7 -0
- package/src/lib/context/ProviderContext.d.ts +5 -0
- package/src/lib/context/WidgetContext.d.ts +7 -0
- package/src/lib/helper/utils.d.ts +10 -0
- package/src/lib/hooks/usePage.d.ts +37 -0
- package/src/lib/hooks/usePagination.d.ts +15 -0
- package/src/lib/hooks/useWidget.d.ts +46 -0
- package/src/lib/icons/chevronDown.d.ts +4 -0
- package/src/lib/icons/chevronLeft.d.ts +4 -0
- package/src/lib/icons/chevronRight.d.ts +4 -0
- package/src/lib/icons/chevronUp.d.ts +4 -0
- package/src/lib/icons/close.d.ts +4 -0
- package/src/lib/icons/pencil.d.ts +4 -0
- package/src/lib/icons/plus.d.ts +4 -0
- package/src/lib/icons/settings.d.ts +4 -0
- package/src/lib/icons/trash.d.ts +4 -0
- package/src/lib/types/api.d.ts +34 -0
- package/src/lib/types/common.d.ts +30 -0
- package/src/lib/types/components.d.ts +422 -0
- package/src/lib/types/context.d.ts +135 -0
- package/index.d.ts +0 -1
- package/src/lib/api/index.ts +0 -70
- package/src/lib/api/list.ts +0 -59
- package/src/lib/components/Page/AddButton/AddButton.tsx +0 -16
- package/src/lib/components/Page/Form/PageForm.tsx +0 -194
- package/src/lib/components/Page/Page/Page.tsx +0 -151
- package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +0 -50
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +0 -16
- package/src/lib/components/Page/Pagination/PagePagination.tsx +0 -26
- package/src/lib/components/Page/Search/PageSearch.tsx +0 -32
- package/src/lib/components/Page/Table/PageTable.tsx +0 -36
- package/src/lib/components/Widget/AddButton/AddButton.tsx +0 -16
- package/src/lib/components/Widget/Form/ItemsAccordian.tsx +0 -354
- package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +0 -43
- package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +0 -190
- package/src/lib/components/Widget/Form/WidgetForm.tsx +0 -771
- package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +0 -26
- package/src/lib/components/Widget/Search/WidgetSearch.tsx +0 -32
- package/src/lib/components/Widget/Table/WidgetTable.tsx +0 -70
- package/src/lib/components/Widget/Widget/Widget.tsx +0 -173
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +0 -50
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +0 -16
- package/src/lib/components/common/Accordian/Accordian.tsx +0 -56
- package/src/lib/components/common/Button/Button.tsx +0 -45
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +0 -47
- package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +0 -77
- package/src/lib/components/common/DeleteModal/DeleteModal.tsx +0 -72
- package/src/lib/components/common/DeleteModal/index.tsx +0 -3
- package/src/lib/components/common/Drawer/Drawer.tsx +0 -79
- package/src/lib/components/common/Form/Form.tsx +0 -256
- package/src/lib/components/common/Form/SimpleForm.tsx +0 -314
- package/src/lib/components/common/FormActions/FormActions.tsx +0 -37
- package/src/lib/components/common/ImageUpload/ImageUpload.tsx +0 -113
- package/src/lib/components/common/ImageUpload/index.tsx +0 -3
- package/src/lib/components/common/Input/Checkbox.tsx +0 -25
- package/src/lib/components/common/Input/Input.tsx +0 -51
- package/src/lib/components/common/Input/ReactSelect.tsx +0 -61
- package/src/lib/components/common/Input/Select.tsx +0 -47
- package/src/lib/components/common/Input/SrcSet.tsx +0 -143
- package/src/lib/components/common/Input/index.ts +0 -20
- package/src/lib/components/common/Modal/Modal.tsx +0 -57
- package/src/lib/components/common/Modal/index.tsx +0 -3
- package/src/lib/components/common/Pagination/Pagination.tsx +0 -88
- package/src/lib/components/common/Table/Table.tsx +0 -133
- package/src/lib/components/common/Toggle/Toggle.tsx +0 -23
- package/src/lib/constants/common.ts +0 -145
- package/src/lib/context/PageContext.tsx +0 -100
- package/src/lib/context/ProviderContext.tsx +0 -52
- package/src/lib/context/WidgetContext.tsx +0 -127
- package/src/lib/helper/utils.ts +0 -46
- package/src/lib/hooks/usePage.tsx +0 -306
- package/src/lib/hooks/usePagination.tsx +0 -41
- package/src/lib/hooks/useWidget.tsx +0 -503
- package/src/lib/icons/chevronDown.tsx +0 -21
- package/src/lib/icons/chevronLeft.tsx +0 -20
- package/src/lib/icons/chevronRight.tsx +0 -20
- package/src/lib/icons/chevronUp.tsx +0 -21
- package/src/lib/icons/close.tsx +0 -21
- package/src/lib/icons/pencil.tsx +0 -21
- package/src/lib/icons/plus.tsx +0 -23
- package/src/lib/icons/settings.tsx +0 -35
- package/src/lib/icons/trash.tsx +0 -21
- package/src/lib/types/api.ts +0 -44
- package/src/lib/types/common.ts +0 -31
- package/src/lib/types/components.ts +0 -428
- package/src/lib/types/context.ts +0 -184
- package/src/styles/index.css +0 -481
- /package/src/lib/types/{index.ts → index.d.ts} +0 -0
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
3
|
-
import CloseIcon from '../../../icons/close';
|
|
4
|
-
|
|
5
|
-
interface DrawerProps extends React.PropsWithChildren {
|
|
6
|
-
open: boolean;
|
|
7
|
-
onClose: () => void;
|
|
8
|
-
title?: string;
|
|
9
|
-
footerContent?: React.ReactNode;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const Drawer = ({
|
|
13
|
-
children,
|
|
14
|
-
open,
|
|
15
|
-
onClose,
|
|
16
|
-
title,
|
|
17
|
-
footerContent,
|
|
18
|
-
}: DrawerProps) => {
|
|
19
|
-
const nodeRef = useRef(null);
|
|
20
|
-
return (
|
|
21
|
-
<CSSTransition
|
|
22
|
-
ref={nodeRef}
|
|
23
|
-
in={open}
|
|
24
|
-
timeout={{ enter: 250, exit: 350 }}
|
|
25
|
-
classNames="khb_drawer"
|
|
26
|
-
mountOnEnter
|
|
27
|
-
unmountOnExit
|
|
28
|
-
>
|
|
29
|
-
<div
|
|
30
|
-
className="khb_drawer-wrapper-1"
|
|
31
|
-
aria-labelledby="modal"
|
|
32
|
-
role="dialog"
|
|
33
|
-
aria-modal="true"
|
|
34
|
-
ref={nodeRef}
|
|
35
|
-
data-testid="drawer"
|
|
36
|
-
>
|
|
37
|
-
<div className="khb_drawer-wrapper-2">
|
|
38
|
-
<div
|
|
39
|
-
className="khb_drawer-backdrop"
|
|
40
|
-
role="button"
|
|
41
|
-
onClick={onClose}
|
|
42
|
-
onKeyDown={onClose}
|
|
43
|
-
tabIndex={0}
|
|
44
|
-
/>
|
|
45
|
-
<div className="khb_drawer-container-1">
|
|
46
|
-
<div className="khb_drawer-container-2">
|
|
47
|
-
<div className="khb_drawer-close-section">
|
|
48
|
-
<button
|
|
49
|
-
type="button"
|
|
50
|
-
className="khb_drawer-close-btn"
|
|
51
|
-
onClick={onClose}
|
|
52
|
-
data-testid="drawer-close"
|
|
53
|
-
>
|
|
54
|
-
<span className="khb_sr-only">Close panel</span>
|
|
55
|
-
<CloseIcon />
|
|
56
|
-
</button>
|
|
57
|
-
</div>
|
|
58
|
-
<div className="khb_drawer-main">
|
|
59
|
-
<div className="khb_drawer-header">
|
|
60
|
-
<p className="khb_drawer-header-title">{title}</p>
|
|
61
|
-
</div>
|
|
62
|
-
<div className="khb_darwer-content">
|
|
63
|
-
{/* Replace with your content */}
|
|
64
|
-
{children}
|
|
65
|
-
{/* /End replace */}
|
|
66
|
-
</div>
|
|
67
|
-
{footerContent && (
|
|
68
|
-
<div className="khb_drawer-footer">{footerContent}</div>
|
|
69
|
-
)}
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
</CSSTransition>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default Drawer;
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, MutableRefObject, useEffect } from 'react';
|
|
2
|
-
import { useForm, Controller, EventType } from 'react-hook-form';
|
|
3
|
-
import {
|
|
4
|
-
CombineObjectType,
|
|
5
|
-
ObjectType,
|
|
6
|
-
OptionType,
|
|
7
|
-
SchemaType,
|
|
8
|
-
} from '../../../types';
|
|
9
|
-
|
|
10
|
-
import Input from '../Input';
|
|
11
|
-
import { isEmpty } from '../../../helper/utils';
|
|
12
|
-
import CustomReactSelect from '../Input/ReactSelect';
|
|
13
|
-
|
|
14
|
-
interface FormProps {
|
|
15
|
-
schema: SchemaType[];
|
|
16
|
-
data?: CombineObjectType;
|
|
17
|
-
isUpdating?: boolean;
|
|
18
|
-
onSubmit: (data: CombineObjectType) => void;
|
|
19
|
-
enable?: boolean;
|
|
20
|
-
updates?: CombineObjectType;
|
|
21
|
-
ref: MutableRefObject<HTMLFormElement | null>;
|
|
22
|
-
watcher?: (
|
|
23
|
-
value: ObjectType,
|
|
24
|
-
name: string | undefined,
|
|
25
|
-
type: EventType | undefined
|
|
26
|
-
) => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const Form = forwardRef<HTMLFormElement | null, FormProps>(
|
|
30
|
-
(
|
|
31
|
-
{
|
|
32
|
-
schema,
|
|
33
|
-
onSubmit,
|
|
34
|
-
data,
|
|
35
|
-
isUpdating = false,
|
|
36
|
-
enable = true,
|
|
37
|
-
updates,
|
|
38
|
-
watcher,
|
|
39
|
-
},
|
|
40
|
-
ref
|
|
41
|
-
) => {
|
|
42
|
-
const {
|
|
43
|
-
register,
|
|
44
|
-
formState: { errors },
|
|
45
|
-
handleSubmit,
|
|
46
|
-
reset,
|
|
47
|
-
setValue,
|
|
48
|
-
control,
|
|
49
|
-
setError,
|
|
50
|
-
watch,
|
|
51
|
-
} = useForm();
|
|
52
|
-
|
|
53
|
-
// setting update data in form
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (!isEmpty(data)) {
|
|
56
|
-
reset(data);
|
|
57
|
-
}
|
|
58
|
-
}, [data, reset]);
|
|
59
|
-
|
|
60
|
-
// setting subscriber if watcher is provided
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (watcher) {
|
|
63
|
-
const subscription = watch((value, { name, type }) =>
|
|
64
|
-
watcher(value, name, type)
|
|
65
|
-
);
|
|
66
|
-
return () => subscription.unsubscribe();
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
68
|
-
} else return () => {};
|
|
69
|
-
}, [watch, watcher]);
|
|
70
|
-
|
|
71
|
-
// setting values if updates are provided
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (updates) {
|
|
74
|
-
Object.keys(updates).forEach((key) => {
|
|
75
|
-
setValue(key, updates[key]);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}, [setValue, updates]);
|
|
79
|
-
|
|
80
|
-
const inputRenderer = (schema: SchemaType) => {
|
|
81
|
-
let input;
|
|
82
|
-
if (typeof schema.show !== 'undefined' && !schema.show) return null;
|
|
83
|
-
if (schema.type) {
|
|
84
|
-
switch (schema.type) {
|
|
85
|
-
case 'ReactSelect':
|
|
86
|
-
input = (
|
|
87
|
-
<CustomReactSelect
|
|
88
|
-
disabled={!enable}
|
|
89
|
-
label={schema.label}
|
|
90
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
91
|
-
onChange={(value: OptionType | OptionType[] | null) => {
|
|
92
|
-
if (value) {
|
|
93
|
-
setValue(
|
|
94
|
-
schema.accessor,
|
|
95
|
-
Array.isArray(value)
|
|
96
|
-
? value.map((item) => item.value)
|
|
97
|
-
: value.value
|
|
98
|
-
);
|
|
99
|
-
if (schema.onChange) schema.onChange(value);
|
|
100
|
-
}
|
|
101
|
-
}}
|
|
102
|
-
selectedOptions={schema.selectedOptions}
|
|
103
|
-
required={schema.required}
|
|
104
|
-
isMulti={schema.isMulti}
|
|
105
|
-
isSearchable={schema.isSearchable}
|
|
106
|
-
isLoading={schema.isLoading}
|
|
107
|
-
placeholder={schema.placeholder}
|
|
108
|
-
wrapperClassName={schema.wrapperClassName}
|
|
109
|
-
formatOptionLabel={schema.formatOptionLabel}
|
|
110
|
-
selectKey={schema.selectKey}
|
|
111
|
-
loadOptions={schema.loadOptions}
|
|
112
|
-
/>
|
|
113
|
-
);
|
|
114
|
-
break;
|
|
115
|
-
case 'checkbox':
|
|
116
|
-
input = (
|
|
117
|
-
<Input.Checkbox
|
|
118
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
119
|
-
switchClass={schema.switchClass}
|
|
120
|
-
label={schema.label}
|
|
121
|
-
rest={register(schema.accessor, schema.validations || {})}
|
|
122
|
-
className="block"
|
|
123
|
-
disabled={
|
|
124
|
-
isUpdating &&
|
|
125
|
-
typeof schema.editable !== 'undefined' &&
|
|
126
|
-
!schema.editable
|
|
127
|
-
}
|
|
128
|
-
wrapperClassName={schema.wrapperClassName}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
break;
|
|
132
|
-
case 'select':
|
|
133
|
-
input = (
|
|
134
|
-
<Controller
|
|
135
|
-
control={control}
|
|
136
|
-
name={schema.accessor}
|
|
137
|
-
render={({ field }) => (
|
|
138
|
-
<Input.Select
|
|
139
|
-
options={schema.options}
|
|
140
|
-
label={schema.label}
|
|
141
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
142
|
-
onChange={(e) => field.onChange(e.target.value)}
|
|
143
|
-
value={field.value}
|
|
144
|
-
className="w-full"
|
|
145
|
-
disabled={
|
|
146
|
-
(isUpdating &&
|
|
147
|
-
typeof schema.editable !== 'undefined' &&
|
|
148
|
-
!schema.editable) ||
|
|
149
|
-
!enable
|
|
150
|
-
}
|
|
151
|
-
required={schema.required}
|
|
152
|
-
wrapperClassName={schema.wrapperClassName}
|
|
153
|
-
/>
|
|
154
|
-
)}
|
|
155
|
-
></Controller>
|
|
156
|
-
);
|
|
157
|
-
break;
|
|
158
|
-
case 'text':
|
|
159
|
-
case 'number':
|
|
160
|
-
case 'url':
|
|
161
|
-
default:
|
|
162
|
-
input = (
|
|
163
|
-
<Input
|
|
164
|
-
rest={register(schema.accessor, schema.validations || {})}
|
|
165
|
-
label={schema.label}
|
|
166
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
167
|
-
type={schema.type}
|
|
168
|
-
className="w-full p-2"
|
|
169
|
-
placeholder={schema.placeholder}
|
|
170
|
-
disabled={
|
|
171
|
-
(isUpdating &&
|
|
172
|
-
typeof schema.editable !== 'undefined' &&
|
|
173
|
-
!schema.editable) ||
|
|
174
|
-
!enable
|
|
175
|
-
}
|
|
176
|
-
required={schema.required}
|
|
177
|
-
onInput={schema.onInput}
|
|
178
|
-
wrapperClassName={schema.wrapperClassName}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
} else if (schema.Input) {
|
|
184
|
-
input = (
|
|
185
|
-
<div className="kms_input-wrapper">
|
|
186
|
-
<label className="kms_input-label">{schema.label}</label>
|
|
187
|
-
<Controller
|
|
188
|
-
control={control}
|
|
189
|
-
name={schema.accessor}
|
|
190
|
-
rules={schema.validations}
|
|
191
|
-
render={({ field }) =>
|
|
192
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
193
|
-
schema.Input!({
|
|
194
|
-
field,
|
|
195
|
-
error: errors[schema.accessor]?.message?.toString(),
|
|
196
|
-
disabled:
|
|
197
|
-
(isUpdating &&
|
|
198
|
-
typeof schema.editable !== 'undefined' &&
|
|
199
|
-
!schema.editable) ||
|
|
200
|
-
!enable,
|
|
201
|
-
setError: (msg) =>
|
|
202
|
-
setError.call(null, schema.accessor, {
|
|
203
|
-
type: 'custom',
|
|
204
|
-
message: msg,
|
|
205
|
-
}),
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
/>
|
|
209
|
-
</div>
|
|
210
|
-
);
|
|
211
|
-
} else
|
|
212
|
-
throw new Error(
|
|
213
|
-
`Please provide Input or type prop to render input Labeled ${schema.label}`
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
return input;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const onFormSubmit = async (e: React.FormEvent) => {
|
|
220
|
-
e.preventDefault();
|
|
221
|
-
handleSubmit((data) => {
|
|
222
|
-
const formattedData: CombineObjectType = schema.reduce(
|
|
223
|
-
(values: CombineObjectType, schemaItem: SchemaType) => {
|
|
224
|
-
// Do not add field if editing is disabled for it
|
|
225
|
-
if (
|
|
226
|
-
isUpdating &&
|
|
227
|
-
typeof schemaItem.editable !== 'undefined' &&
|
|
228
|
-
!schemaItem.editable
|
|
229
|
-
)
|
|
230
|
-
return values;
|
|
231
|
-
|
|
232
|
-
if (schemaItem.type === 'number') {
|
|
233
|
-
values[schemaItem.accessor] =
|
|
234
|
-
data[schemaItem.accessor] === ''
|
|
235
|
-
? null
|
|
236
|
-
: parseInt(data[schemaItem.accessor]);
|
|
237
|
-
} else values[schemaItem.accessor] = data[schemaItem.accessor];
|
|
238
|
-
return values;
|
|
239
|
-
},
|
|
240
|
-
{}
|
|
241
|
-
);
|
|
242
|
-
onSubmit(formattedData);
|
|
243
|
-
})();
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return (
|
|
247
|
-
<form onSubmit={onFormSubmit} ref={ref} className="khb-form-items">
|
|
248
|
-
{schema.map((schema, i) => (
|
|
249
|
-
<React.Fragment key={i}>{inputRenderer(schema)}</React.Fragment>
|
|
250
|
-
))}
|
|
251
|
-
</form>
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
export default Form;
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import React, { forwardRef, MutableRefObject } from 'react';
|
|
3
|
-
import { Controller } from 'react-hook-form';
|
|
4
|
-
import {
|
|
5
|
-
CombineObjectType,
|
|
6
|
-
LanguageType,
|
|
7
|
-
OptionType,
|
|
8
|
-
SchemaType,
|
|
9
|
-
} from '../../../types';
|
|
10
|
-
|
|
11
|
-
import Input from '../Input';
|
|
12
|
-
import CustomReactSelect from '../Input/ReactSelect';
|
|
13
|
-
|
|
14
|
-
interface SimpleFormProps {
|
|
15
|
-
schema: SchemaType[];
|
|
16
|
-
isUpdating?: boolean;
|
|
17
|
-
onSubmit: (data: CombineObjectType) => void;
|
|
18
|
-
enable?: boolean;
|
|
19
|
-
languages?: LanguageType[];
|
|
20
|
-
ref: MutableRefObject<HTMLFormElement | null>;
|
|
21
|
-
register: any;
|
|
22
|
-
errors: any;
|
|
23
|
-
handleSubmit: any;
|
|
24
|
-
setValue: any;
|
|
25
|
-
control: any;
|
|
26
|
-
setError: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const SimpleForm = forwardRef<HTMLFormElement | null, SimpleFormProps>(
|
|
30
|
-
(
|
|
31
|
-
{
|
|
32
|
-
schema,
|
|
33
|
-
onSubmit,
|
|
34
|
-
isUpdating = false,
|
|
35
|
-
enable = true,
|
|
36
|
-
register,
|
|
37
|
-
errors,
|
|
38
|
-
handleSubmit,
|
|
39
|
-
setValue,
|
|
40
|
-
control,
|
|
41
|
-
setError,
|
|
42
|
-
languages,
|
|
43
|
-
},
|
|
44
|
-
ref
|
|
45
|
-
) => {
|
|
46
|
-
const inputRenderer = (schema: SchemaType) => {
|
|
47
|
-
let input;
|
|
48
|
-
if (typeof schema.show !== 'undefined' && !schema.show) return null;
|
|
49
|
-
if (schema.type) {
|
|
50
|
-
switch (schema.type) {
|
|
51
|
-
case 'ReactSelect':
|
|
52
|
-
input = (
|
|
53
|
-
<CustomReactSelect
|
|
54
|
-
disabled={!enable}
|
|
55
|
-
label={schema.label}
|
|
56
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
57
|
-
onChange={(value: OptionType | OptionType[] | null) => {
|
|
58
|
-
if (value) {
|
|
59
|
-
setValue(
|
|
60
|
-
schema.accessor,
|
|
61
|
-
Array.isArray(value)
|
|
62
|
-
? value.map((item) => item.value)
|
|
63
|
-
: value.value
|
|
64
|
-
);
|
|
65
|
-
if (schema.onChange) schema.onChange(value);
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
selectedOptions={schema.selectedOptions}
|
|
69
|
-
required={schema.required}
|
|
70
|
-
isMulti={schema.isMulti}
|
|
71
|
-
isSearchable={schema.isSearchable}
|
|
72
|
-
isLoading={schema.isLoading}
|
|
73
|
-
placeholder={schema.placeholder}
|
|
74
|
-
wrapperClassName={schema.wrapperClassName}
|
|
75
|
-
formatOptionLabel={schema.formatOptionLabel}
|
|
76
|
-
listCode={schema.listCode}
|
|
77
|
-
customStyles={schema.customStyles}
|
|
78
|
-
loadOptions={schema.loadOptions}
|
|
79
|
-
selectKey={schema.selectKey}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
break;
|
|
83
|
-
case 'checkbox':
|
|
84
|
-
input = (
|
|
85
|
-
<Input.Checkbox
|
|
86
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
87
|
-
switchClass={schema.switchClass}
|
|
88
|
-
label={schema.label}
|
|
89
|
-
rest={register(schema.accessor, schema.validations || {})}
|
|
90
|
-
className="block"
|
|
91
|
-
disabled={
|
|
92
|
-
isUpdating &&
|
|
93
|
-
typeof schema.editable !== 'undefined' &&
|
|
94
|
-
!schema.editable
|
|
95
|
-
}
|
|
96
|
-
wrapperClassName={schema.wrapperClassName}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
break;
|
|
100
|
-
case 'select':
|
|
101
|
-
input = (
|
|
102
|
-
<Controller
|
|
103
|
-
control={control}
|
|
104
|
-
name={schema.accessor}
|
|
105
|
-
render={({ field }) => (
|
|
106
|
-
<Input.Select
|
|
107
|
-
options={schema.options}
|
|
108
|
-
label={schema.label}
|
|
109
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
110
|
-
// onChange={(e) => field.onChange(e.target.value)}
|
|
111
|
-
rest={field}
|
|
112
|
-
// value={field.value}
|
|
113
|
-
className="w-full"
|
|
114
|
-
disabled={
|
|
115
|
-
(isUpdating &&
|
|
116
|
-
typeof schema.editable !== 'undefined' &&
|
|
117
|
-
!schema.editable) ||
|
|
118
|
-
!enable
|
|
119
|
-
}
|
|
120
|
-
required={schema.required}
|
|
121
|
-
wrapperClassName={schema.wrapperClassName}
|
|
122
|
-
/>
|
|
123
|
-
)}
|
|
124
|
-
></Controller>
|
|
125
|
-
);
|
|
126
|
-
break;
|
|
127
|
-
case 'text':
|
|
128
|
-
case 'number':
|
|
129
|
-
case 'url':
|
|
130
|
-
case 'color':
|
|
131
|
-
default:
|
|
132
|
-
if (
|
|
133
|
-
Array.isArray(languages) &&
|
|
134
|
-
languages.length > 0 &&
|
|
135
|
-
schema.accessor === 'widgetTitles'
|
|
136
|
-
) {
|
|
137
|
-
input = languages.map((lang) => (
|
|
138
|
-
<Input
|
|
139
|
-
key={lang.code}
|
|
140
|
-
rest={register(
|
|
141
|
-
`${schema.accessor}.${lang.code}`,
|
|
142
|
-
schema.validations || {}
|
|
143
|
-
)}
|
|
144
|
-
label={schema.label + ' (' + lang.name + ')'}
|
|
145
|
-
onInput={schema.onInput}
|
|
146
|
-
error={errors[schema.accessor]?.[lang.code]?.message}
|
|
147
|
-
required={schema.required}
|
|
148
|
-
type={schema.type}
|
|
149
|
-
className="kms_w-full kms_p-2"
|
|
150
|
-
placeholder={
|
|
151
|
-
(schema.placeholder || '') + ' (' + lang.name + ')'
|
|
152
|
-
}
|
|
153
|
-
disabled={
|
|
154
|
-
isUpdating &&
|
|
155
|
-
typeof schema.editable !== 'undefined' &&
|
|
156
|
-
!schema.editable
|
|
157
|
-
}
|
|
158
|
-
/>
|
|
159
|
-
));
|
|
160
|
-
} else
|
|
161
|
-
input = (
|
|
162
|
-
<Input
|
|
163
|
-
rest={register(schema.accessor, schema.validations || {})}
|
|
164
|
-
label={schema.label}
|
|
165
|
-
error={errors[schema.accessor]?.message?.toString()}
|
|
166
|
-
type={schema.type}
|
|
167
|
-
className={classNames('w-full p-2', schema.className)}
|
|
168
|
-
placeholder={schema.placeholder}
|
|
169
|
-
disabled={
|
|
170
|
-
(isUpdating &&
|
|
171
|
-
typeof schema.editable !== 'undefined' &&
|
|
172
|
-
!schema.editable) ||
|
|
173
|
-
!enable
|
|
174
|
-
}
|
|
175
|
-
required={schema.required}
|
|
176
|
-
onInput={schema.onInput}
|
|
177
|
-
wrapperClassName={schema.wrapperClassName}
|
|
178
|
-
info={schema.info}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
} else if (schema.Input) {
|
|
184
|
-
if (
|
|
185
|
-
Array.isArray(languages) &&
|
|
186
|
-
languages.length > 0 &&
|
|
187
|
-
schema.accessor === 'widgetTitles'
|
|
188
|
-
) {
|
|
189
|
-
input = languages.map((lang) => (
|
|
190
|
-
<div
|
|
191
|
-
key={lang.code}
|
|
192
|
-
className={classNames(
|
|
193
|
-
'khb_input-wrapper',
|
|
194
|
-
schema.wrapperClassName
|
|
195
|
-
)}
|
|
196
|
-
>
|
|
197
|
-
<label className="khb_input-label">
|
|
198
|
-
{schema.label} ({lang.name})
|
|
199
|
-
{schema.required ? (
|
|
200
|
-
<span className="khb_input-label-required">*</span>
|
|
201
|
-
) : null}
|
|
202
|
-
</label>
|
|
203
|
-
<Controller
|
|
204
|
-
control={control}
|
|
205
|
-
name={`${schema.accessor}.${lang.code}`}
|
|
206
|
-
rules={schema.validations}
|
|
207
|
-
render={({ field }) =>
|
|
208
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
209
|
-
schema.Input!({
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
211
|
-
// @ts-ignore
|
|
212
|
-
field,
|
|
213
|
-
error:
|
|
214
|
-
errors[schema.accessor]?.[lang.code]?.message?.toString(),
|
|
215
|
-
disabled:
|
|
216
|
-
(isUpdating &&
|
|
217
|
-
typeof schema.editable !== 'undefined' &&
|
|
218
|
-
!schema.editable) ||
|
|
219
|
-
!enable,
|
|
220
|
-
setError: (msg) =>
|
|
221
|
-
setError.call(null, schema.accessor, {
|
|
222
|
-
type: 'custom',
|
|
223
|
-
message: msg,
|
|
224
|
-
}),
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
/>
|
|
228
|
-
</div>
|
|
229
|
-
));
|
|
230
|
-
} else
|
|
231
|
-
input = (
|
|
232
|
-
<div
|
|
233
|
-
className={classNames(
|
|
234
|
-
'khb_input-wrapper',
|
|
235
|
-
schema.wrapperClassName
|
|
236
|
-
)}
|
|
237
|
-
>
|
|
238
|
-
{schema.label && (
|
|
239
|
-
<label className="khb_input-label">
|
|
240
|
-
{schema.label}
|
|
241
|
-
{schema.required ? (
|
|
242
|
-
<span className="khb_input-label-required">*</span>
|
|
243
|
-
) : null}
|
|
244
|
-
</label>
|
|
245
|
-
)}
|
|
246
|
-
<Controller
|
|
247
|
-
control={control}
|
|
248
|
-
name={schema.accessor}
|
|
249
|
-
rules={schema.validations}
|
|
250
|
-
render={({ field }) =>
|
|
251
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
252
|
-
schema.Input!({
|
|
253
|
-
field,
|
|
254
|
-
error: errors[schema.accessor]?.message?.toString(),
|
|
255
|
-
disabled:
|
|
256
|
-
(isUpdating &&
|
|
257
|
-
typeof schema.editable !== 'undefined' &&
|
|
258
|
-
!schema.editable) ||
|
|
259
|
-
!enable,
|
|
260
|
-
setError: (msg) =>
|
|
261
|
-
setError.call(null, schema.accessor, {
|
|
262
|
-
type: 'custom',
|
|
263
|
-
message: msg,
|
|
264
|
-
}),
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
/>
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
} else
|
|
271
|
-
throw new Error(
|
|
272
|
-
`Please provide Input or type prop to render input Labeled ${schema.label}`
|
|
273
|
-
);
|
|
274
|
-
return input;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const onFormSubmit = async (e: React.FormEvent) => {
|
|
278
|
-
e.preventDefault();
|
|
279
|
-
handleSubmit((data: any) => {
|
|
280
|
-
const formattedData: CombineObjectType = schema.reduce(
|
|
281
|
-
(values: CombineObjectType, schemaItem: SchemaType) => {
|
|
282
|
-
// Do not add field if editing is disabled for it
|
|
283
|
-
if (
|
|
284
|
-
isUpdating &&
|
|
285
|
-
typeof schemaItem.editable !== 'undefined' &&
|
|
286
|
-
!schemaItem.editable
|
|
287
|
-
)
|
|
288
|
-
return values;
|
|
289
|
-
|
|
290
|
-
if (schemaItem.type === 'number') {
|
|
291
|
-
values[schemaItem.accessor] =
|
|
292
|
-
data[schemaItem.accessor] === ''
|
|
293
|
-
? null
|
|
294
|
-
: parseInt(data[schemaItem.accessor]);
|
|
295
|
-
} else values[schemaItem.accessor] = data[schemaItem.accessor];
|
|
296
|
-
return values;
|
|
297
|
-
},
|
|
298
|
-
{}
|
|
299
|
-
);
|
|
300
|
-
onSubmit(formattedData);
|
|
301
|
-
})();
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
return (
|
|
305
|
-
<form onSubmit={onFormSubmit} ref={ref} className="khb-form-items">
|
|
306
|
-
{schema.map((schema, i) => (
|
|
307
|
-
<React.Fragment key={i}>{inputRenderer(schema)}</React.Fragment>
|
|
308
|
-
))}
|
|
309
|
-
</form>
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
export default SimpleForm;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Button from '../Button';
|
|
3
|
-
|
|
4
|
-
interface FormActionsProps {
|
|
5
|
-
loading?: boolean;
|
|
6
|
-
primaryLabel?: string;
|
|
7
|
-
secondaryLabel?: string;
|
|
8
|
-
onPrimaryButtonClick?: (
|
|
9
|
-
e?: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
10
|
-
) => void;
|
|
11
|
-
onSecondaryButtonClick?: () => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const FormActions = ({
|
|
15
|
-
loading = false,
|
|
16
|
-
primaryLabel = 'Submit',
|
|
17
|
-
secondaryLabel = 'Cancel',
|
|
18
|
-
onPrimaryButtonClick,
|
|
19
|
-
onSecondaryButtonClick,
|
|
20
|
-
}: FormActionsProps) => {
|
|
21
|
-
return (
|
|
22
|
-
<>
|
|
23
|
-
<Button
|
|
24
|
-
type="secondary"
|
|
25
|
-
disabled={loading}
|
|
26
|
-
onClick={onSecondaryButtonClick}
|
|
27
|
-
>
|
|
28
|
-
{secondaryLabel}
|
|
29
|
-
</Button>
|
|
30
|
-
<Button onClick={onPrimaryButtonClick} loading={loading}>
|
|
31
|
-
{primaryLabel}
|
|
32
|
-
</Button>
|
|
33
|
-
</>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default FormActions;
|