@appcorp/fusion-storybook 0.2.98 → 0.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.
@@ -4,6 +4,8 @@ export declare const STUDENT_FEE_DRAWER: {
4
4
  readonly FORM_DRAWER: string;
5
5
  readonly MORE_ACTIONS_DRAWER: string;
6
6
  readonly VIEW_DRAWER: string;
7
+ readonly SINGLE_ENTRY_DRAWER: "SINGLE_ENTRY_DRAWER";
8
+ readonly CREATE_MONTHLY_DRAWER: "CREATE_MONTHLY_DRAWER";
7
9
  };
8
10
  export interface StudentFeesListResponse {
9
11
  items: StudentFeeBE[];
@@ -11,6 +11,8 @@ export const STUDENT_FEE_DRAWER = {
11
11
  FORM_DRAWER: DRAWER_TYPES.FORM_DRAWER,
12
12
  MORE_ACTIONS_DRAWER: DRAWER_TYPES.MORE_ACTIONS_DRAWER,
13
13
  VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
14
+ SINGLE_ENTRY_DRAWER: "SINGLE_ENTRY_DRAWER",
15
+ CREATE_MONTHLY_DRAWER: "CREATE_MONTHLY_DRAWER",
14
16
  };
15
17
  const studentFeeConfig = {
16
18
  name: "StudentFee",
@@ -9,12 +9,15 @@ export declare const useStudentFeeModule: () => {
9
9
  deleteLoading: boolean;
10
10
  handleChange: (field: string, value: string | number | boolean | PAYMENT_STATUS | FEE_RISK_LEVEL | null | undefined) => void;
11
11
  handleCreate: () => void;
12
+ handleCreateMonthly: () => void;
13
+ handleCreateSingleEntry: () => void;
12
14
  handleDelete: (row?: TableRow) => void;
13
15
  handleEdit: (row?: TableRow) => void;
14
16
  handleFilters: () => void;
15
17
  handleMoreActions: () => void;
16
18
  handlePageChange: (page: number | unknown) => void;
17
19
  handlePageLimitChange: (k: string, value: object) => void;
20
+ handleProceedMonthlyCreation: () => Promise<void>;
18
21
  handleSearch: (query: string) => void;
19
22
  handleSubmit: () => void;
20
23
  handleView: (row?: TableRow) => void;
@@ -29,7 +29,7 @@ export const useStudentFeeModule = () => {
29
29
  // ============================================================================
30
30
  // 1.4.1 STATE & CORE HOOKS
31
31
  // ============================================================================
32
- var _a, _b, _c, _d;
32
+ var _a, _b, _c, _d, _e;
33
33
  const context = useStudentFeeContext();
34
34
  const { dispatch } = context;
35
35
  const state = context.state;
@@ -102,10 +102,9 @@ export const useStudentFeeModule = () => {
102
102
  }, [dispatch]);
103
103
  const resetRecordFormState = useCallback(() => {
104
104
  var _a, _b;
105
- const days = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.dueDateLength) !== null && _a !== void 0 ? _a : 0;
105
+ const dueDay = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.dueDateLength) !== null && _a !== void 0 ? _a : 1;
106
106
  const dueDate = new Date();
107
- if (days > 0)
108
- dueDate.setDate(dueDate.getDate() + days);
107
+ dueDate.setDate(dueDay);
109
108
  dispatch({
110
109
  type: STUDENT_FEE_ACTION_TYPES.SET_ERRORS,
111
110
  payload: { errors: {} },
@@ -464,6 +463,20 @@ export const useStudentFeeModule = () => {
464
463
  payload: { drawer: STUDENT_FEE_DRAWER.FORM_DRAWER },
465
464
  });
466
465
  }, [dispatch, resetRecordFormState]);
466
+ const handleCreateSingleEntry = useCallback(() => {
467
+ resetRecordFormState();
468
+ dispatch({
469
+ type: STUDENT_FEE_ACTION_TYPES.SET_DRAWER,
470
+ payload: { drawer: STUDENT_FEE_DRAWER.SINGLE_ENTRY_DRAWER },
471
+ });
472
+ }, [dispatch, resetRecordFormState]);
473
+ const handleCreateMonthly = useCallback(() => {
474
+ resetRecordFormState();
475
+ dispatch({
476
+ type: STUDENT_FEE_ACTION_TYPES.SET_DRAWER,
477
+ payload: { drawer: STUDENT_FEE_DRAWER.CREATE_MONTHLY_DRAWER },
478
+ });
479
+ }, [dispatch, resetRecordFormState]);
467
480
  const handleView = useCallback((row) => {
468
481
  resetRecordFormState();
469
482
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
@@ -525,6 +538,42 @@ export const useStudentFeeModule = () => {
525
538
  // ============================================================================
526
539
  // 1.4.7 NETWORK ACTIONS
527
540
  // ============================================================================
541
+ const handleProceedMonthlyCreation = useCallback(async () => {
542
+ var _a, _b;
543
+ const schoolId = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id;
544
+ if (!schoolId) {
545
+ showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
546
+ return;
547
+ }
548
+ dispatch({
549
+ type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
550
+ payload: { disabled: true },
551
+ });
552
+ try {
553
+ const res = await fetch(STUDENT_FEE_API_ROUTES.CREATE_MONTHLY, {
554
+ method: "POST",
555
+ headers: { "Content-Type": "application/json" },
556
+ body: JSON.stringify({ schoolId }),
557
+ });
558
+ if (!res.ok) {
559
+ const err = (await res.json().catch(() => ({})));
560
+ showToast(err.error || t("messagesNetworkError"), TOAST_VARIANT.ERROR);
561
+ return;
562
+ }
563
+ showToast(t("messagesMonthlyJobQueued"), TOAST_VARIANT.SUCCESS);
564
+ resetFormAndCloseDrawer();
565
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
566
+ }
567
+ catch (_c) {
568
+ showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
569
+ }
570
+ finally {
571
+ dispatch({
572
+ type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
573
+ payload: { disabled: false },
574
+ });
575
+ }
576
+ }, [dispatch, showToast, t, (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id, resetFormAndCloseDrawer]);
528
577
  const handleSubmit = useCallback(() => {
529
578
  dispatch({
530
579
  type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
@@ -557,23 +606,42 @@ export const useStudentFeeModule = () => {
557
606
  const headerActions = useMemo(() => [
558
607
  {
559
608
  enabled: true,
609
+ handleOnClick: handleCreateMonthly,
610
+ label: t("actionsButtonCreateMonthly"),
611
+ order: 1,
612
+ },
613
+ {
614
+ enabled: true,
615
+ handleOnClick: handleCreateSingleEntry,
616
+ label: t("actionsButtonSingleEntry"),
617
+ order: 2,
618
+ },
619
+ {
620
+ enabled: false,
560
621
  handleOnClick: handleMoreActions,
561
622
  label: t("actionsButtonMoreActions"),
562
- order: 0,
623
+ order: 3,
563
624
  },
564
625
  {
565
626
  enabled: true,
566
627
  handleOnClick: handleFilters,
567
628
  label: t("actionsButtonFilters"),
568
- order: 1,
629
+ order: 4,
569
630
  },
570
631
  {
571
632
  enabled: true,
572
633
  handleOnClick: handleCreate,
573
634
  label: t("actionsButtonAdd"),
574
- order: 2,
635
+ order: 5,
575
636
  },
576
- ], [handleMoreActions, handleFilters, handleCreate, t]);
637
+ ], [
638
+ handleCreateMonthly,
639
+ handleCreateSingleEntry,
640
+ handleMoreActions,
641
+ handleFilters,
642
+ handleCreate,
643
+ t,
644
+ ]);
577
645
  const rowActions = useMemo(() => [
578
646
  {
579
647
  enabled: true,
@@ -606,7 +674,7 @@ export const useStudentFeeModule = () => {
606
674
  if (!((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id))
607
675
  return;
608
676
  (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
609
- }, [dispatch, listParams, (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id, showToast, t]);
677
+ }, [dispatch, listParams, (_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id, showToast, t]);
610
678
  // ============================================================================
611
679
  // 1.4.10 RETURN
612
680
  // ============================================================================
@@ -618,12 +686,15 @@ export const useStudentFeeModule = () => {
618
686
  deleteLoading,
619
687
  handleChange,
620
688
  handleCreate,
689
+ handleCreateMonthly,
690
+ handleCreateSingleEntry,
621
691
  handleDelete,
622
692
  handleEdit,
623
693
  handleFilters,
624
694
  handleMoreActions,
625
695
  handlePageChange,
626
696
  handlePageLimitChange,
697
+ handleProceedMonthlyCreation,
627
698
  handleSearch,
628
699
  handleSubmit,
629
700
  handleView,
@@ -0,0 +1 @@
1
+ export declare const StudentFeeCreateMonthly: () => import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { EnhancedDrawerHeader } from "@appcorp/shadcn/components/enhanced-drawer-header";
4
+ import { EnhancedDrawerFooter, DRAWER_FOOTER_COMPONENT_TYPE, } from "@appcorp/shadcn/components/enhanced-drawer-footer";
5
+ import { DrawerGeneric } from "@appcorp/shadcn/components/drawer-generic";
6
+ import { useStudentFeeModule, STUDENT_FEE_DRAWER } from "./context";
7
+ import { useTranslations } from "next-intl";
8
+ import { StudentFeeMonthlyForm } from "./monthly-form";
9
+ export const StudentFeeCreateMonthly = () => {
10
+ const { closeDrawer, handleProceedMonthlyCreation, state, updateLoading } = useStudentFeeModule();
11
+ const t = useTranslations("studentFee");
12
+ const { disableSaveButton, drawer, errors } = state;
13
+ const isOpen = drawer === STUDENT_FEE_DRAWER.CREATE_MONTHLY_DRAWER;
14
+ return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? _jsx(StudentFeeMonthlyForm, {}) : null, formDrawerHeader: isOpen ? (_jsx(EnhancedDrawerHeader, { title: t("drawerCreateMonthlyTitle"), description: t("drawerCreateMonthlyDescription") })) : null, formDrawerFooter: isOpen ? (_jsx(EnhancedDrawerFooter, { applyFilters: () => { }, clearFilters: () => { }, closeDrawer: closeDrawer, disableSaveButton: disableSaveButton, drawerType: DRAWER_FOOTER_COMPONENT_TYPE.FORM_DRAWER, errors: errors, handleSubmit: handleProceedMonthlyCreation, updateLoading: updateLoading })) : null, viewDrawer: null, viewDrawerHeader: null, viewDrawerFooter: null, moreActionsDrawer: null, moreActionsDrawerHeader: null, moreActionsDrawerFooter: null, onOpenChange: (open) => !open && closeDrawer(), open: isOpen }));
15
+ };
@@ -0,0 +1 @@
1
+ export declare const StudentFeeMonthlyForm: () => import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useTranslations } from "next-intl";
4
+ export const StudentFeeMonthlyForm = () => {
5
+ const t = useTranslations("studentFee");
6
+ return (_jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsxs("div", { children: [_jsx("h3", { children: t("formMonthlyProceedInfo") }), _jsx("p", { children: t("formMonthlyAdjustmentNote") })] }) }));
7
+ };
@@ -13,7 +13,7 @@
13
13
  * - `StudentFeePage` — root component that wraps with StudentFeeProvider
14
14
  */
15
15
  "use client";
16
- import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
17
  import { useMemo } from "react";
18
18
  import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
19
19
  import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
@@ -23,6 +23,8 @@ import { StudentFeeFilter } from "./filter";
23
23
  import { StudentFeeForm } from "./form";
24
24
  import { StudentFeeMoreActions } from "./more-actions";
25
25
  import { StudentFeeView } from "./view";
26
+ import { StudentFeeSingleEntry } from "./single-entry";
27
+ import { StudentFeeCreateMonthly } from "./monthly-create";
26
28
  import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
27
29
  import { RbacNoAccess } from "../../components/rbac-no-access";
28
30
  import { formatStudentName, formatAmount, formatAmountPaid, formatAmountDue, } from "./constants";
@@ -177,7 +179,7 @@ const StudentFeePageInner = (props) => {
177
179
  if (!hasPermission) {
178
180
  return _jsx(RbacNoAccess, { moduleName: "Student Fee" });
179
181
  }
180
- return (_jsx("div", { className: "p-4", children: _jsx(GenericStudentFeePage, { overrideConfig: studentFeeConfig, context: context, tableBodyCols: tableBodyCols }) }));
182
+ return (_jsxs("div", { className: "p-4", children: [_jsx(GenericStudentFeePage, { overrideConfig: studentFeeConfig, context: context, tableBodyCols: tableBodyCols }), _jsx(StudentFeeSingleEntry, {}), _jsx(StudentFeeCreateMonthly, {})] }));
181
183
  };
182
184
  // ============================================================================
183
185
  // PAGE EXPORTS
@@ -0,0 +1 @@
1
+ export declare const StudentFeeSingleEntry: () => import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { EnhancedDrawerHeader } from "@appcorp/shadcn/components/enhanced-drawer-header";
4
+ import { EnhancedDrawerFooter, DRAWER_FOOTER_COMPONENT_TYPE, } from "@appcorp/shadcn/components/enhanced-drawer-footer";
5
+ import { DrawerGeneric } from "@appcorp/shadcn/components/drawer-generic";
6
+ import { useStudentFeeModule, STUDENT_FEE_DRAWER } from "./context";
7
+ import { useTranslations } from "next-intl";
8
+ import { StudentFeeForm } from "./form";
9
+ export const StudentFeeSingleEntry = () => {
10
+ const { closeDrawer, handleSubmit, state, updateLoading } = useStudentFeeModule();
11
+ const t = useTranslations("studentFee");
12
+ const { disableSaveButton, drawer, errors } = state;
13
+ const isOpen = drawer === STUDENT_FEE_DRAWER.SINGLE_ENTRY_DRAWER;
14
+ return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? _jsx(StudentFeeForm, {}) : null, formDrawerHeader: isOpen ? (_jsx(EnhancedDrawerHeader, { title: t("drawerSingleEntryTitle"), description: t("drawerSingleEntryDescription") })) : null, formDrawerFooter: isOpen ? (_jsx(EnhancedDrawerFooter, { applyFilters: () => { }, clearFilters: () => { }, closeDrawer: closeDrawer, disableSaveButton: disableSaveButton, drawerType: DRAWER_FOOTER_COMPONENT_TYPE.FORM_DRAWER, errors: errors, handleSubmit: handleSubmit, updateLoading: updateLoading })) : null, viewDrawer: null, viewDrawerHeader: null, viewDrawerFooter: null, moreActionsDrawer: null, moreActionsDrawerHeader: null, moreActionsDrawerFooter: null, onOpenChange: (open) => !open && closeDrawer(), open: isOpen }));
15
+ };
package/constants.d.ts CHANGED
@@ -73,6 +73,7 @@ export declare const STUDENT_FEE_API_ROUTES: {
73
73
  readonly UNIT: "/api/v1/student-fee";
74
74
  readonly BULK: "/api/v1/student-fee/bulk";
75
75
  readonly BULK_STATUS: (jobId: string) => string;
76
+ readonly CREATE_MONTHLY: "/api/v1/student-fee/create-monthly";
76
77
  };
77
78
  export declare const STUDENT_PROFILE_API_ROUTES: {
78
79
  readonly LIST: "/api/v1/student-profile";
package/constants.js CHANGED
@@ -84,6 +84,7 @@ export const STUDENT_FEE_API_ROUTES = {
84
84
  UNIT: "/api/v1/student-fee",
85
85
  BULK: "/api/v1/student-fee/bulk",
86
86
  BULK_STATUS: (jobId) => `/api/v1/student-fee/bulk/${jobId}`,
87
+ CREATE_MONTHLY: "/api/v1/student-fee/create-monthly",
87
88
  };
88
89
  export const STUDENT_PROFILE_API_ROUTES = {
89
90
  LIST: "/api/v1/student-profile",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.2.98",
3
+ "version": "0.3.0",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",