@appcorp/fusion-storybook 0.4.0 → 0.4.2

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.
@@ -48,20 +48,24 @@ export const StudentFeeSingle = () => {
48
48
  }, [debouncedComputerNumber, (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id]);
49
49
  const accumulatedAmount = useMemo(() => {
50
50
  var _a;
51
- if (!((_a = feeByComputerNumber === null || feeByComputerNumber === void 0 ? void 0 : feeByComputerNumber.items) === null || _a === void 0 ? void 0 : _a.length))
51
+ if (!((_a = feeByComputerNumber === null || feeByComputerNumber === void 0 ? void 0 : feeByComputerNumber.studentFees) === null || _a === void 0 ? void 0 : _a.length))
52
52
  return 0;
53
- return feeByComputerNumber.items.reduce((sum, f) => { var _a; return sum + ((_a = f.amount) !== null && _a !== void 0 ? _a : 0); }, 0);
53
+ return feeByComputerNumber.studentFees.reduce((sum, f) => { var _a; return sum + ((_a = f.amount) !== null && _a !== void 0 ? _a : 0); }, 0);
54
54
  }, [feeByComputerNumber]);
55
+ const accumulatedFine = 0;
55
56
  useEffect(() => {
56
57
  var _a;
57
- if (!((_a = feeByComputerNumber === null || feeByComputerNumber === void 0 ? void 0 : feeByComputerNumber.items) === null || _a === void 0 ? void 0 : _a.length))
58
+ if (!((_a = feeByComputerNumber === null || feeByComputerNumber === void 0 ? void 0 : feeByComputerNumber.studentFees) === null || _a === void 0 ? void 0 : _a.length))
58
59
  return;
59
- const total = accumulatedAmount + 0;
60
+ const total = accumulatedAmount + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0);
61
+ const initialStatus = total > 0 ? PAYMENT_STATUS.PAID : PAYMENT_STATUS.PENDING;
62
+ const today = new Date();
63
+ const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
60
64
  dispatch({
61
65
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
62
66
  payload: {
63
67
  key: "studentFeesSingleEntry",
64
- value: feeByComputerNumber.items,
68
+ value: feeByComputerNumber.studentFees,
65
69
  },
66
70
  });
67
71
  dispatch({
@@ -70,17 +74,20 @@ export const StudentFeeSingle = () => {
70
74
  });
71
75
  dispatch({
72
76
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
73
- payload: { key: "paidAt", value: state.paidAt },
77
+ payload: { key: "status", value: initialStatus },
74
78
  });
75
79
  dispatch({
76
80
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
77
- payload: { key: "remarks", value: "" },
81
+ payload: {
82
+ key: "paidAt",
83
+ value: initialStatus === PAYMENT_STATUS.PAID ? todayStr : "",
84
+ },
78
85
  });
79
86
  dispatch({
80
87
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
81
- payload: { key: "status", value: PAYMENT_STATUS.PENDING },
88
+ payload: { key: "remarks", value: "" },
82
89
  });
83
- }, [feeByComputerNumber, dispatch, accumulatedAmount, state.paidAt]);
90
+ }, [feeByComputerNumber, dispatch, accumulatedAmount, accumulatedFine]);
84
91
  const isStale = computerNumber !== debouncedComputerNumber;
85
92
  const hasData = !!feeByComputerNumber &&
86
93
  !!debouncedComputerNumber &&
@@ -118,16 +125,23 @@ export const StudentFeeSingle = () => {
118
125
  const d = new Date(rawDate);
119
126
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
120
127
  };
121
- // const accumulatedFine = useMemo(() => {
122
- // if (!response?.studentFees?.length) return 0;
123
- // return response.studentFees.reduce((sum, f) => sum + (f.fine ?? 0), 0);
124
- // }, [response]);
125
- const accumulatedFine = 0;
126
128
  const handleUpdateAmountPaid = (value) => {
127
129
  const parsed = parseFloat(value);
128
130
  if (isNaN(parsed))
129
131
  return;
130
132
  handleChange("amountPaid", parsed);
133
+ const total = (accumulatedAmount !== null && accumulatedAmount !== void 0 ? accumulatedAmount : 0) + (accumulatedFine !== null && accumulatedFine !== void 0 ? accumulatedFine : 0);
134
+ const newStatus = parsed <= 0
135
+ ? PAYMENT_STATUS.PENDING
136
+ : parsed >= total
137
+ ? PAYMENT_STATUS.PAID
138
+ : PAYMENT_STATUS.PARTIAL;
139
+ handleChange("status", newStatus);
140
+ if (newStatus === PAYMENT_STATUS.PAID) {
141
+ const today = new Date();
142
+ const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
143
+ handleChange("paidAt", todayStr);
144
+ }
131
145
  };
132
146
  const { enhancedComboboxElement: statusCombo } = useEnhancedCombobox({
133
147
  emptyText: t("formNoStatusEmpty"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",