@appcorp/fusion-storybook 0.5.13 → 0.5.17
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/class/context/use-class-module.d.ts +55 -0
- package/base-modules/class/context/use-class-module.js +421 -0
- package/base-modules/class/context.d.ts +27 -52
- package/base-modules/class/context.js +18 -415
- package/base-modules/class/filter.js +16 -6
- package/base-modules/class/form.js +19 -3
- package/base-modules/class/more-actions.js +48 -10
- package/base-modules/class/page.js +15 -5
- package/base-modules/class/validate.d.ts +2 -2
- package/base-modules/class/validate.js +7 -3
- package/base-modules/class/view.js +2 -4
- package/base-modules/discount-code/context/use-discount-code-module.d.ts +65 -0
- package/base-modules/discount-code/context/use-discount-code-module.js +402 -0
- package/base-modules/discount-code/context.d.ts +32 -80
- package/base-modules/discount-code/context.js +14 -430
- package/base-modules/discount-code/filter.d.ts +1 -10
- package/base-modules/discount-code/filter.js +34 -8
- package/base-modules/discount-code/form.js +9 -35
- package/base-modules/discount-code/page.js +39 -19
- package/base-modules/discount-code/validate.d.ts +2 -1
- package/base-modules/discount-code/validate.js +10 -3
- package/base-modules/discount-code/view.js +15 -4
- package/base-modules/enrollment/context.d.ts +6 -0
- package/base-modules/enrollment/context.js +69 -25
- package/base-modules/enrollment/date.d.ts +8 -0
- package/base-modules/enrollment/date.js +21 -0
- package/base-modules/enrollment/filter.js +1 -1
- package/base-modules/enrollment/form.js +55 -24
- package/base-modules/enrollment/more-actions.js +47 -10
- package/base-modules/enrollment/page.js +11 -14
- package/base-modules/enrollment/validate.d.ts +1 -0
- package/base-modules/enrollment/validate.js +3 -1
- package/base-modules/enrollment/view.js +11 -19
- package/base-modules/expense/context/expense-api-provider.js +22 -9
- package/base-modules/expense/context/shared.d.ts +35 -0
- package/base-modules/expense/context/shared.js +11 -3
- package/base-modules/expense/context/use-expense-module.d.ts +7 -1
- package/base-modules/expense/context/use-expense-module.js +58 -55
- package/base-modules/expense/filter.js +25 -57
- package/base-modules/expense/form.js +17 -74
- package/base-modules/expense/page.js +60 -29
- package/base-modules/expense/validate.d.ts +17 -11
- package/base-modules/expense/validate.js +35 -14
- package/constants.d.ts +1 -3
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +10 -6
- package/base-modules/discount-code/more-actions.d.ts +0 -9
- package/base-modules/discount-code/more-actions.js +0 -13
- package/base-modules/expense/more-actions.d.ts +0 -1
- package/base-modules/expense/more-actions.js +0 -265
|
@@ -65,14 +65,16 @@ export function resolveRbacPermissions({ userRole, moduleName, }) {
|
|
|
65
65
|
[USER_ROLE.PARENT]: true,
|
|
66
66
|
}[userRole] || false);
|
|
67
67
|
}
|
|
68
|
+
// Enrollment — the API seed grants it to SUPER_ADMIN/SCHOOL_ADMIN and STAFF
|
|
69
|
+
// (READ_WRITE) only; this page is a management surface.
|
|
68
70
|
if (moduleName === "Enrollment") {
|
|
69
71
|
return ({
|
|
70
72
|
[USER_ROLE.SUPER_ADMIN]: true,
|
|
71
73
|
[USER_ROLE.SCHOOL_ADMIN]: true,
|
|
72
74
|
[USER_ROLE.STAFF]: true,
|
|
73
|
-
[USER_ROLE.TEACHER]:
|
|
74
|
-
[USER_ROLE.STUDENT]:
|
|
75
|
-
[USER_ROLE.PARENT]:
|
|
75
|
+
[USER_ROLE.TEACHER]: false,
|
|
76
|
+
[USER_ROLE.STUDENT]: false,
|
|
77
|
+
[USER_ROLE.PARENT]: false,
|
|
76
78
|
}[userRole] || false);
|
|
77
79
|
}
|
|
78
80
|
if (moduleName === "Schedule") {
|
|
@@ -270,14 +272,16 @@ export function resolveRbacPermissions({ userRole, moduleName, }) {
|
|
|
270
272
|
[USER_ROLE.PARENT]: false,
|
|
271
273
|
}[userRole] || false);
|
|
272
274
|
}
|
|
275
|
+
// Class — the API seed grants READ to teachers/students/parents, but the
|
|
276
|
+
// page is a management surface; only admin/staff may open it.
|
|
273
277
|
if (moduleName === "Class") {
|
|
274
278
|
return ({
|
|
275
279
|
[USER_ROLE.SUPER_ADMIN]: true,
|
|
276
280
|
[USER_ROLE.SCHOOL_ADMIN]: true,
|
|
277
281
|
[USER_ROLE.STAFF]: true,
|
|
278
|
-
[USER_ROLE.TEACHER]:
|
|
279
|
-
[USER_ROLE.STUDENT]:
|
|
280
|
-
[USER_ROLE.PARENT]:
|
|
282
|
+
[USER_ROLE.TEACHER]: false,
|
|
283
|
+
[USER_ROLE.STUDENT]: false,
|
|
284
|
+
[USER_ROLE.PARENT]: false,
|
|
281
285
|
}[userRole] || false);
|
|
282
286
|
}
|
|
283
287
|
if (moduleName === "Section") {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* DiscountCodeMoreActions
|
|
4
|
-
*
|
|
5
|
-
* Placeholder slot rendered inside the generic page's "more actions"
|
|
6
|
-
* area. Keep this file small — add any contextual bulk-actions here
|
|
7
|
-
* (export/import, bulk enable/disable) as the product requires.
|
|
8
|
-
*/
|
|
9
|
-
export declare const DiscountCodeMoreActions: React.FC;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useTranslations } from "next-intl";
|
|
3
|
-
/**
|
|
4
|
-
* DiscountCodeMoreActions
|
|
5
|
-
*
|
|
6
|
-
* Placeholder slot rendered inside the generic page's "more actions"
|
|
7
|
-
* area. Keep this file small — add any contextual bulk-actions here
|
|
8
|
-
* (export/import, bulk enable/disable) as the product requires.
|
|
9
|
-
*/
|
|
10
|
-
export const DiscountCodeMoreActions = () => {
|
|
11
|
-
const t = useTranslations("discountCode");
|
|
12
|
-
return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "text-sm text-muted-foreground", children: t("moreActionsInfo") }) }));
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const ExpenseMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,265 +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 { EXPENSE_API_ROUTES } from "../../constants";
|
|
11
|
-
import { EXPENSE_ACTION_TYPES, useExpenseContext } 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(`${EXPENSE_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, "expense.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(EXPENSE_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(EXPENSE_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 ExpenseMoreActions = () => {
|
|
82
|
-
const t = useTranslations("expense");
|
|
83
|
-
const { dispatch } = useExpenseContext();
|
|
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, _h, _j, _k;
|
|
93
|
-
const closeDrawer = () => {
|
|
94
|
-
dispatch({
|
|
95
|
-
type: EXPENSE_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.title) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
117
|
-
msgs.push(t("validationExpenseTitleRequired"));
|
|
118
|
-
if (!((_c = row.amount) === null || _c === void 0 ? void 0 : _c.trim()) ||
|
|
119
|
-
isNaN(Number(row.amount)) ||
|
|
120
|
-
Number(row.amount) < 0.01)
|
|
121
|
-
msgs.push(t("validationExpenseAmountRequired"));
|
|
122
|
-
if (!((_d = row.category) === null || _d === void 0 ? void 0 : _d.trim()))
|
|
123
|
-
msgs.push(t("validationExpenseCategoryRequired"));
|
|
124
|
-
if (!((_e = row.expenseDate) === null || _e === void 0 ? void 0 : _e.trim()))
|
|
125
|
-
msgs.push(t("validationExpenseExpenseDateRequired"));
|
|
126
|
-
if (!((_f = row.status) === null || _f === void 0 ? void 0 : _f.trim()))
|
|
127
|
-
msgs.push(t("validationExpenseStatusRequired"));
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
if (!((_g = row.id) === null || _g === void 0 ? void 0 : _g.trim()))
|
|
131
|
-
msgs.push(t("validationExpenseIdForUpdateRequired"));
|
|
132
|
-
}
|
|
133
|
-
if (msgs.length > 0) {
|
|
134
|
-
validationErrors.push({ row: i + 1, messages: msgs });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (validationErrors.length > 0) {
|
|
138
|
-
const summary = validationErrors
|
|
139
|
-
.slice(0, 5)
|
|
140
|
-
.map((e) => t("messagesBulkRowError", {
|
|
141
|
-
row: e.row,
|
|
142
|
-
error: e.messages.join("; "),
|
|
143
|
-
}))
|
|
144
|
-
.join("\n");
|
|
145
|
-
showErrorToast(t("messagesBulkValidationFailed", {
|
|
146
|
-
count: validationErrors.length,
|
|
147
|
-
errors: summary,
|
|
148
|
-
}));
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
|
|
153
|
-
let jobId;
|
|
154
|
-
try {
|
|
155
|
-
jobId = await submitBulkJob(text, method, signal);
|
|
156
|
-
}
|
|
157
|
-
catch (submitError) {
|
|
158
|
-
showErrorToast(t("messagesBulkJobSubmitFailed", {
|
|
159
|
-
action: label,
|
|
160
|
-
error: submitError instanceof Error
|
|
161
|
-
? submitError.message
|
|
162
|
-
: t("unknownError"),
|
|
163
|
-
}));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const status = await pollBulkJob(jobId, signal, (processed, total) => {
|
|
167
|
-
showInfoToast(t("messagesBulkProgress", { processed, total }));
|
|
168
|
-
});
|
|
169
|
-
if (signal.aborted)
|
|
170
|
-
return;
|
|
171
|
-
if (status.status === "completed") {
|
|
172
|
-
const r = status.results;
|
|
173
|
-
if (r && ((_h = r.errors) === null || _h === void 0 ? void 0 : _h.length) > 0) {
|
|
174
|
-
const summary = formatErrorSummary(t, r.errors);
|
|
175
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
176
|
-
created: r.created,
|
|
177
|
-
updated: r.updated,
|
|
178
|
-
skipped: r.skipped,
|
|
179
|
-
}) +
|
|
180
|
-
"\n" +
|
|
181
|
-
summary);
|
|
182
|
-
}
|
|
183
|
-
else if (r) {
|
|
184
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
185
|
-
created: r.created,
|
|
186
|
-
updated: r.updated,
|
|
187
|
-
skipped: r.skipped,
|
|
188
|
-
}));
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
showSuccessToast(t("messagesBulkSuccess"));
|
|
192
|
-
}
|
|
193
|
-
const schoolId = ((_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id) || "";
|
|
194
|
-
fetch(`${EXPENSE_API_ROUTES.UNIT}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
195
|
-
headers: {
|
|
196
|
-
"Content-Type": "application/json",
|
|
197
|
-
},
|
|
198
|
-
})
|
|
199
|
-
.then(async (res) => {
|
|
200
|
-
var _a, _b;
|
|
201
|
-
if (!res.ok)
|
|
202
|
-
return;
|
|
203
|
-
const data = await res.json();
|
|
204
|
-
dispatch({
|
|
205
|
-
type: EXPENSE_ACTION_TYPES.SET_ITEMS,
|
|
206
|
-
payload: {
|
|
207
|
-
items: (_a = data.items) !== null && _a !== void 0 ? _a : [],
|
|
208
|
-
count: (_b = data.count) !== null && _b !== void 0 ? _b : 0,
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
})
|
|
212
|
-
.catch(() => { });
|
|
213
|
-
closeDrawer();
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
const r = status.results;
|
|
217
|
-
const detail = ((_k = r === null || r === void 0 ? void 0 : r.errors) === null || _k === void 0 ? void 0 : _k.length)
|
|
218
|
-
? formatErrorSummary(t, r.errors)
|
|
219
|
-
: t("unknownError");
|
|
220
|
-
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
if (error.message === "Polling cancelled")
|
|
225
|
-
return;
|
|
226
|
-
showErrorToast(t("messagesBulkFailedDetail", {
|
|
227
|
-
action: label,
|
|
228
|
-
error: error instanceof Error ? error.message : t("unknownError"),
|
|
229
|
-
}));
|
|
230
|
-
}
|
|
231
|
-
}, [dispatch, t]);
|
|
232
|
-
const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
|
|
233
|
-
const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
|
|
234
|
-
const create = [
|
|
235
|
-
{
|
|
236
|
-
id: "1",
|
|
237
|
-
title: t("downloadEmptyCsvTemplate"),
|
|
238
|
-
handleOnClick: async () => {
|
|
239
|
-
var _a;
|
|
240
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
{ id: "2", title: t("addYourDataToTheCsv") },
|
|
244
|
-
{
|
|
245
|
-
id: "3",
|
|
246
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
247
|
-
},
|
|
248
|
-
];
|
|
249
|
-
const update = [
|
|
250
|
-
{
|
|
251
|
-
id: "1",
|
|
252
|
-
title: t("downloadPopulatedCsvTemplate"),
|
|
253
|
-
handleOnClick: async () => {
|
|
254
|
-
var _a;
|
|
255
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
{ id: "2", title: t("updateYourDataInTheCsv") },
|
|
259
|
-
{
|
|
260
|
-
id: "3",
|
|
261
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
262
|
-
},
|
|
263
|
-
];
|
|
264
|
-
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 })] }));
|
|
265
|
-
};
|