@appcorp/fusion-storybook 0.5.21 → 0.5.25

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.
Files changed (37) hide show
  1. package/base-modules/school/cache.js +0 -1
  2. package/base-modules/school/context.d.ts +0 -2
  3. package/base-modules/school/context.js +77 -18
  4. package/base-modules/school/drawer.js +1 -3
  5. package/base-modules/school/form.js +4 -23
  6. package/base-modules/school/page.js +2 -2
  7. package/base-modules/section/context.d.ts +6 -0
  8. package/base-modules/section/context.js +66 -34
  9. package/base-modules/section/form.js +2 -2
  10. package/base-modules/section/more-actions.js +71 -16
  11. package/base-modules/section/page.js +7 -3
  12. package/base-modules/student-fee/context/student-fee-api-provider.js +20 -14
  13. package/base-modules/student-fee/context/use-student-fee-module.d.ts +3 -3
  14. package/base-modules/student-fee/context/use-student-fee-module.js +63 -30
  15. package/base-modules/student-fee/form.js +8 -24
  16. package/base-modules/student-fee/more-actions.js +9 -9
  17. package/base-modules/student-fee/page.js +1 -1
  18. package/base-modules/student-profile/constants.d.ts +2 -24
  19. package/base-modules/student-profile/constants.js +2 -68
  20. package/base-modules/student-profile/context/module-base.d.ts +10 -0
  21. package/base-modules/student-profile/context/module-base.js +2 -0
  22. package/base-modules/student-profile/context/use-student-profile-module.d.ts +3 -1
  23. package/base-modules/student-profile/context/use-student-profile-module.js +113 -71
  24. package/base-modules/student-profile/filter.js +5 -22
  25. package/base-modules/student-profile/form.js +22 -46
  26. package/base-modules/student-profile/page.js +2 -4
  27. package/constants.d.ts +3 -3
  28. package/constants.js +0 -2
  29. package/package.json +1 -1
  30. package/tsconfig.build.tsbuildinfo +1 -1
  31. package/utils/resolve-rbac-permissions.js +7 -4
  32. package/base-modules/school/filter.d.ts +0 -1
  33. package/base-modules/school/filter.js +0 -13
  34. package/base-modules/school/more-actions.d.ts +0 -1
  35. package/base-modules/school/more-actions.js +0 -13
  36. package/base-modules/student-profile/more-actions.d.ts +0 -1
  37. package/base-modules/student-profile/more-actions.js +0 -257
@@ -9,20 +9,44 @@ import { useTranslations } from "next-intl";
9
9
  import { pageLimit } from "./constants";
10
10
  import { SECTION_API_ROUTES } from "../../constants";
11
11
  import { SECTION_ACTION_TYPES, useSectionContext } from "./context";
12
+ import { sectionFormValidation } from "./validate";
12
13
  import { useRef, useEffect, useCallback } from "react";
13
- const workspace = getCachedWorkspaceSync();
14
+ /** Read at call time — never cache a workspace captured at module load. */
15
+ const currentSchoolId = () => { var _a, _b; return ((_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.id) || ""; };
14
16
  const POLL_INTERVAL_MS = 2000;
15
17
  const POLL_TIMEOUT_MS = 300000;
18
+ const EXPORT_PAGE_LIMIT = 200;
19
+ const EXPORT_MAX_PAGES = 50;
16
20
  const handleGetAllRecords = async (schoolId, pageLimit) => {
17
- const response = await fetch(`${SECTION_API_ROUTES.UNIT}?pageLimit=${pageLimit}&currentPage=1&schoolId=${schoolId}`);
18
- const result = await response.json();
19
- const csv = await converter.json2csv(result.items || [], {});
21
+ var _a, _b, _c;
22
+ const take = Math.min(pageLimit, EXPORT_PAGE_LIMIT);
23
+ const items = [];
24
+ for (let page = 1; page <= EXPORT_MAX_PAGES; page++) {
25
+ const params = new URLSearchParams({
26
+ currentPage: String(page),
27
+ pageLimit: String(take),
28
+ schoolId,
29
+ });
30
+ const response = await fetch(`${SECTION_API_ROUTES.UNIT}?${params.toString()}`);
31
+ if (!response.ok) {
32
+ const body = (await response.json().catch(() => ({})));
33
+ throw new Error((_a = body.error) !== null && _a !== void 0 ? _a : `Export failed (${response.status})`);
34
+ }
35
+ const result = (await response.json());
36
+ const pageItems = (_b = result.items) !== null && _b !== void 0 ? _b : [];
37
+ items.push(...pageItems);
38
+ if (take <= 1 ||
39
+ pageItems.length < take ||
40
+ items.length >= ((_c = result.count) !== null && _c !== void 0 ? _c : items.length)) {
41
+ break;
42
+ }
43
+ }
44
+ const csv = await converter.json2csv(items, {});
20
45
  const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
21
46
  await downloadFromUrl(blob, "section.csv");
22
47
  };
23
48
  async function submitBulkJob(csvData, method, signal) {
24
- var _a;
25
- const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
49
+ const schoolId = currentSchoolId();
26
50
  if (!schoolId)
27
51
  throw new Error("School ID not found");
28
52
  const res = await fetch(SECTION_API_ROUTES.BULK, {
@@ -112,18 +136,35 @@ export const SectionMoreActions = () => {
112
136
  showErrorToast(t("messagesBulkCsvEmpty"));
113
137
  return;
114
138
  }
115
- // Client-side validation — basic required field check
139
+ // Client-side validation mirrors the API's rules.
116
140
  const validationErrors = [];
117
141
  for (let i = 0; i < records.length; i++) {
118
142
  const row = records[i];
119
143
  const msgs = [];
120
144
  if (method === "POST") {
121
- if (!((_b = row.name) === null || _b === void 0 ? void 0 : _b.trim()))
122
- msgs.push(t("validationRequiredName"));
145
+ const result = sectionFormValidation.safeParse({
146
+ name: row.name,
147
+ capacity: ((_b = row.capacity) === null || _b === void 0 ? void 0 : _b.trim()) ? Number(row.capacity) : null,
148
+ enabled: row.enabled === undefined || row.enabled === ""
149
+ ? undefined
150
+ : /^(true|1|yes)$/i.test(row.enabled),
151
+ });
152
+ if (!result.success) {
153
+ msgs.push(...result.error.issues.map((issue) => `${issue.path.join(".")}: ${t(issue.message)}`));
154
+ }
123
155
  }
124
156
  else {
125
- if (!((_c = row.id) === null || _c === void 0 ? void 0 : _c.trim()))
157
+ if (!((_c = row.id) === null || _c === void 0 ? void 0 : _c.trim())) {
126
158
  msgs.push(t("validationRequiredIdForUpdate"));
159
+ }
160
+ if ((_d = row.capacity) === null || _d === void 0 ? void 0 : _d.trim()) {
161
+ const capacity = Number(row.capacity);
162
+ if (!Number.isInteger(capacity) ||
163
+ capacity < 1 ||
164
+ capacity > 1000) {
165
+ msgs.push(t("validationSectionCapacityRange"));
166
+ }
167
+ }
127
168
  }
128
169
  if (msgs.length > 0) {
129
170
  validationErrors.push({ row: i + 1, messages: msgs });
@@ -165,7 +206,7 @@ export const SectionMoreActions = () => {
165
206
  return;
166
207
  if (status.status === "completed") {
167
208
  const r = status.results;
168
- if (r && ((_d = r.errors) === null || _d === void 0 ? void 0 : _d.length) > 0) {
209
+ if (r && ((_e = r.errors) === null || _e === void 0 ? void 0 : _e.length) > 0) {
169
210
  const summary = formatErrorSummary(t, r.errors);
170
211
  showSuccessToast(t("messagesBulkResults", {
171
212
  created: r.created,
@@ -185,7 +226,7 @@ export const SectionMoreActions = () => {
185
226
  else {
186
227
  showSuccessToast(t("messagesBulkSuccess"));
187
228
  }
188
- const schoolId = ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id) || "";
229
+ const schoolId = currentSchoolId();
189
230
  fetch(`${SECTION_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
190
231
  headers: {
191
232
  "Content-Type": "application/json",
@@ -231,8 +272,15 @@ export const SectionMoreActions = () => {
231
272
  id: "1",
232
273
  title: t("downloadEmptyCsvTemplate"),
233
274
  handleOnClick: async () => {
234
- var _a;
235
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
275
+ try {
276
+ await handleGetAllRecords(currentSchoolId(), 1);
277
+ }
278
+ catch (error) {
279
+ showErrorToast(t("messagesBulkFailedDetail", {
280
+ action: "download",
281
+ error: error instanceof Error ? error.message : t("unknownError"),
282
+ }));
283
+ }
236
284
  },
237
285
  },
238
286
  { id: "2", title: t("addYourDataToTheCsv") },
@@ -246,8 +294,15 @@ export const SectionMoreActions = () => {
246
294
  id: "1",
247
295
  title: t("downloadPopulatedCsvTemplate"),
248
296
  handleOnClick: async () => {
249
- var _a;
250
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
297
+ try {
298
+ await handleGetAllRecords(currentSchoolId(), EXPORT_PAGE_LIMIT);
299
+ }
300
+ catch (error) {
301
+ showErrorToast(t("messagesBulkFailedDetail", {
302
+ action: "download",
303
+ error: error instanceof Error ? error.message : t("unknownError"),
304
+ }));
305
+ }
251
306
  },
252
307
  },
253
308
  { id: "2", title: t("updateYourDataInTheCsv") },
@@ -33,7 +33,11 @@ import { RbacNoAccess } from "../../components/rbac-no-access";
33
33
  const tableBodyCols = [
34
34
  { componentType: COMPONENT_TYPE.ID, key: "id" },
35
35
  { componentType: COMPONENT_TYPE.BOLD_TEXT, key: "name" },
36
- { componentType: COMPONENT_TYPE.TEXT, key: "capacity" },
36
+ {
37
+ componentType: COMPONENT_TYPE.TEXT,
38
+ key: "capacity",
39
+ textFormatter: (value) => value === null || value === undefined ? "—" : String(value),
40
+ },
37
41
  { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
38
42
  { componentType: COMPONENT_TYPE.ACTIONS },
39
43
  ];
@@ -128,10 +132,10 @@ const SectionPageInner = (props) => {
128
132
  ]);
129
133
  const hasPermission = resolveRbacPermissions({
130
134
  userRole: props.userRole,
131
- moduleName: "Academic Operations",
135
+ moduleName: "Section",
132
136
  });
133
137
  if (!hasPermission) {
134
- return _jsx(RbacNoAccess, { moduleName: "Academic Operations" });
138
+ return _jsx(RbacNoAccess, { moduleName: "Section" });
135
139
  }
136
140
  return (_jsx("div", { className: "p-4", children: _jsx(GenericSectionPage, { overrideConfig: sectionConfig, context: context, tableBodyCols: tableBodyCols }) }));
137
141
  };
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, } from "react";
4
4
  import { useTheme } from "next-themes";
5
5
  import { useTranslations } from "next-intl";
6
6
  import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
@@ -113,30 +113,35 @@ export const StudentFeeApiProvider = ({ children, }) => {
113
113
  state.studentProfileId,
114
114
  schoolId,
115
115
  ]);
116
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
117
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
116
+ const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
117
+ const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
118
118
  // ==========================================================================
119
119
  // API CALLBACKS
120
120
  // ==========================================================================
121
+ const apiError = (data) => data === null || data === void 0 ? void 0 : data.error;
121
122
  const listCallback = useCallback(({ data, error }) => {
122
- var _a, _b;
123
+ var _a, _b, _c;
123
124
  if (error) {
124
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
125
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
125
126
  return;
126
127
  }
127
128
  if (data) {
128
129
  const response = data;
129
130
  dispatch({
130
131
  type: STUDENT_FEE_ACTION_TYPES.SET_ITEMS,
131
- payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
132
+ payload: { items: (_b = response.items) !== null && _b !== void 0 ? _b : [], count: (_c = response.count) !== null && _c !== void 0 ? _c : 0 },
132
133
  });
133
134
  }
134
135
  }, [dispatch, showToast, t]);
135
136
  const listFetchNowRef = useRef(null);
136
137
  const updateCallback = useCallback(({ data, error }) => {
137
- var _a;
138
+ var _a, _b;
138
139
  if (error) {
139
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
140
+ dispatch({
141
+ type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
142
+ payload: { disabled: false },
143
+ });
144
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
140
145
  return;
141
146
  }
142
147
  if (data) {
@@ -145,12 +150,13 @@ export const StudentFeeApiProvider = ({ children, }) => {
145
150
  ? t("messagesStudentFeeCreated")
146
151
  : t("messagesStudentFeeUpdated"), TOAST_VARIANT.SUCCESS);
147
152
  resetFormAndCloseDrawer();
148
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
153
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
149
154
  }
150
- }, [showToast, t, resetFormAndCloseDrawer]);
155
+ }, [dispatch, showToast, t, resetFormAndCloseDrawer]);
151
156
  const byIdCallback = useCallback(({ data, error }) => {
157
+ var _a;
152
158
  if (error) {
153
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
159
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
154
160
  return;
155
161
  }
156
162
  if (data) {
@@ -179,14 +185,14 @@ export const StudentFeeApiProvider = ({ children, }) => {
179
185
  }
180
186
  }, [dispatch, showToast, t]);
181
187
  const deleteCallback = useCallback(({ data, error }) => {
182
- var _a;
188
+ var _a, _b;
183
189
  if (error) {
184
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
190
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
185
191
  return;
186
192
  }
187
193
  if (data) {
188
194
  showToast(t("messagesStudentFeeDeleted"), TOAST_VARIANT.SUCCESS);
189
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
195
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
190
196
  }
191
197
  }, [showToast, t]);
192
198
  // ==========================================================================
@@ -1,4 +1,4 @@
1
- import { PAYMENT_STATUS, FEE_RISK_LEVEL, StudentProfileBE } from "../../../type";
1
+ import { PAYMENT_STATUS, FEE_RISK_LEVEL, StudentProfileBE, StudentFeeBE } from "../../../type";
2
2
  import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
3
3
  export declare const useStudentFeeModule: () => {
4
4
  applyFilters: () => void;
@@ -38,7 +38,7 @@ export declare const useStudentFeeModule: () => {
38
38
  updateLoading: boolean;
39
39
  handleCloseDrawer?: () => void;
40
40
  state: {
41
- items: import("../../../types").StudentFeeBE[];
41
+ items: StudentFeeBE[];
42
42
  count: number;
43
43
  currentPage: number;
44
44
  pageLimit: number;
@@ -79,7 +79,7 @@ export declare const useStudentFeeModule: () => {
79
79
  appliedFilterStatus: PAYMENT_STATUS | "";
80
80
  appliedFilterFromDate: string;
81
81
  appliedFilterToDate: string;
82
- studentFeesSingleEntry: import("../../../types").StudentFeeBE[];
82
+ studentFeesSingleEntry: StudentFeeBE[];
83
83
  selectedStudentFeeIds: string[];
84
84
  };
85
85
  dispatch: React.Dispatch<any>;
@@ -196,33 +196,47 @@ export const useStudentFeeModule = () => {
196
196
  payload: { key: "familyId", value: familyId },
197
197
  });
198
198
  }
199
- if (field === "discountCodeId" && typeof value === "string" && value) {
200
- try {
199
+ if (field === "discountCodeId") {
200
+ const gross = Number(currentState.originalFee) ||
201
+ Number(currentState.amount) + Number(currentState.discountAmount) ||
202
+ 0;
203
+ const amountPaid = Number(currentState.amountPaid) || 0;
204
+ let discountAmount = 0;
205
+ if (value && typeof value === "string") {
201
206
  const discountCode = (_c = discountCodes.items) === null || _c === void 0 ? void 0 : _c.find((code) => code.id === value && code.enabled);
202
207
  if (discountCode) {
203
- const originalFee = Number(currentState.originalFee) || 0;
204
- let discountAmount = discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
205
- ? (originalFee * discountCode.discountValue) / 100
206
- : discountCode.discountValue;
207
- discountAmount = Math.min(discountAmount, originalFee);
208
- dispatch({
209
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
210
- payload: { key: "discountAmount", value: discountAmount },
211
- });
212
- const { amount, amountDue } = calculateAmounts(originalFee, discountAmount, Number(currentState.amountPaid) || 0);
213
- dispatch({
214
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
215
- payload: { key: "amount", value: amount },
216
- });
217
- dispatch({
218
- type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
219
- payload: { key: "amountDue", value: amountDue },
220
- });
208
+ discountAmount =
209
+ discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
210
+ ? (gross * discountCode.discountValue) / 100
211
+ : discountCode.discountValue;
212
+ discountAmount = Math.min(discountAmount, gross);
221
213
  }
222
214
  }
223
- catch (_e) {
224
- // silent fallback
225
- }
215
+ // Clearing the code restores the gross amount (amount = gross).
216
+ dispatch({
217
+ type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
218
+ payload: { key: "discountAmount", value: discountAmount },
219
+ });
220
+ const { amount, amountDue } = calculateAmounts(gross, discountAmount, amountPaid);
221
+ dispatch({
222
+ type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
223
+ payload: { key: "amount", value: amount },
224
+ });
225
+ dispatch({
226
+ type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
227
+ payload: { key: "amountDue", value: amountDue },
228
+ });
229
+ dispatch({
230
+ type: STUDENT_FEE_ACTION_TYPES.SET_INPUT_FIELD,
231
+ payload: {
232
+ key: "status",
233
+ value: amountPaid <= 0
234
+ ? PAYMENT_STATUS.PENDING
235
+ : amountPaid >= amount
236
+ ? PAYMENT_STATUS.PAID
237
+ : PAYMENT_STATUS.PARTIAL,
238
+ },
239
+ });
226
240
  }
227
241
  if (field === "discountAmount" && typeof value === "number") {
228
242
  const originalFee = Number(currentState.originalFee) || 0;
@@ -325,9 +339,13 @@ export const useStudentFeeModule = () => {
325
339
  }, [dispatch]);
326
340
  const toggleStatus = useCallback((row) => {
327
341
  updateFetchNow(undefined, {
328
- body: JSON.stringify(Object.assign(Object.assign({}, row), { enabled: !(row === null || row === void 0 ? void 0 : row.enabled) })),
342
+ body: JSON.stringify({
343
+ id: row === null || row === void 0 ? void 0 : row.id,
344
+ schoolId,
345
+ enabled: !(row === null || row === void 0 ? void 0 : row.enabled),
346
+ }),
329
347
  });
330
- }, [updateFetchNow]);
348
+ }, [schoolId, updateFetchNow]);
331
349
  const handleCreate = useCallback(() => {
332
350
  resetRecordFormState();
333
351
  dispatch({
@@ -373,9 +391,9 @@ export const useStudentFeeModule = () => {
373
391
  if (!confirm(t("messagesDeleteConfirmation")))
374
392
  return;
375
393
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
376
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
394
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
377
395
  });
378
- }, [t, deleteFetchNow]);
396
+ }, [t, deleteFetchNow, schoolId]);
379
397
  const handleFilters = useCallback(() => {
380
398
  dispatch({
381
399
  type: STUDENT_FEE_ACTION_TYPES.SET_FILTERS,
@@ -620,7 +638,6 @@ export const useStudentFeeModule = () => {
620
638
  resetFormAndCloseDrawer,
621
639
  listFetchNow,
622
640
  state.studentFeesSingleEntry,
623
- state.amountPaid,
624
641
  state.paidAt,
625
642
  state.remarks,
626
643
  state.status,
@@ -664,13 +681,29 @@ export const useStudentFeeModule = () => {
664
681
  order: 2,
665
682
  },
666
683
  {
667
- enabled: false,
684
+ enabled: (row) => {
685
+ const status = row === null || row === void 0 ? void 0 : row.status;
686
+ return (status !== PAYMENT_STATUS.PAID &&
687
+ status !== PAYMENT_STATUS.CANCELLED &&
688
+ status !== PAYMENT_STATUS.REFUNDED);
689
+ },
668
690
  handleOnClick: handleDelete,
669
691
  label: t("actionsButtonDelete"),
670
692
  order: 3,
671
693
  variant: "destructive",
672
694
  },
673
- ], [handleDelete, handleEdit, handleView, t]);
695
+ {
696
+ enabled: (row) => {
697
+ const status = row === null || row === void 0 ? void 0 : row.status;
698
+ return (status !== PAYMENT_STATUS.PAID &&
699
+ status !== PAYMENT_STATUS.CANCELLED &&
700
+ status !== PAYMENT_STATUS.REFUNDED);
701
+ },
702
+ handleOnClick: toggleStatus,
703
+ label: t("actionsButtonToggleStatus"),
704
+ order: 4,
705
+ },
706
+ ], [handleDelete, handleEdit, handleView, t, toggleStatus]);
674
707
  // ============================================================================
675
708
  // 1.4.7 RETURN
676
709
  // ============================================================================
@@ -8,12 +8,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  */
9
9
  import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
10
10
  import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
11
+ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
11
12
  import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
12
13
  import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
13
14
  import { useEffect } from "react";
14
15
  import { useStudentFeeModule, STUDENT_FEE_DRAWER } from "./context";
15
16
  import { PAYMENT_STATUS_OPTIONS } from "./constants";
16
- import { STUDENT_FEE_API_ROUTES, DISCOUNT_CODE_API_ROUTES, FEE_STRUCTURE_API_ROUTES, STUDENT_PROFILE_API_ROUTES, } from "../../constants";
17
+ import { DISCOUNT_CODE_API_ROUTES, FEE_STRUCTURE_API_ROUTES, STUDENT_PROFILE_API_ROUTES, } from "../../constants";
17
18
  import { getCachedWorkspaceSync } from "../workspace/cache";
18
19
  import { API_METHODS } from "@react-pakistan/util-functions/constants/api-methods";
19
20
  import { setStorageValue } from "@react-pakistan/util-functions/local-storage/set-storage-value";
@@ -22,7 +23,7 @@ import { useTranslations } from "next-intl";
22
23
  import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
23
24
  import { getTranslatedError } from "../../utils/get-translated-error";
24
25
  export const StudentFeeForm = () => {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
26
27
  const { state, handleChange } = useStudentFeeModule();
27
28
  const { amount, amountDue, amountPaid, discountAmount, discountCodeId, drawer, dueDate, enabled, errors, feeStructureId, paidAt, remarks, status, studentProfileId, } = state;
28
29
  const workspace = getCachedWorkspaceSync();
@@ -100,6 +101,7 @@ export const StudentFeeForm = () => {
100
101
  placeholder: t("formFeeStructurePlaceholder"),
101
102
  required: true,
102
103
  searchEndpoint: FEE_STRUCTURE_API_ROUTES.UNIT,
104
+ searchParams: { schoolId: (_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id },
103
105
  searchPlaceholder: t("formSearchFeeStructuresPlaceholder"),
104
106
  formatSearchResult: (item) => {
105
107
  const feeStructure = item;
@@ -116,12 +118,13 @@ export const StudentFeeForm = () => {
116
118
  info: t("formDiscountCodeInfo"),
117
119
  label: t("formDiscountCodeLabel"),
118
120
  onValueChange: (value) => handleChange("discountCodeId", value),
119
- options: ((_j = discountCodes === null || discountCodes === void 0 ? void 0 : discountCodes.items) === null || _j === void 0 ? void 0 : _j.map((code) => ({
121
+ options: ((_k = discountCodes === null || discountCodes === void 0 ? void 0 : discountCodes.items) === null || _k === void 0 ? void 0 : _k.map((code) => ({
120
122
  value: code.id,
121
123
  label: `${code.code} - ${code.discountValue}${code.discountType === DISCOUNT_TYPE.PERCENTAGE ? "%" : currency}`,
122
124
  }))) || [],
123
125
  placeholder: t("formDiscountCodePlaceholder"),
124
126
  searchEndpoint: DISCOUNT_CODE_API_ROUTES.UNIT,
127
+ searchParams: { schoolId: (_l = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _l === void 0 ? void 0 : _l.id },
125
128
  searchPlaceholder: t("formSearchDiscountCodesPlaceholder"),
126
129
  formatSearchResult: (item) => {
127
130
  const discountCode = item;
@@ -132,28 +135,9 @@ export const StudentFeeForm = () => {
132
135
  },
133
136
  value: discountCodeId || "",
134
137
  });
135
- const { enhancedComboboxElement: statusCombo } = useEnhancedCombobox({
136
- emptyText: t("formNoStatusEmpty"),
137
- id: "status",
138
- info: t("formStatusInfo"),
139
- label: t("formStatusLabel"),
140
- onValueChange: (value) => handleChange("status", value),
141
- options: PAYMENT_STATUS_OPTIONS.map((opt) => ({
138
+ const statusCombo = (_jsx(EnhancedCombobox, { emptyText: t("formNoStatusEmpty"), error: getTranslatedError({ errors, key: "status", t }), id: "status", info: t("formStatusInfo"), label: t("formStatusLabel"), onValueChange: (value) => handleChange("status", value), options: PAYMENT_STATUS_OPTIONS.map((opt) => ({
142
139
  value: opt.value,
143
140
  label: paymentStatusLabelMap[opt.value] || opt.label,
144
- })),
145
- placeholder: t("formStatusPlaceholder"),
146
- required: true,
147
- searchEndpoint: STUDENT_FEE_API_ROUTES.UNIT,
148
- searchPlaceholder: t("formSearchStatusPlaceholder"),
149
- formatSearchResult: (item) => {
150
- var _a, _b;
151
- return ({
152
- label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
153
- value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
154
- });
155
- },
156
- value: status,
157
- });
141
+ })), placeholder: t("formStatusPlaceholder"), required: true, value: status }));
158
142
  return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [studentProfileIdCombo, feeStructureIdCombo, discountCodeIdCombo, _jsx(EnhancedInput, { error: errors.discountAmount, id: "discountAmount", info: t("formDiscountAmountInfo"), label: t("formDiscountAmountLabel"), min: "0", onChange: (e) => handleChange("discountAmount", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: discountAmount || 0 }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "amount", t }), id: "amount", info: t("formTotalAmountInfo"), label: t("formTotalAmountLabel"), min: "0", onChange: (e) => handleChange("amount", Number(e.target.value)), placeholder: "0.00", required: true, step: "0.01", type: "number", value: amount }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "amountPaid", t }), id: "amountPaid", info: t("formAmountPaidInfo"), label: t("formAmountPaidLabel"), min: "0", required: true, onChange: (e) => handleChange("amountPaid", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: amountPaid }), _jsx(EnhancedInput, { disabled: true, error: getTranslatedError({ errors, key: "amountDue", t }), id: "amountDue", info: t("formAmountDueInfo"), label: t("formAmountDueLabel"), min: "0", required: true, onChange: (e) => handleChange("amountDue", Number(e.target.value)), placeholder: "0.00", step: "0.01", type: "number", value: amountDue }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dueDate", t }), id: "dueDate", info: t("formDueDateInfo"), label: t("formDueDateLabel"), onChange: (e) => handleChange("dueDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, required: true, type: "date", value: dueDate || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "paidAt", t }), id: "paidAt", info: t("formPaidAtInfo"), label: t("formPaidAtLabel"), onChange: (e) => handleChange("paidAt", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: paidAt || "" }), statusCombo, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", label: t("formRemarksLabel"), onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), value: remarks || "" }), _jsx(EnhancedCheckbox, { checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", !!checked) })] }));
159
143
  };
@@ -12,10 +12,11 @@ import { Separator } from "@appcorp/shadcn/components/ui/separator";
12
12
  import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
13
13
  import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
14
14
  import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
15
- const workspace = getCachedWorkspaceSync();
15
+ /** Read at call time — never cache a workspace captured at module load. */
16
+ const currentSchoolId = () => { var _a, _b; return ((_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.id) || ""; };
16
17
  const POLL_INTERVAL_MS = 2000;
17
18
  const POLL_TIMEOUT_MS = 300000;
18
- const PAGE_LIMIT = 5000;
19
+ const PAGE_LIMIT = 200;
19
20
  async function pollJob(statusUrl, signal, onProgress) {
20
21
  const startTime = Date.now();
21
22
  let lastProgressToast = 0;
@@ -76,8 +77,7 @@ export const StudentFeeMoreActions = () => {
76
77
  });
77
78
  }, [dispatch]);
78
79
  const refreshList = useCallback(() => {
79
- var _a;
80
- const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
80
+ const schoolId = currentSchoolId();
81
81
  fetch(`${STUDENT_FEE_API_ROUTES.UNIT}?currentPage=1&pageLimit=${PAGE_LIMIT}&schoolId=${schoolId}`, {
82
82
  headers: {
83
83
  "Content-Type": "application/json",
@@ -99,8 +99,8 @@ export const StudentFeeMoreActions = () => {
99
99
  .catch(() => { });
100
100
  }, [dispatch]);
101
101
  const handleAutoPost = useCallback(async () => {
102
- var _a, _b, _c, _d;
103
- const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
102
+ var _a, _b, _c;
103
+ const schoolId = currentSchoolId();
104
104
  const numbers = computerNumbersText
105
105
  .split(",")
106
106
  .map((n) => n.trim())
@@ -115,7 +115,7 @@ export const StudentFeeMoreActions = () => {
115
115
  return;
116
116
  }
117
117
  setSubmitting(true);
118
- (_b = abortRef.current) === null || _b === void 0 ? void 0 : _b.abort();
118
+ (_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
119
119
  const controller = new AbortController();
120
120
  abortRef.current = controller;
121
121
  const { signal } = controller;
@@ -158,7 +158,7 @@ export const StudentFeeMoreActions = () => {
158
158
  return;
159
159
  if (status.status === "completed") {
160
160
  const r = status.results;
161
- if (r && ((_c = r.errors) === null || _c === void 0 ? void 0 : _c.length) > 0) {
161
+ if (r && ((_b = r.errors) === null || _b === void 0 ? void 0 : _b.length) > 0) {
162
162
  const summary = formatErrorSummary(t, r.errors);
163
163
  showSuccessToast(`${t("messagesAutoPostResults", { paid: r.paid, skipped: r.skipped })}\n${summary}`);
164
164
  }
@@ -173,7 +173,7 @@ export const StudentFeeMoreActions = () => {
173
173
  }
174
174
  else {
175
175
  const r = status.results;
176
- const detail = ((_d = r === null || r === void 0 ? void 0 : r.errors) === null || _d === void 0 ? void 0 : _d.length)
176
+ const detail = ((_c = r === null || r === void 0 ? void 0 : r.errors) === null || _c === void 0 ? void 0 : _c.length)
177
177
  ? formatErrorSummary(t, r.errors)
178
178
  : t("unknownError");
179
179
  showErrorToast(`${t("messagesAutoPostFailed")}\n${detail}`);
@@ -68,7 +68,7 @@ const tableBodyCols = [
68
68
  { componentType: COMPONENT_TYPE.TEXT, key: "status" },
69
69
  {
70
70
  componentType: COMPONENT_TYPE.TEXT,
71
- key: "amount",
71
+ key: "lastPaidMonths",
72
72
  textFormatter: (_, row) => {
73
73
  var _a, _b, _c, _d, _e, _f, _g;
74
74
  return ((_g = (_f = (_e = (_d = (_c = (_b = (_a = row.family) === null || _a === void 0 ? void 0 : _a.studentFees) === null || _b === void 0 ? void 0 : _b.filter((sf) => sf.paidAt !== null && sf.status === "PAID")) === null || _c === void 0 ? void 0 : _c.filter((sf) => sf.studentProfileId ===
@@ -8,29 +8,7 @@
8
8
  * - Status Options
9
9
  * - Gender Options
10
10
  */
11
- import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
12
11
  export declare const pageLimit: number;
13
- export declare const tableHeadItems: {
14
- label: string;
15
- width: string;
16
- }[];
17
- export declare const tableBodyCols: ({
18
- componentType: COMPONENT_TYPE;
19
- key: string;
20
- textFormatter?: undefined;
21
- } | {
22
- componentType: COMPONENT_TYPE;
23
- key: string[];
24
- textFormatter?: undefined;
25
- } | {
26
- componentType: COMPONENT_TYPE;
27
- key: string;
28
- textFormatter: (value: unknown) => string;
29
- } | {
30
- componentType: COMPONENT_TYPE;
31
- key?: undefined;
32
- textFormatter?: undefined;
33
- })[];
34
12
  export declare const STATUS_OPTIONS: readonly [{
35
13
  readonly label: "Active";
36
14
  readonly value: "ACTIVE";
@@ -44,8 +22,8 @@ export declare const STATUS_OPTIONS: readonly [{
44
22
  readonly label: "Transferred";
45
23
  readonly value: "TRANSFERRED";
46
24
  }, {
47
- readonly label: "Expelled";
48
- readonly value: "EXPELLED";
25
+ readonly label: "Dropped";
26
+ readonly value: "DROPPED";
49
27
  }];
50
28
  export declare const STATUS_BADGE_COLORS: Record<string, string>;
51
29
  export declare const GENDER_OPTIONS: readonly [{