@appcorp/fusion-storybook 0.5.25 → 0.5.29

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.
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { PAYMENT_STATUS } from "../../type";
10
10
  export declare const pageLimit: number;
11
+ export declare const MONTHLY_CHECKBOX_KEYS: readonly ["formMonthlyCheckStudentProfile", "formMonthlyCheckFeeStructure", "formMonthlyCheckReady"];
11
12
  export declare const filterDateDefaults: () => {
12
13
  filterFromDate: string;
13
14
  filterToDate: string;
@@ -12,6 +12,14 @@ import { PAYMENT_STATUS } from "../../type";
12
12
  // ============================================================================
13
13
  export const pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
14
14
  // ============================================================================
15
+ // MONTHLY CREATION CHECKLIST
16
+ // ============================================================================
17
+ export const MONTHLY_CHECKBOX_KEYS = [
18
+ "formMonthlyCheckStudentProfile",
19
+ "formMonthlyCheckFeeStructure",
20
+ "formMonthlyCheckReady",
21
+ ];
22
+ // ============================================================================
15
23
  // FILTER DATE DEFAULTS
16
24
  // ============================================================================
17
25
  export const filterDateDefaults = () => {
@@ -10,24 +10,19 @@ import { useCallback, useState } from "react";
10
10
  import { STUDENT_FEE_ACTION_TYPES, useStudentFeeModule } from "./context";
11
11
  import { useTranslations } from "next-intl";
12
12
  import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
13
- const CHECKBOX_KEYS = [
14
- "formMonthlyCheckStudentProfile",
15
- "formMonthlyCheckFeeStructure",
16
- "formMonthlyCheckGmail",
17
- "formMonthlyCheckReady",
18
- ];
13
+ import { MONTHLY_CHECKBOX_KEYS } from "./constants";
19
14
  export const StudentFeeMonthly = () => {
20
15
  const t = useTranslations("studentFee");
21
16
  const { dispatch } = useStudentFeeModule();
22
- const [checked, setChecked] = useState(Object.fromEntries(CHECKBOX_KEYS.map((key) => [key, false])));
23
- // const allChecked = CHECKBOX_KEYS.every((key) => checked[key]);
17
+ const [checked, setChecked] = useState(Object.fromEntries(MONTHLY_CHECKBOX_KEYS.map((key) => [key, false])));
18
+ // const allChecked = MONTHLY_CHECKBOX_KEYS.every((key) => checked[key]);
24
19
  const handleCheckChange = useCallback((key, value) => {
25
20
  const next = Object.assign(Object.assign({}, checked), { [key]: value });
26
21
  setChecked(next);
27
22
  dispatch({
28
23
  type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
29
- payload: { disabled: !CHECKBOX_KEYS.every((k) => next[k]) },
24
+ payload: { disabled: !MONTHLY_CHECKBOX_KEYS.every((k) => next[k]) },
30
25
  });
31
26
  }, [checked, dispatch]);
32
- return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx("p", { className: "text-foreground text-sm", children: t("formMonthlyWarningMessage") }), _jsx("div", { className: "flex flex-col gap-3", children: CHECKBOX_KEYS.map((key) => (_jsx(EnhancedCheckbox, { checked: checked[key], id: key, label: t(key), onCheckedChange: (value) => handleCheckChange(key, value) }, key))) })] }));
27
+ return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx("p", { className: "text-foreground text-sm", children: t("formMonthlyWarningMessage") }), _jsx("div", { className: "flex flex-col gap-3", children: MONTHLY_CHECKBOX_KEYS.map((key) => (_jsx(EnhancedCheckbox, { checked: checked[key], id: key, label: t(key), onCheckedChange: (value) => handleCheckChange(key, value) }, key))) })] }));
33
28
  };
@@ -31,6 +31,7 @@ export declare const SUBJECT_ACTION_TYPES: {
31
31
  enabled: boolean;
32
32
  errors: Record<string, string>;
33
33
  filterEnabled: boolean | undefined;
34
+ appliedFilterEnabled: boolean | undefined;
34
35
  id: string;
35
36
  name: string;
36
37
  schoolId: string;
@@ -47,6 +48,7 @@ export declare const SUBJECT_ACTION_TYPES: {
47
48
  enabled: boolean;
48
49
  errors: Record<string, string>;
49
50
  filterEnabled: boolean | undefined;
51
+ appliedFilterEnabled: boolean | undefined;
50
52
  id: string;
51
53
  name: string;
52
54
  schoolId: string;
@@ -65,6 +67,7 @@ export declare const SUBJECT_ACTION_TYPES: {
65
67
  enabled: boolean;
66
68
  errors: Record<string, string>;
67
69
  filterEnabled: boolean | undefined;
70
+ appliedFilterEnabled: boolean | undefined;
68
71
  id: string;
69
72
  name: string;
70
73
  schoolId: string;
@@ -81,6 +84,7 @@ export declare const SUBJECT_ACTION_TYPES: {
81
84
  enabled: boolean;
82
85
  errors: Record<string, string>;
83
86
  filterEnabled: boolean | undefined;
87
+ appliedFilterEnabled: boolean | undefined;
84
88
  id: string;
85
89
  name: string;
86
90
  schoolId: string;
@@ -97,6 +101,7 @@ export declare const SUBJECT_ACTION_TYPES: {
97
101
  enabled: boolean;
98
102
  errors: Record<string, string>;
99
103
  filterEnabled: boolean | undefined;
104
+ appliedFilterEnabled: boolean | undefined;
100
105
  id: string;
101
106
  name: string;
102
107
  schoolId: string;
@@ -129,6 +134,7 @@ export declare const useSubjectModule: () => {
129
134
  listLoading: boolean;
130
135
  resetRecordFormState: () => void;
131
136
  rowActions: RowAction[];
137
+ toggleStatus: (row?: TableRow) => void;
132
138
  updateLoading: boolean;
133
139
  handleCloseDrawer?: () => void;
134
140
  state: {
@@ -144,6 +150,7 @@ export declare const useSubjectModule: () => {
144
150
  enabled: boolean;
145
151
  errors: Record<string, string>;
146
152
  filterEnabled: boolean | undefined;
153
+ appliedFilterEnabled: boolean | undefined;
147
154
  id: string;
148
155
  name: string;
149
156
  schoolId: string;
@@ -19,7 +19,6 @@
19
19
  * - `useSubjectModule()` — hook that returns handlers and state
20
20
  */
21
21
  import { useCallback, useEffect, useMemo, useRef } from "react";
22
- import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
23
22
  import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
24
23
  import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
25
24
  import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
@@ -64,7 +63,8 @@ const subjectConfig = {
64
63
  description: "",
65
64
  enabled: true,
66
65
  errors: {},
67
- filterEnabled: undefined,
66
+ filterEnabled: true,
67
+ appliedFilterEnabled: true,
68
68
  id: "",
69
69
  name: "",
70
70
  schoolId: "",
@@ -81,7 +81,7 @@ export const { actionTypes: SUBJECT_ACTION_TYPES, config: subjectModuleConfig, i
81
81
  export const useSubjectModule = () => {
82
82
  var _a;
83
83
  const context = useSubjectContext();
84
- const { dispatch } = context;
84
+ const { dispatch, handleCloseDrawer } = context;
85
85
  const state = context.state;
86
86
  const t = useTranslations("subject");
87
87
  const { theme } = useTheme();
@@ -92,11 +92,11 @@ export const useSubjectModule = () => {
92
92
  // ============================================================================
93
93
  // API PARAMETERS
94
94
  // ============================================================================
95
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
96
- ? { filterEnabled: String(state.filterEnabled) }
95
+ const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
96
+ ? { filterEnabled: String(state.appliedFilterEnabled) }
97
97
  : {}))), [
98
+ state.appliedFilterEnabled,
98
99
  state.currentPage,
99
- state.filterEnabled,
100
100
  state.pageLimit,
101
101
  debouncedQuery,
102
102
  schoolId,
@@ -109,8 +109,8 @@ export const useSubjectModule = () => {
109
109
  name: state.name,
110
110
  schoolId: state.schoolId || schoolId,
111
111
  }), [state, schoolId]);
112
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
113
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
112
+ const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
113
+ const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
114
114
  // ============================================================================
115
115
  // UTILITIES
116
116
  // ============================================================================
@@ -122,7 +122,15 @@ export const useSubjectModule = () => {
122
122
  });
123
123
  }, [theme]);
124
124
  const resetFormAndCloseDrawer = useCallback(() => {
125
+ const applied = state.appliedFilterEnabled;
126
+ const staged = state.filterEnabled;
125
127
  dispatch({ type: SUBJECT_ACTION_TYPES.RESET_FORM });
128
+ dispatch({
129
+ type: SUBJECT_ACTION_TYPES.SET_FILTERS,
130
+ payload: {
131
+ filters: { appliedFilterEnabled: applied, filterEnabled: staged },
132
+ },
133
+ });
126
134
  dispatch({
127
135
  type: SUBJECT_ACTION_TYPES.SET_ERRORS,
128
136
  payload: { errors: {} },
@@ -135,7 +143,7 @@ export const useSubjectModule = () => {
135
143
  type: SUBJECT_ACTION_TYPES.SET_DRAWER,
136
144
  payload: { drawer: null },
137
145
  });
138
- }, [dispatch]);
146
+ }, [dispatch, state.appliedFilterEnabled, state.filterEnabled]);
139
147
  const resetRecordFormState = useCallback(() => {
140
148
  dispatch({
141
149
  type: SUBJECT_ACTION_TYPES.SET_ERRORS,
@@ -152,7 +160,6 @@ export const useSubjectModule = () => {
152
160
  code: "",
153
161
  description: "",
154
162
  enabled: true,
155
- filterEnabled: undefined,
156
163
  id: "",
157
164
  name: "",
158
165
  schoolId,
@@ -163,57 +170,61 @@ export const useSubjectModule = () => {
163
170
  // ============================================================================
164
171
  // API CALLBACKS
165
172
  // ============================================================================
173
+ const apiError = (data) => data === null || data === void 0 ? void 0 : data.error;
166
174
  const listCallback = useCallback(({ data, error }) => {
167
- var _a, _b;
175
+ var _a, _b, _c;
168
176
  if (error) {
169
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
177
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
170
178
  return;
171
179
  }
172
180
  if (data) {
173
181
  const response = data;
174
182
  dispatch({
175
183
  type: SUBJECT_ACTION_TYPES.SET_ITEMS,
176
- payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
184
+ payload: { items: (_b = response.items) !== null && _b !== void 0 ? _b : [], count: (_c = response.count) !== null && _c !== void 0 ? _c : 0 },
177
185
  });
178
186
  }
179
187
  }, [dispatch, showToast, t]);
180
188
  const updateCallback = useCallback(({ data, error }) => {
181
- var _a;
189
+ var _a, _b;
182
190
  if (error) {
183
- const isCreated = isCreatedOrUpdated(data);
184
- showToast(isCreated ? t("messagesCreateFailed") : t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
191
+ dispatch({
192
+ type: SUBJECT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
193
+ payload: { disabled: false },
194
+ });
195
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
185
196
  return;
186
197
  }
187
198
  if (data) {
188
199
  showToast(t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
189
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
200
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
190
201
  resetFormAndCloseDrawer();
191
202
  }
192
- }, [resetFormAndCloseDrawer, showToast, t]);
203
+ }, [dispatch, resetFormAndCloseDrawer, showToast, t]);
193
204
  const byIdCallback = useCallback(({ data, error }) => {
194
- var _a;
205
+ var _a, _b;
195
206
  if (error) {
196
- showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
207
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
197
208
  return;
198
209
  }
199
210
  if (data) {
200
211
  dispatch({
201
212
  type: SUBJECT_ACTION_TYPES.SET_FORM_DATA,
202
213
  payload: {
203
- form: Object.assign(Object.assign({}, data), { description: (_a = data.description) !== null && _a !== void 0 ? _a : "", filterEnabled: undefined }),
214
+ form: Object.assign(Object.assign({}, data), { description: (_b = data.description) !== null && _b !== void 0 ? _b : "" }),
204
215
  },
205
216
  });
206
217
  }
207
218
  }, [dispatch, showToast, t]);
208
219
  const deleteCallback = useCallback(({ data, error }) => {
209
- var _a;
220
+ var _a, _b;
210
221
  if (error) {
211
- showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
222
+ showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
212
223
  return;
213
224
  }
214
225
  if (data) {
215
226
  showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
216
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
227
+ (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
217
228
  }
218
229
  }, [showToast, t]);
219
230
  // ============================================================================
@@ -284,11 +295,12 @@ export const useSubjectModule = () => {
284
295
  });
285
296
  }, [dispatch]);
286
297
  const handleCreate = useCallback(() => {
298
+ resetRecordFormState();
287
299
  dispatch({
288
300
  type: SUBJECT_ACTION_TYPES.SET_DRAWER,
289
301
  payload: { drawer: SUBJECT_DRAWER.FORM_DRAWER },
290
302
  });
291
- }, [dispatch]);
303
+ }, [dispatch, resetRecordFormState]);
292
304
  const handleView = useCallback((row) => {
293
305
  resetRecordFormState();
294
306
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
@@ -309,9 +321,9 @@ export const useSubjectModule = () => {
309
321
  if (!confirm(t("messagesDeleteConfirmation")))
310
322
  return;
311
323
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
312
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
324
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
313
325
  });
314
- }, [t, deleteFetchNow]);
326
+ }, [t, deleteFetchNow, schoolId]);
315
327
  const handleFilters = useCallback(() => {
316
328
  dispatch({
317
329
  type: SUBJECT_ACTION_TYPES.SET_DRAWER,
@@ -327,13 +339,25 @@ export const useSubjectModule = () => {
327
339
  const clearFilters = useCallback(() => {
328
340
  dispatch({
329
341
  type: SUBJECT_ACTION_TYPES.SET_FILTERS,
330
- payload: { filters: { filterEnabled: undefined } },
342
+ payload: {
343
+ filters: { filterEnabled: undefined, appliedFilterEnabled: undefined },
344
+ },
331
345
  });
332
346
  dispatch({
333
347
  type: SUBJECT_ACTION_TYPES.SET_CURRENT_PAGE,
334
348
  payload: { currentPage: 1 },
335
349
  });
336
- }, [dispatch]);
350
+ handleCloseDrawer === null || handleCloseDrawer === void 0 ? void 0 : handleCloseDrawer();
351
+ }, [dispatch, handleCloseDrawer]);
352
+ const toggleStatus = useCallback((row) => {
353
+ updateFetchNow(undefined, {
354
+ body: JSON.stringify({
355
+ id: row === null || row === void 0 ? void 0 : row.id,
356
+ schoolId,
357
+ enabled: !(row === null || row === void 0 ? void 0 : row.enabled),
358
+ }),
359
+ });
360
+ }, [schoolId, updateFetchNow]);
337
361
  const handleSearch = useCallback((query) => {
338
362
  dispatch({
339
363
  type: SUBJECT_ACTION_TYPES.SET_SEARCH_QUERY,
@@ -411,21 +435,31 @@ export const useSubjectModule = () => {
411
435
  icon: Edit,
412
436
  },
413
437
  {
414
- enabled: (row) => !(row === null || row === void 0 ? void 0 : row.enabled),
438
+ enabled: true,
415
439
  handleOnClick: handleDelete,
416
440
  label: t("actionsButtonDelete"),
417
441
  order: 3,
418
442
  icon: Trash2,
419
443
  variant: "destructive",
420
444
  },
421
- ], [handleView, handleEdit, handleDelete, t]);
445
+ {
446
+ enabled: true,
447
+ handleOnClick: toggleStatus,
448
+ label: t("actionsButtonToggleStatus"),
449
+ order: 4,
450
+ },
451
+ ], [handleView, handleEdit, handleDelete, t, toggleStatus]);
422
452
  const applyFilters = useCallback(() => {
453
+ dispatch({
454
+ type: SUBJECT_ACTION_TYPES.SET_FILTERS,
455
+ payload: { filters: { appliedFilterEnabled: state.filterEnabled } },
456
+ });
423
457
  dispatch({
424
458
  type: SUBJECT_ACTION_TYPES.SET_CURRENT_PAGE,
425
459
  payload: { currentPage: 1 },
426
460
  });
427
- closeDrawer();
428
- }, [dispatch, closeDrawer]);
461
+ handleCloseDrawer === null || handleCloseDrawer === void 0 ? void 0 : handleCloseDrawer();
462
+ }, [dispatch, handleCloseDrawer, state.filterEnabled]);
429
463
  // ============================================================================
430
464
  // EFFECTS
431
465
  // ============================================================================
@@ -462,5 +496,6 @@ export const useSubjectModule = () => {
462
496
  listLoading,
463
497
  resetRecordFormState,
464
498
  rowActions,
499
+ toggleStatus,
465
500
  updateLoading });
466
501
  };
@@ -15,5 +15,5 @@ export const SubjectForm = () => {
15
15
  const { state, handleChange } = useSubjectModule();
16
16
  const { code, description, enabled, errors, name } = state;
17
17
  const t = useTranslations("subject");
18
- return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formNameInfo"), label: t("formNameLabel"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("formNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formCodeInfo"), label: t("formCodeLabel"), onChange: (e) => handleChange("code", e.target.value), placeholder: t("formCodePlaceholder"), required: true, value: code }), _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "description", t }), id: "description", info: t("formDescriptionInfo"), label: t("formDescriptionLabel"), onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), value: description !== null && description !== void 0 ? description : "" }), _jsx(EnhancedCheckbox, { label: t("formEnabledLabel"), defaultChecked: enabled, onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
18
+ return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formNameInfo"), label: t("formNameLabel"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("formNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formCodeInfo"), label: t("formCodeLabel"), onChange: (e) => handleChange("code", e.target.value), placeholder: t("formCodePlaceholder"), required: true, value: code }), _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "description", t }), id: "description", info: t("formDescriptionInfo"), label: t("formDescriptionLabel"), onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), value: description !== null && description !== void 0 ? description : "" }), _jsx(EnhancedCheckbox, { checked: enabled, label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
19
19
  };
@@ -10,19 +10,42 @@ import { pageLimit } from "./constants";
10
10
  import { SUBJECT_API_ROUTES } from "../../constants";
11
11
  import { SUBJECT_ACTION_TYPES, useSubjectContext } from "./context";
12
12
  import { useRef, useEffect, useCallback } from "react";
13
- const workspace = getCachedWorkspaceSync();
13
+ /** Read at call time — never cache a workspace captured at module load. */
14
+ 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
15
  const POLL_INTERVAL_MS = 2000;
15
16
  const POLL_TIMEOUT_MS = 300000;
17
+ const EXPORT_PAGE_LIMIT = 200;
18
+ const EXPORT_MAX_PAGES = 50;
16
19
  const handleGetAllRecords = async (schoolId, pageLimit) => {
17
- const response = await fetch(`${SUBJECT_API_ROUTES.UNIT}?pageLimit=${pageLimit}&currentPage=1&schoolId=${schoolId}`);
18
- const result = await response.json();
19
- const csv = await converter.json2csv(result.items || [], {});
20
+ var _a, _b, _c;
21
+ const take = Math.min(pageLimit, EXPORT_PAGE_LIMIT);
22
+ const items = [];
23
+ for (let page = 1; page <= EXPORT_MAX_PAGES; page++) {
24
+ const params = new URLSearchParams({
25
+ currentPage: String(page),
26
+ pageLimit: String(take),
27
+ schoolId,
28
+ });
29
+ const response = await fetch(`${SUBJECT_API_ROUTES.UNIT}?${params.toString()}`);
30
+ if (!response.ok) {
31
+ const body = (await response.json().catch(() => ({})));
32
+ throw new Error((_a = body.error) !== null && _a !== void 0 ? _a : `Export failed (${response.status})`);
33
+ }
34
+ const result = (await response.json());
35
+ const pageItems = (_b = result.items) !== null && _b !== void 0 ? _b : [];
36
+ items.push(...pageItems);
37
+ if (take <= 1 ||
38
+ pageItems.length < take ||
39
+ items.length >= ((_c = result.count) !== null && _c !== void 0 ? _c : items.length)) {
40
+ break;
41
+ }
42
+ }
43
+ const csv = await converter.json2csv(items, {});
20
44
  const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
21
45
  await downloadFromUrl(blob, "subject.csv");
22
46
  };
23
47
  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) || "";
48
+ const schoolId = currentSchoolId();
26
49
  if (!schoolId)
27
50
  throw new Error("School ID not found");
28
51
  const res = await fetch(SUBJECT_API_ROUTES.BULK, {
@@ -93,7 +116,7 @@ export const SubjectMoreActions = () => {
93
116
  };
94
117
  }, []);
95
118
  const handleBulkFlow = useCallback(async (files, method) => {
96
- var _a, _b, _c, _d, _e, _f, _g;
119
+ var _a, _b, _c, _d, _e, _f;
97
120
  const closeDrawer = () => {
98
121
  dispatch({
99
122
  type: SUBJECT_ACTION_TYPES.SET_DRAWER,
@@ -187,7 +210,7 @@ export const SubjectMoreActions = () => {
187
210
  else {
188
211
  showSuccessToast(t("messagesBulkSuccess"));
189
212
  }
190
- const schoolId = ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id) || "";
213
+ const schoolId = currentSchoolId();
191
214
  fetch(`${SUBJECT_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
192
215
  headers: {
193
216
  "Content-Type": "application/json",
@@ -211,7 +234,7 @@ export const SubjectMoreActions = () => {
211
234
  }
212
235
  else {
213
236
  const r = status.results;
214
- const detail = ((_g = r === null || r === void 0 ? void 0 : r.errors) === null || _g === void 0 ? void 0 : _g.length)
237
+ const detail = ((_f = r === null || r === void 0 ? void 0 : r.errors) === null || _f === void 0 ? void 0 : _f.length)
215
238
  ? formatErrorSummary(t, r.errors)
216
239
  : t("unknownError");
217
240
  showErrorToast(`${t("messagesBulkFailed", { action: label })}\n${detail}`);
@@ -233,8 +256,7 @@ export const SubjectMoreActions = () => {
233
256
  id: "1",
234
257
  title: t("downloadEmptyCsvTemplate"),
235
258
  handleOnClick: async () => {
236
- var _a;
237
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
259
+ await handleGetAllRecords(currentSchoolId(), 1);
238
260
  },
239
261
  },
240
262
  { id: "2", title: t("addYourDataToTheCsv") },
@@ -248,8 +270,7 @@ export const SubjectMoreActions = () => {
248
270
  id: "1",
249
271
  title: t("downloadPopulatedCsvTemplate"),
250
272
  handleOnClick: async () => {
251
- var _a;
252
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
273
+ await handleGetAllRecords(currentSchoolId(), EXPORT_PAGE_LIMIT);
253
274
  },
254
275
  },
255
276
  { id: "2", title: t("updateYourDataInTheCsv") },
@@ -132,10 +132,10 @@ const SubjectPageInner = (props) => {
132
132
  ]);
133
133
  const hasPermission = resolveRbacPermissions({
134
134
  userRole: props.userRole,
135
- moduleName: "Academic Operations",
135
+ moduleName: "Subject",
136
136
  });
137
137
  if (!hasPermission) {
138
- return _jsx(RbacNoAccess, { moduleName: "Academic Operations" });
138
+ return _jsx(RbacNoAccess, { moduleName: "Subject" });
139
139
  }
140
140
  return (_jsx("div", { className: "p-4", children: _jsx(GenericSubjectPage, { overrideConfig: subjectConfig, context: context, tableBodyCols: tableBodyCols }) }));
141
141
  };
@@ -26,17 +26,13 @@ export const subjectFormValidation = z.object({
26
26
  .string()
27
27
  .min(1, VALIDATION_KEYS.name)
28
28
  .min(2, VALIDATION_KEYS.nameMin)
29
- .max(100, VALIDATION_KEYS.nameMax)
30
- .regex(/^[a-zA-Z\s]+$/, VALIDATION_KEYS.nameInvalid),
29
+ .max(100, VALIDATION_KEYS.nameMax),
31
30
  code: z
32
31
  .string()
33
32
  .min(1, VALIDATION_KEYS.code)
34
33
  .min(2, VALIDATION_KEYS.codeMin)
35
34
  .max(20, VALIDATION_KEYS.codeMax)
36
35
  .regex(/^[A-Z0-9_-]+$/, VALIDATION_KEYS.codeInvalid),
37
- description: z
38
- .string()
39
- .max(500, VALIDATION_KEYS.descriptionMax)
40
- .optional(),
36
+ description: z.string().max(500, VALIDATION_KEYS.descriptionMax).optional(),
41
37
  enabled: z.boolean().optional(),
42
38
  });
@@ -16,7 +16,5 @@ export const SubjectView = () => {
16
16
  const { state } = useSubjectModule();
17
17
  const { code, description, enabled, name } = state;
18
18
  const t = useTranslations("subject");
19
- return (_jsxs("div", { className: "space-y-4", children: [_jsx(Card, { children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "flex items-center gap-6", children: [_jsx("div", { className: "bg-primary/10 flex h-24 w-24 items-center justify-center rounded-full", children: _jsx(BookOpen, { className: "text-primary h-12 w-12" }) }), _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("h2", { className: "text-2xl font-bold", children: name }), enabled ? (_jsx(CheckCircle2, { className: "h-5 w-5 text-green-500" })) : (_jsx(XCircle, { className: "h-5 w-5 text-red-500" }))] }), _jsx("p", { className: "text-muted-foreground mt-1", children: code })] })] }) }) }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionSubjectDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteSubjectInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formNameLabel") }), _jsx("p", { className: "text-base", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formCodeLabel") }), _jsx("p", { className: "text-base", children: formatValue(code) })] }), description && (_jsxs("div", { className: "col-span-full space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formDescriptionLabel") }), _jsx("p", { className: "text-base", children: description })] })), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled
20
- ? t("badgeActive")
21
- : t("badgeInactive") })] })] }) })] })] }));
19
+ return (_jsxs("div", { className: "space-y-4", children: [_jsx(Card, { children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "flex items-center gap-6", children: [_jsx("div", { className: "bg-primary/10 flex h-24 w-24 items-center justify-center rounded-full", children: _jsx(BookOpen, { className: "text-primary h-12 w-12" }) }), _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("h2", { className: "text-2xl font-bold", children: name }), enabled ? (_jsx(CheckCircle2, { className: "h-5 w-5 text-green-500" })) : (_jsx(XCircle, { className: "h-5 w-5 text-red-500" }))] }), _jsx("p", { className: "text-muted-foreground mt-1", children: code })] })] }) }) }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionSubjectDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteSubjectInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formNameLabel") }), _jsx("p", { className: "text-base", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formCodeLabel") }), _jsx("p", { className: "text-base", children: formatValue(code) })] }), description && (_jsxs("div", { className: "col-span-full space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formDescriptionLabel") }), _jsx("p", { className: "text-base", children: description })] })), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled ? t("badgeActive") : t("badgeInactive") })] })] }) })] })] }));
22
20
  };
@@ -51,6 +51,7 @@ export declare const TEACHER_ACTION_TYPES: {
51
51
  teacherCode: string;
52
52
  userId: string | null;
53
53
  filterEnabled: boolean | undefined;
54
+ appliedFilterEnabled: boolean | undefined;
54
55
  }>, initialTeacherState: {
55
56
  items: TeacherBE[];
56
57
  count: number;
@@ -84,6 +85,7 @@ export declare const TEACHER_ACTION_TYPES: {
84
85
  teacherCode: string;
85
86
  userId: string | null;
86
87
  filterEnabled: boolean | undefined;
88
+ appliedFilterEnabled: boolean | undefined;
87
89
  }, TeacherProvider: import("react").FC<{
88
90
  children: React.ReactNode;
89
91
  }>, teacherReducer: (state: {
@@ -119,6 +121,7 @@ export declare const TEACHER_ACTION_TYPES: {
119
121
  teacherCode: string;
120
122
  userId: string | null;
121
123
  filterEnabled: boolean | undefined;
124
+ appliedFilterEnabled: boolean | undefined;
122
125
  }, action: any) => {
123
126
  items: TeacherBE[];
124
127
  count: number;
@@ -152,6 +155,7 @@ export declare const TEACHER_ACTION_TYPES: {
152
155
  teacherCode: string;
153
156
  userId: string | null;
154
157
  filterEnabled: boolean | undefined;
158
+ appliedFilterEnabled: boolean | undefined;
155
159
  }, useTeacherContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
156
160
  items: TeacherBE[];
157
161
  count: number;
@@ -185,6 +189,7 @@ export declare const TEACHER_ACTION_TYPES: {
185
189
  teacherCode: string;
186
190
  userId: string | null;
187
191
  filterEnabled: boolean | undefined;
192
+ appliedFilterEnabled: boolean | undefined;
188
193
  }>;
189
194
  export declare const useTeacherModule: () => {
190
195
  applyFilters: () => void;
@@ -252,6 +257,7 @@ export declare const useTeacherModule: () => {
252
257
  teacherCode: string;
253
258
  userId: string | null;
254
259
  filterEnabled: boolean | undefined;
260
+ appliedFilterEnabled: boolean | undefined;
255
261
  };
256
262
  dispatch: React.Dispatch<any>;
257
263
  };