@knovator/pagecreator-admin 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -205
- package/index.d.ts +1 -0
- package/package.json +38 -42
- package/src/{index.d.ts → index.ts} +1 -0
- package/src/lib/api/index.ts +70 -0
- package/src/lib/api/list.ts +59 -0
- package/src/lib/components/Page/AddButton/AddButton.tsx +16 -0
- package/src/lib/components/Page/AddButton/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Form/PageForm.tsx +194 -0
- package/src/lib/components/Page/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Page/Page.tsx +151 -0
- package/src/lib/components/Page/Page/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +50 -0
- package/src/lib/components/Page/PageFormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +16 -0
- package/src/lib/components/Page/PageFormWrapper/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Pagination/PagePagination.tsx +26 -0
- package/src/lib/components/Page/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Search/PageSearch.tsx +32 -0
- package/src/lib/components/Page/Search/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/Page/Table/PageTable.tsx +36 -0
- package/src/lib/components/Page/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/AddButton/AddButton.tsx +16 -0
- package/src/lib/components/Widget/AddButton/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Form/ItemsAccordian.tsx +354 -0
- package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +43 -0
- package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +190 -0
- package/src/lib/components/Widget/Form/Tabs/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Form/WidgetForm.tsx +771 -0
- package/src/lib/components/Widget/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +26 -0
- package/src/lib/components/Widget/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Search/WidgetSearch.tsx +32 -0
- package/src/lib/components/Widget/Search/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/Widget/Table/WidgetTable.tsx +70 -0
- package/src/lib/components/Widget/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Widget/Widget.tsx +173 -0
- package/src/lib/components/Widget/Widget/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +50 -0
- package/src/lib/components/Widget/WidgetFormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +16 -0
- package/src/lib/components/Widget/WidgetFormWrapper/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/common/Accordian/Accordian.tsx +56 -0
- package/src/lib/components/common/Accordian/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Button/Button.tsx +45 -0
- package/src/lib/components/common/Button/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +47 -0
- package/src/lib/components/common/ConfirmPopover/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +53 -0
- package/src/lib/components/common/DNDItemsList/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/DeleteModal/DeleteModal.tsx +72 -0
- package/src/lib/components/common/DeleteModal/index.tsx +3 -0
- package/src/lib/components/common/Drawer/Drawer.tsx +79 -0
- package/src/lib/components/common/Drawer/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Form/Form.tsx +256 -0
- package/src/lib/components/common/Form/SimpleForm.tsx +314 -0
- package/src/lib/components/common/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/FormActions/FormActions.tsx +37 -0
- package/src/lib/components/common/FormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/ImageUpload/ImageUpload.tsx +113 -0
- package/src/lib/components/common/ImageUpload/index.tsx +3 -0
- package/src/lib/components/common/Input/Checkbox.tsx +25 -0
- package/src/lib/components/common/Input/Input.tsx +51 -0
- package/src/lib/components/common/Input/ReactSelect.tsx +60 -0
- package/src/lib/components/common/Input/Select.tsx +47 -0
- package/src/lib/components/common/Input/SrcSet.tsx +143 -0
- package/src/lib/components/common/Input/index.ts +20 -0
- package/src/lib/components/common/Modal/Modal.tsx +57 -0
- package/src/lib/components/common/Modal/index.tsx +3 -0
- package/src/lib/components/common/Pagination/Pagination.tsx +88 -0
- package/src/lib/components/common/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Table/Table.tsx +133 -0
- package/src/lib/components/common/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Toggle/Toggle.tsx +23 -0
- package/src/lib/components/common/Toggle/{index.d.ts → index.ts} +1 -0
- package/src/lib/constants/common.ts +145 -0
- package/src/lib/context/PageContext.tsx +100 -0
- package/src/lib/context/ProviderContext.tsx +52 -0
- package/src/lib/context/WidgetContext.tsx +127 -0
- package/src/lib/helper/utils.ts +46 -0
- package/src/lib/hooks/usePage.tsx +307 -0
- package/src/lib/hooks/usePagination.tsx +41 -0
- package/src/lib/hooks/useWidget.tsx +503 -0
- package/src/lib/icons/chevronDown.tsx +21 -0
- package/src/lib/icons/chevronLeft.tsx +20 -0
- package/src/lib/icons/chevronRight.tsx +20 -0
- package/src/lib/icons/chevronUp.tsx +21 -0
- package/src/lib/icons/close.tsx +21 -0
- package/src/lib/icons/pencil.tsx +21 -0
- package/src/lib/icons/plus.tsx +23 -0
- package/src/lib/icons/trash.tsx +21 -0
- package/src/lib/types/api.ts +44 -0
- package/src/lib/types/common.ts +31 -0
- package/src/lib/types/components.ts +427 -0
- package/src/lib/types/context.ts +184 -0
- package/src/styles/index.css +469 -0
- package/index.cjs +0 -7714
- package/index.css +0 -2258
- package/index.js +0 -7700
- package/src/lib/api/index.d.ts +0 -10
- package/src/lib/api/list.d.ts +0 -56
- package/src/lib/components/Page/AddButton/AddButton.d.ts +0 -3
- package/src/lib/components/Page/Form/PageForm.d.ts +0 -4
- package/src/lib/components/Page/Page/Page.d.ts +0 -13
- package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +0 -4
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +0 -4
- package/src/lib/components/Page/Pagination/PagePagination.d.ts +0 -3
- package/src/lib/components/Page/Search/PageSearch.d.ts +0 -3
- package/src/lib/components/Page/Table/PageTable.d.ts +0 -4
- package/src/lib/components/Widget/AddButton/AddButton.d.ts +0 -3
- package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +0 -4
- package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +0 -4
- package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +0 -4
- package/src/lib/components/Widget/Form/WidgetForm.d.ts +0 -4
- package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +0 -3
- package/src/lib/components/Widget/Search/WidgetSearch.d.ts +0 -3
- package/src/lib/components/Widget/Table/WidgetTable.d.ts +0 -4
- package/src/lib/components/Widget/Widget/Widget.d.ts +0 -13
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +0 -4
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +0 -4
- package/src/lib/components/common/Accordian/Accordian.d.ts +0 -13
- package/src/lib/components/common/Button/Button.d.ts +0 -4
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +0 -4
- package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +0 -4
- package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +0 -4
- package/src/lib/components/common/DeleteModal/index.d.ts +0 -2
- package/src/lib/components/common/Drawer/Drawer.d.ts +0 -9
- package/src/lib/components/common/Form/Form.d.ts +0 -15
- package/src/lib/components/common/Form/SimpleForm.d.ts +0 -18
- package/src/lib/components/common/FormActions/FormActions.d.ts +0 -10
- package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +0 -4
- package/src/lib/components/common/ImageUpload/index.d.ts +0 -2
- package/src/lib/components/common/Input/Checkbox.d.ts +0 -4
- package/src/lib/components/common/Input/Input.d.ts +0 -4
- package/src/lib/components/common/Input/ReactSelect.d.ts +0 -4
- package/src/lib/components/common/Input/Select.d.ts +0 -4
- package/src/lib/components/common/Input/SrcSet.d.ts +0 -4
- package/src/lib/components/common/Input/index.d.ts +0 -12
- package/src/lib/components/common/Modal/Modal.d.ts +0 -8
- package/src/lib/components/common/Modal/index.d.ts +0 -2
- package/src/lib/components/common/Pagination/Pagination.d.ts +0 -4
- package/src/lib/components/common/Table/Table.d.ts +0 -4
- package/src/lib/components/common/Toggle/Toggle.d.ts +0 -4
- package/src/lib/constants/common.d.ts +0 -122
- package/src/lib/context/PageContext.d.ts +0 -7
- package/src/lib/context/ProviderContext.d.ts +0 -5
- package/src/lib/context/WidgetContext.d.ts +0 -7
- package/src/lib/helper/utils.d.ts +0 -10
- package/src/lib/hooks/usePage.d.ts +0 -43
- package/src/lib/hooks/usePagination.d.ts +0 -15
- package/src/lib/hooks/useWidget.d.ts +0 -46
- package/src/lib/icons/chevronDown.d.ts +0 -4
- package/src/lib/icons/chevronLeft.d.ts +0 -4
- package/src/lib/icons/chevronRight.d.ts +0 -4
- package/src/lib/icons/chevronUp.d.ts +0 -4
- package/src/lib/icons/close.d.ts +0 -4
- package/src/lib/icons/pencil.d.ts +0 -4
- package/src/lib/icons/plus.d.ts +0 -4
- package/src/lib/icons/trash.d.ts +0 -4
- package/src/lib/types/api.d.ts +0 -34
- package/src/lib/types/common.d.ts +0 -29
- package/src/lib/types/components.d.ts +0 -420
- package/src/lib/types/context.d.ts +0 -135
- /package/src/lib/types/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import Button from '../Button';
|
|
3
|
+
import Input from '../Input';
|
|
4
|
+
import Modal from '../Modal';
|
|
5
|
+
import { DeleteModalProps } from '../../../types';
|
|
6
|
+
import { TRANSLATION_PAIRS_COMMON } from '../../../constants/common';
|
|
7
|
+
|
|
8
|
+
const DeleteModal = ({
|
|
9
|
+
formState,
|
|
10
|
+
onClose,
|
|
11
|
+
itemData,
|
|
12
|
+
onConfirmDelete,
|
|
13
|
+
confirmationRequired,
|
|
14
|
+
permanentlyDelete,
|
|
15
|
+
lossOfData,
|
|
16
|
+
pleaseType,
|
|
17
|
+
toProceedOrCancel,
|
|
18
|
+
confirm,
|
|
19
|
+
typeHerePlaceholder,
|
|
20
|
+
}: DeleteModalProps) => {
|
|
21
|
+
const [userInput, setUserInput] = useState<string>('');
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setUserInput('');
|
|
24
|
+
}, [formState]);
|
|
25
|
+
return itemData ? (
|
|
26
|
+
<Modal
|
|
27
|
+
open={formState === 'DELETE' && itemData ? true : false}
|
|
28
|
+
onClose={onClose}
|
|
29
|
+
title={
|
|
30
|
+
confirmationRequired || TRANSLATION_PAIRS_COMMON.confirmationRequired
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<div className="khb_delete-header">
|
|
34
|
+
<p>
|
|
35
|
+
{permanentlyDelete || TRANSLATION_PAIRS_COMMON.permanentlyDelete}{' '}
|
|
36
|
+
<b>{itemData['name']}</b>
|
|
37
|
+
</p>
|
|
38
|
+
</div>
|
|
39
|
+
<div className="khb_delete-content">
|
|
40
|
+
<p>{lossOfData || TRANSLATION_PAIRS_COMMON.lossOfData}</p>
|
|
41
|
+
<p className="khb_delete-note">
|
|
42
|
+
{pleaseType || TRANSLATION_PAIRS_COMMON.pleaseType}{' '}
|
|
43
|
+
<b className="text-black font-bold">{itemData['name']}</b>{' '}
|
|
44
|
+
{toProceedOrCancel || TRANSLATION_PAIRS_COMMON.toProceedOrCancel}
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
<div className="khb_delete-actions">
|
|
48
|
+
<Input
|
|
49
|
+
placeholder={
|
|
50
|
+
typeHerePlaceholder || TRANSLATION_PAIRS_COMMON.typeHerePlaceholder
|
|
51
|
+
}
|
|
52
|
+
wrapperClassName="w-full"
|
|
53
|
+
className="khb_delete-input"
|
|
54
|
+
value={userInput}
|
|
55
|
+
onChange={(e) => setUserInput(e.target.value)}
|
|
56
|
+
/>
|
|
57
|
+
<div className="khb_delete-buttons">
|
|
58
|
+
<Button
|
|
59
|
+
disabled={
|
|
60
|
+
userInput.toString().trim() !== itemData?.['name']?.trim()
|
|
61
|
+
}
|
|
62
|
+
onClick={onConfirmDelete}
|
|
63
|
+
>
|
|
64
|
+
{confirm || TRANSLATION_PAIRS_COMMON.confirm}
|
|
65
|
+
</Button>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</Modal>
|
|
69
|
+
) : null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default DeleteModal;
|
|
@@ -0,0 +1,79 @@
|
|
|
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;
|
|
@@ -0,0 +1,256 @@
|
|
|
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;
|