@appcorp/fusion-storybook 0.5.19 → 0.5.23

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 (38) hide show
  1. package/base-modules/fee-structure/context/fee-structure-api-provider.js +48 -18
  2. package/base-modules/fee-structure/context/shared.d.ts +5 -0
  3. package/base-modules/fee-structure/context/shared.js +3 -0
  4. package/base-modules/fee-structure/context/use-fee-structure-module.d.ts +1 -0
  5. package/base-modules/fee-structure/context/use-fee-structure-module.js +35 -26
  6. package/base-modules/fee-structure/form.js +16 -48
  7. package/base-modules/fee-structure/more-actions.js +68 -14
  8. package/base-modules/fee-structure/page.js +52 -25
  9. package/base-modules/fee-structure/validate.d.ts +8 -1
  10. package/base-modules/fee-structure/validate.js +6 -1
  11. package/base-modules/fee-structure/view.js +20 -4
  12. package/base-modules/rbac/assign-permissions.js +5 -3
  13. package/base-modules/rbac/context.d.ts +8 -1
  14. package/base-modules/rbac/context.js +92 -65
  15. package/base-modules/rbac/page.js +6 -8
  16. package/base-modules/school/cache.js +0 -1
  17. package/base-modules/school/context.d.ts +0 -2
  18. package/base-modules/school/context.js +77 -18
  19. package/base-modules/school/drawer.js +1 -3
  20. package/base-modules/school/form.js +4 -23
  21. package/base-modules/school/page.js +2 -2
  22. package/base-modules/section/context.d.ts +6 -0
  23. package/base-modules/section/context.js +66 -34
  24. package/base-modules/section/form.js +2 -2
  25. package/base-modules/section/more-actions.js +71 -16
  26. package/base-modules/section/page.js +7 -3
  27. package/constants.d.ts +8 -2
  28. package/package.json +1 -1
  29. package/tsconfig.build.tsbuildinfo +1 -1
  30. package/utils/resolve-rbac-permissions.js +8 -4
  31. package/base-modules/rbac/filter.d.ts +0 -1
  32. package/base-modules/rbac/filter.js +0 -20
  33. package/base-modules/rbac/more-actions.d.ts +0 -1
  34. package/base-modules/rbac/more-actions.js +0 -12
  35. package/base-modules/school/filter.d.ts +0 -1
  36. package/base-modules/school/filter.js +0 -13
  37. package/base-modules/school/more-actions.d.ts +0 -1
  38. package/base-modules/school/more-actions.js +0 -13
@@ -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
  };
package/constants.d.ts CHANGED
@@ -66,8 +66,14 @@ export declare const PUSH_CAMPAIGN_API_ROUTES: {
66
66
  readonly START: "/api/v1/push-campaign/start";
67
67
  readonly AI_CHECK: "/api/v1/push-campaign/ai-check";
68
68
  };
69
- export declare const RBAC_API_ROUTES: Record<string, string>;
70
- export declare const SCHOOL_API_ROUTES: Record<string, string>;
69
+ export declare const RBAC_API_ROUTES: {
70
+ readonly UNIT: "/api/v1/role";
71
+ readonly PERMISSIONS_LIST: "/api/v1/permission";
72
+ readonly ROLE_PERMISSION_UNIT: "/api/v1/role-permission";
73
+ };
74
+ export declare const SCHOOL_API_ROUTES: {
75
+ readonly UNIT: "/api/v1/school";
76
+ };
71
77
  export declare const SECTION_API_ROUTES: {
72
78
  readonly LIST: "/api/v1/section";
73
79
  readonly UNIT: "/api/v1/section";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.5.19",
3
+ "version": "0.5.23",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",