@appcorp/fusion-storybook 0.3.1 → 0.3.3
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.js +4 -0
- package/base-modules/student-fee/form.js +2 -2
- package/base-modules/student-fee/monthly-form.js +21 -1
- package/base-modules/student-fee/single-entry-form.d.ts +1 -0
- package/base-modules/student-fee/single-entry-form.js +75 -0
- package/base-modules/student-fee/single-entry.js +2 -2
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -472,6 +472,10 @@ export const useStudentFeeModule = () => {
|
|
|
472
472
|
}, [dispatch, resetRecordFormState]);
|
|
473
473
|
const handleCreateMonthly = useCallback(() => {
|
|
474
474
|
resetRecordFormState();
|
|
475
|
+
dispatch({
|
|
476
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
477
|
+
payload: { disabled: true },
|
|
478
|
+
});
|
|
475
479
|
dispatch({
|
|
476
480
|
type: STUDENT_FEE_ACTION_TYPES.SET_DRAWER,
|
|
477
481
|
payload: { drawer: STUDENT_FEE_DRAWER.CREATE_MONTHLY_DRAWER },
|
|
@@ -15,7 +15,7 @@ import { useStudentFeeModule } from "./context";
|
|
|
15
15
|
import { PAYMENT_STATUS_OPTIONS } from "./constants";
|
|
16
16
|
import { STUDENT_FEE_API_ROUTES, DISCOUNT_CODE_API_ROUTES, FEE_STRUCTURE_API_ROUTES, STUDENT_PROFILE_API_ROUTES, } from "../../constants";
|
|
17
17
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
18
|
-
import { API_METHODS
|
|
18
|
+
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
19
19
|
import { DISCOUNT_TYPE, } from "../../type";
|
|
20
20
|
import { useTranslations } from "next-intl";
|
|
21
21
|
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
@@ -148,5 +148,5 @@ export const StudentFeeForm = () => {
|
|
|
148
148
|
},
|
|
149
149
|
value: status,
|
|
150
150
|
});
|
|
151
|
-
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [studentProfileIdCombo, feeStructureIdCombo, discountCodeIdCombo, _jsx(EnhancedInput, { error: errors.discountAmount, id: "discountAmount", info: t("formDiscountAmountInfo"), label: t("formDiscountAmountLabel"), min: "0", onChange: (e) => handleChange("discountAmount", Number(e.target.value)), placeholder: "0.00",
|
|
151
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [studentProfileIdCombo, feeStructureIdCombo, discountCodeIdCombo, _jsx(EnhancedInput, { error: errors.discountAmount, id: "discountAmount", info: t("formDiscountAmountInfo"), label: t("formDiscountAmountLabel"), min: "0", onChange: (e) => handleChange("discountAmount", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: discountAmount || 0 }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "amount", t }), id: "amount", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), min: "0", onChange: (e) => handleChange("amount", Number(e.target.value)), placeholder: "0.00", required: true, step: "0.01", type: "number", value: amount }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "amountPaid", t }), id: "amountPaid", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), min: "0", required: true, onChange: (e) => handleChange("amountPaid", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: amountPaid }), _jsx(EnhancedInput, { disabled: true, error: getTranslatedError({ errors, key: "amountDue", t }), id: "amountDue", info: t("formAmountDueInfo"), label: t("formAmountDueLabel"), min: "0", required: true, onChange: (e) => handleChange("amountDue", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: amountDue }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dueDate", t }), id: "dueDate", info: t("formDueDateInfo"), label: t("formDueDateLabel"), onChange: (e) => handleChange("dueDate", e.target.value), required: true, type: "date", value: dueDate || "" }), statusCombo, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", label: t("formRemarksLabel"), onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), value: remarks || "" }), _jsx(EnhancedCheckbox, { checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", !!checked) })] }));
|
|
152
152
|
};
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
3
4
|
import { useTranslations } from "next-intl";
|
|
5
|
+
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
6
|
+
import { useStudentFeeModule, STUDENT_FEE_ACTION_TYPES } from "./context";
|
|
7
|
+
const CHECKBOX_KEYS = [
|
|
8
|
+
"formMonthlyCheckStudentProfile",
|
|
9
|
+
"formMonthlyCheckFeeStructure",
|
|
10
|
+
"formMonthlyCheckGmail",
|
|
11
|
+
"formMonthlyCheckReady",
|
|
12
|
+
];
|
|
4
13
|
export const StudentFeeMonthlyForm = () => {
|
|
5
14
|
const t = useTranslations("studentFee");
|
|
6
|
-
|
|
15
|
+
const { dispatch } = useStudentFeeModule();
|
|
16
|
+
const [checked, setChecked] = useState(Object.fromEntries(CHECKBOX_KEYS.map((key) => [key, false])));
|
|
17
|
+
// const allChecked = CHECKBOX_KEYS.every((key) => checked[key]);
|
|
18
|
+
const handleCheckChange = useCallback((key, value) => {
|
|
19
|
+
const next = Object.assign(Object.assign({}, checked), { [key]: value });
|
|
20
|
+
setChecked(next);
|
|
21
|
+
dispatch({
|
|
22
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
23
|
+
payload: { disabled: !CHECKBOX_KEYS.every((k) => next[k]) },
|
|
24
|
+
});
|
|
25
|
+
}, [checked, dispatch]);
|
|
26
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx("p", { className: "text-foreground text-sm", children: t("formMonthlyWarningMessage") }), _jsx("div", { className: "flex flex-col gap-3", children: CHECKBOX_KEYS.map((key) => (_jsx(EnhancedCheckbox, { checked: checked[key], id: key, label: t(key), onCheckedChange: (value) => handleCheckChange(key, value) }, key))) })] }));
|
|
7
27
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SingleEntryStudentFeeForm: () => import("react").JSX.Element;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
4
|
+
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { useStudentFeeModule, STUDENT_FEE_ACTION_TYPES } from "./context";
|
|
7
|
+
import { STUDENT_FEE_API_ROUTES } from "../../constants";
|
|
8
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
9
|
+
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
10
|
+
import { DISCOUNT_TYPE } from "../../type";
|
|
11
|
+
import { useTranslations } from "next-intl";
|
|
12
|
+
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
13
|
+
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
14
|
+
import { Loader2 } from "lucide-react";
|
|
15
|
+
export const SingleEntryStudentFeeForm = () => {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
|
+
const { dispatch } = useStudentFeeModule();
|
|
18
|
+
const workspace = getCachedWorkspaceSync();
|
|
19
|
+
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 : "";
|
|
20
|
+
const t = useTranslations("studentFee");
|
|
21
|
+
const [computerNumber, setComputerNumber] = useState("");
|
|
22
|
+
const debouncedComputerNumber = useDebounce(computerNumber, 500);
|
|
23
|
+
const { fetchNow: fetchByComputerNumber, data: feeByComputerNumber, loading: fetchingByCN, } = useFetch(STUDENT_FEE_API_ROUTES.BY_COMPUTER_NUMBER, {
|
|
24
|
+
method: API_METHODS.GET,
|
|
25
|
+
});
|
|
26
|
+
const fetchByCNRef = useRef(fetchByComputerNumber);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
fetchByCNRef.current = fetchByComputerNumber;
|
|
29
|
+
}, [fetchByComputerNumber]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!debouncedComputerNumber)
|
|
32
|
+
return;
|
|
33
|
+
fetchByCNRef.current(undefined, {
|
|
34
|
+
params: { computerNumber: debouncedComputerNumber },
|
|
35
|
+
});
|
|
36
|
+
}, [debouncedComputerNumber]);
|
|
37
|
+
const isStale = computerNumber !== debouncedComputerNumber;
|
|
38
|
+
const hasData = !!feeByComputerNumber &&
|
|
39
|
+
!!debouncedComputerNumber &&
|
|
40
|
+
!isStale &&
|
|
41
|
+
!fetchingByCN;
|
|
42
|
+
const fee = hasData ? feeByComputerNumber : null;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
dispatch({
|
|
45
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
46
|
+
payload: { disabled: !!fee },
|
|
47
|
+
});
|
|
48
|
+
}, [fee, dispatch]);
|
|
49
|
+
const paymentStatusLabelMap = {
|
|
50
|
+
PENDING: t("formOptionPending"),
|
|
51
|
+
PARTIAL: t("formOptionPartial"),
|
|
52
|
+
PAID: t("formOptionPaid"),
|
|
53
|
+
OVERDUE: t("formOptionOverdue"),
|
|
54
|
+
CANCELLED: t("formOptionCancelled"),
|
|
55
|
+
REFUNDED: t("formOptionRefunded"),
|
|
56
|
+
};
|
|
57
|
+
const studentName = (fee === null || fee === void 0 ? void 0 : fee.studentProfile)
|
|
58
|
+
? `${(_d = (_c = fee.studentProfile.familyMember) === null || _c === void 0 ? void 0 : _c.firstName) !== null && _d !== void 0 ? _d : ""} ${(_f = (_e = fee.studentProfile.familyMember) === null || _e === void 0 ? void 0 : _e.lastName) !== null && _f !== void 0 ? _f : ""}`.trim() ||
|
|
59
|
+
fee.studentProfileId
|
|
60
|
+
: (fee === null || fee === void 0 ? void 0 : fee.studentProfileId) || "";
|
|
61
|
+
const feeStructureName = ((_g = fee === null || fee === void 0 ? void 0 : fee.feeStructure) === null || _g === void 0 ? void 0 : _g.name) || (fee === null || fee === void 0 ? void 0 : fee.feeStructureId) || "";
|
|
62
|
+
const discountCodeLabel = (fee === null || fee === void 0 ? void 0 : fee.discountCode)
|
|
63
|
+
? `${fee.discountCode.code} - ${fee.discountCode.discountValue}${fee.discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE ? "%" : currency}`
|
|
64
|
+
: (fee === null || fee === void 0 ? void 0 : fee.discountCodeId) || "";
|
|
65
|
+
const statusDisplay = (fee === null || fee === void 0 ? void 0 : fee.status)
|
|
66
|
+
? paymentStatusLabelMap[fee.status] || fee.status
|
|
67
|
+
: "";
|
|
68
|
+
const formatDisplayDate = (rawDate) => {
|
|
69
|
+
if (!rawDate)
|
|
70
|
+
return "";
|
|
71
|
+
const d = rawDate instanceof Date ? rawDate : new Date(rawDate);
|
|
72
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
73
|
+
};
|
|
74
|
+
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 ? (_jsxs(_Fragment, { children: [_jsx(EnhancedInput, { disabled: true, id: "studentProfileId-readonly", label: t("formStudentLabel"), value: studentName }), _jsx(EnhancedInput, { disabled: true, id: "feeStructureId-readonly", label: t("formFeeStructureLabel"), value: feeStructureName }), _jsx(EnhancedInput, { disabled: true, id: "discountCodeId-readonly", label: t("formDiscountCodeLabel"), value: discountCodeLabel }), _jsx(EnhancedInput, { disabled: true, id: "discountAmount-readonly", label: t("formDiscountAmountLabel"), value: (_h = fee.discountAmount) !== null && _h !== void 0 ? _h : 0, type: "number", step: "0.01" }), _jsx(EnhancedInput, { disabled: true, id: "amount-readonly", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), value: fee.amount, type: "number", step: "0.01" }), _jsx(EnhancedInput, { disabled: true, id: "amountPaid-readonly", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), value: fee.amountPaid, type: "number", step: "0.01" }), _jsx(EnhancedInput, { disabled: true, id: "amountDue-readonly", info: t("formAmountDueInfo"), label: t("formAmountDueLabel"), value: fee.amountDue, type: "number", step: "0.01" }), _jsx(EnhancedInput, { disabled: true, id: "dueDate-readonly", label: t("formDueDateLabel"), value: formatDisplayDate(fee.dueDate), type: "date" }), _jsx(EnhancedInput, { disabled: true, id: "status-readonly", label: t("formStatusLabel"), value: statusDisplay }), _jsx(EnhancedTextarea, { disabled: true, id: "remarks-readonly", label: t("formRemarksLabel"), value: fee.remarks || "" })] })) : null] }));
|
|
75
|
+
};
|
|
@@ -5,11 +5,11 @@ import { EnhancedDrawerFooter, DRAWER_FOOTER_COMPONENT_TYPE, } from "@appcorp/sh
|
|
|
5
5
|
import { DrawerGeneric } from "@appcorp/shadcn/components/drawer-generic";
|
|
6
6
|
import { useStudentFeeModule, STUDENT_FEE_DRAWER } from "./context";
|
|
7
7
|
import { useTranslations } from "next-intl";
|
|
8
|
-
import {
|
|
8
|
+
import { SingleEntryStudentFeeForm } from "./single-entry-form";
|
|
9
9
|
export const StudentFeeSingleEntry = () => {
|
|
10
10
|
const { closeDrawer, handleSubmit, state, updateLoading } = useStudentFeeModule();
|
|
11
11
|
const t = useTranslations("studentFee");
|
|
12
12
|
const { disableSaveButton, drawer, errors } = state;
|
|
13
13
|
const isOpen = drawer === STUDENT_FEE_DRAWER.SINGLE_ENTRY_DRAWER;
|
|
14
|
-
return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? _jsx(
|
|
14
|
+
return (_jsx(DrawerGeneric, { filterDrawer: null, filterDrawerHeader: null, filterDrawerFooter: null, formDrawer: isOpen ? _jsx(SingleEntryStudentFeeForm, {}) : 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
15
|
};
|
package/constants.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export declare const STUDENT_FEE_API_ROUTES: {
|
|
|
74
74
|
readonly BULK: "/api/v1/student-fee/bulk";
|
|
75
75
|
readonly BULK_STATUS: (jobId: string) => string;
|
|
76
76
|
readonly CREATE_MONTHLY: "/api/v1/student-fee/create-monthly";
|
|
77
|
+
readonly BY_COMPUTER_NUMBER: "/api/v1/student-fee/by-computer-number";
|
|
77
78
|
};
|
|
78
79
|
export declare const STUDENT_PROFILE_API_ROUTES: {
|
|
79
80
|
readonly LIST: "/api/v1/student-profile";
|
package/constants.js
CHANGED
|
@@ -85,6 +85,7 @@ export const STUDENT_FEE_API_ROUTES = {
|
|
|
85
85
|
BULK: "/api/v1/student-fee/bulk",
|
|
86
86
|
BULK_STATUS: (jobId) => `/api/v1/student-fee/bulk/${jobId}`,
|
|
87
87
|
CREATE_MONTHLY: "/api/v1/student-fee/create-monthly",
|
|
88
|
+
BY_COMPUTER_NUMBER: "/api/v1/student-fee/by-computer-number",
|
|
88
89
|
};
|
|
89
90
|
export const STUDENT_PROFILE_API_ROUTES = {
|
|
90
91
|
LIST: "/api/v1/student-profile",
|