@appcorp/fusion-storybook 0.5.11 → 0.5.15

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 (41) hide show
  1. package/base-modules/campus/context/use-campus-module.d.ts +57 -0
  2. package/base-modules/campus/context/use-campus-module.js +447 -0
  3. package/base-modules/campus/context.d.ts +21 -54
  4. package/base-modules/campus/context.js +18 -442
  5. package/base-modules/campus/filter.js +1 -1
  6. package/base-modules/campus/form.js +6 -4
  7. package/base-modules/campus/page.d.ts +0 -2
  8. package/base-modules/campus/page.js +10 -18
  9. package/base-modules/campus/validate.js +4 -1
  10. package/base-modules/campus/view.js +2 -2
  11. package/base-modules/class/context/use-class-module.d.ts +55 -0
  12. package/base-modules/class/context/use-class-module.js +421 -0
  13. package/base-modules/class/context.d.ts +27 -52
  14. package/base-modules/class/context.js +18 -415
  15. package/base-modules/class/filter.js +16 -6
  16. package/base-modules/class/form.js +19 -3
  17. package/base-modules/class/more-actions.js +48 -10
  18. package/base-modules/class/page.js +15 -5
  19. package/base-modules/class/validate.d.ts +2 -2
  20. package/base-modules/class/validate.js +7 -3
  21. package/base-modules/class/view.js +2 -4
  22. package/base-modules/discount-code/context/use-discount-code-module.d.ts +65 -0
  23. package/base-modules/discount-code/context/use-discount-code-module.js +402 -0
  24. package/base-modules/discount-code/context.d.ts +32 -80
  25. package/base-modules/discount-code/context.js +14 -430
  26. package/base-modules/discount-code/filter.d.ts +1 -10
  27. package/base-modules/discount-code/filter.js +34 -8
  28. package/base-modules/discount-code/form.js +9 -35
  29. package/base-modules/discount-code/page.js +39 -19
  30. package/base-modules/discount-code/validate.d.ts +2 -1
  31. package/base-modules/discount-code/validate.js +10 -3
  32. package/base-modules/discount-code/view.js +15 -4
  33. package/constants.d.ts +4 -2
  34. package/package.json +1 -1
  35. package/tsconfig.build.tsbuildinfo +1 -1
  36. package/types/user-management.d.ts +0 -1
  37. package/utils/resolve-rbac-permissions.js +10 -7
  38. package/base-modules/campus/more-actions.d.ts +0 -1
  39. package/base-modules/campus/more-actions.js +0 -40
  40. package/base-modules/discount-code/more-actions.d.ts +0 -9
  41. package/base-modules/discount-code/more-actions.js +0 -13
@@ -1,5 +1,4 @@
1
- import { type TableRow } from "@appcorp/shadcn/components/enhanced-table";
2
- import { DiscountCodeBE } from "../../type";
1
+ import { DiscountCodeBE, DISCOUNT_TYPE } from "../../type";
3
2
  export declare const DISCOUNT_CODE_DRAWER: {
4
3
  readonly FILTER_DRAWER: string;
5
4
  readonly FORM_DRAWER: string;
@@ -21,11 +20,10 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
21
20
  }, discountCodeModuleConfig: import("@react-pakistan/util-functions/factory/generic-module-factory").ModuleConfig<{
22
21
  code: string;
23
22
  description: string;
24
- discountType: string;
23
+ discountType: DISCOUNT_TYPE | "";
25
24
  discountValue: number;
26
25
  enabled: boolean;
27
26
  errors: Record<string, string>;
28
- filterEnabled: boolean | undefined;
29
27
  id: string;
30
28
  count: number;
31
29
  items: DiscountCodeBE[];
@@ -33,16 +31,18 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
33
31
  pageLimit: number;
34
32
  searchQuery: string;
35
33
  disableSaveButton: boolean;
36
- drawer: null;
37
- modal: null;
34
+ drawer: string | null;
35
+ filterEnabled: boolean | undefined;
36
+ filterDiscountType: DISCOUNT_TYPE | undefined;
37
+ appliedFilterEnabled: boolean | undefined;
38
+ appliedFilterDiscountType: DISCOUNT_TYPE | undefined;
38
39
  }>, initialDiscountCodeState: {
39
40
  code: string;
40
41
  description: string;
41
- discountType: string;
42
+ discountType: DISCOUNT_TYPE | "";
42
43
  discountValue: number;
43
44
  enabled: boolean;
44
45
  errors: Record<string, string>;
45
- filterEnabled: boolean | undefined;
46
46
  id: string;
47
47
  count: number;
48
48
  items: DiscountCodeBE[];
@@ -50,18 +50,20 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
50
50
  pageLimit: number;
51
51
  searchQuery: string;
52
52
  disableSaveButton: boolean;
53
- drawer: null;
54
- modal: null;
53
+ drawer: string | null;
54
+ filterEnabled: boolean | undefined;
55
+ filterDiscountType: DISCOUNT_TYPE | undefined;
56
+ appliedFilterEnabled: boolean | undefined;
57
+ appliedFilterDiscountType: DISCOUNT_TYPE | undefined;
55
58
  }, DiscountCodeProvider: import("react").FC<{
56
59
  children: React.ReactNode;
57
60
  }>, discountCodeReducer: (state: {
58
61
  code: string;
59
62
  description: string;
60
- discountType: string;
63
+ discountType: DISCOUNT_TYPE | "";
61
64
  discountValue: number;
62
65
  enabled: boolean;
63
66
  errors: Record<string, string>;
64
- filterEnabled: boolean | undefined;
65
67
  id: string;
66
68
  count: number;
67
69
  items: DiscountCodeBE[];
@@ -69,16 +71,18 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
69
71
  pageLimit: number;
70
72
  searchQuery: string;
71
73
  disableSaveButton: boolean;
72
- drawer: null;
73
- modal: null;
74
+ drawer: string | null;
75
+ filterEnabled: boolean | undefined;
76
+ filterDiscountType: DISCOUNT_TYPE | undefined;
77
+ appliedFilterEnabled: boolean | undefined;
78
+ appliedFilterDiscountType: DISCOUNT_TYPE | undefined;
74
79
  }, action: any) => {
75
80
  code: string;
76
81
  description: string;
77
- discountType: string;
82
+ discountType: DISCOUNT_TYPE | "";
78
83
  discountValue: number;
79
84
  enabled: boolean;
80
85
  errors: Record<string, string>;
81
- filterEnabled: boolean | undefined;
82
86
  id: string;
83
87
  count: number;
84
88
  items: DiscountCodeBE[];
@@ -86,16 +90,18 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
86
90
  pageLimit: number;
87
91
  searchQuery: string;
88
92
  disableSaveButton: boolean;
89
- drawer: null;
90
- modal: null;
93
+ drawer: string | null;
94
+ filterEnabled: boolean | undefined;
95
+ filterDiscountType: DISCOUNT_TYPE | undefined;
96
+ appliedFilterEnabled: boolean | undefined;
97
+ appliedFilterDiscountType: DISCOUNT_TYPE | undefined;
91
98
  }, useDiscountCodeStateContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
92
99
  code: string;
93
100
  description: string;
94
- discountType: string;
101
+ discountType: DISCOUNT_TYPE | "";
95
102
  discountValue: number;
96
103
  enabled: boolean;
97
104
  errors: Record<string, string>;
98
- filterEnabled: boolean | undefined;
99
105
  id: string;
100
106
  count: number;
101
107
  items: DiscountCodeBE[];
@@ -103,64 +109,10 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
103
109
  pageLimit: number;
104
110
  searchQuery: string;
105
111
  disableSaveButton: boolean;
106
- drawer: null;
107
- modal: null;
112
+ drawer: string | null;
113
+ filterEnabled: boolean | undefined;
114
+ filterDiscountType: DISCOUNT_TYPE | undefined;
115
+ appliedFilterEnabled: boolean | undefined;
116
+ appliedFilterDiscountType: DISCOUNT_TYPE | undefined;
108
117
  }>;
109
- export declare const useDiscountCodeModule: () => {
110
- applyFilters: () => void;
111
- byIdLoading: boolean;
112
- clearFilters: () => void;
113
- clearSearch: () => void;
114
- closeDrawer: () => void;
115
- deleteLoading: boolean;
116
- resetRecordFormState: () => void;
117
- handleChange: (key: string, value: string | number | boolean | string[]) => void;
118
- handleCreate: () => void;
119
- handleDelete: (row?: TableRow) => void;
120
- handleEdit: (row?: TableRow) => void;
121
- handleFilters: () => void;
122
- handleMoreActions: () => void;
123
- handleNextClick: () => void;
124
- handlePageChange: (page: number | unknown) => void;
125
- handlePageLimitChange: (k: string, value: object) => void;
126
- handlePreviousClick: () => void;
127
- handleSearch: (query: string) => void;
128
- handleSubmit: () => void;
129
- handleView: (row?: TableRow) => void;
130
- headerActions: {
131
- enabled: boolean;
132
- handleOnClick: () => void;
133
- label: string;
134
- order: number;
135
- }[];
136
- listError: Error | undefined;
137
- listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
138
- listLoading: boolean;
139
- rowActions: {
140
- enabled: boolean;
141
- handleOnClick: (row?: TableRow) => void;
142
- label: string;
143
- order: number;
144
- }[];
145
- updateLoading: boolean;
146
- handleCloseDrawer?: () => void;
147
- state: {
148
- code: string;
149
- description: string;
150
- discountType: string;
151
- discountValue: number;
152
- enabled: boolean;
153
- errors: Record<string, string>;
154
- filterEnabled: boolean | undefined;
155
- id: string;
156
- count: number;
157
- items: DiscountCodeBE[];
158
- currentPage: number;
159
- pageLimit: number;
160
- searchQuery: string;
161
- disableSaveButton: boolean;
162
- drawer: null;
163
- modal: null;
164
- };
165
- dispatch: React.Dispatch<any>;
166
- };
118
+ export { useDiscountCodeModule } from "./context/use-discount-code-module";
@@ -1,38 +1,15 @@
1
1
  "use client";
2
2
  /**
3
- * Discount Code Context
3
+ * Discount Code Module — configuration + provider.
4
4
  *
5
- * Wires the generic module state (created by `createGenericModule`) to network
6
- * actions using `useModuleEntityV2`. Contains domain-specific handlers for
7
- * CRUD operations, pagination, and search.
8
- *
9
- * Key responsibilities:
10
- * - Expose `useDiscountCodeModule()` which UI components call for actions
11
- * - Keep module-specific `apiParams` and callbacks in one place
12
- * - Ensure cache invalidation and toast notifications on mutation
13
- *
14
- * Exported utilities:
15
- * - `DiscountCodeProvider` — provider component used by the page
16
- * - `DISCOUNT_CODE_ACTION_TYPES` — action type constants (from factory)
17
- * - `DISCOUNT_CODE_DRAWER` — drawer type constants
18
- * - `useDiscountCodeModule()` — hook that returns state, dispatch, and handlers
5
+ * Business logic lives in `context/use-discount-code-module.ts` and is
6
+ * re-exported here so components keep importing from `./context`.
19
7
  */
20
- import { useCallback, useEffect, useMemo, useRef } from "react";
21
- import { useTheme } from "next-themes";
22
- import { useTranslations } from "next-intl";
23
- import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
24
- import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
25
- import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
26
- import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
27
8
  import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
28
9
  import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
29
- import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
30
10
  import { pageLimit } from "./constants";
31
- import { DISCOUNT_CODE_API_ROUTES } from "../../constants";
32
- import { accountDiscountCodeFormValidation } from "./validate";
33
- import { getCachedWorkspaceSync } from "../workspace/cache";
34
11
  // ============================================================================
35
- // 1.1 DRAWER TYPES
12
+ // DRAWER TYPES
36
13
  // ============================================================================
37
14
  export const DISCOUNT_CODE_DRAWER = {
38
15
  FILTER_DRAWER: DRAWER_TYPES.FILTER_DRAWER,
@@ -41,7 +18,7 @@ export const DISCOUNT_CODE_DRAWER = {
41
18
  VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
42
19
  };
43
20
  // ============================================================================
44
- // 1.2 MODULE CONFIGURATION
21
+ // MODULE CONFIGURATION
45
22
  // ============================================================================
46
23
  const discountCodeConfig = {
47
24
  name: "DiscountCode",
@@ -55,7 +32,6 @@ const discountCodeConfig = {
55
32
  discountValue: 0,
56
33
  enabled: true,
57
34
  errors: {},
58
- filterEnabled: undefined,
59
35
  id: "",
60
36
  // List Data
61
37
  count: 0,
@@ -67,411 +43,19 @@ const discountCodeConfig = {
67
43
  // UI State
68
44
  disableSaveButton: false,
69
45
  drawer: null,
70
- modal: null,
46
+ // Staged filters: the drawer edits `filter*`; Apply copies them to
47
+ // `appliedFilter*`, which is what the list request uses.
48
+ filterEnabled: true,
49
+ filterDiscountType: undefined,
50
+ appliedFilterEnabled: true,
51
+ appliedFilterDiscountType: undefined,
71
52
  },
72
53
  };
73
54
  // ============================================================================
74
- // 1.3 CREATE DISCOUNT CODE MODULE
55
+ // CREATE DISCOUNT CODE MODULE
75
56
  // ============================================================================
76
57
  export const { actionTypes: DISCOUNT_CODE_ACTION_TYPES, config: discountCodeModuleConfig, initialState: initialDiscountCodeState, Provider: DiscountCodeProvider, reducer: discountCodeReducer, useContext: useDiscountCodeStateContext, } = createGenericModule(discountCodeConfig);
77
58
  // ============================================================================
78
- // 1.4 ENHANCED DISCOUNT CODE HOOK WITH API INTEGRATION
59
+ // EXPORT ENHANCED HOOK
79
60
  // ============================================================================
80
- export const useDiscountCodeModule = () => {
81
- var _a;
82
- // ============================================================================
83
- // 1.4.1 STATE & CORE HOOKS
84
- // ============================================================================
85
- const context = useDiscountCodeStateContext();
86
- const { dispatch } = context;
87
- const state = context.state;
88
- const t = useTranslations("discountCode");
89
- const { theme } = useTheme();
90
- const workspace = getCachedWorkspaceSync();
91
- const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
92
- const listFetchNowRef = useRef(null);
93
- const debouncedQuery = useDebounce(state.searchQuery, 800);
94
- // ============================================================================
95
- // 1.4.2 API PARAMETERS
96
- // ============================================================================
97
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
98
- ? { filterEnabled: String(state.filterEnabled) }
99
- : {}))), [
100
- state.currentPage,
101
- state.pageLimit,
102
- state.filterEnabled,
103
- debouncedQuery,
104
- schoolId,
105
- ]);
106
- const updateParams = useMemo(() => ({
107
- code: state.code,
108
- description: state.description,
109
- discountType: state.discountType,
110
- discountValue: state.discountValue,
111
- enabled: state.enabled,
112
- id: state.id,
113
- schoolId,
114
- }), [
115
- state.code,
116
- state.description,
117
- state.discountType,
118
- state.discountValue,
119
- state.enabled,
120
- state.id,
121
- schoolId,
122
- ]);
123
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
124
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
125
- // ============================================================================
126
- // 1.4.3 UTILITIES
127
- // ============================================================================
128
- const showToast = useCallback((description, variant) => {
129
- generateThemeToast({
130
- description,
131
- theme: theme,
132
- variant,
133
- });
134
- }, [theme]);
135
- const resetFormAndCloseDrawer = useCallback(() => {
136
- dispatch({ type: DISCOUNT_CODE_ACTION_TYPES.RESET_FORM });
137
- dispatch({
138
- type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
139
- payload: { errors: {} },
140
- });
141
- dispatch({
142
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
143
- payload: { drawer: null },
144
- });
145
- }, [dispatch]);
146
- // ============================================================================
147
- // 1.4.4 API CALLBACKS
148
- // ============================================================================
149
- const listCallback = useCallback(({ data, error }) => {
150
- if (error) {
151
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
152
- return;
153
- }
154
- if (data) {
155
- dispatch({
156
- type: DISCOUNT_CODE_ACTION_TYPES.SET_ITEMS,
157
- payload: { items: data.items || [], count: data.count || 0 },
158
- });
159
- }
160
- }, [dispatch, showToast, t]);
161
- const updateCallback = useCallback(({ data, error }) => {
162
- var _a;
163
- if (error) {
164
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
165
- return;
166
- }
167
- if (data) {
168
- const isCreated = isCreatedOrUpdated(data);
169
- showToast(isCreated
170
- ? t("messagesDiscountCodeCreated")
171
- : t("messagesDiscountCodeUpdated"), TOAST_VARIANT.SUCCESS);
172
- resetFormAndCloseDrawer();
173
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
174
- }
175
- }, [resetFormAndCloseDrawer, showToast, t]);
176
- const byIdCallback = useCallback(({ data, error }) => {
177
- if (error) {
178
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
179
- return;
180
- }
181
- if (data) {
182
- dispatch({
183
- type: DISCOUNT_CODE_ACTION_TYPES.SET_FORM_DATA,
184
- payload: { form: data },
185
- });
186
- }
187
- }, [dispatch, showToast, t]);
188
- const deleteCallback = useCallback(({ data, error }) => {
189
- var _a;
190
- if (error) {
191
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
192
- return;
193
- }
194
- if (data) {
195
- showToast(t("messagesDiscountCodeDeleted"), TOAST_VARIANT.SUCCESS);
196
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
197
- }
198
- }, [showToast, t]);
199
- // ============================================================================
200
- // 1.4.5 API HOOKS
201
- // ============================================================================
202
- const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listError, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
203
- byIdCallback,
204
- byIdParams,
205
- deleteCallback,
206
- deleteParams,
207
- listCallback,
208
- listParams,
209
- listUrl: DISCOUNT_CODE_API_ROUTES.UNIT,
210
- searchQuery: debouncedQuery,
211
- unitByIdUrl: DISCOUNT_CODE_API_ROUTES.UNIT,
212
- unitUrl: DISCOUNT_CODE_API_ROUTES.UNIT,
213
- updateCallback,
214
- updateParams,
215
- headers: {
216
- "Content-Type": "application/json",
217
- // "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
218
- },
219
- });
220
- // ============================================================================
221
- // 1.4.6 HANDLERS
222
- // ============================================================================
223
- const handleChange = useCallback((key, value) => {
224
- dispatch({
225
- type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
226
- payload: { errors: {} },
227
- });
228
- dispatch({
229
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
230
- payload: { disableSaveButton: false },
231
- });
232
- dispatch({
233
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
234
- payload: { key, value },
235
- });
236
- }, [dispatch]);
237
- const closeDrawer = useCallback(() => {
238
- resetFormAndCloseDrawer();
239
- }, [resetFormAndCloseDrawer]);
240
- const handleNextClick = useCallback(() => {
241
- dispatch({
242
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
243
- payload: { currentPage: state.currentPage + 1 },
244
- });
245
- }, [dispatch, state.currentPage]);
246
- const handlePreviousClick = useCallback(() => {
247
- dispatch({
248
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
249
- payload: { currentPage: state.currentPage - 1 },
250
- });
251
- }, [dispatch, state.currentPage]);
252
- const handlePageChange = useCallback((page) => {
253
- const nextPage = typeof page === "number" ? page : state.currentPage + 1;
254
- dispatch({
255
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
256
- payload: { currentPage: nextPage },
257
- });
258
- }, [dispatch, state.currentPage]);
259
- const handlePageLimitChange = useCallback((k, value) => {
260
- const val = Object.assign({}, value);
261
- dispatch({
262
- type: DISCOUNT_CODE_ACTION_TYPES.SET_PAGE_LIMIT,
263
- payload: { pageLimit: Number(val.option) },
264
- });
265
- dispatch({
266
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
267
- payload: { currentPage: 1 },
268
- });
269
- }, [dispatch]);
270
- const resetRecordFormState = useCallback(() => {
271
- dispatch({
272
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
273
- payload: { key: "code", value: "" },
274
- });
275
- dispatch({
276
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
277
- payload: { key: "description", value: "" },
278
- });
279
- dispatch({
280
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
281
- payload: { key: "discountType", value: "" },
282
- });
283
- dispatch({
284
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
285
- payload: { key: "discountValue", value: 0 },
286
- });
287
- dispatch({
288
- type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
289
- payload: { key: "enabled", value: true },
290
- });
291
- }, [dispatch]);
292
- const handleView = useCallback((row) => {
293
- resetRecordFormState();
294
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
295
- dispatch({
296
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
297
- payload: { drawer: DISCOUNT_CODE_DRAWER.VIEW_DRAWER },
298
- });
299
- }, [byIdFetchNow, dispatch, resetRecordFormState]);
300
- const handleEdit = useCallback((row) => {
301
- resetRecordFormState();
302
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
303
- dispatch({
304
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
305
- payload: { drawer: DISCOUNT_CODE_DRAWER.FORM_DRAWER },
306
- });
307
- }, [byIdFetchNow, dispatch, resetRecordFormState]);
308
- const handleDelete = useCallback((row) => {
309
- if (confirm(t("messagesDeleteConfirmation"))) {
310
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
311
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
312
- });
313
- }
314
- }, [deleteFetchNow, t]);
315
- const handleCreate = useCallback(() => {
316
- dispatch({
317
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
318
- payload: { drawer: DISCOUNT_CODE_DRAWER.FORM_DRAWER },
319
- });
320
- }, [dispatch]);
321
- const handleFilters = useCallback(() => {
322
- dispatch({
323
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
324
- payload: { drawer: DISCOUNT_CODE_DRAWER.FILTER_DRAWER },
325
- });
326
- }, [dispatch]);
327
- const handleMoreActions = useCallback(() => {
328
- dispatch({
329
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
330
- payload: { drawer: DISCOUNT_CODE_DRAWER.MORE_ACTIONS_DRAWER },
331
- });
332
- }, [dispatch]);
333
- const clearSearch = useCallback(() => {
334
- dispatch({
335
- type: DISCOUNT_CODE_ACTION_TYPES.SET_SEARCH_QUERY,
336
- payload: { searchQuery: "" },
337
- });
338
- }, [dispatch]);
339
- const handleSearch = useCallback((query) => {
340
- dispatch({
341
- type: DISCOUNT_CODE_ACTION_TYPES.SET_SEARCH_QUERY,
342
- payload: { searchQuery: query },
343
- });
344
- }, [dispatch]);
345
- const applyFilters = useCallback(() => {
346
- dispatch({
347
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
348
- payload: { currentPage: 1 },
349
- });
350
- closeDrawer();
351
- }, [dispatch, closeDrawer]);
352
- const clearFilters = useCallback(() => {
353
- dispatch({
354
- type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
355
- payload: { currentPage: 1 },
356
- });
357
- dispatch({
358
- type: DISCOUNT_CODE_ACTION_TYPES.SET_FILTERS,
359
- payload: { filters: { filterEnabled: undefined } },
360
- });
361
- }, [dispatch]);
362
- // ============================================================================
363
- // 1.4.7 NETWORK ACTIONS
364
- // ============================================================================
365
- const handleSubmit = useCallback(() => {
366
- dispatch({
367
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
368
- payload: { disableSaveButton: true },
369
- });
370
- validateForm({
371
- params: updateParams,
372
- schema: accountDiscountCodeFormValidation,
373
- successCallback: () => {
374
- updateFetchNow(undefined, {
375
- body: JSON.stringify(updateParams),
376
- });
377
- },
378
- errorCallback: (errors) => {
379
- dispatch({
380
- type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
381
- payload: { disableSaveButton: false },
382
- });
383
- dispatch({
384
- type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
385
- payload: { errors },
386
- });
387
- showToast(t("messagesValidationError"), TOAST_VARIANT.ERROR);
388
- },
389
- });
390
- }, [dispatch, showToast, t, updateFetchNow, updateParams]);
391
- // ============================================================================
392
- // 1.4.8 HEADER & ROW ACTIONS
393
- // ============================================================================
394
- const headerActions = useMemo(() => [
395
- {
396
- enabled: true,
397
- handleOnClick: handleMoreActions,
398
- label: t("actionsButtonMoreActions"),
399
- order: 0,
400
- },
401
- {
402
- enabled: true,
403
- handleOnClick: handleFilters,
404
- label: t("actionsButtonFilters"),
405
- order: 1,
406
- },
407
- {
408
- enabled: true,
409
- handleOnClick: handleCreate,
410
- label: t("actionsButtonAdd"),
411
- order: 2,
412
- },
413
- ], [handleCreate, handleFilters, handleMoreActions, t]);
414
- const rowActions = useMemo(() => [
415
- {
416
- enabled: true,
417
- handleOnClick: handleView,
418
- label: t("actionsButtonView"),
419
- order: 1,
420
- },
421
- {
422
- enabled: true,
423
- handleOnClick: handleEdit,
424
- label: t("actionsButtonEdit"),
425
- order: 2,
426
- },
427
- {
428
- enabled: true,
429
- handleOnClick: handleDelete,
430
- label: t("actionsButtonDelete"),
431
- order: 3,
432
- },
433
- ], [handleDelete, handleEdit, handleView, t]);
434
- // ============================================================================
435
- // 1.4.9 EFFECTS
436
- // ============================================================================
437
- // Keep ref in sync with latest listFetchNow (avoids stale closure in callbacks)
438
- useEffect(() => {
439
- listFetchNowRef.current = listFetchNow;
440
- }, [listFetchNow]);
441
- // Fetch list on mount and on page/search/filter change
442
- useEffect(() => {
443
- var _a;
444
- if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
445
- return;
446
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
447
- }, [dispatch, listParams, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
448
- // ============================================================================
449
- // 1.4.10 RETURN
450
- // ============================================================================
451
- return Object.assign(Object.assign({}, context), { applyFilters,
452
- byIdLoading,
453
- clearFilters,
454
- clearSearch,
455
- closeDrawer,
456
- deleteLoading,
457
- resetRecordFormState,
458
- handleChange,
459
- handleCreate,
460
- handleDelete,
461
- handleEdit,
462
- handleFilters,
463
- handleMoreActions,
464
- handleNextClick,
465
- handlePageChange,
466
- handlePageLimitChange,
467
- handlePreviousClick,
468
- handleSearch,
469
- handleSubmit,
470
- handleView,
471
- headerActions,
472
- listError,
473
- listFetchNow,
474
- listLoading,
475
- rowActions,
476
- updateLoading });
477
- };
61
+ export { useDiscountCodeModule } from "./context/use-discount-code-module";
@@ -1,10 +1 @@
1
- import React from "react";
2
- /**
3
- * DiscountCodeFilter
4
- *
5
- * Lightweight filter UI for the discount-code drawer. The generic page
6
- * will render this component inside the filter drawer slot. Keep filters
7
- * minimal and explicit (enabled flag, type select) so caching remains
8
- * predictable.
9
- */
10
- export declare const DiscountCodeFilter: () => React.JSX.Element;
1
+ export declare const DiscountCodeFilter: () => import("react").JSX.Element;