@appcorp/fusion-storybook 0.4.13 → 0.4.14

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.
@@ -8,6 +8,10 @@
8
8
  */
9
9
  import { PAYMENT_STATUS } from "../../type";
10
10
  export declare const pageLimit: number;
11
+ export declare const filterDateDefaults: () => {
12
+ filterFromDate: string;
13
+ filterToDate: string;
14
+ };
11
15
  export declare const PAYMENT_STATUS_OPTIONS: {
12
16
  label: string;
13
17
  value: PAYMENT_STATUS;
@@ -12,6 +12,19 @@ import { PAYMENT_STATUS } from "../../type";
12
12
  // ============================================================================
13
13
  export const pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
14
14
  // ============================================================================
15
+ // FILTER DATE DEFAULTS
16
+ // ============================================================================
17
+ export const filterDateDefaults = () => {
18
+ const now = new Date();
19
+ const start = new Date(now.getFullYear(), now.getMonth(), 1);
20
+ const end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
21
+ const toISODate = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
22
+ return {
23
+ filterFromDate: toISODate(start),
24
+ filterToDate: toISODate(end),
25
+ };
26
+ };
27
+ // ============================================================================
15
28
  // STATUS OPTIONS
16
29
  // ============================================================================
17
30
  export const PAYMENT_STATUS_OPTIONS = [
@@ -58,6 +58,12 @@ export declare const STUDENT_FEE_ACTION_TYPES: {
58
58
  studentProfileId: string;
59
59
  filterEnabled: boolean | undefined;
60
60
  filterStatus: PAYMENT_STATUS | "";
61
+ filterFromDate: string;
62
+ filterToDate: string;
63
+ appliedFilterEnabled: boolean | undefined;
64
+ appliedFilterStatus: PAYMENT_STATUS | "";
65
+ appliedFilterFromDate: string;
66
+ appliedFilterToDate: string;
61
67
  studentFeesSingleEntry: StudentFeeBE[];
62
68
  }>, initialStudentFeeState: {
63
69
  items: StudentFeeBE[];
@@ -92,6 +98,12 @@ export declare const STUDENT_FEE_ACTION_TYPES: {
92
98
  studentProfileId: string;
93
99
  filterEnabled: boolean | undefined;
94
100
  filterStatus: PAYMENT_STATUS | "";
101
+ filterFromDate: string;
102
+ filterToDate: string;
103
+ appliedFilterEnabled: boolean | undefined;
104
+ appliedFilterStatus: PAYMENT_STATUS | "";
105
+ appliedFilterFromDate: string;
106
+ appliedFilterToDate: string;
95
107
  studentFeesSingleEntry: StudentFeeBE[];
96
108
  }, StudentFeeProvider: import("react").FC<{
97
109
  children: React.ReactNode;
@@ -128,6 +140,12 @@ export declare const STUDENT_FEE_ACTION_TYPES: {
128
140
  studentProfileId: string;
129
141
  filterEnabled: boolean | undefined;
130
142
  filterStatus: PAYMENT_STATUS | "";
143
+ filterFromDate: string;
144
+ filterToDate: string;
145
+ appliedFilterEnabled: boolean | undefined;
146
+ appliedFilterStatus: PAYMENT_STATUS | "";
147
+ appliedFilterFromDate: string;
148
+ appliedFilterToDate: string;
131
149
  studentFeesSingleEntry: StudentFeeBE[];
132
150
  }, action: any) => {
133
151
  items: StudentFeeBE[];
@@ -162,6 +180,12 @@ export declare const STUDENT_FEE_ACTION_TYPES: {
162
180
  studentProfileId: string;
163
181
  filterEnabled: boolean | undefined;
164
182
  filterStatus: PAYMENT_STATUS | "";
183
+ filterFromDate: string;
184
+ filterToDate: string;
185
+ appliedFilterEnabled: boolean | undefined;
186
+ appliedFilterStatus: PAYMENT_STATUS | "";
187
+ appliedFilterFromDate: string;
188
+ appliedFilterToDate: string;
165
189
  studentFeesSingleEntry: StudentFeeBE[];
166
190
  }, useStudentFeeContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
167
191
  items: StudentFeeBE[];
@@ -196,5 +220,11 @@ export declare const STUDENT_FEE_ACTION_TYPES: {
196
220
  studentProfileId: string;
197
221
  filterEnabled: boolean | undefined;
198
222
  filterStatus: PAYMENT_STATUS | "";
223
+ filterFromDate: string;
224
+ filterToDate: string;
225
+ appliedFilterEnabled: boolean | undefined;
226
+ appliedFilterStatus: PAYMENT_STATUS | "";
227
+ appliedFilterFromDate: string;
228
+ appliedFilterToDate: string;
199
229
  studentFeesSingleEntry: StudentFeeBE[];
200
230
  }>;
@@ -2,7 +2,8 @@
2
2
  import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
3
3
  import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
4
4
  import { PAYMENT_STATUS } from "../../../type";
5
- import { pageLimit } from "../constants";
5
+ import { filterDateDefaults, pageLimit } from "../constants";
6
+ const { filterFromDate: defaultFilterFromDate, filterToDate: defaultFilterToDate } = filterDateDefaults();
6
7
  // ============================================================================
7
8
  // 1.1 DRAWER TYPES
8
9
  // ============================================================================
@@ -59,9 +60,16 @@ const studentFeeConfig = {
59
60
  schoolId: "",
60
61
  status: PAYMENT_STATUS.PENDING,
61
62
  studentProfileId: "",
62
- // Filters
63
+ // Draft filters (drawer edits; not fetched until Apply)
63
64
  filterEnabled: undefined,
64
65
  filterStatus: "",
66
+ filterFromDate: defaultFilterFromDate,
67
+ filterToDate: defaultFilterToDate,
68
+ // Applied filters (committed on Apply; drive the fetch via listParams)
69
+ appliedFilterEnabled: undefined,
70
+ appliedFilterStatus: "",
71
+ appliedFilterFromDate: defaultFilterFromDate,
72
+ appliedFilterToDate: defaultFilterToDate,
65
73
  studentFeesSingleEntry: [],
66
74
  },
67
75
  };
@@ -62,7 +62,24 @@ export const StudentFeeApiProvider = ({ children, }) => {
62
62
  // ==========================================================================
63
63
  // API PARAMETERS
64
64
  // ==========================================================================
65
- const listParams = useMemo(() => (Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {}))), [state.currentPage, state.pageLimit, debouncedQuery, schoolId]);
65
+ const listParams = useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined && {
66
+ filterEnabled: String(state.appliedFilterEnabled),
67
+ })), (state.appliedFilterStatus && {
68
+ filterStatus: state.appliedFilterStatus,
69
+ })), (state.appliedFilterFromDate && {
70
+ fromDate: state.appliedFilterFromDate,
71
+ })), (state.appliedFilterToDate && {
72
+ toDate: state.appliedFilterToDate,
73
+ }))), [
74
+ state.currentPage,
75
+ state.pageLimit,
76
+ debouncedQuery,
77
+ schoolId,
78
+ state.appliedFilterEnabled,
79
+ state.appliedFilterStatus,
80
+ state.appliedFilterFromDate,
81
+ state.appliedFilterToDate,
82
+ ]);
66
83
  const updateParams = useMemo(() => ({
67
84
  amount: Number(state.amount),
68
85
  amountDue: Number(state.amountDue),
@@ -70,6 +70,12 @@ export declare const useStudentFeeModule: () => {
70
70
  studentProfileId: string;
71
71
  filterEnabled: boolean | undefined;
72
72
  filterStatus: PAYMENT_STATUS | "";
73
+ filterFromDate: string;
74
+ filterToDate: string;
75
+ appliedFilterEnabled: boolean | undefined;
76
+ appliedFilterStatus: PAYMENT_STATUS | "";
77
+ appliedFilterFromDate: string;
78
+ appliedFilterToDate: string;
73
79
  studentFeesSingleEntry: import("../../../types").StudentFeeBE[];
74
80
  };
75
81
  dispatch: React.Dispatch<any>;
@@ -12,6 +12,7 @@ import { studentFeeFormValidation } from "../validate";
12
12
  import { getCachedWorkspaceSync } from "../../workspace/cache";
13
13
  import { getCachedFeeStructureById } from "../../fee-structure/cache";
14
14
  import { getCachedDiscountCodesSync } from "../../discount-code/cache";
15
+ import { filterDateDefaults } from "../constants";
15
16
  import { STUDENT_FEE_ACTION_TYPES, STUDENT_FEE_DRAWER, useStudentFeeContext, } from "./shared";
16
17
  import { useStudentFeeApiContext } from "./student-fee-api-provider";
17
18
  // ============================================================================
@@ -374,11 +375,28 @@ export const useStudentFeeModule = () => {
374
375
  });
375
376
  }, [t, deleteFetchNow]);
376
377
  const handleFilters = useCallback(() => {
378
+ dispatch({
379
+ type: STUDENT_FEE_ACTION_TYPES.SET_FILTERS,
380
+ payload: {
381
+ filters: {
382
+ filterEnabled: state.appliedFilterEnabled,
383
+ filterStatus: state.appliedFilterStatus,
384
+ filterFromDate: state.appliedFilterFromDate,
385
+ filterToDate: state.appliedFilterToDate,
386
+ },
387
+ },
388
+ });
377
389
  dispatch({
378
390
  type: STUDENT_FEE_ACTION_TYPES.SET_DRAWER,
379
391
  payload: { drawer: STUDENT_FEE_DRAWER.FILTER_DRAWER },
380
392
  });
381
- }, [dispatch]);
393
+ }, [
394
+ dispatch,
395
+ state.appliedFilterEnabled,
396
+ state.appliedFilterStatus,
397
+ state.appliedFilterFromDate,
398
+ state.appliedFilterToDate,
399
+ ]);
382
400
  const handleMoreActions = useCallback(() => {
383
401
  dispatch({
384
402
  type: STUDENT_FEE_ACTION_TYPES.SET_DRAWER,
@@ -388,38 +406,42 @@ export const useStudentFeeModule = () => {
388
406
  const applyFilters = useCallback(() => {
389
407
  closeDrawer();
390
408
  dispatch({
391
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
392
- payload: { key: "filterEnabled", value: state.filterEnabled },
393
- });
394
- dispatch({
395
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
396
- payload: { key: "filterStatus", value: state.filterStatus },
409
+ type: STUDENT_FEE_ACTION_TYPES.SET_FILTERS,
410
+ payload: {
411
+ filters: {
412
+ appliedFilterEnabled: state.filterEnabled,
413
+ appliedFilterStatus: state.filterStatus,
414
+ appliedFilterFromDate: state.filterFromDate,
415
+ appliedFilterToDate: state.filterToDate,
416
+ },
417
+ },
397
418
  });
398
419
  dispatch({
399
420
  type: STUDENT_FEE_ACTION_TYPES.SET_CURRENT_PAGE,
400
421
  payload: { currentPage: 1 },
401
422
  });
402
- listFetchNow === null || listFetchNow === void 0 ? void 0 : listFetchNow(undefined, {
403
- params: Object.assign(Object.assign({ currentPage: 1, pageLimit: state.pageLimit, schoolId }, (state.filterEnabled !== undefined && {
404
- filterEnabled: state.filterEnabled,
405
- })), (state.filterStatus && { filterStatus: state.filterStatus })),
406
- });
407
423
  }, [
408
424
  closeDrawer,
409
425
  dispatch,
410
- listFetchNow,
411
- schoolId,
412
426
  state.filterEnabled,
413
427
  state.filterStatus,
414
- state.pageLimit,
428
+ state.filterFromDate,
429
+ state.filterToDate,
415
430
  ]);
416
431
  const clearFilters = useCallback(() => {
432
+ const { filterFromDate, filterToDate } = filterDateDefaults();
417
433
  dispatch({
418
434
  type: STUDENT_FEE_ACTION_TYPES.SET_FILTERS,
419
435
  payload: {
420
436
  filters: {
421
437
  filterEnabled: undefined,
422
438
  filterStatus: "",
439
+ filterFromDate,
440
+ filterToDate,
441
+ appliedFilterEnabled: undefined,
442
+ appliedFilterStatus: "",
443
+ appliedFilterFromDate: filterFromDate,
444
+ appliedFilterToDate: filterToDate,
423
445
  },
424
446
  },
425
447
  });
@@ -427,14 +449,7 @@ export const useStudentFeeModule = () => {
427
449
  type: STUDENT_FEE_ACTION_TYPES.SET_CURRENT_PAGE,
428
450
  payload: { currentPage: 1 },
429
451
  });
430
- listFetchNow(undefined, {
431
- params: {
432
- currentPage: 1,
433
- pageLimit: state.pageLimit,
434
- schoolId,
435
- },
436
- });
437
- }, [dispatch, listFetchNow, state.pageLimit, schoolId]);
452
+ }, [dispatch]);
438
453
  const handleSearch = useCallback((query) => {
439
454
  dispatch({
440
455
  type: STUDENT_FEE_ACTION_TYPES.SET_SEARCH_QUERY,
@@ -11,6 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  * child components no longer creates redundant API hooks or auto-fetch effects.
12
12
  */
13
13
  import { EnhancedRadio } from "@appcorp/shadcn/components/enhanced-radio";
14
+ import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
14
15
  import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
15
16
  import { useStudentFeeModule } from "./context";
16
17
  import { PAYMENT_STATUS_OPTIONS } from "./constants";
@@ -18,7 +19,7 @@ import { STUDENT_FEE_API_ROUTES } from "../../constants";
18
19
  import { useTranslations } from "next-intl";
19
20
  export const StudentFeeFilter = () => {
20
21
  const { state, handleChange } = useStudentFeeModule();
21
- const { filterEnabled, filterStatus } = state;
22
+ const { filterEnabled, filterStatus, filterFromDate, filterToDate } = state;
22
23
  const t = useTranslations("studentFee");
23
24
  const paymentStatusLabelMap = {
24
25
  PENDING: t("formOptionPending"),
@@ -55,7 +56,7 @@ export const StudentFeeFilter = () => {
55
56
  },
56
57
  value: filterStatus || "",
57
58
  });
58
- return (_jsxs("div", { className: "space-y-4", children: [filterStatusCombo, _jsx(EnhancedRadio, { label: t("filterEnabledLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
59
+ return (_jsxs("div", { className: "space-y-4", children: [filterStatusCombo, _jsx(EnhancedInput, { id: "filterFromDate", info: t("filterFromDateInfo"), label: t("filterFromDateLabel"), onChange: (e) => handleChange("filterFromDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: filterFromDate || "" }), _jsx(EnhancedInput, { id: "filterToDate", info: t("filterToDateInfo"), label: t("filterToDateLabel"), onChange: (e) => handleChange("filterToDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: filterToDate || "" }), _jsx(EnhancedRadio, { label: t("filterEnabledLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
59
60
  { label: t("filterOptionAll"), value: "undefined" },
60
61
  { label: t("filterOptionEnabled"), value: "true" },
61
62
  { label: t("filterOptionDisabled"), value: "false" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",