@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.
Files changed (167) hide show
  1. package/index.cjs +7878 -0
  2. package/index.css +2 -0
  3. package/index.js +7864 -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 +422 -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,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;