@appcorp/fusion-storybook 0.3.15 → 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, API_METHODS, fetchData, } from "@react-pakistan/util-functions";
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";
@@ -11,7 +11,6 @@ import { STUDENT_FEE_API_ROUTES } from "../../../constants";
11
11
  import { studentFeeFormValidation } from "../validate";
12
12
  import { getCachedWorkspaceSync } from "../../workspace/cache";
13
13
  import { getCachedFeeStructureById } from "../../fee-structure/cache";
14
- import { getCachedStudentProfilesSync } from "../../student-profile/cache";
15
14
  import { getCachedDiscountCodesSync } from "../../discount-code/cache";
16
15
  import { STUDENT_FEE_ACTION_TYPES, STUDENT_FEE_DRAWER, useStudentFeeContext, } from "./shared";
17
16
  // ============================================================================
@@ -231,7 +230,7 @@ export const useStudentFeeModule = () => {
231
230
  // 1.4.6 HANDLERS
232
231
  // ============================================================================
233
232
  const handleChange = useCallback(async (field, value) => {
234
- var _a, _b, _c, _d, _e, _f, _g;
233
+ var _a, _b, _c;
235
234
  dispatch({
236
235
  type: STUDENT_FEE_ACTION_TYPES.SET_ERRORS,
237
236
  payload: { errors: {} },
@@ -281,72 +280,22 @@ export const useStudentFeeModule = () => {
281
280
  });
282
281
  }
283
282
  }
284
- catch (_h) {
283
+ catch (_d) {
285
284
  // silent fallback
286
285
  }
287
286
  }
288
287
  if (field === "studentProfileId" && typeof value === "string" && value) {
289
- try {
290
- // eslint-disable-next-line
291
- let apiResponse;
292
- (async () => {
293
- var _a;
294
- const response = await fetchData({
295
- url: "/api/v1/student-profile",
296
- method: API_METHODS.GET,
297
- headers: { "Content-Type": "application/json" },
298
- params: { id: value, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id },
299
- });
300
- apiResponse = response;
301
- })();
302
- const familyId = ((_d = (_c = (_b = apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.data) === null || _b === void 0 ? void 0 : _b.studentProfile) === null || _c === void 0 ? void 0 : _c.familyMember) === null || _d === void 0 ? void 0 : _d.familyId) || "";
303
- const studentProfile = (_e = getCachedStudentProfilesSync().items) === null || _e === void 0 ? void 0 : _e.find((s) => s.id === value);
304
- dispatch({
305
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
306
- payload: {
307
- key: "familyId",
308
- value: familyId,
309
- },
310
- });
311
- if (studentProfile === null || studentProfile === void 0 ? void 0 : studentProfile.discountCode) {
312
- const discountCode = (_f = discountCodes.items) === null || _f === void 0 ? void 0 : _f.find((code) => code.code === studentProfile.discountCode && code.enabled);
313
- if (discountCode) {
314
- dispatch({
315
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
316
- payload: { key: "discountCodeId", value: discountCode.id },
317
- });
318
- const originalFee = Number(currentState.originalFee) || 0;
319
- let discountAmount = 0;
320
- if (originalFee > 0) {
321
- discountAmount =
322
- discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
323
- ? (originalFee * discountCode.discountValue) / 100
324
- : discountCode.discountValue;
325
- discountAmount = Math.min(discountAmount, originalFee);
326
- const { amount, amountDue } = calculateAmounts(originalFee, discountAmount, Number(currentState.amountPaid) || 0);
327
- dispatch({
328
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
329
- payload: { key: "amount", value: amount },
330
- });
331
- dispatch({
332
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
333
- payload: { key: "amountDue", value: amountDue },
334
- });
335
- }
336
- dispatch({
337
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
338
- payload: { key: "discountAmount", value: discountAmount },
339
- });
340
- }
341
- }
342
- }
343
- catch (_j) {
344
- // silent fallback
345
- }
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
+ });
346
295
  }
347
296
  if (field === "discountCodeId" && typeof value === "string" && value) {
348
297
  try {
349
- const discountCode = (_g = discountCodes.items) === null || _g === void 0 ? void 0 : _g.find((code) => code.id === value && code.enabled);
298
+ const discountCode = (_c = discountCodes.items) === null || _c === void 0 ? void 0 : _c.find((code) => code.id === value && code.enabled);
350
299
  if (discountCode) {
351
300
  const originalFee = Number(currentState.originalFee) || 0;
352
301
  let discountAmount = discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
@@ -368,7 +317,7 @@ export const useStudentFeeModule = () => {
368
317
  });
369
318
  }
370
319
  }
371
- catch (_k) {
320
+ catch (_e) {
372
321
  // silent fallback
373
322
  }
374
323
  }
@@ -605,7 +554,6 @@ export const useStudentFeeModule = () => {
605
554
  });
606
555
  },
607
556
  errorCallback: (errors) => {
608
- console.log("_>>>,", errors);
609
557
  dispatch({
610
558
  type: STUDENT_FEE_ACTION_TYPES.SET_ERRORS,
611
559
  payload: { errors },
@@ -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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",