@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,133 +0,0 @@
1
- import React from 'react';
2
- import Pencil from '../../../icons/pencil';
3
- import Trash from '../../../icons/trash';
4
- import { ObjectType, TableDataItemFormat, TableProps } from '../../../types';
5
-
6
- const Table = ({
7
- data,
8
- dataKeys,
9
- actions,
10
- loader,
11
- loading,
12
- extraActions,
13
- actionsLabel,
14
- extraColumns,
15
- }: TableProps) => {
16
- const cellItemRenderer = (
17
- item: ObjectType,
18
- dataKey: TableDataItemFormat,
19
- index: number
20
- ) => {
21
- if (dataKey.highlight)
22
- return (
23
- <th scope="row" className="khb_table-row-heading" key={index}>
24
- {item[dataKey.dataKey]}
25
- </th>
26
- );
27
- else if (dataKey.Cell)
28
- return (
29
- <td className="khb_table-row-data" key={index}>
30
- {dataKey.Cell({ row: item })}
31
- </td>
32
- );
33
- else
34
- return (
35
- <td className="khb_table-row-data" key={index}>
36
- {item[dataKey.dataKey]}
37
- </td>
38
- );
39
- };
40
- return (
41
- <div className={`khb_table-container`} data-testid="table">
42
- <div className={`khb_table-height`}>
43
- {loading && loader ? (
44
- <div className="khb_table-height">{loader}</div>
45
- ) : (
46
- <table
47
- className={`khb_table ${data.length > 0 ? '' : 'empty-table'}`}
48
- >
49
- <thead className="khb_thead">
50
- <tr>
51
- {dataKeys.map((key, i) => (
52
- <th scope="col" className="khb_table-heading" key={i}>
53
- {key.label}
54
- </th>
55
- ))}
56
- {Array.isArray(extraColumns)
57
- ? extraColumns.map((action) => (
58
- <th scope="col" className="khb_table-heading">
59
- {action.label}
60
- </th>
61
- ))
62
- : null}
63
- {(actions && (actions?.edit || actions?.delete)) ||
64
- typeof extraActions === 'function' ? (
65
- <th scope="col" className="khb_table-heading">
66
- {actionsLabel}
67
- </th>
68
- ) : null}
69
- </tr>
70
- </thead>
71
- <tbody className="khb_tbody">
72
- {data.length > 0 ? (
73
- data.map((item: ObjectType, i: number) => (
74
- <tr
75
- className="khb_table-row"
76
- key={item['id'] || item['_id'] || i}
77
- >
78
- {dataKeys.map((key, j) => cellItemRenderer(item, key, j))}
79
- {Array.isArray(extraColumns)
80
- ? extraColumns.map((column) => (
81
- <td className="khb_table-row-data" key={i}>
82
- {column.Cell(item)}
83
- </td>
84
- ))
85
- : null}
86
- {(actions && (actions?.edit || actions?.delete)) ||
87
- typeof extraActions === 'function' ? (
88
- <td className="khb_table-row-actions">
89
- {actions &&
90
- actions.edit &&
91
- typeof actions.edit === 'function' ? (
92
- <button
93
- className="khb_actions-update"
94
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
95
- // @ts-ignore
96
- onClick={() => actions.edit(item)}
97
- >
98
- <Pencil />
99
- </button>
100
- ) : null}
101
- {actions &&
102
- actions.delete &&
103
- typeof actions.delete === 'function' && !!item['canDel'] !== false && (
104
- <button
105
- className="khb_actions-delete"
106
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
107
- // @ts-ignore
108
- onClick={() => actions.delete!(item)}
109
- >
110
- <Trash />
111
- </button>
112
- )}
113
- {typeof extraActions === 'function'
114
- ? extraActions(item)
115
- : null}
116
- </td>
117
- ) : null}
118
- </tr>
119
- ))
120
- ) : (
121
- <tr className="empty-row">
122
- <td colSpan={(dataKeys?.length || 0) + 1}>No data found</td>
123
- </tr>
124
- )}
125
- </tbody>
126
- </table>
127
- )}
128
- </div>
129
- </div>
130
- );
131
- };
132
-
133
- export default Table;
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import { ToggleProps } from '../../../types';
3
-
4
- const Toggle = ({
5
- isChecked,
6
- disabled,
7
- onChange,
8
- switchClass,
9
- }: ToggleProps) => {
10
- return (
11
- <label className={switchClass || 'khb_switch'} data-testid="khb_switch">
12
- <input
13
- type="checkbox"
14
- onChange={() => onChange && onChange(!isChecked)}
15
- checked={isChecked}
16
- disabled={disabled}
17
- />
18
- <span className="slider round" />
19
- </label>
20
- );
21
- };
22
-
23
- export default Toggle;
@@ -1,145 +0,0 @@
1
- const DEFAULT_OFFSET_PAYLOAD = 0;
2
- const DECIMAL_REDIX = 10;
3
- const DEFAULT_CURRENT_PAGE = 1;
4
- const INTERNAL_ERROR_CODE = 'INTERNAL_ERROR';
5
- const DEFAULT_LIMIT = 10;
6
- const PAGE_LIMITS = [10, 20, 30];
7
-
8
- enum CALLBACK_CODES {
9
- 'GET_ALL' = 'GET_ALL',
10
- 'GET_SINGLE' = 'GET_SINGLE',
11
- 'CREATE' = 'CREATE',
12
- 'UPDATE' = 'UPDATE',
13
- 'PARTIAL_UPDATE' = 'PARTIAL_UPDATE',
14
- 'DELETE' = 'DELETE',
15
- 'IMAGE_UPLOAD' = 'IMAGE_UPLOAD',
16
- 'IMAGE_REMOVE' = 'IMAGE_REMOVE',
17
- 'INTERNAL' = 'INTERNAL',
18
- }
19
-
20
- const CONSTANTS = {
21
- EMPTY_REGEX: / /g,
22
- SLUG_REGEX: /^[\da-z-]*$/,
23
- SLUG_REPLACE_REGEX: /[^\da-z-]/gi,
24
- };
25
-
26
- const DEFAULT_PERMISSIONS = {
27
- list: true,
28
- add: true,
29
- delete: true,
30
- partialUpdate: true,
31
- update: true,
32
- };
33
-
34
- const TRANSLATION_PAIRS_COMMON = {
35
- confirmationRequired: 'Confirmation Required',
36
- permanentlyDelete: 'You are about to permanently delete the',
37
- lossOfData:
38
- 'This action can lead to data loss. To prevent accidental actions we ask you to confirm your intention.',
39
- pleaseType: 'Please type',
40
- toProceedOrCancel: 'to processed or close this modal to cancel.',
41
- confirm: 'Confirm',
42
- next: 'Next',
43
- previous: 'Previous',
44
- page: 'Page',
45
- indicatesRequired: 'Indicates fields are required',
46
- cancel: 'Cancel',
47
- yes: 'Yes',
48
- delete: 'Delete',
49
- create: 'Create',
50
- update: 'Update',
51
- showing: 'Showing',
52
- add: 'Add',
53
- of: 'of',
54
- typeHerePlaceholder: 'Type Here',
55
-
56
- code: 'Code',
57
- codePlaceholder: 'Enter code',
58
- codeRequired: 'Code is required',
59
- name: 'Name',
60
- namePlaceholder: 'Enter name',
61
- nameRequired: 'Name is required',
62
- title: 'Title',
63
- titlePlaceholder: 'Enter title',
64
- titleRequired: 'Title is required',
65
-
66
- active: 'Active',
67
- actions: 'Actions',
68
- };
69
-
70
- const TRANSLATION_PAIRS_WIDGET = {
71
- itemsType: 'Items Type',
72
- itemsTypePlaceholder: 'Select Items Type',
73
- widgetType: 'Widget Type',
74
- widgetTypeRequired: 'Widget Type is required',
75
- color: 'Color',
76
- webPerRow: 'Web Per Row',
77
- webPerRowPlaceholder: 'Enter web per row',
78
- mobilePerRow: 'Mobile Per Row',
79
- mobilePerRowPlaceholder: 'Enter mobile per row',
80
- tabletPerRow: 'Tablet Per Row',
81
- tabletPerRowPlaceholder: 'Enter tablet per row',
82
- mobileItems: 'Mobile Items',
83
- webItems: 'Web Items',
84
- searchPlaceholder: 'Search Widgets...',
85
- autoPlay: 'Auto Play',
86
- addWidgetTitle: 'Add Widget',
87
- updateWidgetTitle: 'Update Widget',
88
- webPerRowRequired: 'Web Per Row is required',
89
- tabletPerRowRequired: 'Tablet Per Row is required',
90
- mobilePerRowRequired: 'Mobile Per Row is required',
91
- tabDeleteTitle: 'Are you sure you want to delete this tab?',
92
- widgetTitleInfo: 'HTML is supported',
93
- minPerRow: 'Value must be greater than zero',
94
- // actionsLabel': 'Actions', -> 'actions'
95
- tabNameRequired: 'Tab Name is required',
96
-
97
- subtitle: 'Subtitle',
98
- subTitlePlaceholder: 'Enter Subtitle',
99
- altText: 'Alt Text',
100
- altTextPlaceholder: 'Enter alt text',
101
- link: 'Link',
102
- linkPlaceholder: 'Enter link',
103
- image: 'Image',
104
- uploadFile: 'Upload File',
105
- dragDrop: 'or drag and drop',
106
- allowedFormat: 'PNG, JPG, SVG up to 2 MB',
107
- srcset: 'Srcset',
108
- screenSizeRequired: 'ScreenSize is required',
109
- widthRequired: 'Width is required',
110
- heightRequired: 'Height is required',
111
- minScreenSize: 'ScreenSize should be greater than 0',
112
- minWidth: 'Width should be greater than 0',
113
- minHeight: 'Height should be greater than 0',
114
- deleteTitle: 'Are you sure you want to delete this item?',
115
- htmlContent: 'HTML',
116
- htmlContentPlaceholder: 'Enter your html',
117
- htmlContentRequired: 'html is required',
118
- textContent: 'Text',
119
- textContentRequired: 'Text is required',
120
- textContentInfo: 'HTML is supported',
121
- textContentPlaceholder: 'Enter text',
122
- };
123
- const TRANSLATION_PAIRS_PAGE = {
124
- widgets: 'Widgets',
125
- slug: 'Slug',
126
- slugPlaceholder: 'Enter Slug',
127
- slugRequired: 'Slug is required',
128
- addPage: 'Add Page',
129
- updatePage: 'Update Page',
130
- searchPages: 'Search Pages...',
131
- };
132
- export {
133
- CONSTANTS,
134
- CALLBACK_CODES,
135
- DECIMAL_REDIX,
136
- DEFAULT_CURRENT_PAGE,
137
- DEFAULT_OFFSET_PAYLOAD,
138
- INTERNAL_ERROR_CODE,
139
- DEFAULT_PERMISSIONS,
140
- TRANSLATION_PAIRS_COMMON,
141
- DEFAULT_LIMIT,
142
- PAGE_LIMITS,
143
- TRANSLATION_PAIRS_WIDGET,
144
- TRANSLATION_PAIRS_PAGE,
145
- };
@@ -1,100 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- import React, { createContext, useContext } from 'react';
3
- import { PAGE_LIMITS, TRANSLATION_PAIRS_PAGE } from '../constants/common';
4
- import { PageContextType } from '../types';
5
-
6
- interface PageContextProviderProps
7
- extends React.PropsWithChildren,
8
- Partial<PageContextType> {}
9
-
10
- const PageContext = createContext<PageContextType | null>(null);
11
-
12
- const PageContextProvider = ({
13
- searchText = '',
14
- changeSearch = () => {},
15
- list = [],
16
- widgets = [],
17
- formState = '',
18
- closeForm = () => {},
19
- getPages = () => {},
20
- loading = false,
21
- getWidgets = () => {},
22
- onChangeFormState = () => {},
23
- onPageFormSubmit = () => {},
24
- canAdd = false,
25
- canUpdate = false,
26
- selectedWidgets = [],
27
- setSelectedWidgets = () => {},
28
- onChangeWidgetSequence = () => {},
29
- // Pagination
30
- currentPage = 1,
31
- limits = PAGE_LIMITS,
32
- pageSize = PAGE_LIMITS[0],
33
- setCurrentPage = () => {},
34
- setPageSize = () => {},
35
- totalPages = 0,
36
- totalRecords = 0,
37
- canList = false,
38
- // Table
39
- columns = [],
40
- data = [],
41
- canDelete = false,
42
- loader = undefined,
43
- pageTranslations,
44
- // other
45
- children,
46
- }: PageContextProviderProps) => {
47
- return (
48
- <PageContext.Provider
49
- value={{
50
- // Form
51
- list,
52
- searchText,
53
- changeSearch,
54
- widgets,
55
- closeForm,
56
- formState,
57
- loading,
58
- getWidgets,
59
- onChangeFormState,
60
- canAdd,
61
- canUpdate,
62
- onPageFormSubmit,
63
- selectedWidgets,
64
- setSelectedWidgets,
65
- onChangeWidgetSequence,
66
- // Pagination
67
- getPages,
68
- currentPage,
69
- limits,
70
- pageSize,
71
- setCurrentPage,
72
- setPageSize,
73
- totalPages,
74
- totalRecords,
75
- canList,
76
- // Table
77
- columns,
78
- data,
79
- canDelete,
80
- loader,
81
- pageTranslations: {
82
- ...TRANSLATION_PAIRS_PAGE,
83
- ...(pageTranslations || {}),
84
- },
85
- }}
86
- >
87
- {children}
88
- </PageContext.Provider>
89
- );
90
- };
91
-
92
- export function usePageState() {
93
- const context = useContext(PageContext);
94
- if (!context)
95
- throw new Error('Page Context must be used within PageContext.Provider');
96
-
97
- return context;
98
- }
99
-
100
- export default PageContextProvider;
@@ -1,52 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- import React, { createContext, useContext } from 'react';
3
- import { TRANSLATION_PAIRS_COMMON } from '../constants/common';
4
- import { ProviderContextProviderProps, ProviderContextType } from '../types';
5
-
6
- const ProviderContext = createContext<ProviderContextType | null>(null);
7
-
8
- const Provider = ({
9
- children,
10
- baseUrl,
11
- token,
12
- translations,
13
- onError = () => {},
14
- onSuccess = () => {},
15
- onLogout = () => {},
16
- switchClass = 'khb_switch',
17
- widgetRoutesPrefix = 'widgets',
18
- pageRoutesPrefix = 'pages',
19
- }: ProviderContextProviderProps) => {
20
- return (
21
- <ProviderContext.Provider
22
- value={{
23
- baseUrl,
24
- token,
25
- onError,
26
- onSuccess,
27
- onLogout,
28
- switchClass,
29
- widgetRoutesPrefix,
30
- pageRoutesPrefix,
31
- commonTranslations: {
32
- ...TRANSLATION_PAIRS_COMMON,
33
- ...(translations || {}),
34
- },
35
- }}
36
- >
37
- {children}
38
- </ProviderContext.Provider>
39
- );
40
- };
41
-
42
- export function useProviderState() {
43
- const context = useContext(ProviderContext);
44
- if (!context)
45
- throw new Error(
46
- 'Provider Context must be used within ProviderContext.Provider'
47
- );
48
-
49
- return context;
50
- }
51
-
52
- export default Provider;
@@ -1,127 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- import React, { createContext, useContext } from 'react';
3
- import { PAGE_LIMITS, TRANSLATION_PAIRS_WIDGET } from '../constants/common';
4
- import { WidgetContextType } from '../types';
5
-
6
- interface WidgetContextProviderProps
7
- extends React.PropsWithChildren,
8
- Partial<WidgetContextType> {}
9
-
10
- const WidgetContext = createContext<WidgetContextType | null>(null);
11
-
12
- const WidgetContextProvider = ({
13
- // Form
14
- list = [],
15
- languages = [],
16
- imageBaseUrl = '',
17
- searchText = '',
18
- changeSearch = () => {},
19
- formState = '',
20
- closeForm = () => {},
21
- loading = false,
22
- onChangeFormState = () => {},
23
- onWidgetFormSubmit = () => {},
24
- updateData = null,
25
- canAdd = false,
26
- canUpdate = false,
27
- onDeleteItem = () => {},
28
- getWidgets = () => {},
29
- onImageUpload = async (file: File) => {},
30
- onImageRemove = async (id: string) => {},
31
- itemsTypes = [],
32
- widgetTypes = [],
33
- getCollectionData = () => Promise.resolve(),
34
- collectionDataLoading = false,
35
- collectionData = [],
36
- formatListItem,
37
- formatOptionLabel,
38
- // Pagination
39
- currentPage = 1,
40
- limits = PAGE_LIMITS,
41
- pageSize = PAGE_LIMITS[0],
42
- setCurrentPage = () => {},
43
- setPageSize = () => {},
44
- totalPages = 0,
45
- totalRecords = 0,
46
- // Table
47
- canList = false,
48
- canPartialUpdate = false,
49
- columns = [],
50
- data = [],
51
- canDelete = false,
52
- loader = <span />,
53
- onPartialUpdateWidget = () => Promise.resolve(),
54
- reactSelectStyles = {},
55
- imageMaxSize = 10_485_760,
56
- widgetTranslations,
57
- // other
58
- children,
59
- }: WidgetContextProviderProps) => {
60
- return (
61
- <WidgetContext.Provider
62
- value={{
63
- // Form
64
- list,
65
- languages,
66
- imageBaseUrl,
67
- closeForm,
68
- formState,
69
- loading,
70
- searchText,
71
- changeSearch,
72
- onChangeFormState,
73
- onWidgetFormSubmit,
74
- updateData,
75
- canAdd,
76
- canUpdate,
77
- onDeleteItem,
78
- getWidgets,
79
- onImageUpload,
80
- onImageRemove,
81
- onPartialUpdateWidget,
82
- itemsTypes,
83
- widgetTypes,
84
- getCollectionData,
85
- collectionDataLoading,
86
- collectionData,
87
- formatListItem,
88
- formatOptionLabel,
89
- reactSelectStyles,
90
- // Pagination
91
- currentPage,
92
- limits,
93
- pageSize,
94
- setCurrentPage,
95
- setPageSize,
96
- totalPages,
97
- totalRecords,
98
- // Table
99
- canList,
100
- canPartialUpdate,
101
- columns,
102
- data,
103
- canDelete,
104
- loader,
105
- imageMaxSize,
106
- widgetTranslations: {
107
- ...TRANSLATION_PAIRS_WIDGET,
108
- ...(widgetTranslations || {}),
109
- },
110
- }}
111
- >
112
- {children}
113
- </WidgetContext.Provider>
114
- );
115
- };
116
-
117
- export function useWidgetState() {
118
- const context = useContext(WidgetContext);
119
- if (!context)
120
- throw new Error(
121
- 'Widget Context must be used within WidgetContext.Provider'
122
- );
123
-
124
- return context;
125
- }
126
-
127
- export default WidgetContextProvider;
@@ -1,46 +0,0 @@
1
- import { CONSTANTS } from '../constants/common';
2
- import { TFunc } from '../types';
3
-
4
- /* eslint-disable no-useless-escape */
5
- export const paginationDataGatter = (data: any) => {
6
- return data.data.docs;
7
- };
8
- export const dataGatter = (data: any) => {
9
- return data.data;
10
- };
11
-
12
- export const capitalizeFirstLetter = (string = '') =>
13
- `${string?.trim().charAt(0)?.toUpperCase()}${string?.slice(1)}`;
14
-
15
- export const changeToCode = (string = '') =>
16
- string
17
- .replace(/[^\s\w]/gi, '')
18
- ?.toUpperCase()
19
- ?.replace(CONSTANTS.EMPTY_REGEX, '_');
20
-
21
- export const changeToSlug = (string = '') =>
22
- string?.toLowerCase()?.replace(CONSTANTS.EMPTY_REGEX, '-');
23
-
24
- export const isObject = (data: any) => data?.constructor?.name === 'Object';
25
- export const isString = (data: any) => data?.constructor?.name === 'String';
26
- export const isArray = (data: any) => data?.constructor?.name === 'Array';
27
-
28
- export const isEmpty = (data: any) => {
29
- if (isObject(data)) return Object.keys(data).length === 0;
30
- if (isArray(data)) return data.length === 0;
31
- if (isString(data)) return !data || data.length === 0;
32
- if ([undefined, null, ''].includes(data)) return true;
33
- return false;
34
- };
35
- export const build_path = (...args: string[]) => {
36
- return args
37
- .map((part, i) => {
38
- if (i === 0) {
39
- return part.trim().replace(/[\/]*$/g, '');
40
- } else {
41
- return part.trim().replace(/(^[\/]*|[\/]*$)/g, '');
42
- }
43
- })
44
- .filter((x) => x.length)
45
- .join('/');
46
- };