@appcorp/fusion-storybook 0.5.21 → 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.
- package/base-modules/school/cache.js +0 -1
- package/base-modules/school/context.d.ts +0 -2
- package/base-modules/school/context.js +77 -18
- package/base-modules/school/drawer.js +1 -3
- package/base-modules/school/form.js +4 -23
- package/base-modules/school/page.js +2 -2
- package/base-modules/section/context.d.ts +6 -0
- package/base-modules/section/context.js +66 -34
- package/base-modules/section/form.js +2 -2
- package/base-modules/section/more-actions.js +71 -16
- package/base-modules/section/page.js +7 -3
- package/constants.d.ts +3 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +5 -3
- package/base-modules/school/filter.d.ts +0 -1
- package/base-modules/school/filter.js +0 -13
- package/base-modules/school/more-actions.d.ts +0 -1
- 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
|
-
|
|
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
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
122
|
-
|
|
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 && ((
|
|
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 = (
|
|
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
|
-
|
|
235
|
-
|
|
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
|
-
|
|
250
|
-
|
|
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
|
-
{
|
|
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: "
|
|
135
|
+
moduleName: "Section",
|
|
132
136
|
});
|
|
133
137
|
if (!hasPermission) {
|
|
134
|
-
return _jsx(RbacNoAccess, { moduleName: "
|
|
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
|
@@ -71,7 +71,9 @@ export declare const RBAC_API_ROUTES: {
|
|
|
71
71
|
readonly PERMISSIONS_LIST: "/api/v1/permission";
|
|
72
72
|
readonly ROLE_PERMISSION_UNIT: "/api/v1/role-permission";
|
|
73
73
|
};
|
|
74
|
-
export declare const SCHOOL_API_ROUTES:
|
|
74
|
+
export declare const SCHOOL_API_ROUTES: {
|
|
75
|
+
readonly UNIT: "/api/v1/school";
|
|
76
|
+
};
|
|
75
77
|
export declare const SECTION_API_ROUTES: {
|
|
76
78
|
readonly LIST: "/api/v1/section";
|
|
77
79
|
readonly UNIT: "/api/v1/section";
|