@knovator/pagecreator-admin 1.2.9 → 1.3.0

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.
Files changed (167) hide show
  1. package/index.cjs +7876 -0
  2. package/index.css +2 -0
  3. package/index.js +7862 -0
  4. package/package.json +42 -38
  5. package/src/{index.ts → index.d.ts} +0 -1
  6. package/src/lib/api/index.d.ts +10 -0
  7. package/src/lib/api/list.d.ts +56 -0
  8. package/src/lib/components/Page/AddButton/AddButton.d.ts +3 -0
  9. package/src/lib/components/Page/AddButton/{index.ts → index.d.ts} +0 -1
  10. package/src/lib/components/Page/Form/PageForm.d.ts +4 -0
  11. package/src/lib/components/Page/Form/{index.ts → index.d.ts} +0 -1
  12. package/src/lib/components/Page/Page/Page.d.ts +13 -0
  13. package/src/lib/components/Page/Page/{index.ts → index.d.ts} +0 -1
  14. package/src/lib/components/Page/PageFormActions/PageFormActions.d.ts +4 -0
  15. package/src/lib/components/Page/PageFormActions/{index.ts → index.d.ts} +0 -1
  16. package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.d.ts +4 -0
  17. package/src/lib/components/Page/PageFormWrapper/{index.ts → index.d.ts} +0 -1
  18. package/src/lib/components/Page/Pagination/PagePagination.d.ts +3 -0
  19. package/src/lib/components/Page/Pagination/{index.ts → index.d.ts} +0 -1
  20. package/src/lib/components/Page/Search/PageSearch.d.ts +3 -0
  21. package/src/lib/components/Page/Search/{index.tsx → index.d.ts} +0 -1
  22. package/src/lib/components/Page/Table/PageTable.d.ts +4 -0
  23. package/src/lib/components/Page/Table/{index.ts → index.d.ts} +0 -1
  24. package/src/lib/components/Page/{index.ts → index.d.ts} +0 -1
  25. package/src/lib/components/Widget/AddButton/AddButton.d.ts +3 -0
  26. package/src/lib/components/Widget/AddButton/{index.ts → index.d.ts} +0 -1
  27. package/src/lib/components/Widget/Form/ItemsAccordian.d.ts +4 -0
  28. package/src/lib/components/Widget/Form/Tabs/TabItem.d.ts +4 -0
  29. package/src/lib/components/Widget/Form/Tabs/Tabs.d.ts +4 -0
  30. package/src/lib/components/Widget/Form/Tabs/{index.ts → index.d.ts} +0 -1
  31. package/src/lib/components/Widget/Form/WidgetForm.d.ts +4 -0
  32. package/src/lib/components/Widget/Form/{index.ts → index.d.ts} +0 -1
  33. package/src/lib/components/Widget/Pagination/WidgetPagination.d.ts +3 -0
  34. package/src/lib/components/Widget/Pagination/{index.ts → index.d.ts} +0 -1
  35. package/src/lib/components/Widget/Search/WidgetSearch.d.ts +3 -0
  36. package/src/lib/components/Widget/Search/{index.tsx → index.d.ts} +0 -1
  37. package/src/lib/components/Widget/Table/WidgetTable.d.ts +4 -0
  38. package/src/lib/components/Widget/Table/{index.ts → index.d.ts} +0 -1
  39. package/src/lib/components/Widget/Widget/Widget.d.ts +13 -0
  40. package/src/lib/components/Widget/Widget/{index.ts → index.d.ts} +0 -1
  41. package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.d.ts +4 -0
  42. package/src/lib/components/Widget/WidgetFormActions/{index.ts → index.d.ts} +0 -1
  43. package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.d.ts +4 -0
  44. package/src/lib/components/Widget/WidgetFormWrapper/{index.ts → index.d.ts} +0 -1
  45. package/src/lib/components/Widget/{index.tsx → index.d.ts} +0 -1
  46. package/src/lib/components/common/Accordian/Accordian.d.ts +13 -0
  47. package/src/lib/components/common/Accordian/{index.ts → index.d.ts} +0 -1
  48. package/src/lib/components/common/Button/Button.d.ts +4 -0
  49. package/src/lib/components/common/Button/{index.ts → index.d.ts} +0 -1
  50. package/src/lib/components/common/ConfirmPopover/ConfirmPopover.d.ts +4 -0
  51. package/src/lib/components/common/ConfirmPopover/{index.ts → index.d.ts} +0 -1
  52. package/src/lib/components/common/DNDItemsList/DNDItemsList.d.ts +4 -0
  53. package/src/lib/components/common/DNDItemsList/{index.ts → index.d.ts} +0 -1
  54. package/src/lib/components/common/DeleteModal/DeleteModal.d.ts +4 -0
  55. package/src/lib/components/common/DeleteModal/index.d.ts +2 -0
  56. package/src/lib/components/common/Drawer/Drawer.d.ts +9 -0
  57. package/src/lib/components/common/Drawer/{index.ts → index.d.ts} +0 -1
  58. package/src/lib/components/common/Form/Form.d.ts +15 -0
  59. package/src/lib/components/common/Form/SimpleForm.d.ts +18 -0
  60. package/src/lib/components/common/Form/{index.ts → index.d.ts} +0 -1
  61. package/src/lib/components/common/FormActions/FormActions.d.ts +10 -0
  62. package/src/lib/components/common/FormActions/{index.ts → index.d.ts} +0 -1
  63. package/src/lib/components/common/ImageUpload/ImageUpload.d.ts +4 -0
  64. package/src/lib/components/common/ImageUpload/index.d.ts +2 -0
  65. package/src/lib/components/common/Input/Checkbox.d.ts +4 -0
  66. package/src/lib/components/common/Input/Input.d.ts +4 -0
  67. package/src/lib/components/common/Input/ReactSelect.d.ts +4 -0
  68. package/src/lib/components/common/Input/Select.d.ts +4 -0
  69. package/src/lib/components/common/Input/SrcSet.d.ts +4 -0
  70. package/src/lib/components/common/Input/index.d.ts +12 -0
  71. package/src/lib/components/common/Modal/Modal.d.ts +8 -0
  72. package/src/lib/components/common/Modal/index.d.ts +2 -0
  73. package/src/lib/components/common/Pagination/Pagination.d.ts +4 -0
  74. package/src/lib/components/common/Pagination/{index.ts → index.d.ts} +0 -1
  75. package/src/lib/components/common/Table/Table.d.ts +4 -0
  76. package/src/lib/components/common/Table/{index.ts → index.d.ts} +0 -1
  77. package/src/lib/components/common/Toggle/Toggle.d.ts +4 -0
  78. package/src/lib/components/common/Toggle/{index.ts → index.d.ts} +0 -1
  79. package/src/lib/constants/common.d.ts +122 -0
  80. package/src/lib/context/PageContext.d.ts +7 -0
  81. package/src/lib/context/ProviderContext.d.ts +5 -0
  82. package/src/lib/context/WidgetContext.d.ts +7 -0
  83. package/src/lib/helper/utils.d.ts +10 -0
  84. package/src/lib/hooks/usePage.d.ts +37 -0
  85. package/src/lib/hooks/usePagination.d.ts +15 -0
  86. package/src/lib/hooks/useWidget.d.ts +46 -0
  87. package/src/lib/icons/chevronDown.d.ts +4 -0
  88. package/src/lib/icons/chevronLeft.d.ts +4 -0
  89. package/src/lib/icons/chevronRight.d.ts +4 -0
  90. package/src/lib/icons/chevronUp.d.ts +4 -0
  91. package/src/lib/icons/close.d.ts +4 -0
  92. package/src/lib/icons/pencil.d.ts +4 -0
  93. package/src/lib/icons/plus.d.ts +4 -0
  94. package/src/lib/icons/settings.d.ts +4 -0
  95. package/src/lib/icons/trash.d.ts +4 -0
  96. package/src/lib/types/api.d.ts +34 -0
  97. package/src/lib/types/common.d.ts +30 -0
  98. package/src/lib/types/components.d.ts +421 -0
  99. package/src/lib/types/context.d.ts +135 -0
  100. package/index.d.ts +0 -1
  101. package/src/lib/api/index.ts +0 -70
  102. package/src/lib/api/list.ts +0 -59
  103. package/src/lib/components/Page/AddButton/AddButton.tsx +0 -16
  104. package/src/lib/components/Page/Form/PageForm.tsx +0 -194
  105. package/src/lib/components/Page/Page/Page.tsx +0 -151
  106. package/src/lib/components/Page/PageFormActions/PageFormActions.tsx +0 -50
  107. package/src/lib/components/Page/PageFormWrapper/PageFormWrapper.tsx +0 -16
  108. package/src/lib/components/Page/Pagination/PagePagination.tsx +0 -26
  109. package/src/lib/components/Page/Search/PageSearch.tsx +0 -32
  110. package/src/lib/components/Page/Table/PageTable.tsx +0 -36
  111. package/src/lib/components/Widget/AddButton/AddButton.tsx +0 -16
  112. package/src/lib/components/Widget/Form/ItemsAccordian.tsx +0 -354
  113. package/src/lib/components/Widget/Form/Tabs/TabItem.tsx +0 -43
  114. package/src/lib/components/Widget/Form/Tabs/Tabs.tsx +0 -190
  115. package/src/lib/components/Widget/Form/WidgetForm.tsx +0 -771
  116. package/src/lib/components/Widget/Pagination/WidgetPagination.tsx +0 -26
  117. package/src/lib/components/Widget/Search/WidgetSearch.tsx +0 -32
  118. package/src/lib/components/Widget/Table/WidgetTable.tsx +0 -70
  119. package/src/lib/components/Widget/Widget/Widget.tsx +0 -173
  120. package/src/lib/components/Widget/WidgetFormActions/WidgetFormActions.tsx +0 -50
  121. package/src/lib/components/Widget/WidgetFormWrapper/WidgetFormWrapper.tsx +0 -16
  122. package/src/lib/components/common/Accordian/Accordian.tsx +0 -56
  123. package/src/lib/components/common/Button/Button.tsx +0 -45
  124. package/src/lib/components/common/ConfirmPopover/ConfirmPopover.tsx +0 -47
  125. package/src/lib/components/common/DNDItemsList/DNDItemsList.tsx +0 -77
  126. package/src/lib/components/common/DeleteModal/DeleteModal.tsx +0 -72
  127. package/src/lib/components/common/DeleteModal/index.tsx +0 -3
  128. package/src/lib/components/common/Drawer/Drawer.tsx +0 -79
  129. package/src/lib/components/common/Form/Form.tsx +0 -256
  130. package/src/lib/components/common/Form/SimpleForm.tsx +0 -314
  131. package/src/lib/components/common/FormActions/FormActions.tsx +0 -37
  132. package/src/lib/components/common/ImageUpload/ImageUpload.tsx +0 -113
  133. package/src/lib/components/common/ImageUpload/index.tsx +0 -3
  134. package/src/lib/components/common/Input/Checkbox.tsx +0 -25
  135. package/src/lib/components/common/Input/Input.tsx +0 -51
  136. package/src/lib/components/common/Input/ReactSelect.tsx +0 -61
  137. package/src/lib/components/common/Input/Select.tsx +0 -47
  138. package/src/lib/components/common/Input/SrcSet.tsx +0 -143
  139. package/src/lib/components/common/Input/index.ts +0 -20
  140. package/src/lib/components/common/Modal/Modal.tsx +0 -57
  141. package/src/lib/components/common/Modal/index.tsx +0 -3
  142. package/src/lib/components/common/Pagination/Pagination.tsx +0 -88
  143. package/src/lib/components/common/Table/Table.tsx +0 -133
  144. package/src/lib/components/common/Toggle/Toggle.tsx +0 -23
  145. package/src/lib/constants/common.ts +0 -145
  146. package/src/lib/context/PageContext.tsx +0 -100
  147. package/src/lib/context/ProviderContext.tsx +0 -52
  148. package/src/lib/context/WidgetContext.tsx +0 -127
  149. package/src/lib/helper/utils.ts +0 -46
  150. package/src/lib/hooks/usePage.tsx +0 -306
  151. package/src/lib/hooks/usePagination.tsx +0 -41
  152. package/src/lib/hooks/useWidget.tsx +0 -503
  153. package/src/lib/icons/chevronDown.tsx +0 -21
  154. package/src/lib/icons/chevronLeft.tsx +0 -20
  155. package/src/lib/icons/chevronRight.tsx +0 -20
  156. package/src/lib/icons/chevronUp.tsx +0 -21
  157. package/src/lib/icons/close.tsx +0 -21
  158. package/src/lib/icons/pencil.tsx +0 -21
  159. package/src/lib/icons/plus.tsx +0 -23
  160. package/src/lib/icons/settings.tsx +0 -35
  161. package/src/lib/icons/trash.tsx +0 -21
  162. package/src/lib/types/api.ts +0 -44
  163. package/src/lib/types/common.ts +0 -31
  164. package/src/lib/types/components.ts +0 -428
  165. package/src/lib/types/context.ts +0 -184
  166. package/src/styles/index.css +0 -481
  167. /package/src/lib/types/{index.ts → index.d.ts} +0 -0
@@ -1,503 +0,0 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { CALLBACK_CODES, INTERNAL_ERROR_CODE } from '../constants/common';
3
- import { useProviderState } from '../context/ProviderContext';
4
- import { paginationDataGatter, dataGatter, build_path } from '../helper/utils';
5
- import usePagination from './usePagination';
6
- import request, { getApiType } from '../api';
7
- import { Routes_Input, WidgetType, ItemsType } from '../types';
8
- import { FormActionTypes, ObjectType, LanguageType } from '../types/common';
9
-
10
- interface UseWidgetProps {
11
- canList?: boolean;
12
- defaultLimit: number;
13
- routes?: Routes_Input;
14
- preConfirmDelete?: (data: { row: ObjectType }) => Promise<boolean>;
15
- imageBaseUrl?: string;
16
- }
17
-
18
- const useWidget = ({
19
- canList = true,
20
- defaultLimit,
21
- routes,
22
- preConfirmDelete,
23
- imageBaseUrl,
24
- }: UseWidgetProps) => {
25
- const [list, setList] = useState<ObjectType[]>([]);
26
- const [loading, setLoading] = useState(false);
27
- const [totalPages, setTotalPages] = useState(0);
28
- const [totalRecords, setTotalRecords] = useState(0);
29
- const [languages, setLanguages] = useState<LanguageType[]>([]);
30
- const [itemData, setItemData] = useState<ObjectType | null>(null);
31
- const [formState, setFormState] = useState<FormActionTypes>();
32
- const [itemsTypes, setItemsTypes] = useState<ItemsType[]>([]);
33
- const [widgetTypes, setWidgetTypes] = useState<WidgetType[]>([]);
34
- const [collectionDataLoading, setCollectionDataLoading] =
35
- useState<boolean>(false);
36
- const [collectionData, setCollectionData] = useState<any[]>([]);
37
-
38
- const { baseUrl, token, onError, onSuccess, onLogout, widgetRoutesPrefix } =
39
- useProviderState();
40
- const {
41
- changeSearch,
42
- setPageSize,
43
- pageSize,
44
- limitRef,
45
- currentPageRef,
46
- setCurrentPage,
47
- offsetRef,
48
- searchRef,
49
- } = usePagination({ defaultLimit });
50
-
51
- const handleError = useCallback(
52
- (code: CALLBACK_CODES) => (error: any) => {
53
- const { data = {} } = error?.response || {};
54
- if (data?.code === 'UNAUTHENTICATED') {
55
- onLogout();
56
- }
57
- onError(code, 'error', data?.message);
58
- },
59
- [onError, onLogout]
60
- );
61
- // List operations
62
- const getWidgets = useCallback(
63
- async (search?: string) => {
64
- try {
65
- setLoading(true);
66
- const api = getApiType({
67
- routes,
68
- action: 'LIST',
69
- prefix: widgetRoutesPrefix,
70
- });
71
- const response = await request({
72
- baseUrl,
73
- token,
74
- method: api.method,
75
- url: api.url,
76
- onError: handleError(CALLBACK_CODES.GET_ALL),
77
- data: {
78
- search,
79
- options: {
80
- offset: offsetRef.current,
81
- limit: limitRef.current,
82
- page: currentPageRef.current,
83
- },
84
- },
85
- });
86
- if (response?.code === 'SUCCESS') {
87
- setLoading(false);
88
- setTotalPages(response.data.totalPages);
89
- setTotalRecords(response.data.totalDocs);
90
- return setList(paginationDataGatter(response));
91
- }
92
- setLoading(false);
93
- } catch (error) {
94
- setLoading(false);
95
- }
96
- },
97
- [
98
- baseUrl,
99
- currentPageRef,
100
- limitRef,
101
- offsetRef,
102
- handleError,
103
- routes,
104
- token,
105
- widgetRoutesPrefix,
106
- ]
107
- );
108
- const getLanguagesList = useCallback(async () => {
109
- const api = getApiType({
110
- routes,
111
- action: 'LANGUAGES',
112
- prefix: widgetRoutesPrefix,
113
- });
114
- const response = await request({
115
- baseUrl,
116
- token,
117
- method: api.method,
118
- url: api.url,
119
- onError: handleError(CALLBACK_CODES.GET_ALL),
120
- });
121
- if (response?.code === 'SUCCESS') {
122
- setLanguages(response.data);
123
- return response.data;
124
- }
125
- }, [baseUrl, handleError, widgetRoutesPrefix, routes, token]);
126
-
127
- const onCofirmDeleteWidget = async () => {
128
- try {
129
- let proceed = true;
130
- if (typeof preConfirmDelete === 'function' && itemData) {
131
- try {
132
- proceed = await preConfirmDelete({ row: itemData });
133
- } catch (error) {
134
- proceed = false;
135
- }
136
- }
137
-
138
- if (proceed) {
139
- setLoading(true);
140
- const api = getApiType({
141
- routes,
142
- action: 'DELETE',
143
- prefix: widgetRoutesPrefix,
144
- id: itemData?.['_id'],
145
- });
146
- const response = await request({
147
- baseUrl,
148
- token,
149
- method: api.method,
150
- url: api.url,
151
- onError: handleError(CALLBACK_CODES.DELETE),
152
- });
153
- if (response?.code === 'SUCCESS') {
154
- setLoading(false);
155
- onSuccess(CALLBACK_CODES.DELETE, response?.code, response?.message);
156
- getWidgets();
157
- onCloseForm();
158
- return;
159
- }
160
- setLoading(false);
161
- onError(CALLBACK_CODES.DELETE, response?.code, response?.message);
162
- onCloseForm();
163
- }
164
- } catch (error) {
165
- setLoading(false);
166
- onError(
167
- CALLBACK_CODES.DELETE,
168
- INTERNAL_ERROR_CODE,
169
- (error as Error).message
170
- );
171
- onCloseForm();
172
- }
173
- };
174
- const onPartialUpdateWidget = async (data: ObjectType, id: string) => {
175
- try {
176
- const api = getApiType({
177
- routes,
178
- action: 'PARTIAL_UPDATE',
179
- prefix: widgetRoutesPrefix,
180
- id,
181
- });
182
- const response = await request({
183
- baseUrl,
184
- token,
185
- data,
186
- url: api.url,
187
- method: api.method,
188
- onError: handleError(CALLBACK_CODES.PARTIAL_UPDATE),
189
- });
190
- if (response?.code === 'SUCCESS') {
191
- setList((oldListData) =>
192
- oldListData.map((item) => (item['_id'] === id ? response.data : item))
193
- );
194
- if (response.message)
195
- onSuccess(
196
- CALLBACK_CODES.PARTIAL_UPDATE,
197
- response?.code,
198
- response?.message
199
- );
200
- } else {
201
- onError(
202
- CALLBACK_CODES.PARTIAL_UPDATE,
203
- response?.code,
204
- response?.message
205
- );
206
- }
207
- } catch (error) {
208
- onError(
209
- CALLBACK_CODES.PARTIAL_UPDATE,
210
- INTERNAL_ERROR_CODE,
211
- (error as Error).message
212
- );
213
- }
214
- };
215
- const getWidgetsTypes = async () => {
216
- if (itemsTypes?.length > 0) return;
217
- setLoading(true);
218
- const api = getApiType({
219
- routes,
220
- action: 'WIDGET_TYPES',
221
- prefix: widgetRoutesPrefix,
222
- });
223
- const response = await request({
224
- baseUrl,
225
- token,
226
- method: api.method,
227
- url: api.url,
228
- onError: handleError(CALLBACK_CODES.GET_ALL),
229
- });
230
- if (response?.code === 'SUCCESS') {
231
- setLoading(false);
232
- return setItemsTypes(dataGatter(response));
233
- }
234
- setLoading(false);
235
- };
236
- const getWidgetTypes = async () => {
237
- if (widgetTypes?.length > 0) return;
238
- setLoading(true);
239
- const api = getApiType({
240
- routes,
241
- action: 'SELECTION_TYPES',
242
- prefix: widgetRoutesPrefix,
243
- });
244
- const response = await request({
245
- baseUrl,
246
- token,
247
- method: api.method,
248
- url: api.url,
249
- onError: handleError(CALLBACK_CODES.GET_ALL),
250
- });
251
- if (response?.code === 'SUCCESS') {
252
- setLoading(false);
253
- return setWidgetTypes(dataGatter(response));
254
- }
255
- setLoading(false);
256
- };
257
- const getCollectionData = async (
258
- collectionName: string,
259
- search?: string,
260
- callback?: (data: any) => void,
261
- collectionItems?: string[]
262
- ) => {
263
- setCollectionDataLoading(true);
264
- const api = getApiType({
265
- routes,
266
- action: 'COLLECTION_DATA',
267
- prefix: widgetRoutesPrefix,
268
- id: collectionName,
269
- });
270
- const response = await request({
271
- baseUrl,
272
- token,
273
- method: api.method,
274
- url: api.url,
275
- onError: handleError(CALLBACK_CODES.GET_ALL),
276
- data: {
277
- search: search || '',
278
- collectionName,
279
- collectionItems: collectionItems || [],
280
- },
281
- });
282
- if (response?.code === 'SUCCESS') {
283
- setCollectionDataLoading(false);
284
- if (typeof callback === 'function')
285
- callback(paginationDataGatter(response));
286
- return setCollectionData(paginationDataGatter(response));
287
- }
288
- setCollectionDataLoading(false);
289
- };
290
- // Form operations
291
- const onWidgetFormSubmit = async (data: ObjectType) => {
292
- try {
293
- setLoading(true);
294
- const code =
295
- formState === 'ADD' ? CALLBACK_CODES.CREATE : CALLBACK_CODES.UPDATE;
296
- const api = getApiType({
297
- routes,
298
- action: formState === 'ADD' ? 'CREATE' : 'UPDATE',
299
- prefix: widgetRoutesPrefix,
300
- id: itemData?.['_id'],
301
- });
302
- const response = await request({
303
- baseUrl,
304
- token,
305
- data,
306
- url: api.url,
307
- method: api.method,
308
- onError: handleError(code),
309
- });
310
- if (response?.code === 'SUCCESS') {
311
- if (formState === 'ADD') {
312
- setCurrentPage(1);
313
- }
314
- setLoading(false);
315
- onSuccess(code, response?.code, response?.message);
316
- getWidgets();
317
- onCloseForm();
318
- }
319
- } catch (error) {
320
- setLoading(false);
321
- }
322
- };
323
- const onCloseForm = () => {
324
- setFormState(undefined);
325
- setItemData(null);
326
- };
327
- const getAndSetWidget = async (id: string) => {
328
- try {
329
- setLoading(true);
330
- const api = getApiType({
331
- routes,
332
- action: 'GET_ONE',
333
- prefix: widgetRoutesPrefix,
334
- id,
335
- });
336
- const response = await request({
337
- baseUrl,
338
- token,
339
- url: api.url,
340
- method: api.method,
341
- onError: handleError(CALLBACK_CODES.GET_SINGLE),
342
- });
343
- if (response?.code === 'SUCCESS') {
344
- setLoading(false);
345
- const data = response?.data;
346
- if (Array.isArray(data.items)) {
347
- const items = JSON.parse(JSON.stringify(data.items));
348
- data.webItems = items.filter((item: any) => item.itemType === 'Web');
349
- data.mobileItems = items.filter(
350
- (item: any) => item.itemType === 'Mobile'
351
- );
352
- delete data.items;
353
- }
354
- setItemData(data);
355
- }
356
- } catch (error) {
357
- setLoading(false);
358
- onError(CALLBACK_CODES.UPDATE, '', (error as Error).message);
359
- }
360
- };
361
- const onChangeFormState = async (
362
- state: FormActionTypes,
363
- data?: ObjectType
364
- ) => {
365
- setFormState(state);
366
- // fetch ItemsTypes & WidgetTypes if needed
367
- if (state === 'ADD' || state === 'UPDATE') {
368
- getWidgetsTypes();
369
- getWidgetTypes();
370
- }
371
- // get Item data if widget is updating
372
- if (state === 'UPDATE' && data) {
373
- getAndSetWidget(data['_id']);
374
- } else if (state === 'ADD') {
375
- // reset Item data if widget is adding
376
- setItemData(null);
377
- } else if (state === 'DELETE' && data) {
378
- setItemData(data);
379
- setFormState(state);
380
- }
381
- };
382
- // Image Upload operations
383
- const onImageUpload = async (
384
- file: File
385
- ): Promise<{ fileUrl: string; fileId: string; fileUri: string } | void> => {
386
- try {
387
- const payload = new FormData();
388
- payload?.append('folder', 'images');
389
- payload?.append('file', file, file.name);
390
- const api = getApiType({
391
- routes,
392
- action: 'IMAGE_UPLOAD',
393
- prefix: 'media',
394
- });
395
- const response = await request({
396
- data: payload,
397
- baseUrl,
398
- token,
399
- method: api.method,
400
- url: api.url,
401
- config: {
402
- contentType: 'multipart/form-data',
403
- },
404
- onError: handleError(CALLBACK_CODES.IMAGE_UPLOAD),
405
- });
406
- if (response.code === 'SUCCESS') {
407
- const responseData = response?.data[0] || response?.data;
408
- return {
409
- fileId: responseData?._id || responseData?.id,
410
- fileUrl: build_path(
411
- imageBaseUrl ? imageBaseUrl : baseUrl,
412
- responseData?.uri
413
- ),
414
- fileUri: responseData?.uri,
415
- };
416
- } else
417
- onError(CALLBACK_CODES.IMAGE_REMOVE, response.code, response.message);
418
- } catch (error) {
419
- onError(
420
- CALLBACK_CODES.IMAGE_REMOVE,
421
- INTERNAL_ERROR_CODE,
422
- (error as Error).message
423
- );
424
- }
425
- };
426
- const onImageRemove = async (id: string): Promise<void> => {
427
- try {
428
- const api = getApiType({
429
- routes,
430
- action: 'IMAGE_REMOVE',
431
- prefix: 'media',
432
- id,
433
- });
434
- const response = await request({
435
- baseUrl,
436
- token,
437
- method: api.method,
438
- url: api.url,
439
- onError: handleError(CALLBACK_CODES.IMAGE_REMOVE),
440
- });
441
- if (response?.code === 'SUCCESS') {
442
- onSuccess(CALLBACK_CODES.IMAGE_REMOVE, response.code, response.message);
443
- } else {
444
- onError(CALLBACK_CODES.IMAGE_REMOVE, response.code, response.message);
445
- }
446
- } catch (error) {
447
- onError(
448
- CALLBACK_CODES.IMAGE_REMOVE,
449
- INTERNAL_ERROR_CODE,
450
- (error as Error).message
451
- );
452
- }
453
- };
454
- const changeCurrentPage = (page: number) => {
455
- setCurrentPage(page);
456
- getWidgets(searchRef.current);
457
- };
458
-
459
- useEffect(() => {
460
- if (canList) getWidgets();
461
- // eslint-disable-next-line react-hooks/exhaustive-deps
462
- }, [canList]);
463
-
464
- useEffect(() => {
465
- getLanguagesList();
466
- }, [getLanguagesList]);
467
-
468
- return {
469
- list,
470
- getWidgets,
471
- loading,
472
- languages,
473
- setLoading,
474
-
475
- // Pagination
476
- searchText: searchRef.current,
477
- pageSize,
478
- totalPages,
479
- currentPage: currentPageRef.current,
480
- totalRecords,
481
- setCurrentPage: changeCurrentPage,
482
- setPageSize,
483
-
484
- // Form
485
- formState,
486
- itemData,
487
- onChangeFormState,
488
- onCloseForm,
489
- onWidgetFormSubmit,
490
- onCofirmDeleteWidget,
491
- onPartialUpdateWidget,
492
- onImageUpload,
493
- onImageRemove,
494
- itemsTypes,
495
- widgetTypes,
496
- changeSearch,
497
- collectionDataLoading,
498
- getCollectionData,
499
- collectionData,
500
- };
501
- };
502
-
503
- export default useWidget;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const ChevronDown = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="-5 -8 24 24"
11
- width="24"
12
- fill="currentColor"
13
- className={className}
14
- >
15
- <path d="M7.071 5.314l4.95-4.95a1 1 0 1 1 1.414 1.414L7.778 7.435a1 1 0 0 1-1.414 0L.707 1.778A1 1 0 1 1 2.121.364l4.95 4.95z"></path>
16
- </svg>
17
- </>
18
- );
19
- };
20
-
21
- export default ChevronDown;
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const ChevronLeft = ({ srText }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="-8 -5 24 24"
11
- width="24"
12
- fill="currentColor"
13
- >
14
- <path d="M2.757 7l4.95 4.95a1 1 0 1 1-1.414 1.414L.636 7.707a1 1 0 0 1 0-1.414L6.293.636A1 1 0 0 1 7.707 2.05L2.757 7z"></path>
15
- </svg>
16
- </>
17
- );
18
- };
19
-
20
- export default ChevronLeft;
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const ChevronRight = ({ srText }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="-8 -5 24 24"
11
- width="24"
12
- fill="currentColor"
13
- >
14
- <path d="M5.314 7.071l-4.95-4.95A1 1 0 0 1 1.778.707l5.657 5.657a1 1 0 0 1 0 1.414l-5.657 5.657a1 1 0 0 1-1.414-1.414l4.95-4.95z"></path>
15
- </svg>
16
- </>
17
- );
18
- };
19
-
20
- export default ChevronRight;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const ChevronUp = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="-5 -7.5 24 24"
11
- width="24"
12
- fill="currentColor"
13
- className={className}
14
- >
15
- <path d="M7.071 2.828l-4.95 4.95A1 1 0 0 1 .707 6.364L6.364.707a1 1 0 0 1 1.414 0l5.657 5.657a1 1 0 0 1-1.414 1.414l-4.95-4.95z"></path>
16
- </svg>
17
- </>
18
- );
19
- };
20
-
21
- export default ChevronUp;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const Close = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- className={className}
10
- xmlns="http://www.w3.org/2000/svg"
11
- viewBox="-6 -6 24 24"
12
- width="24"
13
- fill="currentColor"
14
- >
15
- <path d="M7.314 5.9l3.535-3.536A1 1 0 1 0 9.435.95L5.899 4.485 2.364.95A1 1 0 1 0 .95 2.364l3.535 3.535L.95 9.435a1 1 0 1 0 1.414 1.414l3.535-3.535 3.536 3.535a1 1 0 1 0 1.414-1.414L7.314 5.899z"></path>
16
- </svg>
17
- </>
18
- );
19
- };
20
-
21
- export default Close;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const Pencil = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="-2.5 -2.5 24 24"
11
- width="24"
12
- fill="currentColor"
13
- className={className}
14
- >
15
- <path d="M12.238 5.472L3.2 14.51l-.591 2.016 1.975-.571 9.068-9.068-1.414-1.415zM13.78 3.93l1.414 1.414 1.318-1.318a.5.5 0 0 0 0-.707l-.708-.707a.5.5 0 0 0-.707 0L13.781 3.93zm3.439-2.732l.707.707a2.5 2.5 0 0 1 0 3.535L5.634 17.733l-4.22 1.22a1 1 0 0 1-1.237-1.241l1.248-4.255 12.26-12.26a2.5 2.5 0 0 1 3.535 0z"></path>
16
- </svg>
17
- </>
18
- );
19
- };
20
-
21
- export default Pencil;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const Plus = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- fill="currentColor"
11
- width="24"
12
- viewBox="0 0 24 24"
13
- strokeWidth={1.5}
14
- stroke="currentColor"
15
- className={className}
16
- >
17
- <path strokeLinecap="round" strokeLinejoin="round" d="M12 6v12m6-6H6" />
18
- </svg>
19
- </>
20
- );
21
- };
22
-
23
- export default Plus;
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
- import { IconProps } from '../types';
3
-
4
- const Settings = ({ srText, className }: IconProps) => {
5
- return (
6
- <>
7
- {srText ? <span className="khb_sr-only">{srText}</span> : null}
8
- <svg
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="0 0 20 20"
11
- width="20"
12
- height="20"
13
- fill="none"
14
- className={className}
15
- >
16
- <g clipPath="url(#clip0_33400_61483)">
17
- <path
18
- d="M3.33203 3.33301H16.6654V5.14301C16.6653 5.585 16.4896 6.00885 16.177 6.32134L12.4987 9.99967V15.833L7.4987 17.4997V10.4163L3.76536 6.30967C3.48657 6.00295 3.33208 5.60334 3.33203 5.18884V3.33301Z"
19
- stroke="#BEBEBE"
20
- strokeWidth="2"
21
- strokeLinecap="round"
22
- strokeLinejoin="round"
23
- />
24
- </g>
25
- <defs>
26
- <clipPath id="clip0_33400_61483">
27
- <rect width="20" height="20" fill="white" />
28
- </clipPath>
29
- </defs>
30
- </svg>
31
- </>
32
- );
33
- };
34
-
35
- export default Settings;