@appcorp/fusion-storybook 0.3.14 → 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;
233
+ var _a, _b, _c;
235
234
  dispatch({
236
235
  type: STUDENT_FEE_ACTION_TYPES.SET_ERRORS,
237
236
  payload: { errors: {} },
@@ -281,66 +280,77 @@ export const useStudentFeeModule = () => {
281
280
  });
282
281
  }
283
282
  }
284
- catch (_f) {
283
+ catch (_d) {
285
284
  // silent fallback
286
285
  }
287
286
  }
288
287
  if (field === "studentProfileId" && typeof value === "string" && value) {
289
288
  try {
290
- const { data } = await fetchData({
289
+ fetchData({
291
290
  url: "/api/v1/student-profile",
292
291
  method: API_METHODS.GET,
293
292
  headers: { "Content-Type": "application/json" },
294
293
  params: { id: value, schoolId: (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id },
295
- });
296
- const familyId = (data === null || data === void 0 ? void 0 : data.studentProfile.familyMember.familyId) || "";
297
- const studentProfile = (_c = getCachedStudentProfilesSync().items) === null || _c === void 0 ? void 0 : _c.find((s) => s.id === value);
298
- dispatch({
299
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
300
- payload: {
301
- key: "familyId",
302
- value: familyId,
303
- },
304
- });
305
- if (studentProfile === null || studentProfile === void 0 ? void 0 : studentProfile.discountCode) {
306
- const discountCode = (_d = discountCodes.items) === null || _d === void 0 ? void 0 : _d.find((code) => code.code === studentProfile.discountCode && code.enabled);
307
- if (discountCode) {
308
- dispatch({
309
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
310
- payload: { key: "discountCodeId", value: discountCode.id },
311
- });
312
- const originalFee = Number(currentState.originalFee) || 0;
313
- let discountAmount = 0;
314
- if (originalFee > 0) {
315
- discountAmount =
316
- discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
317
- ? (originalFee * discountCode.discountValue) / 100
318
- : discountCode.discountValue;
319
- discountAmount = Math.min(discountAmount, originalFee);
320
- const { amount, amountDue } = calculateAmounts(originalFee, discountAmount, Number(currentState.amountPaid) || 0);
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) {
321
310
  dispatch({
322
311
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
323
- payload: { key: "amount", value: amount },
312
+ payload: {
313
+ key: "discountCodeId",
314
+ value: discountCode.id,
315
+ },
324
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
+ }
325
335
  dispatch({
326
336
  type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
327
- payload: { key: "amountDue", value: amountDue },
337
+ payload: {
338
+ key: "discountAmount",
339
+ value: discountAmount,
340
+ },
328
341
  });
329
342
  }
330
- dispatch({
331
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
332
- payload: { key: "discountAmount", value: discountAmount },
333
- });
334
343
  }
335
- }
344
+ })
345
+ .catch(() => { });
336
346
  }
337
- catch (_g) {
347
+ catch (_e) {
338
348
  // silent fallback
339
349
  }
340
350
  }
341
351
  if (field === "discountCodeId" && typeof value === "string" && value) {
342
352
  try {
343
- const discountCode = (_e = discountCodes.items) === null || _e === void 0 ? void 0 : _e.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);
344
354
  if (discountCode) {
345
355
  const originalFee = Number(currentState.originalFee) || 0;
346
356
  let discountAmount = discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
@@ -362,7 +372,7 @@ export const useStudentFeeModule = () => {
362
372
  });
363
373
  }
364
374
  }
365
- catch (_h) {
375
+ catch (_f) {
366
376
  // silent fallback
367
377
  }
368
378
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",