@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,194 +0,0 @@
|
|
|
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;
|
|
@@ -1,151 +0,0 @@
|
|
|
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;
|
|
@@ -1,50 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { usePageState } from "../../../context/PageContext";
|
|
3
|
-
import Pagination from "../../common/Pagination";
|
|
4
|
-
import { useProviderState } from '../../../context/ProviderContext';
|
|
5
|
-
|
|
6
|
-
const PagePagination = () => {
|
|
7
|
-
const { commonTranslations } = useProviderState();
|
|
8
|
-
const { totalPages, totalRecords, currentPage, pageSize, setCurrentPage } =
|
|
9
|
-
usePageState();
|
|
10
|
-
return (
|
|
11
|
-
<Pagination
|
|
12
|
-
ofText={commonTranslations.of}
|
|
13
|
-
pageText={commonTranslations.confirm}
|
|
14
|
-
showingText={commonTranslations.showing}
|
|
15
|
-
nextContent={commonTranslations.next}
|
|
16
|
-
previousContent={commonTranslations.previous}
|
|
17
|
-
totalPages={totalPages}
|
|
18
|
-
totalRecords={totalRecords}
|
|
19
|
-
currentPage={currentPage}
|
|
20
|
-
pageSize={pageSize}
|
|
21
|
-
setCurrentPage={setCurrentPage}
|
|
22
|
-
/>
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default PagePagination;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from "react";
|
|
2
|
-
import Input from "../../common/Input";
|
|
3
|
-
import { usePageState } from "../../../context/PageContext";
|
|
4
|
-
|
|
5
|
-
const PageSearch = () => {
|
|
6
|
-
const { pageTranslations, canList, changeSearch, setCurrentPage } =
|
|
7
|
-
usePageState();
|
|
8
|
-
const callerRef = useRef<NodeJS.Timeout | null>(null);
|
|
9
|
-
const [search, setSearch] = useState<string>('');
|
|
10
|
-
|
|
11
|
-
const onChangeSearch = (str: string) => {
|
|
12
|
-
setSearch(str);
|
|
13
|
-
changeSearch(str);
|
|
14
|
-
if (callerRef.current) clearTimeout(callerRef.current);
|
|
15
|
-
|
|
16
|
-
callerRef.current = setTimeout(() => {
|
|
17
|
-
setCurrentPage(1);
|
|
18
|
-
}, 300);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<Input
|
|
23
|
-
type="search"
|
|
24
|
-
value={search}
|
|
25
|
-
disabled={!canList}
|
|
26
|
-
onChange={(e) => onChangeSearch(e.target.value)}
|
|
27
|
-
placeholder={pageTranslations.searchPages}
|
|
28
|
-
/>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default PageSearch;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Table from '../../common/Table';
|
|
3
|
-
import { usePageState } from '../../../context/PageContext';
|
|
4
|
-
import { useProviderState } from '../../../context/ProviderContext';
|
|
5
|
-
import { CombineObjectType, DerivedTableProps } from '../../../types';
|
|
6
|
-
|
|
7
|
-
const PageTable = ({ extraActions, extraColumns }: DerivedTableProps) => {
|
|
8
|
-
const { commonTranslations } = useProviderState();
|
|
9
|
-
const { list, onChangeFormState, loading, loader, canUpdate, canDelete } =
|
|
10
|
-
usePageState();
|
|
11
|
-
|
|
12
|
-
const onUpdateClick = (item: CombineObjectType) =>
|
|
13
|
-
onChangeFormState('UPDATE', item);
|
|
14
|
-
const onDeleteClick = (item: CombineObjectType) =>
|
|
15
|
-
onChangeFormState('DELETE', item);
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<Table
|
|
19
|
-
data={list}
|
|
20
|
-
loader={loader}
|
|
21
|
-
loading={loading}
|
|
22
|
-
dataKeys={[
|
|
23
|
-
{ label: commonTranslations.name, dataKey: 'name', highlight: true },
|
|
24
|
-
{ label: commonTranslations.code, dataKey: 'code' },
|
|
25
|
-
]}
|
|
26
|
-
actionsLabel={commonTranslations.actions}
|
|
27
|
-
actions={{
|
|
28
|
-
edit: canUpdate ? onUpdateClick : undefined,
|
|
29
|
-
delete: canDelete ? onDeleteClick : undefined,
|
|
30
|
-
}}
|
|
31
|
-
extraColumns={extraColumns}
|
|
32
|
-
extraActions={extraActions}
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
export default PageTable;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import Button from "../../common/Button";
|
|
3
|
-
import { useWidgetState } from "../../../context/WidgetContext";
|
|
4
|
-
import { useProviderState } from '../../../context/ProviderContext';
|
|
5
|
-
|
|
6
|
-
const AddButton = () => {
|
|
7
|
-
const { commonTranslations } = useProviderState();
|
|
8
|
-
const { onChangeFormState, canAdd } = useWidgetState();
|
|
9
|
-
return (
|
|
10
|
-
<Button disabled={!canAdd} onClick={() => onChangeFormState('ADD')}>
|
|
11
|
-
{commonTranslations.add}
|
|
12
|
-
</Button>
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default AddButton;
|