@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.
- 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/base-modules/student-fee/context/student-fee-api-provider.js +20 -14
- package/base-modules/student-fee/context/use-student-fee-module.d.ts +3 -3
- package/base-modules/student-fee/context/use-student-fee-module.js +63 -30
- package/base-modules/student-fee/form.js +8 -24
- package/base-modules/student-fee/more-actions.js +9 -9
- package/base-modules/student-fee/page.js +1 -1
- package/base-modules/student-profile/constants.d.ts +2 -24
- package/base-modules/student-profile/constants.js +2 -68
- package/base-modules/student-profile/context/module-base.d.ts +10 -0
- package/base-modules/student-profile/context/module-base.js +2 -0
- package/base-modules/student-profile/context/use-student-profile-module.d.ts +3 -1
- package/base-modules/student-profile/context/use-student-profile-module.js +113 -71
- package/base-modules/student-profile/filter.js +5 -22
- package/base-modules/student-profile/form.js +22 -46
- package/base-modules/student-profile/page.js +2 -4
- package/constants.d.ts +3 -3
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +7 -4
- 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
- package/base-modules/student-profile/more-actions.d.ts +0 -1
- package/base-modules/student-profile/more-actions.js +0 -257
|
@@ -129,11 +129,12 @@ export function resolveRbacPermissions({ userRole, moduleName, }) {
|
|
|
129
129
|
[USER_ROLE.PARENT]: false,
|
|
130
130
|
}[userRole] || false);
|
|
131
131
|
}
|
|
132
|
+
// The API seed grants student-fee READ_WRITE to STAFF.
|
|
132
133
|
if (moduleName === "Student Fee") {
|
|
133
134
|
return ({
|
|
134
135
|
[USER_ROLE.SUPER_ADMIN]: true,
|
|
135
136
|
[USER_ROLE.SCHOOL_ADMIN]: true,
|
|
136
|
-
[USER_ROLE.STAFF]:
|
|
137
|
+
[USER_ROLE.STAFF]: true,
|
|
137
138
|
[USER_ROLE.TEACHER]: false,
|
|
138
139
|
[USER_ROLE.STUDENT]: false,
|
|
139
140
|
[USER_ROLE.PARENT]: false,
|
|
@@ -286,14 +287,16 @@ export function resolveRbacPermissions({ userRole, moduleName, }) {
|
|
|
286
287
|
[USER_ROLE.PARENT]: false,
|
|
287
288
|
}[userRole] || false);
|
|
288
289
|
}
|
|
290
|
+
// Section is a management surface; teachers/students/parents keep API
|
|
291
|
+
// READ for dropdowns but do not get the page.
|
|
289
292
|
if (moduleName === "Section") {
|
|
290
293
|
return ({
|
|
291
294
|
[USER_ROLE.SUPER_ADMIN]: true,
|
|
292
295
|
[USER_ROLE.SCHOOL_ADMIN]: true,
|
|
293
296
|
[USER_ROLE.STAFF]: true,
|
|
294
|
-
[USER_ROLE.TEACHER]:
|
|
295
|
-
[USER_ROLE.STUDENT]:
|
|
296
|
-
[USER_ROLE.PARENT]:
|
|
297
|
+
[USER_ROLE.TEACHER]: false,
|
|
298
|
+
[USER_ROLE.STUDENT]: false,
|
|
299
|
+
[USER_ROLE.PARENT]: false,
|
|
297
300
|
}[userRole] || false);
|
|
298
301
|
}
|
|
299
302
|
if (moduleName === "Subject") {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SchoolFilter: () => import("react").JSX.Element;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
/**
|
|
4
|
-
* School Filter
|
|
5
|
-
*
|
|
6
|
-
* Placeholder component for school filters.
|
|
7
|
-
* Currently no filters are available for schools.
|
|
8
|
-
*/
|
|
9
|
-
import { useTranslations } from "next-intl";
|
|
10
|
-
export const SchoolFilter = () => {
|
|
11
|
-
const t = useTranslations("school");
|
|
12
|
-
return (_jsx("div", { className: "p-6 text-center text-muted-foreground", children: _jsx("p", { children: t("filterFallbackText") }) }));
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SchoolMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
/**
|
|
4
|
-
* School More Actions
|
|
5
|
-
*
|
|
6
|
-
* Placeholder component for additional school actions.
|
|
7
|
-
* Currently no additional actions are available for schools.
|
|
8
|
-
*/
|
|
9
|
-
import { useTranslations } from "next-intl";
|
|
10
|
-
export const SchoolMoreActions = () => {
|
|
11
|
-
const t = useTranslations("school");
|
|
12
|
-
return (_jsx("div", { className: "p-6 text-center text-muted-foreground", children: _jsx("p", { children: t("moreActionsFallbackText") }) }));
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const StudentProfileMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { downloadFromUrl } from "@react-pakistan/util-functions/general/download-from-url";
|
|
4
|
-
import { showErrorToast, showSuccessToast, showInfoToast, } from "@appcorp/shadcn/lib/toast-utils";
|
|
5
|
-
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
6
|
-
import converter from "json-2-csv";
|
|
7
|
-
import { Timeline } from "../../components/timeline";
|
|
8
|
-
import { useTranslations } from "next-intl";
|
|
9
|
-
import { pageLimit } from "./constants";
|
|
10
|
-
import { STUDENT_PROFILE_API_ROUTES } from "../../constants";
|
|
11
|
-
import { STUDENT_PROFILE_ACTION_TYPES, useStudentProfileContext, } from "./context";
|
|
12
|
-
import { useRef, useEffect, useCallback } from "react";
|
|
13
|
-
const workspace = getCachedWorkspaceSync();
|
|
14
|
-
const POLL_INTERVAL_MS = 2000;
|
|
15
|
-
const POLL_TIMEOUT_MS = 300000;
|
|
16
|
-
const handleGetAllRecords = async (schoolId, pageLimit) => {
|
|
17
|
-
const response = await fetch(`${STUDENT_PROFILE_API_ROUTES.UNIT}?pageLimit=${pageLimit}¤tPage=1&schoolId=${schoolId}`);
|
|
18
|
-
const result = await response.json();
|
|
19
|
-
const csv = await converter.json2csv(result.items || [], {});
|
|
20
|
-
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
21
|
-
await downloadFromUrl(blob, "student-profile.csv");
|
|
22
|
-
};
|
|
23
|
-
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) || "";
|
|
26
|
-
if (!schoolId)
|
|
27
|
-
throw new Error("School ID not found");
|
|
28
|
-
const res = await fetch(STUDENT_PROFILE_API_ROUTES.BULK, {
|
|
29
|
-
method,
|
|
30
|
-
headers: {
|
|
31
|
-
"Content-Type": "application/json",
|
|
32
|
-
},
|
|
33
|
-
body: JSON.stringify({ schoolId, csvData }),
|
|
34
|
-
signal,
|
|
35
|
-
});
|
|
36
|
-
if (!res.ok) {
|
|
37
|
-
const errorData = (await res.json().catch(() => ({})));
|
|
38
|
-
throw new Error(errorData.error || `Bulk operation failed with status ${res.status}`);
|
|
39
|
-
}
|
|
40
|
-
const data = (await res.json());
|
|
41
|
-
return data.jobId;
|
|
42
|
-
}
|
|
43
|
-
async function pollBulkJob(jobId, signal, onProgress) {
|
|
44
|
-
const startTime = Date.now();
|
|
45
|
-
let lastProgressToast = 0;
|
|
46
|
-
while (true) {
|
|
47
|
-
if (signal.aborted)
|
|
48
|
-
throw new Error("Polling cancelled");
|
|
49
|
-
if (Date.now() - startTime > POLL_TIMEOUT_MS) {
|
|
50
|
-
throw new Error("Bulk operation timed out");
|
|
51
|
-
}
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
53
|
-
if (signal.aborted)
|
|
54
|
-
throw new Error("Polling cancelled");
|
|
55
|
-
const res = await fetch(STUDENT_PROFILE_API_ROUTES.BULK_STATUS(jobId), {
|
|
56
|
-
signal,
|
|
57
|
-
});
|
|
58
|
-
if (!res.ok)
|
|
59
|
-
continue;
|
|
60
|
-
const data = (await res.json());
|
|
61
|
-
if (data.status === "completed" || data.status === "failed") {
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
if (data.status === "running" && Date.now() - lastProgressToast > 10000) {
|
|
65
|
-
lastProgressToast = Date.now();
|
|
66
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress(data.processed, data.total);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function formatErrorSummary(t, errors) {
|
|
71
|
-
if (!(errors === null || errors === void 0 ? void 0 : errors.length))
|
|
72
|
-
return "";
|
|
73
|
-
const lines = errors
|
|
74
|
-
.slice(0, 5)
|
|
75
|
-
.map((e) => t("messagesBulkRowError", { row: e.row, error: e.error }));
|
|
76
|
-
const remaining = errors.length - 5;
|
|
77
|
-
if (remaining > 0)
|
|
78
|
-
lines.push(t("messagesBulkMoreRows", { count: remaining }));
|
|
79
|
-
return lines.join("\n");
|
|
80
|
-
}
|
|
81
|
-
export const StudentProfileMoreActions = () => {
|
|
82
|
-
const t = useTranslations("studentProfile");
|
|
83
|
-
const { dispatch } = useStudentProfileContext();
|
|
84
|
-
const abortRef = useRef(null);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
return () => {
|
|
87
|
-
var _a;
|
|
88
|
-
(_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
|
|
89
|
-
};
|
|
90
|
-
}, []);
|
|
91
|
-
const handleBulkFlow = useCallback(async (files, method) => {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
93
|
-
const closeDrawer = () => {
|
|
94
|
-
dispatch({
|
|
95
|
-
type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
|
|
96
|
-
payload: { drawer: null },
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
(_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
|
|
100
|
-
const controller = new AbortController();
|
|
101
|
-
abortRef.current = controller;
|
|
102
|
-
const { signal } = controller;
|
|
103
|
-
const label = method === "POST" ? "create" : "update";
|
|
104
|
-
const file = files[0];
|
|
105
|
-
const text = await file.text();
|
|
106
|
-
const records = converter.csv2json(text);
|
|
107
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
108
|
-
showErrorToast(t("messagesBulkCsvEmpty"));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const validationErrors = [];
|
|
112
|
-
for (let i = 0; i < records.length; i++) {
|
|
113
|
-
const row = records[i];
|
|
114
|
-
const msgs = [];
|
|
115
|
-
if (method === "POST") {
|
|
116
|
-
if (!((_b = row.firstName) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
117
|
-
msgs.push(t("validationRequiredFirstName"));
|
|
118
|
-
if (!((_c = row.lastName) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
119
|
-
msgs.push(t("validationRequiredLastName"));
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
if (!((_d = row.id) === null || _d === void 0 ? void 0 : _d.trim()))
|
|
123
|
-
msgs.push(t("validationRequiredIdForUpdate"));
|
|
124
|
-
}
|
|
125
|
-
if (msgs.length > 0) {
|
|
126
|
-
validationErrors.push({ row: i + 1, messages: msgs });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (validationErrors.length > 0) {
|
|
130
|
-
const summary = validationErrors
|
|
131
|
-
.slice(0, 5)
|
|
132
|
-
.map((e) => t("messagesBulkRowError", {
|
|
133
|
-
row: e.row,
|
|
134
|
-
error: e.messages.join("; "),
|
|
135
|
-
}))
|
|
136
|
-
.join("\n");
|
|
137
|
-
showErrorToast(t("messagesBulkValidationFailed", {
|
|
138
|
-
count: validationErrors.length,
|
|
139
|
-
errors: summary,
|
|
140
|
-
}));
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
|
|
145
|
-
let jobId;
|
|
146
|
-
try {
|
|
147
|
-
jobId = await submitBulkJob(text, method, signal);
|
|
148
|
-
}
|
|
149
|
-
catch (submitError) {
|
|
150
|
-
showErrorToast(t("messagesBulkJobSubmitFailed", {
|
|
151
|
-
action: label,
|
|
152
|
-
error: submitError instanceof Error
|
|
153
|
-
? submitError.message
|
|
154
|
-
: t("unknownError"),
|
|
155
|
-
}));
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const status = await pollBulkJob(jobId, signal, (processed, total) => {
|
|
159
|
-
showInfoToast(t("messagesBulkProgress", { processed, total }));
|
|
160
|
-
});
|
|
161
|
-
if (signal.aborted)
|
|
162
|
-
return;
|
|
163
|
-
if (status.status === "completed") {
|
|
164
|
-
const r = status.results;
|
|
165
|
-
if (r && ((_e = r.errors) === null || _e === void 0 ? void 0 : _e.length) > 0) {
|
|
166
|
-
const summary = formatErrorSummary(t, r.errors);
|
|
167
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
168
|
-
created: r.created,
|
|
169
|
-
updated: r.updated,
|
|
170
|
-
skipped: r.skipped,
|
|
171
|
-
}) +
|
|
172
|
-
"\n" +
|
|
173
|
-
summary);
|
|
174
|
-
}
|
|
175
|
-
else if (r) {
|
|
176
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
177
|
-
created: r.created,
|
|
178
|
-
updated: r.updated,
|
|
179
|
-
skipped: r.skipped,
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
showSuccessToast(t("messagesBulkSuccess"));
|
|
184
|
-
}
|
|
185
|
-
const schoolId = ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id) || "";
|
|
186
|
-
fetch(`${STUDENT_PROFILE_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
187
|
-
headers: {
|
|
188
|
-
"Content-Type": "application/json",
|
|
189
|
-
},
|
|
190
|
-
})
|
|
191
|
-
.then(async (res) => {
|
|
192
|
-
var _a, _b;
|
|
193
|
-
if (!res.ok)
|
|
194
|
-
return;
|
|
195
|
-
const data = await res.json();
|
|
196
|
-
dispatch({
|
|
197
|
-
type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
|
|
198
|
-
payload: {
|
|
199
|
-
items: (_a = data.items) !== null && _a !== void 0 ? _a : [],
|
|
200
|
-
count: (_b = data.count) !== null && _b !== void 0 ? _b : 0,
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
})
|
|
204
|
-
.catch(() => { });
|
|
205
|
-
closeDrawer();
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
const r = status.results;
|
|
209
|
-
const detail = ((_g = r === null || r === void 0 ? void 0 : r.errors) === null || _g === void 0 ? void 0 : _g.length)
|
|
210
|
-
? formatErrorSummary(t, r.errors)
|
|
211
|
-
: t("unknownError");
|
|
212
|
-
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
if (error.message === "Polling cancelled")
|
|
217
|
-
return;
|
|
218
|
-
showErrorToast(t("messagesBulkFailedDetail", {
|
|
219
|
-
action: label,
|
|
220
|
-
error: error instanceof Error ? error.message : t("unknownError"),
|
|
221
|
-
}));
|
|
222
|
-
}
|
|
223
|
-
}, [dispatch, t]);
|
|
224
|
-
const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
|
|
225
|
-
const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
|
|
226
|
-
const create = [
|
|
227
|
-
{
|
|
228
|
-
id: "1",
|
|
229
|
-
title: t("downloadEmptyCsvTemplate"),
|
|
230
|
-
handleOnClick: async () => {
|
|
231
|
-
var _a;
|
|
232
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
{ id: "2", title: t("addYourDataToTheCsv") },
|
|
236
|
-
{
|
|
237
|
-
id: "3",
|
|
238
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
239
|
-
},
|
|
240
|
-
];
|
|
241
|
-
const update = [
|
|
242
|
-
{
|
|
243
|
-
id: "1",
|
|
244
|
-
title: t("downloadPopulatedCsvTemplate"),
|
|
245
|
-
handleOnClick: async () => {
|
|
246
|
-
var _a;
|
|
247
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 5000);
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
{ id: "2", title: t("updateYourDataInTheCsv") },
|
|
251
|
-
{
|
|
252
|
-
id: "3",
|
|
253
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
254
|
-
},
|
|
255
|
-
];
|
|
256
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Timeline, { events: create, heading: t("bulkCreate"), handleOnBulkCreate: handleBulkCreate }), _jsx(Timeline, { events: update, heading: t("bulkUpdate"), handleOnBulkCreate: handleBulkUpdate })] }));
|
|
257
|
-
};
|