@appcorp/fusion-storybook 0.3.18 → 0.3.20
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.
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
4
4
|
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
5
|
-
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { useStudentFeeModule, STUDENT_FEE_ACTION_TYPES } from "./context";
|
|
7
7
|
import { STUDENT_FEE_API_ROUTES } from "../../constants";
|
|
8
8
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
9
9
|
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
10
10
|
import { DISCOUNT_TYPE } from "../../type";
|
|
11
|
+
import { calculateAccumulatedStudentFeeFines } from "../../utils/fine";
|
|
11
12
|
import { useTranslations } from "next-intl";
|
|
12
13
|
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
13
14
|
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
@@ -85,11 +86,19 @@ export const SingleEntryStudentFeeForm = () => {
|
|
|
85
86
|
const d = new Date(rawDate);
|
|
86
87
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
87
88
|
};
|
|
89
|
+
const PER_DATE_RATE = 10;
|
|
90
|
+
const accumulatedFine = useMemo(() => {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
if (!((_a = response === null || response === void 0 ? void 0 : response.studentFees) === null || _a === void 0 ? void 0 : _a.length) || !workspace)
|
|
93
|
+
return 0;
|
|
94
|
+
const dueDateLength = (_b = workspace.dueDateLength) !== null && _b !== void 0 ? _b : 1;
|
|
95
|
+
return calculateAccumulatedStudentFeeFines(response.studentFees, dueDateLength, PER_DATE_RATE);
|
|
96
|
+
}, [response, workspace]);
|
|
88
97
|
const handleUpdateAmountPaid = (value) => {
|
|
89
98
|
const amountPaid = parseFloat(value);
|
|
90
99
|
if (isNaN(amountPaid))
|
|
91
100
|
return;
|
|
92
101
|
setAmountPaid(value);
|
|
93
102
|
};
|
|
94
|
-
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: "computerNumber-readonly", label: t("formComputerNumberLabel"), value: profile === null || profile === void 0 ? void 0 : profile.computerNumber, type: "number" }), _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: "amount-readonly", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), value: fee === null || fee === void 0 ? void 0 : fee.amount, type: "number", step: "0.01" }), _jsx(EnhancedInput, { id: "amountPaid", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), value: amountPaid, 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) - 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] }));
|
|
103
|
+
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: "computerNumber-readonly", label: t("formComputerNumberLabel"), value: profile === null || profile === void 0 ? void 0 : profile.computerNumber, type: "number" }), _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: "amount-readonly", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), value: fee === null || fee === void 0 ? void 0 : fee.amount, type: "number", step: "0.01" }), _jsx(EnhancedInput, { id: "amountPaid", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), value: amountPaid, 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) - parseFloat(amountPaid || "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: "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] }));
|
|
95
104
|
};
|