@appcorp/fusion-storybook 0.2.99 → 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;
@@ -463,6 +463,20 @@ export const useStudentFeeModule = () => {
463
463
  payload: { drawer: STUDENT_FEE_DRAWER.FORM_DRAWER },
464
464
  });
465
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]);
466
480
  const handleView = useCallback((row) => {
467
481
  resetRecordFormState();
468
482
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
@@ -524,6 +538,42 @@ export const useStudentFeeModule = () => {
524
538
  // ============================================================================
525
539
  // 1.4.7 NETWORK ACTIONS
526
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]);
527
577
  const handleSubmit = useCallback(() => {
528
578
  dispatch({
529
579
  type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
@@ -556,23 +606,42 @@ export const useStudentFeeModule = () => {
556
606
  const headerActions = useMemo(() => [
557
607
  {
558
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,
559
621
  handleOnClick: handleMoreActions,
560
622
  label: t("actionsButtonMoreActions"),
561
- order: 0,
623
+ order: 3,
562
624
  },
563
625
  {
564
626
  enabled: true,
565
627
  handleOnClick: handleFilters,
566
628
  label: t("actionsButtonFilters"),
567
- order: 1,
629
+ order: 4,
568
630
  },
569
631
  {
570
632
  enabled: true,
571
633
  handleOnClick: handleCreate,
572
634
  label: t("actionsButtonAdd"),
573
- order: 2,
635
+ order: 5,
574
636
  },
575
- ], [handleMoreActions, handleFilters, handleCreate, t]);
637
+ ], [
638
+ handleCreateMonthly,
639
+ handleCreateSingleEntry,
640
+ handleMoreActions,
641
+ handleFilters,
642
+ handleCreate,
643
+ t,
644
+ ]);
576
645
  const rowActions = useMemo(() => [
577
646
  {
578
647
  enabled: true,
@@ -605,7 +674,7 @@ export const useStudentFeeModule = () => {
605
674
  if (!((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id))
606
675
  return;
607
676
  (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
608
- }, [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]);
609
678
  // ============================================================================
610
679
  // 1.4.10 RETURN
611
680
  // ============================================================================
@@ -617,12 +686,15 @@ export const useStudentFeeModule = () => {
617
686
  deleteLoading,
618
687
  handleChange,
619
688
  handleCreate,
689
+ handleCreateMonthly,
690
+ handleCreateSingleEntry,
620
691
  handleDelete,
621
692
  handleEdit,
622
693
  handleFilters,
623
694
  handleMoreActions,
624
695
  handlePageChange,
625
696
  handlePageLimitChange,
697
+ handleProceedMonthlyCreation,
626
698
  handleSearch,
627
699
  handleSubmit,
628
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.99",
3
+ "version": "0.3.0",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",