@appcorp/fusion-storybook 0.3.6 → 0.3.8

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.
@@ -13,11 +13,12 @@ import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
13
13
  import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
14
14
  import { Loader2 } from "lucide-react";
15
15
  export const SingleEntryStudentFeeForm = () => {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h;
17
17
  const { dispatch } = useStudentFeeModule();
18
18
  const workspace = getCachedWorkspaceSync();
19
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
20
  const t = useTranslations("studentFee");
21
+ const [amountPaid, setAmountPaid] = useState("");
21
22
  const [computerNumber, setComputerNumber] = useState("");
22
23
  const debouncedComputerNumber = useDebounce(computerNumber, 800);
23
24
  const { fetchNow: fetchByComputerNumber, data: feeByComputerNumber, loading: fetchingByCN, } = useFetch(STUDENT_FEE_API_ROUTES.BY_COMPUTER_NUMBER, {
@@ -43,7 +44,16 @@ export const SingleEntryStudentFeeForm = () => {
43
44
  !!debouncedComputerNumber &&
44
45
  !isStale &&
45
46
  !fetchingByCN;
46
- const fee = hasData ? feeByComputerNumber : null;
47
+ const response = hasData
48
+ ? feeByComputerNumber
49
+ : null;
50
+ const profile = (_d = response === null || response === void 0 ? void 0 : response.studentProfile) !== null && _d !== void 0 ? _d : null;
51
+ const fee = (_f = (_e = response === null || response === void 0 ? void 0 : response.studentFees) === null || _e === void 0 ? void 0 : _e[0]) !== null && _f !== void 0 ? _f : null;
52
+ useEffect(() => {
53
+ (async () => {
54
+ setAmountPaid(String(fee === null || fee === void 0 ? void 0 : fee.amount));
55
+ })();
56
+ }, [fee]);
47
57
  useEffect(() => {
48
58
  dispatch({
49
59
  type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
@@ -58,11 +68,10 @@ export const SingleEntryStudentFeeForm = () => {
58
68
  CANCELLED: t("formOptionCancelled"),
59
69
  REFUNDED: t("formOptionRefunded"),
60
70
  };
61
- const studentName = (fee === null || fee === void 0 ? void 0 : fee.studentProfile)
62
- ? `${(_e = (_d = fee.studentProfile.familyMember) === null || _d === void 0 ? void 0 : _d.firstName) !== null && _e !== void 0 ? _e : ""} ${(_g = (_f = fee.studentProfile.familyMember) === null || _f === void 0 ? void 0 : _f.lastName) !== null && _g !== void 0 ? _g : ""}`.trim() ||
63
- fee.studentProfileId
64
- : (fee === null || fee === void 0 ? void 0 : fee.studentProfileId) || "";
65
- const feeStructureName = ((_h = fee === null || fee === void 0 ? void 0 : fee.feeStructure) === null || _h === void 0 ? void 0 : _h.name) || (fee === null || fee === void 0 ? void 0 : fee.feeStructureId) || "";
71
+ const studentName = profile
72
+ ? `${profile.firstName} ${profile.lastName}`.trim() || profile.id
73
+ : "";
74
+ 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) || "";
66
75
  const discountCodeLabel = (fee === null || fee === void 0 ? void 0 : fee.discountCode)
67
76
  ? `${fee.discountCode.code} - ${fee.discountCode.discountValue}${fee.discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE ? "%" : currency}`
68
77
  : (fee === null || fee === void 0 ? void 0 : fee.discountCodeId) || "";
@@ -72,8 +81,14 @@ export const SingleEntryStudentFeeForm = () => {
72
81
  const formatDisplayDate = (rawDate) => {
73
82
  if (!rawDate)
74
83
  return "";
75
- const d = rawDate instanceof Date ? rawDate : new Date(rawDate);
84
+ const d = new Date(rawDate);
76
85
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
77
86
  };
78
- 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: (_j = fee.discountAmount) !== null && _j !== void 0 ? _j : 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] }));
87
+ const handleUpdateAmountPaid = (value) => {
88
+ const amountPaid = parseFloat(value);
89
+ if (isNaN(amountPaid))
90
+ return;
91
+ setAmountPaid(value);
92
+ };
93
+ 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, _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: fee === null || fee === void 0 ? void 0 : fee.amountDue, 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, { readOnly: true, id: "remarks-readonly", label: t("formRemarksLabel"), value: (fee === null || fee === void 0 ? void 0 : fee.remarks) || "" })] })] }));
79
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",