@knovator/pagecreator-admin 1.2.6 → 1.2.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/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 +77 -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 +61 -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 +306 -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/settings.tsx +35 -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 +428 -0
- package/src/lib/types/context.ts +184 -0
- package/src/styles/index.css +481 -0
- package/index.cjs +0 -7714
- package/index.css +0 -2
- 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
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@knovator/api';
|
package/package.json
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@knovator/pagecreator-admin",
|
|
3
|
-
"version":
|
|
4
|
-
"dependencies": {
|
|
5
|
-
"classnames": "^2.3.1",
|
|
6
|
-
"react-beautiful-dnd": "^13.1.0",
|
|
7
|
-
"react-transition-group": "^4.4.5",
|
|
8
|
-
"react-hook-form": "^7.34.2",
|
|
9
|
-
"react-dropzone": "^14.2.2",
|
|
10
|
-
"react-select": "^5.4.0",
|
|
11
|
-
"react-tabs": "^6.0.0",
|
|
12
|
-
"react-tiny-popover": "^7.2.0"
|
|
13
|
-
},
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"react": "^18 | ^17",
|
|
16
|
-
"@knovator/api": "^0.0.10"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git@github.com:knovator/pagecreator.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"pagecreator",
|
|
24
|
-
"pagebuilder",
|
|
25
|
-
"knovator",
|
|
26
|
-
"chavda-bhavik"
|
|
27
|
-
],
|
|
28
|
-
"author": "knovator (https://knovator.com/)",
|
|
29
|
-
"files": [
|
|
30
|
-
"src",
|
|
31
|
-
"package.json",
|
|
32
|
-
"README.md",
|
|
33
|
-
"index.css",
|
|
34
|
-
"index.d.ts",
|
|
35
|
-
"index.js",
|
|
36
|
-
"index.cjs"
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
"main": "./index.cjs",
|
|
40
|
-
"type": "module",
|
|
41
|
-
"types": "./src\\index.d.ts"
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@knovator/pagecreator-admin",
|
|
3
|
+
"version":"1.2.8",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"classnames": "^2.3.1",
|
|
6
|
+
"react-beautiful-dnd": "^13.1.0",
|
|
7
|
+
"react-transition-group": "^4.4.5",
|
|
8
|
+
"react-hook-form": "^7.34.2",
|
|
9
|
+
"react-dropzone": "^14.2.2",
|
|
10
|
+
"react-select": "^5.4.0",
|
|
11
|
+
"react-tabs": "^6.0.0",
|
|
12
|
+
"react-tiny-popover": "^7.2.0"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"react": "^18 | ^17",
|
|
16
|
+
"@knovator/api": "^0.0.10"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git@github.com:knovator/pagecreator.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"pagecreator",
|
|
24
|
+
"pagebuilder",
|
|
25
|
+
"knovator",
|
|
26
|
+
"chavda-bhavik"
|
|
27
|
+
],
|
|
28
|
+
"author": "knovator (https://knovator.com/)",
|
|
29
|
+
"files": [
|
|
30
|
+
"src",
|
|
31
|
+
"package.json",
|
|
32
|
+
"README.md",
|
|
33
|
+
"index.css",
|
|
34
|
+
"index.d.ts",
|
|
35
|
+
"index.js",
|
|
36
|
+
"index.cjs"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fetchUrl, { setAPIConfig } from '@knovator/api';
|
|
2
|
+
import apiList from './list';
|
|
3
|
+
import {
|
|
4
|
+
ACTION_TYPES,
|
|
5
|
+
API_TYPE,
|
|
6
|
+
BaseAPIProps,
|
|
7
|
+
Routes_Input,
|
|
8
|
+
ResponseType,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
const handleError = (error: Error) => {
|
|
12
|
+
console.log(error);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const commonApi = async ({
|
|
16
|
+
data,
|
|
17
|
+
config,
|
|
18
|
+
|
|
19
|
+
baseUrl,
|
|
20
|
+
token,
|
|
21
|
+
|
|
22
|
+
url,
|
|
23
|
+
method,
|
|
24
|
+
|
|
25
|
+
onError = handleError,
|
|
26
|
+
}: BaseAPIProps): Promise<ResponseType> => {
|
|
27
|
+
let apiToken = token;
|
|
28
|
+
if (typeof token === 'function') {
|
|
29
|
+
apiToken = await token();
|
|
30
|
+
}
|
|
31
|
+
setAPIConfig({
|
|
32
|
+
baseUrl,
|
|
33
|
+
tokenPrefix: 'jwt',
|
|
34
|
+
getToken: apiToken,
|
|
35
|
+
onError,
|
|
36
|
+
});
|
|
37
|
+
const response: ResponseType = (await fetchUrl({
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
type: method,
|
|
41
|
+
url,
|
|
42
|
+
data,
|
|
43
|
+
config,
|
|
44
|
+
})) as ResponseType;
|
|
45
|
+
return response;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const getApiType = ({
|
|
49
|
+
routes,
|
|
50
|
+
action,
|
|
51
|
+
prefix,
|
|
52
|
+
id,
|
|
53
|
+
}: {
|
|
54
|
+
routes?: Routes_Input;
|
|
55
|
+
action: ACTION_TYPES;
|
|
56
|
+
prefix: string;
|
|
57
|
+
id?: string;
|
|
58
|
+
}): API_TYPE => {
|
|
59
|
+
let route: API_TYPE;
|
|
60
|
+
if (routes && typeof routes[action] === 'function') {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
62
|
+
route = routes[action]!({ prefix, id });
|
|
63
|
+
} else {
|
|
64
|
+
route = apiList[action]({ prefix, id });
|
|
65
|
+
}
|
|
66
|
+
return route;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default commonApi;
|
|
70
|
+
export { getApiType };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { API_INPUT_TYPE } from '../types';
|
|
2
|
+
|
|
3
|
+
const apiList = {
|
|
4
|
+
GET_ONE: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
5
|
+
url: `${prefix}/${id}`,
|
|
6
|
+
method: 'GET',
|
|
7
|
+
}),
|
|
8
|
+
LIST: ({ prefix }: API_INPUT_TYPE) => ({
|
|
9
|
+
url: `${prefix}/list`,
|
|
10
|
+
method: 'POST',
|
|
11
|
+
}),
|
|
12
|
+
CREATE: ({ prefix }: API_INPUT_TYPE) => ({
|
|
13
|
+
url: `${prefix}`,
|
|
14
|
+
method: 'POST',
|
|
15
|
+
}),
|
|
16
|
+
UPDATE: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
17
|
+
url: `${prefix}/${id}`,
|
|
18
|
+
method: 'PUT',
|
|
19
|
+
}),
|
|
20
|
+
PARTIAL_UPDATE: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
21
|
+
url: `${prefix}/${id}`,
|
|
22
|
+
method: 'PATCH',
|
|
23
|
+
}),
|
|
24
|
+
DELETE: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
25
|
+
url: `${prefix}/${id}`,
|
|
26
|
+
method: 'DELETE',
|
|
27
|
+
}),
|
|
28
|
+
WIDGET_TYPES: ({ prefix }: API_INPUT_TYPE) => ({
|
|
29
|
+
url: `${prefix}/widget-types`,
|
|
30
|
+
method: 'GET',
|
|
31
|
+
}),
|
|
32
|
+
SELECTION_TYPES: ({ prefix }: API_INPUT_TYPE) => ({
|
|
33
|
+
url: `${prefix}/selection-types`,
|
|
34
|
+
method: 'GET',
|
|
35
|
+
}),
|
|
36
|
+
ITEM: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
37
|
+
url: `${prefix}/${id}`,
|
|
38
|
+
method: 'GET',
|
|
39
|
+
}),
|
|
40
|
+
COLLECTION_DATA: ({ prefix }: API_INPUT_TYPE) => ({
|
|
41
|
+
url: `${prefix}/collection-data`,
|
|
42
|
+
method: 'POST',
|
|
43
|
+
}),
|
|
44
|
+
LANGUAGES: ({ prefix }: API_INPUT_TYPE) => ({
|
|
45
|
+
url: `${prefix}/languages`,
|
|
46
|
+
method: 'GET',
|
|
47
|
+
}),
|
|
48
|
+
// Image Upload API
|
|
49
|
+
IMAGE_UPLOAD: ({ prefix }: API_INPUT_TYPE) => ({
|
|
50
|
+
url: `${prefix}/upload`,
|
|
51
|
+
method: 'post',
|
|
52
|
+
}),
|
|
53
|
+
IMAGE_REMOVE: ({ prefix, id }: API_INPUT_TYPE) => ({
|
|
54
|
+
url: `${prefix}/${id}/delete`,
|
|
55
|
+
method: 'DELETE',
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default apiList;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Button from "../../common/Button";
|
|
3
|
+
import { usePageState } from "../../../context/PageContext";
|
|
4
|
+
import { useProviderState } from '../../../context/ProviderContext';
|
|
5
|
+
|
|
6
|
+
const AddButton = () => {
|
|
7
|
+
const { commonTranslations } = useProviderState();
|
|
8
|
+
const { onChangeFormState, canAdd } = usePageState();
|
|
9
|
+
return (
|
|
10
|
+
<Button disabled={!canAdd} onClick={() => onChangeFormState('ADD')}>
|
|
11
|
+
{commonTranslations.add}
|
|
12
|
+
</Button>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default AddButton;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { useForm } from 'react-hook-form';
|
|
3
|
+
import { DropResult } from 'react-beautiful-dnd';
|
|
4
|
+
import { FormProps, SchemaType } from '../../../types';
|
|
5
|
+
|
|
6
|
+
import { SimpleForm } from '../../common/Form';
|
|
7
|
+
import DNDItemsList from '../../common/DNDItemsList';
|
|
8
|
+
|
|
9
|
+
import { usePageState } from '../../../context/PageContext';
|
|
10
|
+
import {
|
|
11
|
+
capitalizeFirstLetter,
|
|
12
|
+
changeToCode,
|
|
13
|
+
changeToSlug,
|
|
14
|
+
isEmpty,
|
|
15
|
+
} from '../../../helper/utils';
|
|
16
|
+
import { CONSTANTS } from '../../../constants/common';
|
|
17
|
+
import { useProviderState } from '../../../context/ProviderContext';
|
|
18
|
+
|
|
19
|
+
const PageForm = ({ formRef }: FormProps) => {
|
|
20
|
+
const { commonTranslations } = useProviderState();
|
|
21
|
+
const {
|
|
22
|
+
data,
|
|
23
|
+
formState,
|
|
24
|
+
onPageFormSubmit,
|
|
25
|
+
selectedWidgets,
|
|
26
|
+
setSelectedWidgets,
|
|
27
|
+
widgets,
|
|
28
|
+
getWidgets,
|
|
29
|
+
onChangeWidgetSequence,
|
|
30
|
+
canAdd,
|
|
31
|
+
canUpdate,
|
|
32
|
+
pageTranslations,
|
|
33
|
+
} = usePageState();
|
|
34
|
+
const {
|
|
35
|
+
register,
|
|
36
|
+
formState: { errors },
|
|
37
|
+
handleSubmit,
|
|
38
|
+
reset,
|
|
39
|
+
setValue,
|
|
40
|
+
control,
|
|
41
|
+
setError,
|
|
42
|
+
getValues,
|
|
43
|
+
} = useForm();
|
|
44
|
+
const callerRef = useRef<NodeJS.Timeout | null>(null);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!isEmpty(data)) {
|
|
48
|
+
reset(data);
|
|
49
|
+
}
|
|
50
|
+
}, [data, reset]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (formState === 'ADD') {
|
|
54
|
+
setSelectedWidgets([]);
|
|
55
|
+
}
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
}, [formState]);
|
|
58
|
+
|
|
59
|
+
// Form Utility Functions
|
|
60
|
+
function handleCapitalize(event: React.ChangeEvent<HTMLInputElement>) {
|
|
61
|
+
event.target.value = capitalizeFirstLetter(event.target.value);
|
|
62
|
+
return event;
|
|
63
|
+
}
|
|
64
|
+
function handleCode(event: React.ChangeEvent<HTMLInputElement>) {
|
|
65
|
+
event.target.value = changeToCode(event.target.value);
|
|
66
|
+
return event;
|
|
67
|
+
}
|
|
68
|
+
function handleSlug(event: React.ChangeEvent<HTMLInputElement>) {
|
|
69
|
+
let slugValue = changeToSlug(event.target.value);
|
|
70
|
+
if (!slugValue || !CONSTANTS.SLUG_REGEX.test(slugValue)) {
|
|
71
|
+
slugValue = '';
|
|
72
|
+
} else {
|
|
73
|
+
slugValue = slugValue.replace(CONSTANTS.SLUG_REPLACE_REGEX, '');
|
|
74
|
+
}
|
|
75
|
+
event.target.value = slugValue;
|
|
76
|
+
return event;
|
|
77
|
+
}
|
|
78
|
+
function loadOptions(value?: string, callback?: (data: any) => void): any {
|
|
79
|
+
let widgetItems: any[] = [];
|
|
80
|
+
if (formState === 'UPDATE') {
|
|
81
|
+
widgetItems = getValues('widgets');
|
|
82
|
+
}
|
|
83
|
+
widgetItems = Array.isArray(widgetItems)
|
|
84
|
+
? widgetItems
|
|
85
|
+
: data?.widgets
|
|
86
|
+
? data?.widgets
|
|
87
|
+
: [];
|
|
88
|
+
if (callerRef.current) clearTimeout(callerRef.current);
|
|
89
|
+
|
|
90
|
+
callerRef.current = setTimeout(() => {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
getWidgets(value || '', widgetItems, (widgetsData: any) => {
|
|
94
|
+
if (callback) callback(widgetsData);
|
|
95
|
+
if (formState === 'UPDATE' && data)
|
|
96
|
+
setSelectedWidgets(
|
|
97
|
+
widgetItems
|
|
98
|
+
.map((widgetId: string) =>
|
|
99
|
+
widgetsData.find((widget: any) => widget['value'] === widgetId)
|
|
100
|
+
)
|
|
101
|
+
.filter((widget: any) => widget)
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}, 300);
|
|
105
|
+
}
|
|
106
|
+
// Widget Form Functions
|
|
107
|
+
const onDragEnd = (result: DropResult) => {
|
|
108
|
+
const { destination, source } = result;
|
|
109
|
+
if (destination) onChangeWidgetSequence(source.index, destination.index);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Schemas
|
|
113
|
+
const pageFormSchema: SchemaType[] = [
|
|
114
|
+
{
|
|
115
|
+
label: commonTranslations.name,
|
|
116
|
+
required: true,
|
|
117
|
+
accessor: 'name',
|
|
118
|
+
type: 'text',
|
|
119
|
+
placeholder: commonTranslations.namePlaceholder,
|
|
120
|
+
onInput: handleCapitalize,
|
|
121
|
+
validations: {
|
|
122
|
+
required: commonTranslations.nameRequired,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
label: commonTranslations.code,
|
|
127
|
+
accessor: 'code',
|
|
128
|
+
required: true,
|
|
129
|
+
type: 'text',
|
|
130
|
+
onInput: handleCode,
|
|
131
|
+
editable: false,
|
|
132
|
+
placeholder: commonTranslations.codePlaceholder,
|
|
133
|
+
validations: {
|
|
134
|
+
required: commonTranslations.codeRequired,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
label: pageTranslations.slug,
|
|
139
|
+
accessor: 'slug',
|
|
140
|
+
required: true,
|
|
141
|
+
type: 'text',
|
|
142
|
+
onInput: handleSlug,
|
|
143
|
+
editable: false,
|
|
144
|
+
placeholder: pageTranslations.slugPlaceholder,
|
|
145
|
+
validations: {
|
|
146
|
+
required: pageTranslations.slugRequired,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
label: pageTranslations.widgets,
|
|
151
|
+
accessor: 'widgets',
|
|
152
|
+
type: 'ReactSelect',
|
|
153
|
+
options: widgets,
|
|
154
|
+
selectedOptions: selectedWidgets,
|
|
155
|
+
isMulti: true,
|
|
156
|
+
loadOptions: loadOptions,
|
|
157
|
+
onChange: (widgets) => setSelectedWidgets(widgets),
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
if (!canAdd && !canUpdate) return null;
|
|
162
|
+
return (
|
|
163
|
+
<div className="khb_form">
|
|
164
|
+
<SimpleForm
|
|
165
|
+
schema={pageFormSchema}
|
|
166
|
+
onSubmit={onPageFormSubmit}
|
|
167
|
+
ref={formRef}
|
|
168
|
+
isUpdating={formState === 'UPDATE'}
|
|
169
|
+
register={register}
|
|
170
|
+
errors={errors}
|
|
171
|
+
handleSubmit={handleSubmit}
|
|
172
|
+
setValue={setValue}
|
|
173
|
+
control={control}
|
|
174
|
+
setError={setError}
|
|
175
|
+
/>
|
|
176
|
+
{/* <Form
|
|
177
|
+
schema={pageFormSchema}
|
|
178
|
+
onSubmit={onPageFormSubmit}
|
|
179
|
+
ref={formRef}
|
|
180
|
+
data={data}
|
|
181
|
+
isUpdating={formState === 'UPDATE'}
|
|
182
|
+
updates={{
|
|
183
|
+
widgets: selectedWidgets.map(
|
|
184
|
+
(widget: { value: string }) => widget.value
|
|
185
|
+
),
|
|
186
|
+
}}
|
|
187
|
+
/> */}
|
|
188
|
+
|
|
189
|
+
<DNDItemsList onDragEnd={onDragEnd} items={selectedWidgets} />
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default PageForm;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import usePage from '../../../hooks/usePage';
|
|
3
|
+
import PageContextProvider from '../../../context/PageContext';
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_PERMISSIONS,
|
|
6
|
+
TRANSLATION_PAIRS_PAGE,
|
|
7
|
+
} from '../../../constants/common';
|
|
8
|
+
import { PageProps } from '../../../types';
|
|
9
|
+
|
|
10
|
+
import Table from '../Table';
|
|
11
|
+
import Search from '../Search';
|
|
12
|
+
import PageForm from '../Form';
|
|
13
|
+
import AddButton from '../AddButton';
|
|
14
|
+
import Pagination from '../Pagination';
|
|
15
|
+
import Drawer from '../../common/Drawer';
|
|
16
|
+
import DeleteModal from '../../common/DeleteModal';
|
|
17
|
+
import PageFormActions from '../PageFormActions';
|
|
18
|
+
import PageFormWrapper from '../PageFormWrapper';
|
|
19
|
+
import { useProviderState } from '../../../context/ProviderContext';
|
|
20
|
+
|
|
21
|
+
const Page = ({
|
|
22
|
+
loader,
|
|
23
|
+
translations,
|
|
24
|
+
explicitForm = false,
|
|
25
|
+
children,
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
permissions = {},
|
|
29
|
+
preConfirmDelete,
|
|
30
|
+
}: PageProps) => {
|
|
31
|
+
const { commonTranslations } = useProviderState();
|
|
32
|
+
const derivedPermissions = Object.assign(DEFAULT_PERMISSIONS, permissions);
|
|
33
|
+
const formRef = useRef<HTMLFormElement | null>(null);
|
|
34
|
+
const combinedTranslations = {
|
|
35
|
+
...TRANSLATION_PAIRS_PAGE,
|
|
36
|
+
...translations,
|
|
37
|
+
};
|
|
38
|
+
const {
|
|
39
|
+
list,
|
|
40
|
+
widgets,
|
|
41
|
+
loading,
|
|
42
|
+
totalPages,
|
|
43
|
+
totalRecords,
|
|
44
|
+
currentPage,
|
|
45
|
+
pageSize,
|
|
46
|
+
itemData,
|
|
47
|
+
searchText,
|
|
48
|
+
changeSearch,
|
|
49
|
+
setCurrentPage,
|
|
50
|
+
formState,
|
|
51
|
+
getWidgets,
|
|
52
|
+
onChangeFormState,
|
|
53
|
+
onPageFormSubmit,
|
|
54
|
+
onCloseForm,
|
|
55
|
+
selectedWidgets,
|
|
56
|
+
setSelectedWidgets,
|
|
57
|
+
onCofirmDeletePage,
|
|
58
|
+
onChangeWidgetSequence,
|
|
59
|
+
getPages,
|
|
60
|
+
} = usePage({
|
|
61
|
+
defaultLimit: 10,
|
|
62
|
+
preConfirmDelete,
|
|
63
|
+
canList: derivedPermissions.list,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<PageContextProvider
|
|
68
|
+
loader={loader}
|
|
69
|
+
list={list}
|
|
70
|
+
searchText={searchText}
|
|
71
|
+
changeSearch={changeSearch}
|
|
72
|
+
widgets={widgets}
|
|
73
|
+
data={itemData}
|
|
74
|
+
loading={loading}
|
|
75
|
+
totalPages={totalPages}
|
|
76
|
+
totalRecords={totalRecords}
|
|
77
|
+
currentPage={currentPage}
|
|
78
|
+
onChangeFormState={onChangeFormState}
|
|
79
|
+
pageSize={pageSize}
|
|
80
|
+
getWidgets={getWidgets}
|
|
81
|
+
setCurrentPage={setCurrentPage}
|
|
82
|
+
onPageFormSubmit={onPageFormSubmit}
|
|
83
|
+
selectedWidgets={selectedWidgets}
|
|
84
|
+
setSelectedWidgets={setSelectedWidgets}
|
|
85
|
+
onChangeWidgetSequence={onChangeWidgetSequence}
|
|
86
|
+
getPages={getPages}
|
|
87
|
+
formState={formState}
|
|
88
|
+
closeForm={onCloseForm}
|
|
89
|
+
// permissions
|
|
90
|
+
canAdd={derivedPermissions.add}
|
|
91
|
+
canDelete={derivedPermissions.delete}
|
|
92
|
+
canUpdate={derivedPermissions.update}
|
|
93
|
+
canList={derivedPermissions.list}
|
|
94
|
+
pageTranslations={translations}
|
|
95
|
+
>
|
|
96
|
+
{children ? (
|
|
97
|
+
children
|
|
98
|
+
) : (
|
|
99
|
+
<>
|
|
100
|
+
<AddButton />
|
|
101
|
+
<Search />
|
|
102
|
+
<div className="khb_table-wrapper">
|
|
103
|
+
<Table />
|
|
104
|
+
<Pagination />
|
|
105
|
+
</div>
|
|
106
|
+
</>
|
|
107
|
+
)}
|
|
108
|
+
{!explicitForm && (
|
|
109
|
+
<Drawer
|
|
110
|
+
open={formState === 'ADD' || formState === 'UPDATE'}
|
|
111
|
+
onClose={onCloseForm}
|
|
112
|
+
title={
|
|
113
|
+
formState === 'ADD'
|
|
114
|
+
? combinedTranslations.addPage
|
|
115
|
+
: formState === 'UPDATE'
|
|
116
|
+
? combinedTranslations.updatePage
|
|
117
|
+
: ''
|
|
118
|
+
}
|
|
119
|
+
footerContent={<PageFormActions formRef={formRef} />}
|
|
120
|
+
>
|
|
121
|
+
<PageForm formRef={formRef} />
|
|
122
|
+
</Drawer>
|
|
123
|
+
)}
|
|
124
|
+
{itemData && (
|
|
125
|
+
<DeleteModal
|
|
126
|
+
formState={formState}
|
|
127
|
+
itemData={itemData}
|
|
128
|
+
onClose={onCloseForm}
|
|
129
|
+
onConfirmDelete={onCofirmDeletePage}
|
|
130
|
+
confirmationRequired={commonTranslations.confirmationRequired}
|
|
131
|
+
confirm={commonTranslations.confirm}
|
|
132
|
+
lossOfData={commonTranslations.lossOfData}
|
|
133
|
+
permanentlyDelete={commonTranslations.permanentlyDelete}
|
|
134
|
+
pleaseType={commonTranslations.pleaseType}
|
|
135
|
+
toProceedOrCancel={commonTranslations.toProceedOrCancel}
|
|
136
|
+
typeHerePlaceholder={commonTranslations.typeHerePlaceholder}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
</PageContextProvider>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Page.Table = Table;
|
|
144
|
+
Page.Search = Search;
|
|
145
|
+
Page.Form = PageForm;
|
|
146
|
+
Page.AddButton = AddButton;
|
|
147
|
+
Page.Pagination = Pagination;
|
|
148
|
+
Page.FormActions = PageFormActions;
|
|
149
|
+
Page.FormWrapper = PageFormWrapper;
|
|
150
|
+
|
|
151
|
+
export default Page;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormActions from '../../common/FormActions';
|
|
3
|
+
import { FormActionWrapperProps } from '../../../types';
|
|
4
|
+
import { CALLBACK_CODES } from '../../../constants/common';
|
|
5
|
+
import { usePageState } from '../../../context/PageContext';
|
|
6
|
+
import { useProviderState } from '../../../context/ProviderContext';
|
|
7
|
+
|
|
8
|
+
const PageFormActions = ({ formRef }: FormActionWrapperProps) => {
|
|
9
|
+
const { onError, commonTranslations } = useProviderState();
|
|
10
|
+
const { closeForm, loading, canAdd, canUpdate, formState } = usePageState();
|
|
11
|
+
const onSubmitClick = (
|
|
12
|
+
e?: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
13
|
+
) => {
|
|
14
|
+
if (!formRef) {
|
|
15
|
+
return onError(
|
|
16
|
+
CALLBACK_CODES.INTERNAL,
|
|
17
|
+
'error',
|
|
18
|
+
`formRef is required to submit the form!`
|
|
19
|
+
);
|
|
20
|
+
} else if (!formRef.current) {
|
|
21
|
+
return onError(
|
|
22
|
+
CALLBACK_CODES.INTERNAL,
|
|
23
|
+
'error',
|
|
24
|
+
`formRef is empty, make sure it's passed as 'ref' prop to the form!`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
// formRef is provided
|
|
28
|
+
e?.preventDefault();
|
|
29
|
+
formRef.current?.dispatchEvent(
|
|
30
|
+
new Event('submit', { cancelable: true, bubbles: true })
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (!canAdd && !canUpdate) return null;
|
|
35
|
+
return (
|
|
36
|
+
<FormActions
|
|
37
|
+
loading={loading}
|
|
38
|
+
primaryLabel={
|
|
39
|
+
formState === 'ADD'
|
|
40
|
+
? commonTranslations.create
|
|
41
|
+
: commonTranslations.update
|
|
42
|
+
}
|
|
43
|
+
onPrimaryButtonClick={onSubmitClick}
|
|
44
|
+
onSecondaryButtonClick={closeForm}
|
|
45
|
+
secondaryLabel={commonTranslations.cancel}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default PageFormActions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FormWrapperProps } from '../../../types';
|
|
2
|
+
import { usePageState } from '../../../context/PageContext';
|
|
3
|
+
|
|
4
|
+
const PageFormWrapper = ({ children }: FormWrapperProps) => {
|
|
5
|
+
const { formState, closeForm } = usePageState();
|
|
6
|
+
|
|
7
|
+
return typeof children === 'function'
|
|
8
|
+
? children({
|
|
9
|
+
formState,
|
|
10
|
+
onClose: closeForm,
|
|
11
|
+
open: formState === 'ADD' || formState === 'UPDATE',
|
|
12
|
+
})
|
|
13
|
+
: null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default PageFormWrapper;
|