@knovator/pagecreator-admin 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -205
- package/index.d.ts +1 -0
- package/package.json +38 -42
- package/src/{index.d.ts → index.ts} +1 -0
- package/src/lib/api/index.ts +70 -0
- package/src/lib/api/list.ts +59 -0
- package/src/lib/components/Page/AddButton/AddButton.tsx +16 -0
- package/src/lib/components/Page/AddButton/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Form/PageForm.tsx +194 -0
- package/src/lib/components/Page/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Page/Page.tsx +151 -0
- package/src/lib/components/Page/Page/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +50 -0
- package/src/lib/components/Page/PageFormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +16 -0
- package/src/lib/components/Page/PageFormWrapper/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Pagination/PagePagination.tsx +26 -0
- package/src/lib/components/Page/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/Search/PageSearch.tsx +32 -0
- package/src/lib/components/Page/Search/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/Page/Table/PageTable.tsx +36 -0
- package/src/lib/components/Page/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Page/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/AddButton/AddButton.tsx +16 -0
- package/src/lib/components/Widget/AddButton/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Form/ItemsAccordian.tsx +354 -0
- package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +43 -0
- package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +190 -0
- package/src/lib/components/Widget/Form/Tabs/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Form/WidgetForm.tsx +771 -0
- package/src/lib/components/Widget/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +26 -0
- package/src/lib/components/Widget/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Search/WidgetSearch.tsx +32 -0
- package/src/lib/components/Widget/Search/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/Widget/Table/WidgetTable.tsx +70 -0
- package/src/lib/components/Widget/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/Widget/Widget.tsx +173 -0
- package/src/lib/components/Widget/Widget/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +50 -0
- package/src/lib/components/Widget/WidgetFormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +16 -0
- package/src/lib/components/Widget/WidgetFormWrapper/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/Widget/{index.d.ts → index.tsx} +1 -0
- package/src/lib/components/common/Accordian/Accordian.tsx +56 -0
- package/src/lib/components/common/Accordian/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Button/Button.tsx +45 -0
- package/src/lib/components/common/Button/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +47 -0
- package/src/lib/components/common/ConfirmPopover/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +53 -0
- package/src/lib/components/common/DNDItemsList/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/DeleteModal/DeleteModal.tsx +72 -0
- package/src/lib/components/common/DeleteModal/index.tsx +3 -0
- package/src/lib/components/common/Drawer/Drawer.tsx +79 -0
- package/src/lib/components/common/Drawer/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Form/Form.tsx +256 -0
- package/src/lib/components/common/Form/SimpleForm.tsx +314 -0
- package/src/lib/components/common/Form/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/FormActions/FormActions.tsx +37 -0
- package/src/lib/components/common/FormActions/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/ImageUpload/ImageUpload.tsx +113 -0
- package/src/lib/components/common/ImageUpload/index.tsx +3 -0
- package/src/lib/components/common/Input/Checkbox.tsx +25 -0
- package/src/lib/components/common/Input/Input.tsx +51 -0
- package/src/lib/components/common/Input/ReactSelect.tsx +60 -0
- package/src/lib/components/common/Input/Select.tsx +47 -0
- package/src/lib/components/common/Input/SrcSet.tsx +143 -0
- package/src/lib/components/common/Input/index.ts +20 -0
- package/src/lib/components/common/Modal/Modal.tsx +57 -0
- package/src/lib/components/common/Modal/index.tsx +3 -0
- package/src/lib/components/common/Pagination/Pagination.tsx +88 -0
- package/src/lib/components/common/Pagination/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Table/Table.tsx +133 -0
- package/src/lib/components/common/Table/{index.d.ts → index.ts} +1 -0
- package/src/lib/components/common/Toggle/Toggle.tsx +23 -0
- package/src/lib/components/common/Toggle/{index.d.ts → index.ts} +1 -0
- package/src/lib/constants/common.ts +145 -0
- package/src/lib/context/PageContext.tsx +100 -0
- package/src/lib/context/ProviderContext.tsx +52 -0
- package/src/lib/context/WidgetContext.tsx +127 -0
- package/src/lib/helper/utils.ts +46 -0
- package/src/lib/hooks/usePage.tsx +307 -0
- package/src/lib/hooks/usePagination.tsx +41 -0
- package/src/lib/hooks/useWidget.tsx +503 -0
- package/src/lib/icons/chevronDown.tsx +21 -0
- package/src/lib/icons/chevronLeft.tsx +20 -0
- package/src/lib/icons/chevronRight.tsx +20 -0
- package/src/lib/icons/chevronUp.tsx +21 -0
- package/src/lib/icons/close.tsx +21 -0
- package/src/lib/icons/pencil.tsx +21 -0
- package/src/lib/icons/plus.tsx +23 -0
- package/src/lib/icons/trash.tsx +21 -0
- package/src/lib/types/api.ts +44 -0
- package/src/lib/types/common.ts +31 -0
- package/src/lib/types/components.ts +427 -0
- package/src/lib/types/context.ts +184 -0
- package/src/styles/index.css +469 -0
- package/index.cjs +0 -7714
- package/index.css +0 -2258
- package/index.js +0 -7700
- package/src/lib/api/index.d.ts +0 -10
- package/src/lib/api/list.d.ts +0 -56
- package/src/lib/components/Page/AddButton/AddButton.d.ts +0 -3
- package/src/lib/components/Page/Form/PageForm.d.ts +0 -4
- package/src/lib/components/Page/Page/Page.d.ts +0 -13
- package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +0 -4
- package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +0 -4
- package/src/lib/components/Page/Pagination/PagePagination.d.ts +0 -3
- package/src/lib/components/Page/Search/PageSearch.d.ts +0 -3
- package/src/lib/components/Page/Table/PageTable.d.ts +0 -4
- package/src/lib/components/Widget/AddButton/AddButton.d.ts +0 -3
- package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +0 -4
- package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +0 -4
- package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +0 -4
- package/src/lib/components/Widget/Form/WidgetForm.d.ts +0 -4
- package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +0 -3
- package/src/lib/components/Widget/Search/WidgetSearch.d.ts +0 -3
- package/src/lib/components/Widget/Table/WidgetTable.d.ts +0 -4
- package/src/lib/components/Widget/Widget/Widget.d.ts +0 -13
- package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +0 -4
- package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +0 -4
- package/src/lib/components/common/Accordian/Accordian.d.ts +0 -13
- package/src/lib/components/common/Button/Button.d.ts +0 -4
- package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +0 -4
- package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +0 -4
- package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +0 -4
- package/src/lib/components/common/DeleteModal/index.d.ts +0 -2
- package/src/lib/components/common/Drawer/Drawer.d.ts +0 -9
- package/src/lib/components/common/Form/Form.d.ts +0 -15
- package/src/lib/components/common/Form/SimpleForm.d.ts +0 -18
- package/src/lib/components/common/FormActions/FormActions.d.ts +0 -10
- package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +0 -4
- package/src/lib/components/common/ImageUpload/index.d.ts +0 -2
- package/src/lib/components/common/Input/Checkbox.d.ts +0 -4
- package/src/lib/components/common/Input/Input.d.ts +0 -4
- package/src/lib/components/common/Input/ReactSelect.d.ts +0 -4
- package/src/lib/components/common/Input/Select.d.ts +0 -4
- package/src/lib/components/common/Input/SrcSet.d.ts +0 -4
- package/src/lib/components/common/Input/index.d.ts +0 -12
- package/src/lib/components/common/Modal/Modal.d.ts +0 -8
- package/src/lib/components/common/Modal/index.d.ts +0 -2
- package/src/lib/components/common/Pagination/Pagination.d.ts +0 -4
- package/src/lib/components/common/Table/Table.d.ts +0 -4
- package/src/lib/components/common/Toggle/Toggle.d.ts +0 -4
- package/src/lib/constants/common.d.ts +0 -122
- package/src/lib/context/PageContext.d.ts +0 -7
- package/src/lib/context/ProviderContext.d.ts +0 -5
- package/src/lib/context/WidgetContext.d.ts +0 -7
- package/src/lib/helper/utils.d.ts +0 -10
- package/src/lib/hooks/usePage.d.ts +0 -43
- package/src/lib/hooks/usePagination.d.ts +0 -15
- package/src/lib/hooks/useWidget.d.ts +0 -46
- package/src/lib/icons/chevronDown.d.ts +0 -4
- package/src/lib/icons/chevronLeft.d.ts +0 -4
- package/src/lib/icons/chevronRight.d.ts +0 -4
- package/src/lib/icons/chevronUp.d.ts +0 -4
- package/src/lib/icons/close.d.ts +0 -4
- package/src/lib/icons/pencil.d.ts +0 -4
- package/src/lib/icons/plus.d.ts +0 -4
- package/src/lib/icons/trash.d.ts +0 -4
- package/src/lib/types/api.d.ts +0 -34
- package/src/lib/types/common.d.ts +0 -29
- package/src/lib/types/components.d.ts +0 -420
- package/src/lib/types/context.d.ts +0 -135
- /package/src/lib/types/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import React, { forwardRef, MutableRefObject } from 'react';
|
|
3
|
+
import { Controller } from 'react-hook-form';
|
|
4
|
+
import {
|
|
5
|
+
CombineObjectType,
|
|
6
|
+
LanguageType,
|
|
7
|
+
OptionType,
|
|
8
|
+
SchemaType,
|
|
9
|
+
} from '../../../types';
|
|
10
|
+
|
|
11
|
+
import Input from '../Input';
|
|
12
|
+
import CustomReactSelect from '../Input/ReactSelect';
|
|
13
|
+
|
|
14
|
+
interface SimpleFormProps {
|
|
15
|
+
schema: SchemaType[];
|
|
16
|
+
isUpdating?: boolean;
|
|
17
|
+
onSubmit: (data: CombineObjectType) => void;
|
|
18
|
+
enable?: boolean;
|
|
19
|
+
languages?: LanguageType[];
|
|
20
|
+
ref: MutableRefObject<HTMLFormElement | null>;
|
|
21
|
+
register: any;
|
|
22
|
+
errors: any;
|
|
23
|
+
handleSubmit: any;
|
|
24
|
+
setValue: any;
|
|
25
|
+
control: any;
|
|
26
|
+
setError: any;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const SimpleForm = forwardRef<HTMLFormElement | null, SimpleFormProps>(
|
|
30
|
+
(
|
|
31
|
+
{
|
|
32
|
+
schema,
|
|
33
|
+
onSubmit,
|
|
34
|
+
isUpdating = false,
|
|
35
|
+
enable = true,
|
|
36
|
+
register,
|
|
37
|
+
errors,
|
|
38
|
+
handleSubmit,
|
|
39
|
+
setValue,
|
|
40
|
+
control,
|
|
41
|
+
setError,
|
|
42
|
+
languages,
|
|
43
|
+
},
|
|
44
|
+
ref
|
|
45
|
+
) => {
|
|
46
|
+
const inputRenderer = (schema: SchemaType) => {
|
|
47
|
+
let input;
|
|
48
|
+
if (typeof schema.show !== 'undefined' && !schema.show) return null;
|
|
49
|
+
if (schema.type) {
|
|
50
|
+
switch (schema.type) {
|
|
51
|
+
case 'ReactSelect':
|
|
52
|
+
input = (
|
|
53
|
+
<CustomReactSelect
|
|
54
|
+
disabled={!enable}
|
|
55
|
+
label={schema.label}
|
|
56
|
+
error={errors[schema.accessor]?.message?.toString()}
|
|
57
|
+
onChange={(value: OptionType | OptionType[] | null) => {
|
|
58
|
+
if (value) {
|
|
59
|
+
setValue(
|
|
60
|
+
schema.accessor,
|
|
61
|
+
Array.isArray(value)
|
|
62
|
+
? value.map((item) => item.value)
|
|
63
|
+
: value.value
|
|
64
|
+
);
|
|
65
|
+
if (schema.onChange) schema.onChange(value);
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
selectedOptions={schema.selectedOptions}
|
|
69
|
+
required={schema.required}
|
|
70
|
+
isMulti={schema.isMulti}
|
|
71
|
+
isSearchable={schema.isSearchable}
|
|
72
|
+
isLoading={schema.isLoading}
|
|
73
|
+
placeholder={schema.placeholder}
|
|
74
|
+
wrapperClassName={schema.wrapperClassName}
|
|
75
|
+
formatOptionLabel={schema.formatOptionLabel}
|
|
76
|
+
listCode={schema.listCode}
|
|
77
|
+
customStyles={schema.customStyles}
|
|
78
|
+
loadOptions={schema.loadOptions}
|
|
79
|
+
selectKey={schema.selectKey}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
break;
|
|
83
|
+
case 'checkbox':
|
|
84
|
+
input = (
|
|
85
|
+
<Input.Checkbox
|
|
86
|
+
error={errors[schema.accessor]?.message?.toString()}
|
|
87
|
+
switchClass={schema.switchClass}
|
|
88
|
+
label={schema.label}
|
|
89
|
+
rest={register(schema.accessor, schema.validations || {})}
|
|
90
|
+
className="block"
|
|
91
|
+
disabled={
|
|
92
|
+
isUpdating &&
|
|
93
|
+
typeof schema.editable !== 'undefined' &&
|
|
94
|
+
!schema.editable
|
|
95
|
+
}
|
|
96
|
+
wrapperClassName={schema.wrapperClassName}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
break;
|
|
100
|
+
case 'select':
|
|
101
|
+
input = (
|
|
102
|
+
<Controller
|
|
103
|
+
control={control}
|
|
104
|
+
name={schema.accessor}
|
|
105
|
+
render={({ field }) => (
|
|
106
|
+
<Input.Select
|
|
107
|
+
options={schema.options}
|
|
108
|
+
label={schema.label}
|
|
109
|
+
error={errors[schema.accessor]?.message?.toString()}
|
|
110
|
+
// onChange={(e) => field.onChange(e.target.value)}
|
|
111
|
+
rest={field}
|
|
112
|
+
// value={field.value}
|
|
113
|
+
className="w-full"
|
|
114
|
+
disabled={
|
|
115
|
+
(isUpdating &&
|
|
116
|
+
typeof schema.editable !== 'undefined' &&
|
|
117
|
+
!schema.editable) ||
|
|
118
|
+
!enable
|
|
119
|
+
}
|
|
120
|
+
required={schema.required}
|
|
121
|
+
wrapperClassName={schema.wrapperClassName}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
></Controller>
|
|
125
|
+
);
|
|
126
|
+
break;
|
|
127
|
+
case 'text':
|
|
128
|
+
case 'number':
|
|
129
|
+
case 'url':
|
|
130
|
+
case 'color':
|
|
131
|
+
default:
|
|
132
|
+
if (
|
|
133
|
+
Array.isArray(languages) &&
|
|
134
|
+
languages.length > 0 &&
|
|
135
|
+
schema.accessor === 'widgetTitles'
|
|
136
|
+
) {
|
|
137
|
+
input = languages.map((lang) => (
|
|
138
|
+
<Input
|
|
139
|
+
key={lang.code}
|
|
140
|
+
rest={register(
|
|
141
|
+
`${schema.accessor}.${lang.code}`,
|
|
142
|
+
schema.validations || {}
|
|
143
|
+
)}
|
|
144
|
+
label={schema.label + ' (' + lang.name + ')'}
|
|
145
|
+
onInput={schema.onInput}
|
|
146
|
+
error={errors[schema.accessor]?.[lang.code]?.message}
|
|
147
|
+
required={schema.required}
|
|
148
|
+
type={schema.type}
|
|
149
|
+
className="kms_w-full kms_p-2"
|
|
150
|
+
placeholder={
|
|
151
|
+
(schema.placeholder || '') + ' (' + lang.name + ')'
|
|
152
|
+
}
|
|
153
|
+
disabled={
|
|
154
|
+
isUpdating &&
|
|
155
|
+
typeof schema.editable !== 'undefined' &&
|
|
156
|
+
!schema.editable
|
|
157
|
+
}
|
|
158
|
+
/>
|
|
159
|
+
));
|
|
160
|
+
} else
|
|
161
|
+
input = (
|
|
162
|
+
<Input
|
|
163
|
+
rest={register(schema.accessor, schema.validations || {})}
|
|
164
|
+
label={schema.label}
|
|
165
|
+
error={errors[schema.accessor]?.message?.toString()}
|
|
166
|
+
type={schema.type}
|
|
167
|
+
className={classNames('w-full p-2', schema.className)}
|
|
168
|
+
placeholder={schema.placeholder}
|
|
169
|
+
disabled={
|
|
170
|
+
(isUpdating &&
|
|
171
|
+
typeof schema.editable !== 'undefined' &&
|
|
172
|
+
!schema.editable) ||
|
|
173
|
+
!enable
|
|
174
|
+
}
|
|
175
|
+
required={schema.required}
|
|
176
|
+
onInput={schema.onInput}
|
|
177
|
+
wrapperClassName={schema.wrapperClassName}
|
|
178
|
+
info={schema.info}
|
|
179
|
+
/>
|
|
180
|
+
);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
} else if (schema.Input) {
|
|
184
|
+
if (
|
|
185
|
+
Array.isArray(languages) &&
|
|
186
|
+
languages.length > 0 &&
|
|
187
|
+
schema.accessor === 'widgetTitles'
|
|
188
|
+
) {
|
|
189
|
+
input = languages.map((lang) => (
|
|
190
|
+
<div
|
|
191
|
+
key={lang.code}
|
|
192
|
+
className={classNames(
|
|
193
|
+
'khb_input-wrapper',
|
|
194
|
+
schema.wrapperClassName
|
|
195
|
+
)}
|
|
196
|
+
>
|
|
197
|
+
<label className="khb_input-label">
|
|
198
|
+
{schema.label} ({lang.name})
|
|
199
|
+
{schema.required ? (
|
|
200
|
+
<span className="khb_input-label-required">*</span>
|
|
201
|
+
) : null}
|
|
202
|
+
</label>
|
|
203
|
+
<Controller
|
|
204
|
+
control={control}
|
|
205
|
+
name={`${schema.accessor}.${lang.code}`}
|
|
206
|
+
rules={schema.validations}
|
|
207
|
+
render={({ field }) =>
|
|
208
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
209
|
+
schema.Input!({
|
|
210
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
211
|
+
// @ts-ignore
|
|
212
|
+
field,
|
|
213
|
+
error:
|
|
214
|
+
errors[schema.accessor]?.[lang.code]?.message?.toString(),
|
|
215
|
+
disabled:
|
|
216
|
+
(isUpdating &&
|
|
217
|
+
typeof schema.editable !== 'undefined' &&
|
|
218
|
+
!schema.editable) ||
|
|
219
|
+
!enable,
|
|
220
|
+
setError: (msg) =>
|
|
221
|
+
setError.call(null, schema.accessor, {
|
|
222
|
+
type: 'custom',
|
|
223
|
+
message: msg,
|
|
224
|
+
}),
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
/>
|
|
228
|
+
</div>
|
|
229
|
+
));
|
|
230
|
+
} else
|
|
231
|
+
input = (
|
|
232
|
+
<div
|
|
233
|
+
className={classNames(
|
|
234
|
+
'khb_input-wrapper',
|
|
235
|
+
schema.wrapperClassName
|
|
236
|
+
)}
|
|
237
|
+
>
|
|
238
|
+
{schema.label && (
|
|
239
|
+
<label className="khb_input-label">
|
|
240
|
+
{schema.label}
|
|
241
|
+
{schema.required ? (
|
|
242
|
+
<span className="khb_input-label-required">*</span>
|
|
243
|
+
) : null}
|
|
244
|
+
</label>
|
|
245
|
+
)}
|
|
246
|
+
<Controller
|
|
247
|
+
control={control}
|
|
248
|
+
name={schema.accessor}
|
|
249
|
+
rules={schema.validations}
|
|
250
|
+
render={({ field }) =>
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
252
|
+
schema.Input!({
|
|
253
|
+
field,
|
|
254
|
+
error: errors[schema.accessor]?.message?.toString(),
|
|
255
|
+
disabled:
|
|
256
|
+
(isUpdating &&
|
|
257
|
+
typeof schema.editable !== 'undefined' &&
|
|
258
|
+
!schema.editable) ||
|
|
259
|
+
!enable,
|
|
260
|
+
setError: (msg) =>
|
|
261
|
+
setError.call(null, schema.accessor, {
|
|
262
|
+
type: 'custom',
|
|
263
|
+
message: msg,
|
|
264
|
+
}),
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
/>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
} else
|
|
271
|
+
throw new Error(
|
|
272
|
+
`Please provide Input or type prop to render input Labeled ${schema.label}`
|
|
273
|
+
);
|
|
274
|
+
return input;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const onFormSubmit = async (e: React.FormEvent) => {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
handleSubmit((data: any) => {
|
|
280
|
+
const formattedData: CombineObjectType = schema.reduce(
|
|
281
|
+
(values: CombineObjectType, schemaItem: SchemaType) => {
|
|
282
|
+
// Do not add field if editing is disabled for it
|
|
283
|
+
if (
|
|
284
|
+
isUpdating &&
|
|
285
|
+
typeof schemaItem.editable !== 'undefined' &&
|
|
286
|
+
!schemaItem.editable
|
|
287
|
+
)
|
|
288
|
+
return values;
|
|
289
|
+
|
|
290
|
+
if (schemaItem.type === 'number') {
|
|
291
|
+
values[schemaItem.accessor] =
|
|
292
|
+
data[schemaItem.accessor] === ''
|
|
293
|
+
? null
|
|
294
|
+
: parseInt(data[schemaItem.accessor]);
|
|
295
|
+
} else values[schemaItem.accessor] = data[schemaItem.accessor];
|
|
296
|
+
return values;
|
|
297
|
+
},
|
|
298
|
+
{}
|
|
299
|
+
);
|
|
300
|
+
onSubmit(formattedData);
|
|
301
|
+
})();
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<form onSubmit={onFormSubmit} ref={ref} className="khb-form-items">
|
|
306
|
+
{schema.map((schema, i) => (
|
|
307
|
+
<React.Fragment key={i}>{inputRenderer(schema)}</React.Fragment>
|
|
308
|
+
))}
|
|
309
|
+
</form>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
export default SimpleForm;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Button from '../Button';
|
|
3
|
+
|
|
4
|
+
interface FormActionsProps {
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
primaryLabel?: string;
|
|
7
|
+
secondaryLabel?: string;
|
|
8
|
+
onPrimaryButtonClick?: (
|
|
9
|
+
e?: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
10
|
+
) => void;
|
|
11
|
+
onSecondaryButtonClick?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const FormActions = ({
|
|
15
|
+
loading = false,
|
|
16
|
+
primaryLabel = 'Submit',
|
|
17
|
+
secondaryLabel = 'Cancel',
|
|
18
|
+
onPrimaryButtonClick,
|
|
19
|
+
onSecondaryButtonClick,
|
|
20
|
+
}: FormActionsProps) => {
|
|
21
|
+
return (
|
|
22
|
+
<>
|
|
23
|
+
<Button
|
|
24
|
+
type="secondary"
|
|
25
|
+
disabled={loading}
|
|
26
|
+
onClick={onSecondaryButtonClick}
|
|
27
|
+
>
|
|
28
|
+
{secondaryLabel}
|
|
29
|
+
</Button>
|
|
30
|
+
<Button onClick={onPrimaryButtonClick} loading={loading}>
|
|
31
|
+
{primaryLabel}
|
|
32
|
+
</Button>
|
|
33
|
+
</>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default FormActions;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { useDropzone } from 'react-dropzone';
|
|
3
|
+
import SmallCancel from '../../../icons/close';
|
|
4
|
+
import { ImageUploadProps } from '../../../types';
|
|
5
|
+
import { build_path, isEmpty, isString } from '../../../helper/utils';
|
|
6
|
+
|
|
7
|
+
const ImageUpload = ({
|
|
8
|
+
className,
|
|
9
|
+
text,
|
|
10
|
+
maxSize,
|
|
11
|
+
setImgId,
|
|
12
|
+
onError,
|
|
13
|
+
error,
|
|
14
|
+
imgId = '',
|
|
15
|
+
onImageUpload,
|
|
16
|
+
onImageRemove,
|
|
17
|
+
clearError,
|
|
18
|
+
baseUrl,
|
|
19
|
+
disabled = false,
|
|
20
|
+
}: ImageUploadProps) => {
|
|
21
|
+
const [img, setImg] = useState<string | undefined>(undefined);
|
|
22
|
+
const { getRootProps, getInputProps } = useDropzone({
|
|
23
|
+
// accept: {
|
|
24
|
+
// "image/*": [".jpeg,.jpg,.png"],
|
|
25
|
+
// },
|
|
26
|
+
noClick: true,
|
|
27
|
+
multiple: false,
|
|
28
|
+
minSize: 0,
|
|
29
|
+
maxSize,
|
|
30
|
+
onDrop: async (acceptedFiles, rejectedFiles) => {
|
|
31
|
+
try {
|
|
32
|
+
if (typeof clearError === 'function') clearError();
|
|
33
|
+
if (acceptedFiles?.length > 0) {
|
|
34
|
+
const regex = /\.(png|jpeg|jpg|webp|svg|gif)$/gi;
|
|
35
|
+
const files = acceptedFiles.filter((file) => regex.test(file.name));
|
|
36
|
+
if (files[0]) {
|
|
37
|
+
const response = await onImageUpload(files[0]);
|
|
38
|
+
if (response) {
|
|
39
|
+
setImg(response.fileUrl);
|
|
40
|
+
setImgId(response.fileId);
|
|
41
|
+
}
|
|
42
|
+
} else
|
|
43
|
+
throw new Error(
|
|
44
|
+
'Only .png, .jpg, .jpeg, .web, or .svg image types are supported.'
|
|
45
|
+
);
|
|
46
|
+
} else if (
|
|
47
|
+
rejectedFiles?.[0]?.errors?.[0]?.message ===
|
|
48
|
+
'File size must be smaller than 10485760 bytes'
|
|
49
|
+
) {
|
|
50
|
+
throw new Error('File is larger than 10mb');
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
onError((error as Error).message);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const onRemoveFile = async (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
try {
|
|
61
|
+
if (onImageRemove && imgId)
|
|
62
|
+
await onImageRemove(typeof imgId === 'string' ? imgId : imgId['_id']);
|
|
63
|
+
|
|
64
|
+
setImgId(null);
|
|
65
|
+
setImg('');
|
|
66
|
+
} catch (error) {
|
|
67
|
+
onError((error as Error).message);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (imgId && typeof imgId === 'object') {
|
|
73
|
+
setImg(build_path(baseUrl, imgId['uri']));
|
|
74
|
+
}
|
|
75
|
+
}, [baseUrl, imgId]);
|
|
76
|
+
|
|
77
|
+
const showImage = (fileUrl: string) => {
|
|
78
|
+
return (
|
|
79
|
+
<div className="khb_img-wrapper">
|
|
80
|
+
<img src={`${fileUrl}`} alt="" className="khb_img-wrapper-img" />
|
|
81
|
+
{!disabled && (
|
|
82
|
+
<button onClick={onRemoveFile} className="khb_img-wrapper-del">
|
|
83
|
+
<SmallCancel />
|
|
84
|
+
</button>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (!isEmpty(img) && isString(img) && img) {
|
|
91
|
+
return (
|
|
92
|
+
<div className="khb_img-upload-wrapper-1">
|
|
93
|
+
<div className="khb_img-upload-wrapper-2">
|
|
94
|
+
<div>{showImage(img)}</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<>
|
|
102
|
+
<div {...getRootProps()} className="khb_img-upload-wrapper-1">
|
|
103
|
+
<input disabled={disabled} {...getInputProps()} id="file-upload" />
|
|
104
|
+
<label htmlFor="file-upload" className="khb_img-upload-wrapper-2">
|
|
105
|
+
<div className={className}>{text}</div>
|
|
106
|
+
</label>
|
|
107
|
+
</div>
|
|
108
|
+
{error && <p className="khb_input-error">{error}</p>}
|
|
109
|
+
</>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default React.memo(ImageUpload);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { CheckboxProps } from '../../../types';
|
|
4
|
+
|
|
5
|
+
const Checkbox = ({
|
|
6
|
+
rest,
|
|
7
|
+
label,
|
|
8
|
+
error,
|
|
9
|
+
wrapperClassName,
|
|
10
|
+
disabled,
|
|
11
|
+
switchClass,
|
|
12
|
+
}: CheckboxProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<div className={classNames('khb_input-wrapper', wrapperClassName)}>
|
|
15
|
+
{label && <label className="khb_input-label">{label}</label>}
|
|
16
|
+
<label className={switchClass || 'khb_switch'} data-testid="khb_switch">
|
|
17
|
+
<input type="checkbox" disabled={disabled} {...rest} />
|
|
18
|
+
<span className="slider round" />
|
|
19
|
+
</label>
|
|
20
|
+
{error && <p className="khb_input-error">{error}</p>}
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default Checkbox;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { InputProps } from '../../../types';
|
|
4
|
+
|
|
5
|
+
const Input = ({
|
|
6
|
+
label,
|
|
7
|
+
id,
|
|
8
|
+
placeholder,
|
|
9
|
+
type,
|
|
10
|
+
size = 'base',
|
|
11
|
+
required,
|
|
12
|
+
error,
|
|
13
|
+
className,
|
|
14
|
+
disabled,
|
|
15
|
+
rest,
|
|
16
|
+
onInput,
|
|
17
|
+
onBlur,
|
|
18
|
+
value,
|
|
19
|
+
info,
|
|
20
|
+
onChange,
|
|
21
|
+
wrapperClassName,
|
|
22
|
+
}: InputProps) => {
|
|
23
|
+
return (
|
|
24
|
+
<div className={classNames('khb_input-wrapper', wrapperClassName)}>
|
|
25
|
+
{label && (
|
|
26
|
+
<label className="khb_input-label">
|
|
27
|
+
{label}
|
|
28
|
+
{required ? (
|
|
29
|
+
<span className="khb_input-label-required">*</span>
|
|
30
|
+
) : null}
|
|
31
|
+
</label>
|
|
32
|
+
)}
|
|
33
|
+
<input
|
|
34
|
+
className={classNames('khb_input', `khb_input-${size}`, className)}
|
|
35
|
+
type={type}
|
|
36
|
+
placeholder={placeholder}
|
|
37
|
+
disabled={disabled}
|
|
38
|
+
id={id}
|
|
39
|
+
value={value}
|
|
40
|
+
onChange={onChange}
|
|
41
|
+
{...rest}
|
|
42
|
+
onInput={onInput}
|
|
43
|
+
onBlur={onBlur}
|
|
44
|
+
/>
|
|
45
|
+
{error && <p className="khb_input-error ">{error}</p>}
|
|
46
|
+
{info && <p className="khb_input-info">{info}</p>}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default Input;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import ReactSelect from 'react-select/async';
|
|
4
|
+
import { ReactSelectProps } from '../../../types';
|
|
5
|
+
|
|
6
|
+
const CustomReactSelect = ({
|
|
7
|
+
onChange,
|
|
8
|
+
label,
|
|
9
|
+
error,
|
|
10
|
+
className,
|
|
11
|
+
isMulti,
|
|
12
|
+
selectedOptions = [],
|
|
13
|
+
required,
|
|
14
|
+
isLoading,
|
|
15
|
+
isSearchable,
|
|
16
|
+
loadOptions,
|
|
17
|
+
placeholder,
|
|
18
|
+
wrapperClassName,
|
|
19
|
+
formatOptionLabel,
|
|
20
|
+
listCode,
|
|
21
|
+
customStyles,
|
|
22
|
+
selectKey,
|
|
23
|
+
}: ReactSelectProps) => {
|
|
24
|
+
return (
|
|
25
|
+
<div className={wrapperClassName}>
|
|
26
|
+
{label && (
|
|
27
|
+
<label className="khb_input-label">
|
|
28
|
+
{label}
|
|
29
|
+
{required ? (
|
|
30
|
+
<span className="khb_input-label-required">*</span>
|
|
31
|
+
) : null}
|
|
32
|
+
</label>
|
|
33
|
+
)}
|
|
34
|
+
<ReactSelect
|
|
35
|
+
key={selectKey}
|
|
36
|
+
data-testid={`input-select-${label}`}
|
|
37
|
+
value={selectedOptions}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
onChange={onChange}
|
|
41
|
+
className={classNames(className)}
|
|
42
|
+
isMulti={isMulti}
|
|
43
|
+
defaultOptions
|
|
44
|
+
isSearchable={isSearchable}
|
|
45
|
+
isLoading={isLoading}
|
|
46
|
+
loadOptions={loadOptions}
|
|
47
|
+
placeholder={placeholder}
|
|
48
|
+
formatOptionLabel={
|
|
49
|
+
formatOptionLabel
|
|
50
|
+
? (option) => formatOptionLabel(listCode!, option)
|
|
51
|
+
: undefined
|
|
52
|
+
}
|
|
53
|
+
styles={customStyles}
|
|
54
|
+
/>
|
|
55
|
+
{error && <p className="khb_input-error ">{error}</p>}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default CustomReactSelect;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { SelectProps } from '../../../types';
|
|
4
|
+
|
|
5
|
+
const Select = ({
|
|
6
|
+
onChange,
|
|
7
|
+
value,
|
|
8
|
+
rest,
|
|
9
|
+
label,
|
|
10
|
+
error,
|
|
11
|
+
options = [],
|
|
12
|
+
size = 'base',
|
|
13
|
+
className,
|
|
14
|
+
disabled,
|
|
15
|
+
required,
|
|
16
|
+
wrapperClassName,
|
|
17
|
+
}: SelectProps) => {
|
|
18
|
+
return (
|
|
19
|
+
<div className={classNames('khb_input-wrapper', wrapperClassName)}>
|
|
20
|
+
{label && (
|
|
21
|
+
<label className="khb_input-label">
|
|
22
|
+
{label}
|
|
23
|
+
{required ? (
|
|
24
|
+
<span className="khb_input-label-required">*</span>
|
|
25
|
+
) : null}
|
|
26
|
+
</label>
|
|
27
|
+
)}
|
|
28
|
+
<select
|
|
29
|
+
data-testid={`input-select-${label}`}
|
|
30
|
+
value={value}
|
|
31
|
+
onChange={onChange}
|
|
32
|
+
className={classNames('khb_input', `khb_input-${size}`, className)}
|
|
33
|
+
disabled={disabled}
|
|
34
|
+
{...rest}
|
|
35
|
+
>
|
|
36
|
+
{options.map((option, index) => (
|
|
37
|
+
<option value={option.value} key={index} data-testid="select-option">
|
|
38
|
+
{option.label}
|
|
39
|
+
</option>
|
|
40
|
+
))}
|
|
41
|
+
</select>
|
|
42
|
+
{error && <p className="khb_input-error ">{error}</p>}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default Select;
|