@appcorp/fusion-storybook 0.5.17 → 0.5.21
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/family/context.d.ts +13 -9
- package/base-modules/family/context.js +69 -75
- package/base-modules/family/page.js +11 -4
- package/base-modules/family/view.js +3 -2
- package/base-modules/family-member/constants.d.ts +8 -0
- package/base-modules/family-member/constants.js +12 -0
- package/base-modules/family-member/context.d.ts +12 -2
- package/base-modules/family-member/context.js +78 -81
- package/base-modules/family-member/date.d.ts +6 -0
- package/base-modules/family-member/date.js +13 -0
- package/base-modules/family-member/filter.js +1 -1
- package/base-modules/family-member/form.js +25 -2
- package/base-modules/family-member/page.js +12 -4
- package/base-modules/fee-structure/context/fee-structure-api-provider.js +48 -18
- package/base-modules/fee-structure/context/shared.d.ts +5 -0
- package/base-modules/fee-structure/context/shared.js +3 -0
- package/base-modules/fee-structure/context/use-fee-structure-module.d.ts +1 -0
- package/base-modules/fee-structure/context/use-fee-structure-module.js +35 -26
- package/base-modules/fee-structure/form.js +16 -48
- package/base-modules/fee-structure/more-actions.js +68 -14
- package/base-modules/fee-structure/page.js +52 -25
- package/base-modules/fee-structure/validate.d.ts +8 -1
- package/base-modules/fee-structure/validate.js +6 -1
- package/base-modules/fee-structure/view.js +20 -4
- package/base-modules/rbac/assign-permissions.js +5 -3
- package/base-modules/rbac/context.d.ts +8 -1
- package/base-modules/rbac/context.js +92 -65
- package/base-modules/rbac/page.js +6 -8
- package/constants.d.ts +5 -5
- package/constants.js +0 -4
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +3 -1
- package/base-modules/family/more-actions.d.ts +0 -1
- package/base-modules/family/more-actions.js +0 -255
- package/base-modules/family-member/more-actions.d.ts +0 -1
- package/base-modules/family-member/more-actions.js +0 -261
- package/base-modules/rbac/filter.d.ts +0 -1
- package/base-modules/rbac/filter.js +0 -20
- package/base-modules/rbac/more-actions.d.ts +0 -1
- package/base-modules/rbac/more-actions.js +0 -12
|
@@ -117,11 +117,13 @@ export function resolveRbacPermissions({ userRole, moduleName, }) {
|
|
|
117
117
|
[USER_ROLE.PARENT]: false,
|
|
118
118
|
}[userRole] || false);
|
|
119
119
|
}
|
|
120
|
+
// The API seed grants fee-structure READ_WRITE to STAFF, so the page must
|
|
121
|
+
// be reachable by the people who can operate it.
|
|
120
122
|
if (moduleName === "Fee Structure") {
|
|
121
123
|
return ({
|
|
122
124
|
[USER_ROLE.SUPER_ADMIN]: true,
|
|
123
125
|
[USER_ROLE.SCHOOL_ADMIN]: true,
|
|
124
|
-
[USER_ROLE.STAFF]:
|
|
126
|
+
[USER_ROLE.STAFF]: true,
|
|
125
127
|
[USER_ROLE.TEACHER]: false,
|
|
126
128
|
[USER_ROLE.STUDENT]: false,
|
|
127
129
|
[USER_ROLE.PARENT]: false,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const FamilyMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,255 +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 { FAMILY_API_ROUTES } from "../../constants";
|
|
11
|
-
import { FAMILY_ACTION_TYPES, useFamilyContext } 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(`${FAMILY_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, "family.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(FAMILY_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(FAMILY_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 FamilyMoreActions = () => {
|
|
82
|
-
const t = useTranslations("family");
|
|
83
|
-
const { dispatch } = useFamilyContext();
|
|
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;
|
|
93
|
-
const closeDrawer = () => {
|
|
94
|
-
dispatch({
|
|
95
|
-
type: FAMILY_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.familyCode) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
117
|
-
msgs.push(t("validationFamilyFamilyCodeRequired"));
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
if (!((_c = row.id) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
121
|
-
msgs.push(t("validationFamilyIdForUpdateRequired"));
|
|
122
|
-
}
|
|
123
|
-
if (msgs.length > 0) {
|
|
124
|
-
validationErrors.push({ row: i + 1, messages: msgs });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (validationErrors.length > 0) {
|
|
128
|
-
const summary = validationErrors
|
|
129
|
-
.slice(0, 5)
|
|
130
|
-
.map((e) => t("messagesBulkRowError", {
|
|
131
|
-
row: e.row,
|
|
132
|
-
error: e.messages.join("; "),
|
|
133
|
-
}))
|
|
134
|
-
.join("\n");
|
|
135
|
-
showErrorToast(t("messagesBulkValidationFailed", {
|
|
136
|
-
count: validationErrors.length,
|
|
137
|
-
errors: summary,
|
|
138
|
-
}));
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
|
|
143
|
-
let jobId;
|
|
144
|
-
try {
|
|
145
|
-
jobId = await submitBulkJob(text, method, signal);
|
|
146
|
-
}
|
|
147
|
-
catch (submitError) {
|
|
148
|
-
showErrorToast(t("messagesBulkJobSubmitFailed", {
|
|
149
|
-
action: label,
|
|
150
|
-
error: submitError instanceof Error
|
|
151
|
-
? submitError.message
|
|
152
|
-
: t("unknownError"),
|
|
153
|
-
}));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const status = await pollBulkJob(jobId, signal, (processed, total) => {
|
|
157
|
-
showInfoToast(t("messagesBulkProgress", { processed, total }));
|
|
158
|
-
});
|
|
159
|
-
if (signal.aborted)
|
|
160
|
-
return;
|
|
161
|
-
if (status.status === "completed") {
|
|
162
|
-
const r = status.results;
|
|
163
|
-
if (r && ((_d = r.errors) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
164
|
-
const summary = formatErrorSummary(t, r.errors);
|
|
165
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
166
|
-
created: r.created,
|
|
167
|
-
updated: r.updated,
|
|
168
|
-
skipped: r.skipped,
|
|
169
|
-
}) +
|
|
170
|
-
"\n" +
|
|
171
|
-
summary);
|
|
172
|
-
}
|
|
173
|
-
else if (r) {
|
|
174
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
175
|
-
created: r.created,
|
|
176
|
-
updated: r.updated,
|
|
177
|
-
skipped: r.skipped,
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
showSuccessToast(t("messagesBulkSuccess"));
|
|
182
|
-
}
|
|
183
|
-
const schoolId = ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id) || "";
|
|
184
|
-
fetch(`${FAMILY_API_ROUTES.UNIT}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
185
|
-
headers: {
|
|
186
|
-
"Content-Type": "application/json",
|
|
187
|
-
},
|
|
188
|
-
})
|
|
189
|
-
.then(async (res) => {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
if (!res.ok)
|
|
192
|
-
return;
|
|
193
|
-
const data = await res.json();
|
|
194
|
-
dispatch({
|
|
195
|
-
type: FAMILY_ACTION_TYPES.SET_ITEMS,
|
|
196
|
-
payload: {
|
|
197
|
-
items: (_a = data.items) !== null && _a !== void 0 ? _a : [],
|
|
198
|
-
count: (_b = data.count) !== null && _b !== void 0 ? _b : 0,
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
})
|
|
202
|
-
.catch(() => { });
|
|
203
|
-
closeDrawer();
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
const r = status.results;
|
|
207
|
-
const detail = ((_f = r === null || r === void 0 ? void 0 : r.errors) === null || _f === void 0 ? void 0 : _f.length)
|
|
208
|
-
? formatErrorSummary(t, r.errors)
|
|
209
|
-
: t("unknownError");
|
|
210
|
-
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
if (error.message === "Polling cancelled")
|
|
215
|
-
return;
|
|
216
|
-
showErrorToast(t("messagesBulkFailedDetail", {
|
|
217
|
-
action: label,
|
|
218
|
-
error: error instanceof Error ? error.message : t("unknownError"),
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
}, [dispatch, t]);
|
|
222
|
-
const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
|
|
223
|
-
const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
|
|
224
|
-
const create = [
|
|
225
|
-
{
|
|
226
|
-
id: "1",
|
|
227
|
-
title: t("downloadEmptyCsvTemplate"),
|
|
228
|
-
handleOnClick: async () => {
|
|
229
|
-
var _a;
|
|
230
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
{ id: "2", title: t("addYourDataToTheCsv") },
|
|
234
|
-
{
|
|
235
|
-
id: "3",
|
|
236
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
237
|
-
},
|
|
238
|
-
];
|
|
239
|
-
const update = [
|
|
240
|
-
{
|
|
241
|
-
id: "1",
|
|
242
|
-
title: t("downloadPopulatedCsvTemplate"),
|
|
243
|
-
handleOnClick: async () => {
|
|
244
|
-
var _a;
|
|
245
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
{ id: "2", title: t("updateYourDataInTheCsv") },
|
|
249
|
-
{
|
|
250
|
-
id: "3",
|
|
251
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
252
|
-
},
|
|
253
|
-
];
|
|
254
|
-
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 })] }));
|
|
255
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const FamilyMemberMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,261 +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 { FAMILY_MEMBER_API_ROUTES } from "../../constants";
|
|
11
|
-
import { FAMILY_MEMBER_ACTION_TYPES, useFamilyMemberContext } 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(`${FAMILY_MEMBER_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, "family-member.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(FAMILY_MEMBER_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(FAMILY_MEMBER_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 FamilyMemberMoreActions = () => {
|
|
82
|
-
const t = useTranslations("familyMember");
|
|
83
|
-
const { dispatch } = useFamilyMemberContext();
|
|
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;
|
|
93
|
-
const closeDrawer = () => {
|
|
94
|
-
dispatch({
|
|
95
|
-
type: FAMILY_MEMBER_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.familyId) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
117
|
-
msgs.push(t("validationFamilyMemberFamilyIdRequired"));
|
|
118
|
-
if (!((_c = row.firstName) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
119
|
-
msgs.push(t("validationFamilyMemberFirstNameRequired"));
|
|
120
|
-
if (!((_d = row.lastName) === null || _d === void 0 ? void 0 : _d.trim()))
|
|
121
|
-
msgs.push(t("validationFamilyMemberLastNameRequired"));
|
|
122
|
-
if (!((_e = row.role) === null || _e === void 0 ? void 0 : _e.trim()))
|
|
123
|
-
msgs.push(t("validationFamilyMemberRoleRequired"));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
if (!((_f = row.id) === null || _f === void 0 ? void 0 : _f.trim()))
|
|
127
|
-
msgs.push(t("validationFamilyMemberIdForUpdateRequired"));
|
|
128
|
-
}
|
|
129
|
-
if (msgs.length > 0) {
|
|
130
|
-
validationErrors.push({ row: i + 1, messages: msgs });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (validationErrors.length > 0) {
|
|
134
|
-
const summary = validationErrors
|
|
135
|
-
.slice(0, 5)
|
|
136
|
-
.map((e) => t("messagesBulkRowError", {
|
|
137
|
-
row: e.row,
|
|
138
|
-
error: e.messages.join("; "),
|
|
139
|
-
}))
|
|
140
|
-
.join("\n");
|
|
141
|
-
showErrorToast(t("messagesBulkValidationFailed", {
|
|
142
|
-
count: validationErrors.length,
|
|
143
|
-
errors: summary,
|
|
144
|
-
}));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
|
|
149
|
-
let jobId;
|
|
150
|
-
try {
|
|
151
|
-
jobId = await submitBulkJob(text, method, signal);
|
|
152
|
-
}
|
|
153
|
-
catch (submitError) {
|
|
154
|
-
showErrorToast(t("messagesBulkJobSubmitFailed", {
|
|
155
|
-
action: label,
|
|
156
|
-
error: submitError instanceof Error
|
|
157
|
-
? submitError.message
|
|
158
|
-
: t("unknownError"),
|
|
159
|
-
}));
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const status = await pollBulkJob(jobId, signal, (processed, total) => {
|
|
163
|
-
showInfoToast(t("messagesBulkProgress", { processed, total }));
|
|
164
|
-
});
|
|
165
|
-
if (signal.aborted)
|
|
166
|
-
return;
|
|
167
|
-
if (status.status === "completed") {
|
|
168
|
-
const r = status.results;
|
|
169
|
-
if (r && ((_g = r.errors) === null || _g === void 0 ? void 0 : _g.length) > 0) {
|
|
170
|
-
const summary = formatErrorSummary(t, r.errors);
|
|
171
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
172
|
-
created: r.created,
|
|
173
|
-
updated: r.updated,
|
|
174
|
-
skipped: r.skipped,
|
|
175
|
-
}) +
|
|
176
|
-
"\n" +
|
|
177
|
-
summary);
|
|
178
|
-
}
|
|
179
|
-
else if (r) {
|
|
180
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
181
|
-
created: r.created,
|
|
182
|
-
updated: r.updated,
|
|
183
|
-
skipped: r.skipped,
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
showSuccessToast(t("messagesBulkSuccess"));
|
|
188
|
-
}
|
|
189
|
-
const schoolId = ((_h = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _h === void 0 ? void 0 : _h.id) || "";
|
|
190
|
-
fetch(`${FAMILY_MEMBER_API_ROUTES.UNIT}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
191
|
-
headers: {
|
|
192
|
-
"Content-Type": "application/json",
|
|
193
|
-
},
|
|
194
|
-
})
|
|
195
|
-
.then(async (res) => {
|
|
196
|
-
var _a, _b;
|
|
197
|
-
if (!res.ok)
|
|
198
|
-
return;
|
|
199
|
-
const data = await res.json();
|
|
200
|
-
dispatch({
|
|
201
|
-
type: FAMILY_MEMBER_ACTION_TYPES.SET_ITEMS,
|
|
202
|
-
payload: {
|
|
203
|
-
items: (_a = data.items) !== null && _a !== void 0 ? _a : [],
|
|
204
|
-
count: (_b = data.count) !== null && _b !== void 0 ? _b : 0,
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
})
|
|
208
|
-
.catch(() => { });
|
|
209
|
-
closeDrawer();
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
const r = status.results;
|
|
213
|
-
const detail = ((_j = r === null || r === void 0 ? void 0 : r.errors) === null || _j === void 0 ? void 0 : _j.length)
|
|
214
|
-
? formatErrorSummary(t, r.errors)
|
|
215
|
-
: t("unknownError");
|
|
216
|
-
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
if (error.message === "Polling cancelled")
|
|
221
|
-
return;
|
|
222
|
-
showErrorToast(t("messagesBulkFailedDetail", {
|
|
223
|
-
action: label,
|
|
224
|
-
error: error instanceof Error ? error.message : t("unknownError"),
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
}, [dispatch, t]);
|
|
228
|
-
const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
|
|
229
|
-
const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
|
|
230
|
-
const create = [
|
|
231
|
-
{
|
|
232
|
-
id: "1",
|
|
233
|
-
title: t("downloadEmptyCsvTemplate"),
|
|
234
|
-
handleOnClick: async () => {
|
|
235
|
-
var _a;
|
|
236
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
{ id: "2", title: t("addYourDataToTheCsv") },
|
|
240
|
-
{
|
|
241
|
-
id: "3",
|
|
242
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
243
|
-
},
|
|
244
|
-
];
|
|
245
|
-
const update = [
|
|
246
|
-
{
|
|
247
|
-
id: "1",
|
|
248
|
-
title: t("downloadPopulatedCsvTemplate"),
|
|
249
|
-
handleOnClick: async () => {
|
|
250
|
-
var _a;
|
|
251
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
{ id: "2", title: t("updateYourDataInTheCsv") },
|
|
255
|
-
{
|
|
256
|
-
id: "3",
|
|
257
|
-
title: t("uploadTheCompletedCsvToTheSystem"),
|
|
258
|
-
},
|
|
259
|
-
];
|
|
260
|
-
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 })] }));
|
|
261
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const RbacFilter: () => import("react").JSX.Element;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
/**
|
|
4
|
-
* RBAC Filter Component
|
|
5
|
-
*
|
|
6
|
-
* Filter UI for the RBAC module. Currently a placeholder
|
|
7
|
-
* since roles don't have enabled/status fields.
|
|
8
|
-
*/
|
|
9
|
-
import { useRbacModule } from "./context";
|
|
10
|
-
import { useTranslations } from "next-intl";
|
|
11
|
-
export const RbacFilter = () => {
|
|
12
|
-
const { applyFilters, clearFilters, closeDrawer } = useRbacModule();
|
|
13
|
-
const t = useTranslations("rbac");
|
|
14
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: t("filterTextDescription") }), _jsxs("div", { className: "mt-4 flex gap-2", children: [_jsx("button", { className: "text-muted-foreground text-sm underline", onClick: () => {
|
|
15
|
-
clearFilters();
|
|
16
|
-
closeDrawer();
|
|
17
|
-
}, children: t("drawerButtonClearFilter") }), _jsx("button", { className: "text-sm underline", onClick: () => {
|
|
18
|
-
applyFilters();
|
|
19
|
-
}, children: t("drawerButtonApply") })] })] }));
|
|
20
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const RbacMoreActions: () => import("react").JSX.Element;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
/**
|
|
4
|
-
* RBAC More Actions Component
|
|
5
|
-
*
|
|
6
|
-
* Placeholder for additional actions like bulk operations, exports, etc.
|
|
7
|
-
*/
|
|
8
|
-
import { useTranslations } from "next-intl";
|
|
9
|
-
export const RbacMoreActions = () => {
|
|
10
|
-
const t = useTranslations("rbac");
|
|
11
|
-
return (_jsx("div", { className: "space-y-4", children: _jsx("p", { className: "text-muted-foreground text-sm", children: t("moreActionsTextPlaceholder") }) }));
|
|
12
|
-
};
|