@appcorp/fusion-storybook 0.3.16 → 0.3.17
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,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,
|
|
5
|
+
import { validateForm, isCreatedOrUpdated, getStorageValue, } 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";
|
|
@@ -285,68 +285,13 @@ export const useStudentFeeModule = () => {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
if (field === "studentProfileId" && typeof value === "string" && value) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
.then((response) => {
|
|
296
|
-
var _a, _b, _c;
|
|
297
|
-
const profile = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.studentProfile;
|
|
298
|
-
if (!profile)
|
|
299
|
-
return;
|
|
300
|
-
dispatch({
|
|
301
|
-
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
302
|
-
payload: {
|
|
303
|
-
key: "familyId",
|
|
304
|
-
value: ((_b = profile.familyMember) === null || _b === void 0 ? void 0 : _b.familyId) || "",
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
if (profile.discountCode) {
|
|
308
|
-
const discountCode = (_c = discountCodes.items) === null || _c === void 0 ? void 0 : _c.find((code) => code.code === profile.discountCode && code.enabled);
|
|
309
|
-
if (discountCode) {
|
|
310
|
-
dispatch({
|
|
311
|
-
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
312
|
-
payload: {
|
|
313
|
-
key: "discountCodeId",
|
|
314
|
-
value: discountCode.id,
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
const originalFee = Number(currentState.originalFee) || 0;
|
|
318
|
-
let discountAmount = 0;
|
|
319
|
-
if (originalFee > 0) {
|
|
320
|
-
discountAmount =
|
|
321
|
-
discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
|
|
322
|
-
? (originalFee * discountCode.discountValue) / 100
|
|
323
|
-
: discountCode.discountValue;
|
|
324
|
-
discountAmount = Math.min(discountAmount, originalFee);
|
|
325
|
-
const { amount, amountDue } = calculateAmounts(originalFee, discountAmount, Number(currentState.amountPaid) || 0);
|
|
326
|
-
dispatch({
|
|
327
|
-
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
328
|
-
payload: { key: "amount", value: amount },
|
|
329
|
-
});
|
|
330
|
-
dispatch({
|
|
331
|
-
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
332
|
-
payload: { key: "amountDue", value: amountDue },
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
dispatch({
|
|
336
|
-
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
337
|
-
payload: {
|
|
338
|
-
key: "discountAmount",
|
|
339
|
-
value: discountAmount,
|
|
340
|
-
},
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
})
|
|
345
|
-
.catch(() => { });
|
|
346
|
-
}
|
|
347
|
-
catch (_e) {
|
|
348
|
-
// silent fallback
|
|
349
|
-
}
|
|
288
|
+
const studentProfiles = getStorageValue("studentProfiles");
|
|
289
|
+
const profile = studentProfiles === null || studentProfiles === void 0 ? void 0 : studentProfiles.find((p) => p.id === value);
|
|
290
|
+
const familyId = ((_b = profile === null || profile === void 0 ? void 0 : profile.familyMember) === null || _b === void 0 ? void 0 : _b.familyId) || "";
|
|
291
|
+
dispatch({
|
|
292
|
+
type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
293
|
+
payload: { key: "familyId", value: familyId },
|
|
294
|
+
});
|
|
350
295
|
}
|
|
351
296
|
if (field === "discountCodeId" && typeof value === "string" && value) {
|
|
352
297
|
try {
|
|
@@ -372,7 +317,7 @@ export const useStudentFeeModule = () => {
|
|
|
372
317
|
});
|
|
373
318
|
}
|
|
374
319
|
}
|
|
375
|
-
catch (
|
|
320
|
+
catch (_e) {
|
|
376
321
|
// silent fallback
|
|
377
322
|
}
|
|
378
323
|
}
|
|
@@ -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 } from "@react-pakistan/util-functions";
|
|
18
|
+
import { API_METHODS, setStorageValue } 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";
|
|
@@ -80,6 +80,7 @@ export const StudentFeeForm = () => {
|
|
|
80
80
|
},
|
|
81
81
|
value: studentProfileId || "",
|
|
82
82
|
});
|
|
83
|
+
setStorageValue("studentProfiles", studentProfiles.items);
|
|
83
84
|
const { enhancedComboboxElement: feeStructureIdCombo } = useEnhancedCombobox({
|
|
84
85
|
emptyText: t("formNoFeeStructureEmpty"),
|
|
85
86
|
id: "feeStructureId",
|