@appcorp/fusion-storybook 0.3.15 → 0.3.16

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.
@@ -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,77 @@ 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
288
  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 },
289
+ fetchData({
290
+ url: "/api/v1/student-profile",
291
+ method: API_METHODS.GET,
292
+ headers: { "Content-Type": "application/json" },
293
+ params: { id: value, schoolId: (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id },
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
+ },
299
306
  });
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);
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) {
327
310
  dispatch({
328
311
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
329
- payload: { key: "amount", value: amount },
312
+ payload: {
313
+ key: "discountCodeId",
314
+ value: discountCode.id,
315
+ },
330
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
+ }
331
335
  dispatch({
332
336
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
333
- payload: { key: "amountDue", value: amountDue },
337
+ payload: {
338
+ key: "discountAmount",
339
+ value: discountAmount,
340
+ },
334
341
  });
335
342
  }
336
- dispatch({
337
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
338
- payload: { key: "discountAmount", value: discountAmount },
339
- });
340
343
  }
341
- }
344
+ })
345
+ .catch(() => { });
342
346
  }
343
- catch (_j) {
347
+ catch (_e) {
344
348
  // silent fallback
345
349
  }
346
350
  }
347
351
  if (field === "discountCodeId" && typeof value === "string" && value) {
348
352
  try {
349
- const discountCode = (_g = discountCodes.items) === null || _g === void 0 ? void 0 : _g.find((code) => code.id === value && code.enabled);
353
+ const discountCode = (_c = discountCodes.items) === null || _c === void 0 ? void 0 : _c.find((code) => code.id === value && code.enabled);
350
354
  if (discountCode) {
351
355
  const originalFee = Number(currentState.originalFee) || 0;
352
356
  let discountAmount = discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
@@ -368,7 +372,7 @@ export const useStudentFeeModule = () => {
368
372
  });
369
373
  }
370
374
  }
371
- catch (_k) {
375
+ catch (_f) {
372
376
  // silent fallback
373
377
  }
374
378
  }
@@ -605,7 +609,6 @@ export const useStudentFeeModule = () => {
605
609
  });
606
610
  },
607
611
  errorCallback: (errors) => {
608
- console.log("_>>>,", errors);
609
612
  dispatch({
610
613
  type: STUDENT_FEE_ACTION_TYPES.SET_ERRORS,
611
614
  payload: { errors },
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.16",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",