@appcorp/fusion-storybook 0.3.31 → 0.3.32
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.
- package/base-modules/student-fee/context/use-student-fee-module.d.ts +3 -1
- package/base-modules/student-fee/context/use-student-fee-module.js +40 -5
- package/base-modules/student-fee/single-entry-form.d.ts +5 -1
- package/base-modules/student-fee/single-entry-form.js +5 -13
- package/base-modules/student-fee/single-entry.js +4 -1
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -20,7 +20,9 @@ export declare const useStudentFeeModule: () => {
|
|
|
20
20
|
handleProceedMonthlyCreation: () => Promise<void>;
|
|
21
21
|
handleSearch: (query: string) => void;
|
|
22
22
|
handleSubmit: () => void;
|
|
23
|
-
handleSubmitSingleEntry: (fees:
|
|
23
|
+
handleSubmitSingleEntry: (fees: {
|
|
24
|
+
studentFees: StudentFeeBE[];
|
|
25
|
+
}, amountPaid: string, remarks: string) => Promise<void>;
|
|
24
26
|
handleView: (row?: TableRow) => void;
|
|
25
27
|
headerActions: {
|
|
26
28
|
enabled: boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { useTheme } from "next-themes";
|
|
4
4
|
import { useTranslations } from "next-intl";
|
|
5
|
-
import { validateForm, isCreatedOrUpdated, getStorageValue, } from "@react-pakistan/util-functions";
|
|
5
|
+
import { validateForm, isCreatedOrUpdated, getStorageValue, API_METHODS, } from "@react-pakistan/util-functions";
|
|
6
6
|
import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
|
|
7
7
|
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
8
8
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
@@ -28,7 +28,7 @@ export const useStudentFeeModule = () => {
|
|
|
28
28
|
// ============================================================================
|
|
29
29
|
// 1.4.1 STATE & CORE HOOKS
|
|
30
30
|
// ============================================================================
|
|
31
|
-
var _a, _b, _c, _d, _e, _f;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
32
32
|
const context = useStudentFeeContext();
|
|
33
33
|
const { dispatch } = context;
|
|
34
34
|
const state = context.state;
|
|
@@ -566,9 +566,44 @@ export const useStudentFeeModule = () => {
|
|
|
566
566
|
},
|
|
567
567
|
});
|
|
568
568
|
}, [dispatch, updateParams, t, showToast, updateFetchNow]);
|
|
569
|
-
const handleSubmitSingleEntry = useCallback((fees) => {
|
|
569
|
+
const handleSubmitSingleEntry = useCallback(async (fees, amountPaid, remarks) => {
|
|
570
|
+
var _a, _b;
|
|
570
571
|
console.log("Submitting single entry fees:", fees);
|
|
571
|
-
|
|
572
|
+
dispatch({
|
|
573
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
574
|
+
payload: { disabled: true },
|
|
575
|
+
});
|
|
576
|
+
try {
|
|
577
|
+
// const feeIds = fees.map((f) => f.id);
|
|
578
|
+
const res = await fetch(STUDENT_FEE_API_ROUTES.SINGLE_ENTRY, {
|
|
579
|
+
method: API_METHODS.POST,
|
|
580
|
+
headers: { "Content-Type": "application/json" },
|
|
581
|
+
body: JSON.stringify({
|
|
582
|
+
studentFees: fees.studentFees,
|
|
583
|
+
amountPaid: Number(amountPaid),
|
|
584
|
+
remarks,
|
|
585
|
+
schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "",
|
|
586
|
+
}),
|
|
587
|
+
});
|
|
588
|
+
if (!res.ok) {
|
|
589
|
+
const err = await res.json().catch(() => ({}));
|
|
590
|
+
showToast(err.error || t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
showToast(t("messagesStudentFeeUpdated"), TOAST_VARIANT.SUCCESS);
|
|
594
|
+
resetFormAndCloseDrawer();
|
|
595
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
596
|
+
}
|
|
597
|
+
catch (_c) {
|
|
598
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
599
|
+
}
|
|
600
|
+
finally {
|
|
601
|
+
dispatch({
|
|
602
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
603
|
+
payload: { disabled: false },
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}, [dispatch, showToast, t, (_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id, resetFormAndCloseDrawer]);
|
|
572
607
|
// ============================================================================
|
|
573
608
|
// 1.4.8 HEADER & ROW ACTIONS
|
|
574
609
|
// ============================================================================
|
|
@@ -643,7 +678,7 @@ export const useStudentFeeModule = () => {
|
|
|
643
678
|
if (!((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id))
|
|
644
679
|
return;
|
|
645
680
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
646
|
-
}, [dispatch, listParams, (
|
|
681
|
+
}, [dispatch, listParams, (_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id, showToast, t]);
|
|
647
682
|
// ============================================================================
|
|
648
683
|
// 1.4.10 RETURN
|
|
649
684
|
// ============================================================================
|
|
@@ -52,9 +52,13 @@ interface StudentFeeByCNResponse {
|
|
|
52
52
|
studentFees: FeeRecordSummary[];
|
|
53
53
|
}
|
|
54
54
|
interface SingleEntryStudentFeeFormProps {
|
|
55
|
-
|
|
55
|
+
amountPaid: string;
|
|
56
56
|
feeByComputerNumber: StudentFeeByCNResponse | null;
|
|
57
|
+
fetchByComputerNumber: (url: string | undefined, options: object) => void;
|
|
57
58
|
fetchingByCN: boolean;
|
|
59
|
+
remarks: string;
|
|
60
|
+
setAmountPaid: (value: string) => void;
|
|
61
|
+
setRemarks: (value: string) => void;
|
|
58
62
|
}
|
|
59
63
|
export declare const SingleEntryStudentFeeForm: FC<SingleEntryStudentFeeFormProps>;
|
|
60
64
|
export {};
|
|
@@ -9,23 +9,16 @@ import { DISCOUNT_TYPE } from "../../type";
|
|
|
9
9
|
import { useTranslations } from "next-intl";
|
|
10
10
|
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
11
11
|
import { Loader2 } from "lucide-react";
|
|
12
|
-
export const SingleEntryStudentFeeForm = ({
|
|
12
|
+
export const SingleEntryStudentFeeForm = ({ amountPaid, feeByComputerNumber, fetchByComputerNumber, fetchingByCN, remarks, setAmountPaid, setRemarks, }) => {
|
|
13
13
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
14
14
|
const { dispatch } = useStudentFeeModule();
|
|
15
15
|
const workspace = getCachedWorkspaceSync();
|
|
16
16
|
const currency = (_b = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.currency) !== null && _b !== void 0 ? _b : "";
|
|
17
17
|
const t = useTranslations("studentFee");
|
|
18
|
-
const [amountPaid, setAmountPaid] = useState("");
|
|
19
|
-
const [remarks, setRemarks] = useState("");
|
|
18
|
+
// const [amountPaid, setAmountPaid] = useState("");
|
|
19
|
+
// const [remarks, setRemarks] = useState("");
|
|
20
20
|
const [computerNumber, setComputerNumber] = useState("");
|
|
21
21
|
const debouncedComputerNumber = useDebounce(computerNumber, 800);
|
|
22
|
-
// const {
|
|
23
|
-
// fetchNow: fetchByComputerNumber,
|
|
24
|
-
// data: feeByComputerNumber,
|
|
25
|
-
// loading: fetchingByCN,
|
|
26
|
-
// } = useFetch(STUDENT_FEE_API_ROUTES.BY_COMPUTER_NUMBER, {
|
|
27
|
-
// method: API_METHODS.GET,
|
|
28
|
-
// });
|
|
29
22
|
const fetchByCNRef = useRef(fetchByComputerNumber);
|
|
30
23
|
useEffect(() => {
|
|
31
24
|
fetchByCNRef.current = fetchByComputerNumber;
|
|
@@ -101,10 +94,9 @@ export const SingleEntryStudentFeeForm = ({ fetchByComputerNumber, feeByComputer
|
|
|
101
94
|
};
|
|
102
95
|
useEffect(() => {
|
|
103
96
|
(async () => {
|
|
104
|
-
|
|
105
|
-
setAmountPaid(String(((_a = fee === null || fee === void 0 ? void 0 : fee.amount) !== null && _a !== void 0 ? _a : 0) + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0)));
|
|
97
|
+
setAmountPaid(String((accumulatedAmount !== null && accumulatedAmount !== void 0 ? accumulatedAmount : 0) + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0)));
|
|
106
98
|
})();
|
|
107
|
-
}, [fee, accumulatedFine]);
|
|
99
|
+
}, [fee, accumulatedFine, accumulatedAmount, setAmountPaid]);
|
|
108
100
|
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "computerNumber", info: t("formComputerNumberInfo"), label: t("formComputerNumberLabel"), onChange: (e) => setComputerNumber(e.target.value), placeholder: t("formComputerNumberPlaceholder"), type: "number", required: true, value: computerNumber }), fetchingByCN && debouncedComputerNumber ? (_jsx("div", { className: "flex items-center justify-center py-4", children: _jsx(Loader2, { className: "text-muted-foreground h-5 w-5 animate-spin" }) })) : null, fee && profile ? (_jsxs(_Fragment, { children: [_jsx(EnhancedInput, { readOnly: true, id: "studentProfileId-readonly", label: t("formStudentLabel"), value: studentName }), _jsx(EnhancedInput, { readOnly: true, id: "feeStructureId-readonly", label: t("formFeeStructureLabel"), value: feeStructureName }), _jsx(EnhancedInput, { readOnly: true, id: "discountCodeId-readonly", label: t("formDiscountCodeLabel"), value: discountCodeLabel }), _jsx(EnhancedInput, { readOnly: true, id: "discountAmount-readonly", label: t("formDiscountAmountLabel"), value: (_h = fee === null || fee === void 0 ? void 0 : fee.discountAmount) !== null && _h !== void 0 ? _h : 0, type: "number", step: "0.01" }), _jsx(EnhancedInput, { readOnly: true, id: "accumulatedFine-readonly", info: t("formAccumulatedFineInfo"), label: t("formAccumulatedFineLabel"), value: accumulatedFine, type: "number", step: "0.01" }), _jsx(EnhancedInput, { readOnly: true, id: "amount-readonly", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), value: accumulatedAmount + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0), type: "number", step: "0.01" }), _jsx(EnhancedInput, { id: "amountPaid", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), value: accumulatedAmount + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0) - fee.amountPaid || "0", onChange: (e) => handleUpdateAmountPaid(e.target.value), type: "number", step: "0.01" }), _jsx(EnhancedInput, { readOnly: true, id: "amountDue-readonly", info: t("formAmountDueInfo"), label: t("formAmountDueLabel"), value: Number(fee === null || fee === void 0 ? void 0 : fee.amountDue) +
|
|
109
101
|
(accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0) -
|
|
110
102
|
parseFloat(amountPaid || "0"), type: "number", step: "0.01" }), _jsx(EnhancedInput, { readOnly: true, id: "dueDate-readonly", label: t("formDueDateLabel"), value: formatDisplayDate(fee === null || fee === void 0 ? void 0 : fee.dueDate), type: "date" }), _jsx(EnhancedInput, { readOnly: true, id: "status-readonly", label: t("formStatusLabel"), value: statusDisplay }), _jsx(EnhancedTextarea, { id: "remarks-readonly", label: t("formRemarksLabel"), value: remarks || "", onChange: (e) => setRemarks(e.target.value) })] })) : null] }));
|
|
@@ -9,13 +9,16 @@ import { SingleEntryStudentFeeForm } from "./single-entry-form";
|
|
|
9
9
|
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
10
10
|
import { STUDENT_FEE_API_ROUTES } from "../../constants";
|
|
11
11
|
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
12
|
+
import { useState } from "storybook/internal/preview-api";
|
|
12
13
|
export const StudentFeeSingleEntry = () => {
|
|
13
14
|
const { closeDrawer, handleSubmitSingleEntry, state, updateLoading } = useStudentFeeModule();
|
|
15
|
+
const [amountPaid, setAmountPaid] = useState("");
|
|
16
|
+
const [remarks, setRemarks] = useState("");
|
|
14
17
|
const t = useTranslations("studentFee");
|
|
15
18
|
const { disableSaveButton, drawer, errors } = state;
|
|
16
19
|
const isOpen = drawer === STUDENT_FEE_DRAWER.SINGLE_ENTRY_DRAWER;
|
|
17
20
|
const { fetchNow: fetchByComputerNumber, data: feeByComputerNumber, loading: fetchingByCN, } = useFetch(STUDENT_FEE_API_ROUTES.BY_COMPUTER_NUMBER, {
|
|
18
21
|
method: API_METHODS.GET,
|
|
19
22
|
});
|
|
20
|
-
return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? (_jsx(SingleEntryStudentFeeForm, {
|
|
23
|
+
return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? (_jsx(SingleEntryStudentFeeForm, { amountPaid: amountPaid, feeByComputerNumber: feeByComputerNumber, fetchByComputerNumber: fetchByComputerNumber, fetchingByCN: fetchingByCN, remarks: remarks, setAmountPaid: setAmountPaid, setRemarks: setRemarks })) : 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: () => handleSubmitSingleEntry(feeByComputerNumber, amountPaid, remarks), updateLoading: updateLoading })) : null, viewDrawer: null, viewDrawerHeader: null, viewDrawerFooter: null, moreActionsDrawer: null, moreActionsDrawerHeader: null, moreActionsDrawerFooter: null, onOpenChange: (open) => !open && closeDrawer(), open: isOpen }));
|
|
21
24
|
};
|
package/constants.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare const STUDENT_FEE_API_ROUTES: {
|
|
|
75
75
|
readonly BULK_STATUS: (jobId: string) => string;
|
|
76
76
|
readonly CREATE_MONTHLY: "/api/v1/student-fee/create-monthly";
|
|
77
77
|
readonly BY_COMPUTER_NUMBER: "/api/v1/student-fee-by-student-computer-number";
|
|
78
|
+
readonly SINGLE_ENTRY: "/api/v1/student-fee-single-entry";
|
|
78
79
|
};
|
|
79
80
|
export declare const STUDENT_PROFILE_API_ROUTES: {
|
|
80
81
|
readonly LIST: "/api/v1/student-profile";
|
package/constants.js
CHANGED
|
@@ -86,6 +86,7 @@ export const STUDENT_FEE_API_ROUTES = {
|
|
|
86
86
|
BULK_STATUS: (jobId) => `/api/v1/student-fee/bulk/${jobId}`,
|
|
87
87
|
CREATE_MONTHLY: "/api/v1/student-fee/create-monthly",
|
|
88
88
|
BY_COMPUTER_NUMBER: "/api/v1/student-fee-by-student-computer-number",
|
|
89
|
+
SINGLE_ENTRY: "/api/v1/student-fee-single-entry",
|
|
89
90
|
};
|
|
90
91
|
export const STUDENT_PROFILE_API_ROUTES = {
|
|
91
92
|
LIST: "/api/v1/student-profile",
|