@appcorp/fusion-storybook 0.1.18 → 0.1.19

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.
@@ -107,6 +107,25 @@ export declare const DISCOUNT_CODE_ACTION_TYPES: {
107
107
  id: string;
108
108
  }>;
109
109
  export declare const useDiscountCodeModule: () => {
110
+ state: {
111
+ items: DiscountCodeBE[];
112
+ count: number;
113
+ currentPage: number;
114
+ pageLimit: number;
115
+ searchQuery: string;
116
+ disableSaveButton: boolean;
117
+ drawer: null;
118
+ modal: null;
119
+ code: string;
120
+ description: string;
121
+ discountType: string;
122
+ discountValue: number;
123
+ enabled: boolean;
124
+ errors: Record<string, string>;
125
+ filterEnabled: boolean | undefined;
126
+ id: string;
127
+ };
128
+ dispatch: import("react").Dispatch<any>;
110
129
  applyFilters: () => void;
111
130
  byIdLoading: boolean;
112
131
  clearFilters: () => void;
@@ -132,23 +151,4 @@ export declare const useDiscountCodeModule: () => {
132
151
  listLoading: boolean;
133
152
  rowActions: RowAction[];
134
153
  updateLoading: boolean;
135
- state: {
136
- items: DiscountCodeBE[];
137
- count: number;
138
- currentPage: number;
139
- pageLimit: number;
140
- searchQuery: string;
141
- disableSaveButton: boolean;
142
- drawer: null;
143
- modal: null;
144
- code: string;
145
- description: string;
146
- discountType: string;
147
- discountValue: number;
148
- enabled: boolean;
149
- errors: Record<string, string>;
150
- filterEnabled: boolean | undefined;
151
- id: string;
152
- };
153
- dispatch: React.Dispatch<any>;
154
154
  };
@@ -76,42 +76,42 @@ export const { actionTypes: DISCOUNT_CODE_ACTION_TYPES, config: discountCodeModu
76
76
  // ============================================================================
77
77
  export const useDiscountCodeModule = () => {
78
78
  var _a;
79
- const context = useDiscountCodeStateContext();
79
+ const { state, dispatch } = useDiscountCodeStateContext();
80
80
  const t = useTranslations("discountCode");
81
81
  const workspace = getCachedWorkspaceSync();
82
82
  const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
83
- const debouncedQuery = useDebounce(context.state.searchQuery, 800);
83
+ const debouncedQuery = useDebounce(state.searchQuery, 800);
84
84
  // ============================================================================
85
85
  // API PARAMETERS
86
86
  // ============================================================================
87
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: context.state.currentPage, pageLimit: context.state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (context.state.filterEnabled !== undefined
88
- ? { filterEnabled: String(context.state.filterEnabled) }
87
+ const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
88
+ ? { filterEnabled: String(state.filterEnabled) }
89
89
  : {}))), [
90
- context.state.currentPage,
91
- context.state.pageLimit,
92
- context.state.filterEnabled,
90
+ state.currentPage,
91
+ state.pageLimit,
92
+ state.filterEnabled,
93
93
  debouncedQuery,
94
94
  schoolId,
95
95
  ]);
96
96
  const updateParams = useMemo(() => ({
97
- code: context.state.code,
98
- description: context.state.description,
99
- discountType: context.state.discountType,
100
- discountValue: context.state.discountValue,
101
- enabled: context.state.enabled,
102
- id: context.state.id,
97
+ code: state.code,
98
+ description: state.description,
99
+ discountType: state.discountType,
100
+ discountValue: state.discountValue,
101
+ enabled: state.enabled,
102
+ id: state.id,
103
103
  schoolId,
104
104
  }), [
105
- context.state.code,
106
- context.state.description,
107
- context.state.discountType,
108
- context.state.discountValue,
109
- context.state.enabled,
110
- context.state.id,
105
+ state.code,
106
+ state.description,
107
+ state.discountType,
108
+ state.discountValue,
109
+ state.enabled,
110
+ state.id,
111
111
  schoolId,
112
112
  ]);
113
- const byIdParams = useMemo(() => ({ id: context.state.id }), [context.state.id]);
114
- const deleteParams = useMemo(() => ({ id: context.state.id }), [context.state.id]);
113
+ const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
114
+ const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
115
115
  // ============================================================================
116
116
  // API CALLBACKS
117
117
  // ============================================================================
@@ -121,7 +121,7 @@ export const useDiscountCodeModule = () => {
121
121
  return;
122
122
  }
123
123
  if (data) {
124
- context.dispatch({
124
+ dispatch({
125
125
  type: DISCOUNT_CODE_ACTION_TYPES.SET_ITEMS,
126
126
  payload: { items: data.items || [], count: data.count || 0 },
127
127
  });
@@ -200,62 +200,62 @@ export const useDiscountCodeModule = () => {
200
200
  generateThemeToast({ description: message, variant });
201
201
  }, []);
202
202
  const resetFormAndCloseDrawer = useCallback(() => {
203
- context.dispatch({
203
+ dispatch({
204
204
  type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
205
205
  payload: { errors: {} },
206
206
  });
207
- context.dispatch({
207
+ dispatch({
208
208
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
209
209
  payload: { disabled: false },
210
210
  });
211
- context.dispatch({
211
+ dispatch({
212
212
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
213
213
  payload: { drawer: null },
214
214
  });
215
- }, [context]);
215
+ }, [dispatch]);
216
216
  const setField = useCallback((key, value) => {
217
- context.dispatch({
217
+ dispatch({
218
218
  type: DISCOUNT_CODE_ACTION_TYPES.SET_INPUT_FIELD,
219
219
  payload: { field: key, value },
220
220
  });
221
- }, [context]);
221
+ }, [dispatch]);
222
222
  // ============================================================================
223
223
  // HANDLERS
224
224
  // ============================================================================
225
225
  const handleChange = useCallback((field, value) => {
226
- context.dispatch({
226
+ dispatch({
227
227
  type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
228
228
  payload: { errors: {} },
229
229
  });
230
- context.dispatch({
230
+ dispatch({
231
231
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
232
232
  payload: { disabled: false },
233
233
  });
234
234
  setField(field, value);
235
- }, [setField, context]);
235
+ }, [setField, dispatch]);
236
236
  const handleCloseDrawer = useCallback(() => {
237
237
  resetFormAndCloseDrawer();
238
238
  }, [resetFormAndCloseDrawer]);
239
239
  const handleCreate = useCallback(() => {
240
- context.dispatch({
240
+ dispatch({
241
241
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
242
242
  payload: { drawer: DISCOUNT_CODE_DRAWER.FORM_DRAWER },
243
243
  });
244
- }, [context]);
244
+ }, [dispatch]);
245
245
  const handleView = useCallback((row) => {
246
246
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
247
- context.dispatch({
247
+ dispatch({
248
248
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
249
249
  payload: { drawer: DISCOUNT_CODE_DRAWER.VIEW_DRAWER },
250
250
  });
251
- }, [context, byIdFetchNow]);
251
+ }, [byIdFetchNow, dispatch]);
252
252
  const handleEdit = useCallback((row) => {
253
253
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
254
- context.dispatch({
254
+ dispatch({
255
255
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
256
256
  payload: { drawer: DISCOUNT_CODE_DRAWER.FORM_DRAWER },
257
257
  });
258
- }, [context, byIdFetchNow]);
258
+ }, [byIdFetchNow, dispatch]);
259
259
  const handleDelete = useCallback((row) => {
260
260
  if (confirm(t("confirmDelete"))) {
261
261
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
@@ -264,41 +264,41 @@ export const useDiscountCodeModule = () => {
264
264
  }
265
265
  }, [t, deleteFetchNow]);
266
266
  const handleFilters = useCallback(() => {
267
- context.dispatch({
267
+ dispatch({
268
268
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DRAWER,
269
269
  payload: { drawer: DISCOUNT_CODE_DRAWER.FILTER_DRAWER },
270
270
  });
271
- }, [context]);
271
+ }, [dispatch]);
272
272
  const handlePageChange = useCallback((page) => {
273
- context.dispatch({
273
+ dispatch({
274
274
  type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
275
275
  payload: { currentPage: page },
276
276
  });
277
- }, [context]);
277
+ }, [dispatch]);
278
278
  const handlePageLimitChange = useCallback((limit) => {
279
- context.dispatch({
279
+ dispatch({
280
280
  type: DISCOUNT_CODE_ACTION_TYPES.SET_PAGE_LIMIT,
281
281
  payload: { pageLimit: limit },
282
282
  });
283
- }, [context]);
283
+ }, [dispatch]);
284
284
  const handleSearch = useCallback((query) => {
285
- context.dispatch({
285
+ dispatch({
286
286
  type: DISCOUNT_CODE_ACTION_TYPES.SET_SEARCH_QUERY,
287
287
  payload: { searchQuery: query },
288
288
  });
289
- }, [context]);
289
+ }, [dispatch]);
290
290
  const clearFilters = useCallback(() => {
291
- context.dispatch({
291
+ dispatch({
292
292
  type: DISCOUNT_CODE_ACTION_TYPES.SET_FILTERS,
293
293
  payload: { filters: { filterEnabled: undefined } },
294
294
  });
295
- context.dispatch({
295
+ dispatch({
296
296
  type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
297
297
  payload: { currentPage: 1 },
298
298
  });
299
- }, [context]);
299
+ }, [dispatch]);
300
300
  const handleSubmit = useCallback(() => {
301
- context.dispatch({
301
+ dispatch({
302
302
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
303
303
  payload: { disabled: true },
304
304
  });
@@ -311,18 +311,18 @@ export const useDiscountCodeModule = () => {
311
311
  });
312
312
  },
313
313
  errorCallback: (errors) => {
314
- context.dispatch({
314
+ dispatch({
315
315
  type: DISCOUNT_CODE_ACTION_TYPES.SET_ERRORS,
316
316
  payload: { errors },
317
317
  });
318
- context.dispatch({
318
+ dispatch({
319
319
  type: DISCOUNT_CODE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
320
320
  payload: { disabled: false },
321
321
  });
322
322
  showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
323
323
  },
324
324
  });
325
- }, [context, updateParams, t, showToast, updateFetchNow]);
325
+ }, [dispatch, updateParams, t, showToast, updateFetchNow]);
326
326
  // ============================================================================
327
327
  // HEADER & ROW ACTIONS
328
328
  // ============================================================================
@@ -363,13 +363,13 @@ export const useDiscountCodeModule = () => {
363
363
  },
364
364
  ], [handleView, handleEdit, handleDelete, t]);
365
365
  const applyFilters = useCallback(() => {
366
- context.dispatch({
366
+ dispatch({
367
367
  type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
368
368
  payload: { currentPage: 1 },
369
369
  });
370
370
  listFetchNow();
371
371
  handleCloseDrawer();
372
- }, [context, listFetchNow, handleCloseDrawer]);
372
+ }, [dispatch, listFetchNow, handleCloseDrawer]);
373
373
  // ============================================================================
374
374
  // EFFECTS
375
375
  // ============================================================================
@@ -381,7 +381,7 @@ export const useDiscountCodeModule = () => {
381
381
  const { count, items } = await getCachedDiscountCodes({
382
382
  params: listParams,
383
383
  });
384
- context.dispatch({
384
+ dispatch({
385
385
  type: DISCOUNT_CODE_ACTION_TYPES.SET_ITEMS,
386
386
  payload: { items: items || [], count: count || 0 },
387
387
  });
@@ -390,11 +390,14 @@ export const useDiscountCodeModule = () => {
390
390
  showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
391
391
  }
392
392
  })();
393
- }, [listParams, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id, context]);
393
+ }, [listParams, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id, dispatch]);
394
394
  // ============================================================================
395
395
  // RETURN
396
396
  // ============================================================================
397
- return Object.assign(Object.assign({}, context), { applyFilters,
397
+ return {
398
+ state,
399
+ dispatch,
400
+ applyFilters,
398
401
  byIdLoading,
399
402
  clearFilters,
400
403
  deleteLoading,
@@ -412,5 +415,6 @@ export const useDiscountCodeModule = () => {
412
415
  headerActions,
413
416
  listLoading,
414
417
  rowActions,
415
- updateLoading });
418
+ updateLoading,
419
+ };
416
420
  };
@@ -86,6 +86,7 @@ export const FamilyStateContextProvider = FamilyProvider;
86
86
  export const useFamilyModule = () => {
87
87
  var _a, _b;
88
88
  const context = useFamilyContext();
89
+ const { dispatch } = context;
89
90
  const t = useTranslations("family");
90
91
  const workspace = getCachedWorkspaceSync();
91
92
  const debouncedQuery = useDebounce(context.state.searchQuery, 800);
@@ -134,7 +135,7 @@ export const useFamilyModule = () => {
134
135
  return;
135
136
  }
136
137
  if (data) {
137
- context.dispatch({
138
+ dispatch({
138
139
  type: FAMILY_ACTION_TYPES.SET_ITEMS,
139
140
  payload: { items: data.items || [], count: data.count || 0 },
140
141
  });
@@ -168,7 +169,7 @@ export const useFamilyModule = () => {
168
169
  setField("familyCode", family.familyCode);
169
170
  setField("postalCode", family.postalCode);
170
171
  setField("stateProvince", family.state);
171
- context.dispatch({
172
+ dispatch({
172
173
  type: FAMILY_ACTION_TYPES.SET_FORM_DATA,
173
174
  payload: {
174
175
  form: {
@@ -217,74 +218,74 @@ export const useFamilyModule = () => {
217
218
  generateThemeToast({ description: message, variant });
218
219
  }, []);
219
220
  const resetFormAndCloseDrawer = useCallback(() => {
220
- context.dispatch({
221
+ dispatch({
221
222
  type: FAMILY_ACTION_TYPES.SET_ERRORS,
222
223
  payload: { errors: {} },
223
224
  });
224
- context.dispatch({
225
+ dispatch({
225
226
  type: FAMILY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
226
227
  payload: { disabled: false },
227
228
  });
228
- context.dispatch({
229
+ dispatch({
229
230
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
230
231
  payload: { drawer: null },
231
232
  });
232
- }, [context]);
233
+ }, [dispatch]);
233
234
  const setField = useCallback((key, value) => {
234
- context.dispatch({
235
+ dispatch({
235
236
  type: FAMILY_ACTION_TYPES.SET_INPUT_FIELD,
236
237
  payload: { key, value: value === null ? undefined : value },
237
238
  });
238
- }, [context]);
239
+ }, [dispatch]);
239
240
  // ============================================================================
240
241
  // HANDLERS
241
242
  // ============================================================================
242
243
  const handleChange = useCallback((field, value) => {
243
- context.dispatch({
244
+ dispatch({
244
245
  type: FAMILY_ACTION_TYPES.SET_ERRORS,
245
246
  payload: { errors: {} },
246
247
  });
247
- context.dispatch({
248
+ dispatch({
248
249
  type: FAMILY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
249
250
  payload: { disabled: false },
250
251
  });
251
252
  setField(field, value);
252
- }, [setField, context]);
253
+ }, [setField, dispatch]);
253
254
  const handlePageChange = useCallback((page) => {
254
- context.dispatch({
255
+ dispatch({
255
256
  type: FAMILY_ACTION_TYPES.SET_CURRENT_PAGE,
256
257
  payload: { currentPage: page },
257
258
  });
258
- }, [context]);
259
+ }, [dispatch]);
259
260
  const handlePageLimitChange = useCallback((limit) => {
260
- context.dispatch({
261
+ dispatch({
261
262
  type: FAMILY_ACTION_TYPES.SET_PAGE_LIMIT,
262
263
  payload: { pageLimit: limit },
263
264
  });
264
- }, [context]);
265
+ }, [dispatch]);
265
266
  const handleCloseDrawer = useCallback(() => {
266
267
  resetFormAndCloseDrawer();
267
268
  }, [resetFormAndCloseDrawer]);
268
269
  const handleCreate = useCallback(() => {
269
- context.dispatch({
270
+ dispatch({
270
271
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
271
272
  payload: { drawer: FAMILY_DRAWER.FORM_DRAWER },
272
273
  });
273
- }, [context]);
274
+ }, [dispatch]);
274
275
  const handleView = useCallback((row) => {
275
276
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
276
- context.dispatch({
277
+ dispatch({
277
278
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
278
279
  payload: { drawer: FAMILY_DRAWER.VIEW_DRAWER },
279
280
  });
280
- }, [context, byIdFetchNow]);
281
+ }, [dispatch, byIdFetchNow]);
281
282
  const handleEdit = useCallback((row) => {
282
283
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
283
- context.dispatch({
284
+ dispatch({
284
285
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
285
286
  payload: { drawer: FAMILY_DRAWER.FORM_DRAWER },
286
287
  });
287
- }, [context, byIdFetchNow]);
288
+ }, [dispatch, byIdFetchNow]);
288
289
  const handleDelete = useCallback((row) => {
289
290
  if (!confirm(t("areYouSureYouWantToDeleteThisFamily")))
290
291
  return;
@@ -293,35 +294,35 @@ export const useFamilyModule = () => {
293
294
  });
294
295
  }, [t, deleteFetchNow]);
295
296
  const handleFilters = useCallback(() => {
296
- context.dispatch({
297
+ dispatch({
297
298
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
298
299
  payload: { drawer: FAMILY_DRAWER.FILTER_DRAWER },
299
300
  });
300
- }, [context]);
301
+ }, [dispatch]);
301
302
  const handleMoreActions = useCallback(() => {
302
- context.dispatch({
303
+ dispatch({
303
304
  type: FAMILY_ACTION_TYPES.SET_DRAWER,
304
305
  payload: { drawer: FAMILY_DRAWER.MORE_ACTIONS_DRAWER },
305
306
  });
306
- }, [context]);
307
+ }, [dispatch]);
307
308
  const clearFilters = useCallback(() => {
308
- context.dispatch({
309
+ dispatch({
309
310
  type: FAMILY_ACTION_TYPES.SET_FILTERS,
310
311
  payload: { filters: { filterEnabled: undefined } },
311
312
  });
312
- context.dispatch({
313
+ dispatch({
313
314
  type: FAMILY_ACTION_TYPES.SET_CURRENT_PAGE,
314
315
  payload: { currentPage: 1 },
315
316
  });
316
- }, [context]);
317
+ }, [dispatch]);
317
318
  const handleSearch = useCallback((query) => {
318
- context.dispatch({
319
+ dispatch({
319
320
  type: FAMILY_ACTION_TYPES.SET_SEARCH_QUERY,
320
321
  payload: { searchQuery: query },
321
322
  });
322
- }, [context]);
323
+ }, [dispatch]);
323
324
  const handleSubmit = useCallback(() => {
324
- context.dispatch({
325
+ dispatch({
325
326
  type: FAMILY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
326
327
  payload: { disabled: true },
327
328
  });
@@ -334,26 +335,26 @@ export const useFamilyModule = () => {
334
335
  });
335
336
  },
336
337
  errorCallback: (errors) => {
337
- context.dispatch({
338
+ dispatch({
338
339
  type: FAMILY_ACTION_TYPES.SET_ERRORS,
339
340
  payload: { errors },
340
341
  });
341
- context.dispatch({
342
+ dispatch({
342
343
  type: FAMILY_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
343
344
  payload: { disabled: false },
344
345
  });
345
346
  showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
346
347
  },
347
348
  });
348
- }, [context, updateParams, t, showToast, updateFetchNow]);
349
+ }, [dispatch, updateParams, t, showToast, updateFetchNow]);
349
350
  const applyFilters = useCallback(() => {
350
- context.dispatch({
351
+ dispatch({
351
352
  type: FAMILY_ACTION_TYPES.SET_CURRENT_PAGE,
352
353
  payload: { currentPage: 1 },
353
354
  });
354
355
  listFetchNow();
355
356
  handleCloseDrawer();
356
- }, [context, listFetchNow, handleCloseDrawer]);
357
+ }, [dispatch, listFetchNow, handleCloseDrawer]);
357
358
  const headerActions = useMemo(() => [
358
359
  {
359
360
  enabled: false,
@@ -405,7 +406,7 @@ export const useFamilyModule = () => {
405
406
  const { count, items } = await getCachedFamilies({
406
407
  params: listParams,
407
408
  });
408
- context.dispatch({
409
+ dispatch({
409
410
  type: FAMILY_ACTION_TYPES.SET_ITEMS,
410
411
  payload: { items: items || [], count: count || 0 },
411
412
  });
@@ -414,7 +415,7 @@ export const useFamilyModule = () => {
414
415
  showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
415
416
  }
416
417
  })();
417
- }, [listParams, (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id, context, showToast, t]);
418
+ }, [listParams, (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id, dispatch, showToast, t]);
418
419
  // ============================================================================
419
420
  // RETURN
420
421
  // ============================================================================