@knovator/pagecreator-admin 0.0.7 → 0.0.8
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 +204 -4
- package/index.js +241 -240
- package/lib/components/Page/Form/PageForm.d.ts +1 -1
- package/lib/components/Page/Page/Page.d.ts +1 -1
- package/lib/components/Widget/Form/WidgetForm.d.ts +1 -1
- package/lib/components/Widget/Widget/Widget.d.ts +1 -1
- package/lib/types/components.d.ts +0 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,207 @@
|
|
|
1
|
-
|
|
1
|
+
<a name="readme-top"></a>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![Contributors][contributors-shield]][contributors-url]
|
|
4
|
+
[![Forks][forks-shield]][forks-url]
|
|
5
|
+
[![Stargazers][stars-shield]][stars-url]
|
|
6
|
+
[![Issues][issues-shield]][issues-url]
|
|
4
7
|
|
|
5
|
-
## Running unit tests
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
<!-- PROJECT LOGO -->
|
|
10
|
+
<br />
|
|
11
|
+
<div align="center">
|
|
12
|
+
<!-- <a href="https://github.com/knovator/pagecreator">
|
|
13
|
+
<img src="images/logo.png" alt="Logo" width="80" height="80">
|
|
14
|
+
</a> -->
|
|
15
|
+
|
|
16
|
+
<h3 align="center">@knovator/pagecreator-admin</h3>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
Plug & Play functionality to Build dynamic pages on the fly.
|
|
20
|
+
<br />
|
|
21
|
+
<a href="https://github.com/knovator/pagecreator"><strong>Explore the docs »</strong></a>
|
|
22
|
+
<br />
|
|
23
|
+
<br />
|
|
24
|
+
<a href="https://github.com/knovator/pagecreator">View Demo</a>
|
|
25
|
+
·
|
|
26
|
+
<a href="https://github.com/knovator/pagecreator/issues">Report Bug</a>
|
|
27
|
+
·
|
|
28
|
+
<a href="https://github.com/knovator/pagecreator/issues">Request Feature</a>
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<!-- TABLE OF CONTENTS -->
|
|
35
|
+
<details>
|
|
36
|
+
<summary>Table of Contents</summary>
|
|
37
|
+
<ol>
|
|
38
|
+
<li>
|
|
39
|
+
<a href="#about-the-project">About The Project</a>
|
|
40
|
+
<ul>
|
|
41
|
+
<li><a href="#built-with">Built With</a></li>
|
|
42
|
+
</ul>
|
|
43
|
+
</li>
|
|
44
|
+
<li>
|
|
45
|
+
<a href="#getting-started">Getting Started</a>
|
|
46
|
+
<ul>
|
|
47
|
+
<li><a href="#prerequisites">Prerequisites</a></li>
|
|
48
|
+
<li><a href="#installation">Installation</a></li>
|
|
49
|
+
</ul>
|
|
50
|
+
</li>
|
|
51
|
+
<li><a href="#usage">Usage</a></li>
|
|
52
|
+
<li><a href="#roadmap">Roadmap</a></li>
|
|
53
|
+
<li><a href="#contributing">Contributing</a></li>
|
|
54
|
+
<li><a href="#license">License</a></li>
|
|
55
|
+
<li><a href="#contact">Contact</a></li>
|
|
56
|
+
<li><a href="#acknowledgments">Acknowledgments</a></li>
|
|
57
|
+
</ol>
|
|
58
|
+
</details>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
<!-- ABOUT THE PROJECT -->
|
|
63
|
+
## About The Project
|
|
64
|
+
|
|
65
|
+
<!-- [![Product Name Screen Shot][product-screenshot]](https://example.com) -->
|
|
66
|
+
`@knovator/pagecreator-admin` provides `Widget` and `Page` components to integrate in UI to builds view that manage **widgets** and **page** data.
|
|
67
|
+
|
|
68
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Built With
|
|
72
|
+
|
|
73
|
+
* [ReatJS](https://reactjs.org/)
|
|
74
|
+
* [Nx](https://nx.dev/)
|
|
75
|
+
* [TailwindCSS](https://tailwindcss.com/)
|
|
76
|
+
* [react-hook-form](https://www.npmjs.com/package/react-hook-form)
|
|
77
|
+
* [react-transition-group](https://www.npmjs.com/package/react-transition-group)
|
|
78
|
+
* [react-beautiful-dnd](https://www.npmjs.com/package/react-beautiful-dnd)
|
|
79
|
+
* [react-dropzone](https://www.npmjs.com/package/react-dropzone)
|
|
80
|
+
* [react-select](https://react-select.com/)
|
|
81
|
+
* [@knovator/api](https://www.npmjs.com/package/@knovator/api)
|
|
82
|
+
|
|
83
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<!-- GETTING STARTED -->
|
|
88
|
+
## Getting Started
|
|
89
|
+
|
|
90
|
+
`@knovator/pagecreator-admin` is designed to be used in ReactJS/NextJS project.
|
|
91
|
+
|
|
92
|
+
### Prerequisites
|
|
93
|
+
|
|
94
|
+
We can use `@knovator/pagecreator-admin` in React/Next application, we can create one using following commands
|
|
95
|
+
* Project
|
|
96
|
+
```sh
|
|
97
|
+
npx create-react-app my-app
|
|
98
|
+
# or
|
|
99
|
+
npx create-next-app@latest
|
|
100
|
+
```
|
|
101
|
+
* API
|
|
102
|
+
- Keep your backend application ready according to the steps mentioned in [@knovator/pagecreator-node](https://github.com/knovator/pagecreator/tree/main/libs/node)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### Installation
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
1. Install NPM packages
|
|
109
|
+
```sh
|
|
110
|
+
npm install @knovator/pagecreator-admin
|
|
111
|
+
# or
|
|
112
|
+
yarn add @knovator/pagecreator-admin
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
<!-- USAGE EXAMPLES -->
|
|
120
|
+
## Usage
|
|
121
|
+
|
|
122
|
+
### Provider
|
|
123
|
+
|
|
124
|
+
`@knovator/pagecreator-admin` uses **Context API**, to support communication between components. So, `Widget`/`Page` components should be wrapped by Provider.
|
|
125
|
+
```jsx
|
|
126
|
+
import { Provider } from '@knovator/pagecreator-admin';
|
|
127
|
+
|
|
128
|
+
<Provider
|
|
129
|
+
...
|
|
130
|
+
>
|
|
131
|
+
...
|
|
132
|
+
</Provider>
|
|
133
|
+
```
|
|
134
|
+
**Props**
|
|
135
|
+
- `token`
|
|
136
|
+
- JWT token to be sent along the requests
|
|
137
|
+
- `baseUrl`
|
|
138
|
+
- Base API url, without forward slash at end i.e. `https://api.xyz.in`
|
|
139
|
+
- `onError(callback_code, code, message) (optional)`
|
|
140
|
+
- callback to execute on error
|
|
141
|
+
- `onSuccess(callback_code, code, message) (optional)`
|
|
142
|
+
- callback to execute on success
|
|
143
|
+
- `onLogout (optional)`
|
|
144
|
+
- callback to execute on API request with unauthorized code in body
|
|
145
|
+
- `switchClass`
|
|
146
|
+
- `class` name to apply to `Toggle` component, default is `khb_switch`
|
|
147
|
+
- `widgetRoutesPrefix`
|
|
148
|
+
- Prefix to apply after `baseUrl` while calling `widget` API
|
|
149
|
+
- `tilesRoutesPrefix`
|
|
150
|
+
- Prefix to apply after `baseUrl` while calling `tiles` API
|
|
151
|
+
- `pageRoutesPrefix`
|
|
152
|
+
- Prefix to apply after `baseUrl` while calling `page` API
|
|
153
|
+
|
|
154
|
+
### [Widget](widget.md)
|
|
155
|
+
### [Page](page.md)
|
|
156
|
+
|
|
157
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
<!-- CONTRIBUTING -->
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
|
164
|
+
|
|
165
|
+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
|
166
|
+
Don't forget to give the project a star! Thanks again!
|
|
167
|
+
|
|
168
|
+
1. Fork the Project
|
|
169
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
170
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
|
171
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
172
|
+
5. Open a Pull Request
|
|
173
|
+
|
|
174
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
<!-- LICENSE -->
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
|
182
|
+
|
|
183
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
<!-- CONTACT -->
|
|
187
|
+
## Contact
|
|
188
|
+
|
|
189
|
+
Knovator Technologies
|
|
190
|
+
- Twitter [@knovator](https://twitter.com/knovator)
|
|
191
|
+
- Web [https://knovator.com/](https://knovator.com/)
|
|
192
|
+
|
|
193
|
+
Project Link: [https://github.com/knovator/masters-admin](https://github.com/knovator/masters-admin)
|
|
194
|
+
|
|
195
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
196
|
+
|
|
197
|
+
<!-- MARKDOWN LINKS & IMAGES -->
|
|
198
|
+
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
199
|
+
[contributors-shield]: https://img.shields.io/github/contributors/knovator/pagecreator.svg?style=for-the-badge
|
|
200
|
+
[contributors-url]: https://github.com/knovator/pagecreator/graphs/contributors
|
|
201
|
+
[forks-shield]: https://img.shields.io/github/forks/knovator/pagecreator.svg?style=for-the-badge
|
|
202
|
+
[forks-url]: https://github.com/knovator/pagecreator/network/members
|
|
203
|
+
[stars-shield]: https://img.shields.io/github/stars/knovator/pagecreator.svg?style=for-the-badge
|
|
204
|
+
[stars-url]: https://github.com/knovator/pagecreator/stargazers
|
|
205
|
+
[issues-shield]: https://img.shields.io/github/issues/knovator/pagecreator.svg?style=for-the-badge
|
|
206
|
+
[issues-url]: https://github.com/knovator/pagecreator/issues
|
|
207
|
+
[product-screenshot]: images/screenshot.png
|
package/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import fetchUrl, { setAPIConfig } from '@knovator/api';
|
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import ReactSelect from 'react-select';
|
|
6
6
|
import { useForm, Controller } from 'react-hook-form';
|
|
7
|
-
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
8
7
|
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
|
|
8
|
+
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
9
9
|
import { useDropzone } from 'react-dropzone';
|
|
10
10
|
|
|
11
11
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -3617,7 +3617,8 @@ const Form = /*#__PURE__*/forwardRef(({
|
|
|
3617
3617
|
setValue,
|
|
3618
3618
|
control,
|
|
3619
3619
|
setError,
|
|
3620
|
-
watch
|
|
3620
|
+
watch,
|
|
3621
|
+
getValues
|
|
3621
3622
|
} = useForm(); // setting update data in form
|
|
3622
3623
|
|
|
3623
3624
|
useEffect(() => {
|
|
@@ -3655,7 +3656,7 @@ const Form = /*#__PURE__*/forwardRef(({
|
|
|
3655
3656
|
}, [data, reset, schema]);
|
|
3656
3657
|
|
|
3657
3658
|
const inputRenderer = schema => {
|
|
3658
|
-
var _a, _b, _c, _d, _e, _f
|
|
3659
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3659
3660
|
|
|
3660
3661
|
let input;
|
|
3661
3662
|
if (typeof schema.show !== 'undefined' && !schema.show) return null;
|
|
@@ -3699,15 +3700,26 @@ const Form = /*#__PURE__*/forwardRef(({
|
|
|
3699
3700
|
break;
|
|
3700
3701
|
|
|
3701
3702
|
case 'select':
|
|
3702
|
-
input = jsx(
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3703
|
+
input = jsx(Controller, {
|
|
3704
|
+
control: control,
|
|
3705
|
+
name: schema.accessor,
|
|
3706
|
+
render: ({
|
|
3707
|
+
field
|
|
3708
|
+
}) => {
|
|
3709
|
+
var _a, _b;
|
|
3710
|
+
|
|
3711
|
+
return jsx(Input.Select, {
|
|
3712
|
+
options: schema.options,
|
|
3713
|
+
label: schema.label,
|
|
3714
|
+
error: (_b = (_a = errors[schema.accessor]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
3715
|
+
onChange: e => field.onChange(e.target.value),
|
|
3716
|
+
value: field.value,
|
|
3717
|
+
className: "w-full",
|
|
3718
|
+
disabled: _isUpdating && typeof schema.editable !== 'undefined' && !schema.editable || !_enable,
|
|
3719
|
+
required: schema.required,
|
|
3720
|
+
wrapperClassName: schema.wrapperClassName
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3711
3723
|
});
|
|
3712
3724
|
break;
|
|
3713
3725
|
|
|
@@ -3718,7 +3730,7 @@ const Form = /*#__PURE__*/forwardRef(({
|
|
|
3718
3730
|
input = jsx(Input, {
|
|
3719
3731
|
rest: register(schema.accessor, schema.validations || {}),
|
|
3720
3732
|
label: schema.label,
|
|
3721
|
-
error: (
|
|
3733
|
+
error: (_f = (_e = errors[schema.accessor]) === null || _e === void 0 ? void 0 : _e.message) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
3722
3734
|
type: schema.type,
|
|
3723
3735
|
className: "w-full p-2",
|
|
3724
3736
|
placeholder: schema.placeholder,
|
|
@@ -3792,114 +3804,6 @@ const Form = /*#__PURE__*/forwardRef(({
|
|
|
3792
3804
|
}));
|
|
3793
3805
|
});
|
|
3794
3806
|
|
|
3795
|
-
const Close = ({
|
|
3796
|
-
srText,
|
|
3797
|
-
className
|
|
3798
|
-
}) => {
|
|
3799
|
-
return jsxs(Fragment, {
|
|
3800
|
-
children: [srText ? jsx("span", Object.assign({
|
|
3801
|
-
className: "khb_sr-only"
|
|
3802
|
-
}, {
|
|
3803
|
-
children: srText
|
|
3804
|
-
})) : null, jsx("svg", Object.assign({
|
|
3805
|
-
className: className,
|
|
3806
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
3807
|
-
viewBox: "-6 -6 24 24",
|
|
3808
|
-
width: "24",
|
|
3809
|
-
fill: "currentColor"
|
|
3810
|
-
}, {
|
|
3811
|
-
children: jsx("path", {
|
|
3812
|
-
d: "M7.314 5.9l3.535-3.536A1 1 0 1 0 9.435.95L5.899 4.485 2.364.95A1 1 0 1 0 .95 2.364l3.535 3.535L.95 9.435a1 1 0 1 0 1.414 1.414l3.535-3.535 3.536 3.535a1 1 0 1 0 1.414-1.414L7.314 5.899z"
|
|
3813
|
-
})
|
|
3814
|
-
}))]
|
|
3815
|
-
});
|
|
3816
|
-
};
|
|
3817
|
-
|
|
3818
|
-
const Drawer = ({
|
|
3819
|
-
children,
|
|
3820
|
-
open,
|
|
3821
|
-
onClose,
|
|
3822
|
-
title,
|
|
3823
|
-
footerContent
|
|
3824
|
-
}) => {
|
|
3825
|
-
const nodeRef = useRef(null);
|
|
3826
|
-
return jsx(CSSTransition, Object.assign({
|
|
3827
|
-
ref: nodeRef,
|
|
3828
|
-
in: open,
|
|
3829
|
-
timeout: {
|
|
3830
|
-
enter: 250,
|
|
3831
|
-
exit: 350
|
|
3832
|
-
},
|
|
3833
|
-
classNames: "khb_drawer",
|
|
3834
|
-
mountOnEnter: true,
|
|
3835
|
-
unmountOnExit: true
|
|
3836
|
-
}, {
|
|
3837
|
-
children: jsx("div", Object.assign({
|
|
3838
|
-
className: "khb_drawer-wrapper-1",
|
|
3839
|
-
"aria-labelledby": "modal",
|
|
3840
|
-
role: "dialog",
|
|
3841
|
-
"aria-modal": "true",
|
|
3842
|
-
ref: nodeRef,
|
|
3843
|
-
"data-testid": "drawer"
|
|
3844
|
-
}, {
|
|
3845
|
-
children: jsxs("div", Object.assign({
|
|
3846
|
-
className: "khb_drawer-wrapper-2"
|
|
3847
|
-
}, {
|
|
3848
|
-
children: [jsx("div", {
|
|
3849
|
-
className: "khb_drawer-backdrop",
|
|
3850
|
-
role: "button",
|
|
3851
|
-
onClick: onClose,
|
|
3852
|
-
onKeyDown: onClose,
|
|
3853
|
-
tabIndex: 0
|
|
3854
|
-
}), jsx("div", Object.assign({
|
|
3855
|
-
className: "khb_drawer-container-1"
|
|
3856
|
-
}, {
|
|
3857
|
-
children: jsxs("div", Object.assign({
|
|
3858
|
-
className: "khb_drawer-container-2"
|
|
3859
|
-
}, {
|
|
3860
|
-
children: [jsx("div", Object.assign({
|
|
3861
|
-
className: "khb_drawer-close-section"
|
|
3862
|
-
}, {
|
|
3863
|
-
children: jsxs("button", Object.assign({
|
|
3864
|
-
type: "button",
|
|
3865
|
-
className: "khb_drawer-close-btn",
|
|
3866
|
-
onClick: onClose,
|
|
3867
|
-
"data-testid": "drawer-close"
|
|
3868
|
-
}, {
|
|
3869
|
-
children: [jsx("span", Object.assign({
|
|
3870
|
-
className: "khb_sr-only"
|
|
3871
|
-
}, {
|
|
3872
|
-
children: "Close panel"
|
|
3873
|
-
})), jsx(Close, {})]
|
|
3874
|
-
}))
|
|
3875
|
-
})), jsxs("div", Object.assign({
|
|
3876
|
-
className: "khb_drawer-main"
|
|
3877
|
-
}, {
|
|
3878
|
-
children: [jsx("div", Object.assign({
|
|
3879
|
-
className: "khb_drawer-header"
|
|
3880
|
-
}, {
|
|
3881
|
-
children: jsx("p", Object.assign({
|
|
3882
|
-
className: "khb_drawer-header-title"
|
|
3883
|
-
}, {
|
|
3884
|
-
children: title
|
|
3885
|
-
}))
|
|
3886
|
-
})), jsx("div", Object.assign({
|
|
3887
|
-
className: "relative flex-1 px-6 py-6 overflow-auto"
|
|
3888
|
-
}, {
|
|
3889
|
-
children: children
|
|
3890
|
-
})), footerContent && jsx("div", Object.assign({
|
|
3891
|
-
className: "khb_drawer-footer"
|
|
3892
|
-
}, {
|
|
3893
|
-
children: footerContent
|
|
3894
|
-
}))]
|
|
3895
|
-
}))]
|
|
3896
|
-
}))
|
|
3897
|
-
}))]
|
|
3898
|
-
}))
|
|
3899
|
-
}))
|
|
3900
|
-
}));
|
|
3901
|
-
};
|
|
3902
|
-
|
|
3903
3807
|
const DNDItemsList = ({
|
|
3904
3808
|
onDragEnd,
|
|
3905
3809
|
items,
|
|
@@ -3936,79 +3840,13 @@ const DNDItemsList = ({
|
|
|
3936
3840
|
}));
|
|
3937
3841
|
};
|
|
3938
3842
|
|
|
3939
|
-
const FormActions = ({
|
|
3940
|
-
loading: _loading = false,
|
|
3941
|
-
primaryLabel: _primaryLabel = 'Submit',
|
|
3942
|
-
secondaryLabel: _secondaryLabel = 'Cancel',
|
|
3943
|
-
onPrimaryButtonClick,
|
|
3944
|
-
onSecondaryButtonClick
|
|
3945
|
-
}) => {
|
|
3946
|
-
return jsxs(Fragment, {
|
|
3947
|
-
children: [jsx(Button, Object.assign({
|
|
3948
|
-
type: "secondary",
|
|
3949
|
-
disabled: _loading,
|
|
3950
|
-
onClick: onSecondaryButtonClick
|
|
3951
|
-
}, {
|
|
3952
|
-
children: _secondaryLabel
|
|
3953
|
-
})), jsx(Button, Object.assign({
|
|
3954
|
-
onClick: onPrimaryButtonClick,
|
|
3955
|
-
disabled: _loading
|
|
3956
|
-
}, {
|
|
3957
|
-
children: _primaryLabel
|
|
3958
|
-
}))]
|
|
3959
|
-
});
|
|
3960
|
-
};
|
|
3961
|
-
|
|
3962
|
-
const PageFormActions = ({
|
|
3963
|
-
formRef
|
|
3964
|
-
}) => {
|
|
3965
|
-
const {
|
|
3966
|
-
onError
|
|
3967
|
-
} = useProviderState();
|
|
3968
|
-
const {
|
|
3969
|
-
closeForm,
|
|
3970
|
-
loading,
|
|
3971
|
-
canAdd,
|
|
3972
|
-
canUpdate,
|
|
3973
|
-
t
|
|
3974
|
-
} = usePageState();
|
|
3975
|
-
|
|
3976
|
-
const onSubmitClick = e => {
|
|
3977
|
-
var _a;
|
|
3978
|
-
|
|
3979
|
-
if (!formRef) {
|
|
3980
|
-
return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is required to submit the form!`);
|
|
3981
|
-
} else if (!formRef.current) {
|
|
3982
|
-
return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is empty, make sure it's passed as 'ref' prop to the form!`);
|
|
3983
|
-
} // formRef is provided
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
3987
|
-
(_a = formRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('submit', {
|
|
3988
|
-
cancelable: true,
|
|
3989
|
-
bubbles: true
|
|
3990
|
-
}));
|
|
3991
|
-
};
|
|
3992
|
-
|
|
3993
|
-
if (!canAdd && !canUpdate) return null;
|
|
3994
|
-
return jsx(FormActions, {
|
|
3995
|
-
loading: loading,
|
|
3996
|
-
primaryLabel: t('saveButtonText'),
|
|
3997
|
-
onPrimaryButtonClick: onSubmitClick,
|
|
3998
|
-
onSecondaryButtonClick: closeForm,
|
|
3999
|
-
secondaryLabel: t('cancelButtonText')
|
|
4000
|
-
});
|
|
4001
|
-
};
|
|
4002
|
-
|
|
4003
3843
|
const PageForm = ({
|
|
4004
|
-
onClose,
|
|
4005
|
-
open,
|
|
4006
|
-
formState,
|
|
4007
3844
|
formRef
|
|
4008
3845
|
}) => {
|
|
4009
3846
|
const {
|
|
4010
3847
|
t,
|
|
4011
3848
|
data,
|
|
3849
|
+
formState,
|
|
4012
3850
|
onPageFormSubmit,
|
|
4013
3851
|
selectedWidgets,
|
|
4014
3852
|
setSelectedWidgets,
|
|
@@ -4069,31 +3907,22 @@ const PageForm = ({
|
|
|
4069
3907
|
onChange: widgets => setSelectedWidgets(widgets)
|
|
4070
3908
|
}];
|
|
4071
3909
|
if (!canAdd && !canUpdate) return null;
|
|
4072
|
-
return
|
|
4073
|
-
|
|
4074
|
-
onClose: onClose,
|
|
4075
|
-
title: formState === 'ADD' ? t('page.addPageTitle') : formState === 'UPDATE' ? t('page.updatePageTitle') : '',
|
|
4076
|
-
footerContent: jsx(PageFormActions, {
|
|
4077
|
-
formRef: formRef
|
|
4078
|
-
})
|
|
3910
|
+
return jsxs("div", Object.assign({
|
|
3911
|
+
className: "khb_form"
|
|
4079
3912
|
}, {
|
|
4080
|
-
children:
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
onDragEnd: onDragEnd,
|
|
4094
|
-
items: selectedWidgets
|
|
4095
|
-
})]
|
|
4096
|
-
}))
|
|
3913
|
+
children: [jsx(Form, {
|
|
3914
|
+
schema: pageFormSchema,
|
|
3915
|
+
onSubmit: onPageFormSubmit,
|
|
3916
|
+
ref: formRef,
|
|
3917
|
+
data: data,
|
|
3918
|
+
isUpdating: formState === 'UPDATE',
|
|
3919
|
+
updates: {
|
|
3920
|
+
widgets: selectedWidgets.map(widget => widget.value)
|
|
3921
|
+
}
|
|
3922
|
+
}), jsx(DNDItemsList, {
|
|
3923
|
+
onDragEnd: onDragEnd,
|
|
3924
|
+
items: selectedWidgets
|
|
3925
|
+
})]
|
|
4097
3926
|
}));
|
|
4098
3927
|
};
|
|
4099
3928
|
|
|
@@ -4265,6 +4094,29 @@ const PagePagination = () => {
|
|
|
4265
4094
|
});
|
|
4266
4095
|
};
|
|
4267
4096
|
|
|
4097
|
+
const Close = ({
|
|
4098
|
+
srText,
|
|
4099
|
+
className
|
|
4100
|
+
}) => {
|
|
4101
|
+
return jsxs(Fragment, {
|
|
4102
|
+
children: [srText ? jsx("span", Object.assign({
|
|
4103
|
+
className: "khb_sr-only"
|
|
4104
|
+
}, {
|
|
4105
|
+
children: srText
|
|
4106
|
+
})) : null, jsx("svg", Object.assign({
|
|
4107
|
+
className: className,
|
|
4108
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4109
|
+
viewBox: "-6 -6 24 24",
|
|
4110
|
+
width: "24",
|
|
4111
|
+
fill: "currentColor"
|
|
4112
|
+
}, {
|
|
4113
|
+
children: jsx("path", {
|
|
4114
|
+
d: "M7.314 5.9l3.535-3.536A1 1 0 1 0 9.435.95L5.899 4.485 2.364.95A1 1 0 1 0 .95 2.364l3.535 3.535L.95 9.435a1 1 0 1 0 1.414 1.414l3.535-3.535 3.536 3.535a1 1 0 1 0 1.414-1.414L7.314 5.899z"
|
|
4115
|
+
})
|
|
4116
|
+
}))]
|
|
4117
|
+
});
|
|
4118
|
+
};
|
|
4119
|
+
|
|
4268
4120
|
const Modal = ({
|
|
4269
4121
|
open,
|
|
4270
4122
|
onClose,
|
|
@@ -4399,6 +4251,155 @@ const DeleteModal = ({
|
|
|
4399
4251
|
})) : null;
|
|
4400
4252
|
};
|
|
4401
4253
|
|
|
4254
|
+
const Drawer = ({
|
|
4255
|
+
children,
|
|
4256
|
+
open,
|
|
4257
|
+
onClose,
|
|
4258
|
+
title,
|
|
4259
|
+
footerContent
|
|
4260
|
+
}) => {
|
|
4261
|
+
const nodeRef = useRef(null);
|
|
4262
|
+
return jsx(CSSTransition, Object.assign({
|
|
4263
|
+
ref: nodeRef,
|
|
4264
|
+
in: open,
|
|
4265
|
+
timeout: {
|
|
4266
|
+
enter: 250,
|
|
4267
|
+
exit: 350
|
|
4268
|
+
},
|
|
4269
|
+
classNames: "khb_drawer",
|
|
4270
|
+
mountOnEnter: true,
|
|
4271
|
+
unmountOnExit: true
|
|
4272
|
+
}, {
|
|
4273
|
+
children: jsx("div", Object.assign({
|
|
4274
|
+
className: "khb_drawer-wrapper-1",
|
|
4275
|
+
"aria-labelledby": "modal",
|
|
4276
|
+
role: "dialog",
|
|
4277
|
+
"aria-modal": "true",
|
|
4278
|
+
ref: nodeRef,
|
|
4279
|
+
"data-testid": "drawer"
|
|
4280
|
+
}, {
|
|
4281
|
+
children: jsxs("div", Object.assign({
|
|
4282
|
+
className: "khb_drawer-wrapper-2"
|
|
4283
|
+
}, {
|
|
4284
|
+
children: [jsx("div", {
|
|
4285
|
+
className: "khb_drawer-backdrop",
|
|
4286
|
+
role: "button",
|
|
4287
|
+
onClick: onClose,
|
|
4288
|
+
onKeyDown: onClose,
|
|
4289
|
+
tabIndex: 0
|
|
4290
|
+
}), jsx("div", Object.assign({
|
|
4291
|
+
className: "khb_drawer-container-1"
|
|
4292
|
+
}, {
|
|
4293
|
+
children: jsxs("div", Object.assign({
|
|
4294
|
+
className: "khb_drawer-container-2"
|
|
4295
|
+
}, {
|
|
4296
|
+
children: [jsx("div", Object.assign({
|
|
4297
|
+
className: "khb_drawer-close-section"
|
|
4298
|
+
}, {
|
|
4299
|
+
children: jsxs("button", Object.assign({
|
|
4300
|
+
type: "button",
|
|
4301
|
+
className: "khb_drawer-close-btn",
|
|
4302
|
+
onClick: onClose,
|
|
4303
|
+
"data-testid": "drawer-close"
|
|
4304
|
+
}, {
|
|
4305
|
+
children: [jsx("span", Object.assign({
|
|
4306
|
+
className: "khb_sr-only"
|
|
4307
|
+
}, {
|
|
4308
|
+
children: "Close panel"
|
|
4309
|
+
})), jsx(Close, {})]
|
|
4310
|
+
}))
|
|
4311
|
+
})), jsxs("div", Object.assign({
|
|
4312
|
+
className: "khb_drawer-main"
|
|
4313
|
+
}, {
|
|
4314
|
+
children: [jsx("div", Object.assign({
|
|
4315
|
+
className: "khb_drawer-header"
|
|
4316
|
+
}, {
|
|
4317
|
+
children: jsx("p", Object.assign({
|
|
4318
|
+
className: "khb_drawer-header-title"
|
|
4319
|
+
}, {
|
|
4320
|
+
children: title
|
|
4321
|
+
}))
|
|
4322
|
+
})), jsx("div", Object.assign({
|
|
4323
|
+
className: "relative flex-1 px-6 py-6 overflow-auto"
|
|
4324
|
+
}, {
|
|
4325
|
+
children: children
|
|
4326
|
+
})), footerContent && jsx("div", Object.assign({
|
|
4327
|
+
className: "khb_drawer-footer"
|
|
4328
|
+
}, {
|
|
4329
|
+
children: footerContent
|
|
4330
|
+
}))]
|
|
4331
|
+
}))]
|
|
4332
|
+
}))
|
|
4333
|
+
}))]
|
|
4334
|
+
}))
|
|
4335
|
+
}))
|
|
4336
|
+
}));
|
|
4337
|
+
};
|
|
4338
|
+
|
|
4339
|
+
const FormActions = ({
|
|
4340
|
+
loading: _loading = false,
|
|
4341
|
+
primaryLabel: _primaryLabel = 'Submit',
|
|
4342
|
+
secondaryLabel: _secondaryLabel = 'Cancel',
|
|
4343
|
+
onPrimaryButtonClick,
|
|
4344
|
+
onSecondaryButtonClick
|
|
4345
|
+
}) => {
|
|
4346
|
+
return jsxs(Fragment, {
|
|
4347
|
+
children: [jsx(Button, Object.assign({
|
|
4348
|
+
type: "secondary",
|
|
4349
|
+
disabled: _loading,
|
|
4350
|
+
onClick: onSecondaryButtonClick
|
|
4351
|
+
}, {
|
|
4352
|
+
children: _secondaryLabel
|
|
4353
|
+
})), jsx(Button, Object.assign({
|
|
4354
|
+
onClick: onPrimaryButtonClick,
|
|
4355
|
+
disabled: _loading
|
|
4356
|
+
}, {
|
|
4357
|
+
children: _primaryLabel
|
|
4358
|
+
}))]
|
|
4359
|
+
});
|
|
4360
|
+
};
|
|
4361
|
+
|
|
4362
|
+
const PageFormActions = ({
|
|
4363
|
+
formRef
|
|
4364
|
+
}) => {
|
|
4365
|
+
const {
|
|
4366
|
+
onError
|
|
4367
|
+
} = useProviderState();
|
|
4368
|
+
const {
|
|
4369
|
+
closeForm,
|
|
4370
|
+
loading,
|
|
4371
|
+
canAdd,
|
|
4372
|
+
canUpdate,
|
|
4373
|
+
t
|
|
4374
|
+
} = usePageState();
|
|
4375
|
+
|
|
4376
|
+
const onSubmitClick = e => {
|
|
4377
|
+
var _a;
|
|
4378
|
+
|
|
4379
|
+
if (!formRef) {
|
|
4380
|
+
return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is required to submit the form!`);
|
|
4381
|
+
} else if (!formRef.current) {
|
|
4382
|
+
return onError(CALLBACK_CODES.INTERNAL, 'error', `formRef is empty, make sure it's passed as 'ref' prop to the form!`);
|
|
4383
|
+
} // formRef is provided
|
|
4384
|
+
|
|
4385
|
+
|
|
4386
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
4387
|
+
(_a = formRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('submit', {
|
|
4388
|
+
cancelable: true,
|
|
4389
|
+
bubbles: true
|
|
4390
|
+
}));
|
|
4391
|
+
};
|
|
4392
|
+
|
|
4393
|
+
if (!canAdd && !canUpdate) return null;
|
|
4394
|
+
return jsx(FormActions, {
|
|
4395
|
+
loading: loading,
|
|
4396
|
+
primaryLabel: t('saveButtonText'),
|
|
4397
|
+
onPrimaryButtonClick: onSubmitClick,
|
|
4398
|
+
onSecondaryButtonClick: closeForm,
|
|
4399
|
+
secondaryLabel: t('cancelButtonText')
|
|
4400
|
+
});
|
|
4401
|
+
};
|
|
4402
|
+
|
|
4402
4403
|
const PageFormWrapper = ({
|
|
4403
4404
|
children
|
|
4404
4405
|
}) => {
|
|
@@ -4485,9 +4486,6 @@ const Page = ({
|
|
|
4485
4486
|
})
|
|
4486
4487
|
}, {
|
|
4487
4488
|
children: jsx(PageForm, {
|
|
4488
|
-
open: formState === 'ADD' || formState === 'UPDATE',
|
|
4489
|
-
onClose: onCloseForm,
|
|
4490
|
-
formState: formState,
|
|
4491
4489
|
formRef: formRef
|
|
4492
4490
|
})
|
|
4493
4491
|
})), itemData && jsx(DeleteModal, {
|
|
@@ -4804,28 +4802,33 @@ const useWidget = ({
|
|
|
4804
4802
|
|
|
4805
4803
|
|
|
4806
4804
|
const onWidgetFormSubmit = data => __awaiter(void 0, void 0, void 0, function* () {
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4805
|
+
try {
|
|
4806
|
+
setLoading(true);
|
|
4807
|
+
const code = formState === 'ADD' ? CALLBACK_CODES.CREATE : CALLBACK_CODES.UPDATE;
|
|
4808
|
+
const api = getApiType({
|
|
4809
|
+
routes,
|
|
4810
|
+
action: formState === 'ADD' ? 'CREATE' : 'UPDATE',
|
|
4811
|
+
prefix: widgetRoutesPrefix,
|
|
4812
|
+
id: itemData === null || itemData === void 0 ? void 0 : itemData['_id']
|
|
4813
|
+
});
|
|
4814
|
+
const response = yield commonApi({
|
|
4815
|
+
baseUrl,
|
|
4816
|
+
token,
|
|
4817
|
+
data,
|
|
4818
|
+
url: api.url,
|
|
4819
|
+
method: api.method,
|
|
4820
|
+
onError: handleError(code)
|
|
4821
|
+
});
|
|
4823
4822
|
|
|
4824
|
-
|
|
4823
|
+
if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS') {
|
|
4824
|
+
setLoading(false);
|
|
4825
|
+
onSuccess(code, response === null || response === void 0 ? void 0 : response.code, response === null || response === void 0 ? void 0 : response.message);
|
|
4826
|
+
getWidgets();
|
|
4827
|
+
onCloseForm();
|
|
4828
|
+
}
|
|
4829
|
+
} catch (error) {
|
|
4825
4830
|
setLoading(false);
|
|
4826
|
-
|
|
4827
|
-
getWidgets();
|
|
4828
|
-
onCloseForm();
|
|
4831
|
+
onError(CALLBACK_CODES.UPDATE, INTERNAL_ERROR_CODE, error.message);
|
|
4829
4832
|
}
|
|
4830
4833
|
});
|
|
4831
4834
|
|
|
@@ -6608,7 +6611,6 @@ const TileItemsAccordian = ({
|
|
|
6608
6611
|
};
|
|
6609
6612
|
|
|
6610
6613
|
const WidgetForm = ({
|
|
6611
|
-
formState,
|
|
6612
6614
|
formRef
|
|
6613
6615
|
}) => {
|
|
6614
6616
|
const {
|
|
@@ -6621,6 +6623,7 @@ const WidgetForm = ({
|
|
|
6621
6623
|
canAdd,
|
|
6622
6624
|
canUpdate,
|
|
6623
6625
|
tilesList,
|
|
6626
|
+
formState,
|
|
6624
6627
|
widgetTypes,
|
|
6625
6628
|
selectionTypes,
|
|
6626
6629
|
onTileFormSubmit,
|
|
@@ -6918,7 +6921,8 @@ const WidgetForm = ({
|
|
|
6918
6921
|
}), !tilesEnabled && jsx(DNDItemsList, {
|
|
6919
6922
|
items: selectedCollectionItems,
|
|
6920
6923
|
onDragEnd: onCollectionIndexChange,
|
|
6921
|
-
formatItem: formatListItem
|
|
6924
|
+
formatItem: formatListItem,
|
|
6925
|
+
listCode: selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value
|
|
6922
6926
|
}), tilesEnabled && jsx(Fragment, {
|
|
6923
6927
|
children: jsx(TileItemsAccordian, {
|
|
6924
6928
|
collapseId: "imageItems",
|
|
@@ -7157,9 +7161,6 @@ const Widget = ({
|
|
|
7157
7161
|
})
|
|
7158
7162
|
}, {
|
|
7159
7163
|
children: jsx(WidgetForm, {
|
|
7160
|
-
open: formState === 'ADD' || formState === 'UPDATE',
|
|
7161
|
-
onClose: onCloseForm,
|
|
7162
|
-
formState: formState,
|
|
7163
7164
|
formRef: widgetFormRef
|
|
7164
7165
|
})
|
|
7165
7166
|
})), itemData && jsx(DeleteModal, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FormProps } from '../../../types';
|
|
3
|
-
declare const PageForm: ({
|
|
3
|
+
declare const PageForm: ({ formRef }: FormProps) => JSX.Element | null;
|
|
4
4
|
export default PageForm;
|
|
@@ -4,7 +4,7 @@ declare const Page: {
|
|
|
4
4
|
({ t, loader, explicitForm, children, permissions, }: PageProps): JSX.Element;
|
|
5
5
|
Table: () => JSX.Element | null;
|
|
6
6
|
Search: () => JSX.Element;
|
|
7
|
-
Form: ({
|
|
7
|
+
Form: ({ formRef }: import("../../../types").FormProps) => JSX.Element | null;
|
|
8
8
|
AddButton: () => JSX.Element;
|
|
9
9
|
Pagination: () => JSX.Element;
|
|
10
10
|
FormActions: ({ formRef }: import("../../../types").FormActionWrapperProps) => JSX.Element | null;
|
|
@@ -3,7 +3,7 @@ import { WidgetProps } from '../../../types';
|
|
|
3
3
|
declare const Widget: {
|
|
4
4
|
({ t, routes, loader, explicitForm, permissions, preConfirmDelete, formatListItem, formatOptionLabel, children, }: WidgetProps): JSX.Element;
|
|
5
5
|
Table: () => JSX.Element | null;
|
|
6
|
-
Form: ({
|
|
6
|
+
Form: ({ formRef }: import("../../../types").FormProps) => JSX.Element | null;
|
|
7
7
|
AddButton: () => JSX.Element;
|
|
8
8
|
Search: () => JSX.Element;
|
|
9
9
|
Pagination: () => JSX.Element;
|
|
@@ -125,9 +125,6 @@ export interface SchemaType extends ReactSelectProps {
|
|
|
125
125
|
wrapperClassName?: string;
|
|
126
126
|
}
|
|
127
127
|
export interface FormProps {
|
|
128
|
-
open: boolean;
|
|
129
|
-
onClose: () => void;
|
|
130
|
-
formState: FormActionTypes | undefined;
|
|
131
128
|
formRef: MutableRefObject<HTMLFormElement | null>;
|
|
132
129
|
}
|
|
133
130
|
export interface InputRendererProps {
|