@appcorp/fusion-storybook 0.5.9 → 0.5.13
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/attendance/context/use-attendance-module.d.ts +60 -0
- package/base-modules/attendance/context/use-attendance-module.js +449 -0
- package/base-modules/attendance/context.d.ts +36 -52
- package/base-modules/attendance/context.js +22 -376
- package/base-modules/attendance/date.d.ts +10 -0
- package/base-modules/attendance/date.js +23 -0
- package/base-modules/attendance/filter.js +22 -6
- package/base-modules/attendance/form.js +53 -42
- package/base-modules/attendance/more-actions.js +10 -233
- package/base-modules/attendance/page.js +45 -31
- package/base-modules/attendance/validate.d.ts +3 -1
- package/base-modules/attendance/validate.js +7 -2
- package/base-modules/attendance/view.js +18 -9
- package/base-modules/campus/context/use-campus-module.d.ts +57 -0
- package/base-modules/campus/context/use-campus-module.js +447 -0
- package/base-modules/campus/context.d.ts +21 -54
- package/base-modules/campus/context.js +18 -442
- package/base-modules/campus/filter.js +1 -1
- package/base-modules/campus/form.js +6 -4
- package/base-modules/campus/page.d.ts +0 -2
- package/base-modules/campus/page.js +10 -18
- package/base-modules/campus/validate.js +4 -1
- package/base-modules/campus/view.js +2 -2
- package/constants.d.ts +3 -3
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +0 -1
- package/utils/resolve-rbac-permissions.js +5 -4
- package/base-modules/campus/more-actions.d.ts +0 -1
- package/base-modules/campus/more-actions.js +0 -40
|
@@ -1,85 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
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
3
|
import { showErrorToast, showSuccessToast, showInfoToast, } from "@appcorp/shadcn/lib/toast-utils";
|
|
5
4
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
6
|
-
import converter from "json-2-csv";
|
|
7
5
|
import { useTranslations } from "next-intl";
|
|
8
|
-
import { pageLimit } from "./constants";
|
|
9
6
|
import { ATTENDANCE_API_ROUTES } from "../../constants";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { useAttendanceModule } from "./context";
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
12
9
|
import { Button } from "@appcorp/shadcn/components/ui/button";
|
|
13
10
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
14
11
|
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
15
|
-
const workspace = getCachedWorkspaceSync();
|
|
16
12
|
const POLL_INTERVAL_MS = 2000;
|
|
17
13
|
const POLL_TIMEOUT_MS = 300000;
|
|
18
|
-
const handleGetAllRecords = async (schoolId, pageLimit) => {
|
|
19
|
-
const response = await fetch(`${ATTENDANCE_API_ROUTES.UNIT}?pageLimit=${pageLimit}¤tPage=1&schoolId=${schoolId}`);
|
|
20
|
-
const result = await response.json();
|
|
21
|
-
const csv = await converter.json2csv(result.items || [], {});
|
|
22
|
-
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
23
|
-
await downloadFromUrl(blob, "attendance.csv");
|
|
24
|
-
};
|
|
25
|
-
async function submitBulkJob(csvData, method, signal) {
|
|
26
|
-
var _a;
|
|
27
|
-
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
28
|
-
if (!schoolId)
|
|
29
|
-
throw new Error("School ID not found");
|
|
30
|
-
const res = await fetch(ATTENDANCE_API_ROUTES.BULK, {
|
|
31
|
-
method,
|
|
32
|
-
headers: {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({ schoolId, csvData }),
|
|
36
|
-
signal,
|
|
37
|
-
});
|
|
38
|
-
if (!res.ok) {
|
|
39
|
-
const errorData = (await res.json().catch(() => ({})));
|
|
40
|
-
throw new Error(errorData.error || `Bulk operation failed with status ${res.status}`);
|
|
41
|
-
}
|
|
42
|
-
const data = (await res.json());
|
|
43
|
-
return data.jobId;
|
|
44
|
-
}
|
|
45
|
-
async function pollBulkJob(jobId, signal, onProgress) {
|
|
46
|
-
const startTime = Date.now();
|
|
47
|
-
let lastProgressToast = 0;
|
|
48
|
-
while (true) {
|
|
49
|
-
if (signal.aborted)
|
|
50
|
-
throw new Error("Polling cancelled");
|
|
51
|
-
if (Date.now() - startTime > POLL_TIMEOUT_MS) {
|
|
52
|
-
throw new Error("Bulk operation timed out");
|
|
53
|
-
}
|
|
54
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
55
|
-
if (signal.aborted)
|
|
56
|
-
throw new Error("Polling cancelled");
|
|
57
|
-
const res = await fetch(ATTENDANCE_API_ROUTES.BULK_STATUS(jobId), {
|
|
58
|
-
signal,
|
|
59
|
-
});
|
|
60
|
-
if (!res.ok)
|
|
61
|
-
continue;
|
|
62
|
-
const data = (await res.json());
|
|
63
|
-
if (data.status === "completed" || data.status === "failed") {
|
|
64
|
-
return data;
|
|
65
|
-
}
|
|
66
|
-
if (data.status === "running" && Date.now() - lastProgressToast > 10000) {
|
|
67
|
-
lastProgressToast = Date.now();
|
|
68
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress(data.processed, data.total);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function formatErrorSummary(t, errors) {
|
|
73
|
-
if (!(errors === null || errors === void 0 ? void 0 : errors.length))
|
|
74
|
-
return "";
|
|
75
|
-
const lines = errors
|
|
76
|
-
.slice(0, 5)
|
|
77
|
-
.map((e) => t("messagesBulkRowError", { row: e.row, error: e.error }));
|
|
78
|
-
const remaining = errors.length - 5;
|
|
79
|
-
if (remaining > 0)
|
|
80
|
-
lines.push(t("messagesBulkMoreRows", { count: remaining }));
|
|
81
|
-
return lines.join("\n");
|
|
82
|
-
}
|
|
83
14
|
function formatAutoPostErrorSummary(t, errors) {
|
|
84
15
|
if (!(errors === null || errors === void 0 ? void 0 : errors.length))
|
|
85
16
|
return "";
|
|
@@ -118,8 +49,10 @@ async function pollAutoPostJob(statusUrl, signal, onProgress) {
|
|
|
118
49
|
}
|
|
119
50
|
}
|
|
120
51
|
export const AttendanceMoreActions = () => {
|
|
52
|
+
var _a;
|
|
121
53
|
const t = useTranslations("attendance");
|
|
122
|
-
const
|
|
54
|
+
const workspace = getCachedWorkspaceSync();
|
|
55
|
+
const { closeDrawer, listFetchNow } = useAttendanceModule();
|
|
123
56
|
const abortRef = useRef(null);
|
|
124
57
|
const [autoPostDate, setAutoPostDate] = useState(new Date().toISOString().split("T")[0]);
|
|
125
58
|
const [absentText, setAbsentText] = useState("");
|
|
@@ -133,168 +66,11 @@ export const AttendanceMoreActions = () => {
|
|
|
133
66
|
(_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
|
|
134
67
|
};
|
|
135
68
|
}, []);
|
|
136
|
-
const handleBulkFlow = useCallback(async (files, method) => {
|
|
137
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
138
|
-
const closeDrawer = () => {
|
|
139
|
-
dispatch({
|
|
140
|
-
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
141
|
-
payload: { drawer: null },
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
(_a = abortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
|
|
145
|
-
const controller = new AbortController();
|
|
146
|
-
abortRef.current = controller;
|
|
147
|
-
const { signal } = controller;
|
|
148
|
-
const label = method === "POST" ? "create" : "update";
|
|
149
|
-
const file = files[0];
|
|
150
|
-
const text = await file.text();
|
|
151
|
-
const records = converter.csv2json(text);
|
|
152
|
-
if (!Array.isArray(records) || records.length === 0) {
|
|
153
|
-
showErrorToast(t("messagesBulkCsvEmpty"));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const validationErrors = [];
|
|
157
|
-
for (let i = 0; i < records.length; i++) {
|
|
158
|
-
const row = records[i];
|
|
159
|
-
const msgs = [];
|
|
160
|
-
if (method === "POST") {
|
|
161
|
-
if (!((_b = row.date) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
162
|
-
msgs.push(t("validationRequiredDate"));
|
|
163
|
-
if (!((_c = row.status) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
164
|
-
msgs.push(t("validationRequiredStatus"));
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
if (!((_d = row.id) === null || _d === void 0 ? void 0 : _d.trim()))
|
|
168
|
-
msgs.push(t("validationRequiredIdForUpdate"));
|
|
169
|
-
}
|
|
170
|
-
if (msgs.length > 0) {
|
|
171
|
-
validationErrors.push({ row: i + 1, messages: msgs });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (validationErrors.length > 0) {
|
|
175
|
-
const summary = validationErrors
|
|
176
|
-
.slice(0, 5)
|
|
177
|
-
.map((e) => t("messagesBulkRowError", {
|
|
178
|
-
row: e.row,
|
|
179
|
-
error: e.messages.join("; "),
|
|
180
|
-
}))
|
|
181
|
-
.join("\n");
|
|
182
|
-
showErrorToast(t("messagesBulkValidationFailed", {
|
|
183
|
-
count: validationErrors.length,
|
|
184
|
-
errors: summary,
|
|
185
|
-
}));
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
|
|
190
|
-
let jobId;
|
|
191
|
-
try {
|
|
192
|
-
jobId = await submitBulkJob(text, method, signal);
|
|
193
|
-
}
|
|
194
|
-
catch (submitError) {
|
|
195
|
-
showErrorToast(t("messagesBulkJobSubmitFailed", {
|
|
196
|
-
action: label,
|
|
197
|
-
error: submitError instanceof Error
|
|
198
|
-
? submitError.message
|
|
199
|
-
: t("unknownError"),
|
|
200
|
-
}));
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
const status = await pollBulkJob(jobId, signal, (processed, total) => {
|
|
204
|
-
showInfoToast(t("messagesBulkProgress", { processed, total }));
|
|
205
|
-
});
|
|
206
|
-
if (signal.aborted)
|
|
207
|
-
return;
|
|
208
|
-
if (status.status === "completed") {
|
|
209
|
-
const r = status.results;
|
|
210
|
-
if (r && ((_e = r.errors) === null || _e === void 0 ? void 0 : _e.length) > 0) {
|
|
211
|
-
const summary = formatErrorSummary(t, r.errors);
|
|
212
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
213
|
-
created: r.created,
|
|
214
|
-
updated: r.updated,
|
|
215
|
-
skipped: r.skipped,
|
|
216
|
-
}) +
|
|
217
|
-
"\n" +
|
|
218
|
-
summary);
|
|
219
|
-
}
|
|
220
|
-
else if (r) {
|
|
221
|
-
showSuccessToast(t("messagesBulkResults", {
|
|
222
|
-
created: r.created,
|
|
223
|
-
updated: r.updated,
|
|
224
|
-
skipped: r.skipped,
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
showSuccessToast(t("messagesBulkSuccess"));
|
|
229
|
-
}
|
|
230
|
-
const schoolId = ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id) || "";
|
|
231
|
-
fetch(`${ATTENDANCE_API_ROUTES.UNIT}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
232
|
-
headers: {
|
|
233
|
-
"Content-Type": "application/json",
|
|
234
|
-
},
|
|
235
|
-
})
|
|
236
|
-
.then(async (res) => {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
if (!res.ok)
|
|
239
|
-
return;
|
|
240
|
-
const data = await res.json();
|
|
241
|
-
dispatch({
|
|
242
|
-
type: ATTENDANCE_ACTION_TYPES.SET_ITEMS,
|
|
243
|
-
payload: {
|
|
244
|
-
items: (_a = data.items) !== null && _a !== void 0 ? _a : [],
|
|
245
|
-
count: (_b = data.count) !== null && _b !== void 0 ? _b : 0,
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
})
|
|
249
|
-
.catch(() => { });
|
|
250
|
-
closeDrawer();
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
const r = status.results;
|
|
254
|
-
const detail = ((_g = r === null || r === void 0 ? void 0 : r.errors) === null || _g === void 0 ? void 0 : _g.length)
|
|
255
|
-
? formatErrorSummary(t, r.errors)
|
|
256
|
-
: t("unknownError");
|
|
257
|
-
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
if (error.message === "Polling cancelled")
|
|
262
|
-
return;
|
|
263
|
-
showErrorToast(t("messagesBulkFailedDetail", {
|
|
264
|
-
action: label,
|
|
265
|
-
error: error instanceof Error ? error.message : t("unknownError"),
|
|
266
|
-
}));
|
|
267
|
-
}
|
|
268
|
-
}, [dispatch, t]);
|
|
269
|
-
const closeDrawer = useCallback(() => {
|
|
270
|
-
dispatch({
|
|
271
|
-
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
272
|
-
payload: { drawer: null },
|
|
273
|
-
});
|
|
274
|
-
}, [dispatch]);
|
|
275
|
-
const refreshList = useCallback(() => {
|
|
276
|
-
var _a;
|
|
277
|
-
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
278
|
-
fetch(`${ATTENDANCE_API_ROUTES.UNIT}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
279
|
-
headers: { "Content-Type": "application/json" },
|
|
280
|
-
})
|
|
281
|
-
.then(async (res) => {
|
|
282
|
-
var _a, _b;
|
|
283
|
-
if (!res.ok)
|
|
284
|
-
return;
|
|
285
|
-
const data = await res.json();
|
|
286
|
-
dispatch({
|
|
287
|
-
type: ATTENDANCE_ACTION_TYPES.SET_ITEMS,
|
|
288
|
-
payload: { items: (_a = data.items) !== null && _a !== void 0 ? _a : [], count: (_b = data.count) !== null && _b !== void 0 ? _b : 0 },
|
|
289
|
-
});
|
|
290
|
-
})
|
|
291
|
-
.catch(() => { });
|
|
292
|
-
}, [dispatch]);
|
|
293
69
|
const handleAutoPost = useCallback(async () => {
|
|
294
70
|
var _a, _b, _c, _d;
|
|
295
71
|
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
296
72
|
if (!schoolId) {
|
|
297
|
-
showErrorToast("
|
|
73
|
+
showErrorToast(t("messagesNetworkError"));
|
|
298
74
|
return;
|
|
299
75
|
}
|
|
300
76
|
if (!autoPostDate) {
|
|
@@ -395,7 +171,7 @@ export const AttendanceMoreActions = () => {
|
|
|
395
171
|
else {
|
|
396
172
|
showSuccessToast(t("messagesAutoPostSuccess"));
|
|
397
173
|
}
|
|
398
|
-
|
|
174
|
+
listFetchNow();
|
|
399
175
|
closeDrawer();
|
|
400
176
|
}
|
|
401
177
|
else {
|
|
@@ -419,7 +195,8 @@ export const AttendanceMoreActions = () => {
|
|
|
419
195
|
}, [
|
|
420
196
|
t,
|
|
421
197
|
closeDrawer,
|
|
422
|
-
|
|
198
|
+
listFetchNow,
|
|
199
|
+
(_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
423
200
|
autoPostDate,
|
|
424
201
|
absentText,
|
|
425
202
|
lateText,
|
|
@@ -432,5 +209,5 @@ export const AttendanceMoreActions = () => {
|
|
|
432
209
|
excusedText.trim() !== "" ||
|
|
433
210
|
halfDayText.trim() !== "") &&
|
|
434
211
|
!autoPostSubmitting;
|
|
435
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-sm font-semibold", children: t("actionsButtonAutoPost") }), _jsx(EnhancedInput, { id: "autoPostDate", info: t("formAutoPostDateInfo"), label: t("formAutoPostDateLabel"), onChange: (e) => setAutoPostDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: autoPostDate }), _jsx(EnhancedTextarea, { id: "autoPostAbsent", info: t("formAutoPostAbsentInfo"), label: t("formAutoPostAbsentLabel"), onChange: (e) => setAbsentText(e.target.value), placeholder: t("formAutoPostAbsentPlaceholder"), rows: 6, value: absentText }), _jsx(EnhancedTextarea, { id: "autoPostLate", info: t("formAutoPostLateInfo"), label: t("formAutoPostLateLabel"), onChange: (e) => setLateText(e.target.value), placeholder: t("formAutoPostLatePlaceholder"), rows: 6, value: lateText }), _jsx(EnhancedTextarea, { id: "autoPostExcused", info: t("formAutoPostExcusedInfo"), label: t("formAutoPostExcusedLabel"), onChange: (e) => setExcusedText(e.target.value), placeholder: t("formAutoPostExcusedPlaceholder"), rows: 6, value: excusedText }), _jsx(EnhancedTextarea, { id: "autoPostHalfDay", info: t("formAutoPostHalfDayInfo"), label: t("formAutoPostHalfDayLabel"), onChange: (e) => setHalfDayText(e.target.value), placeholder: t("formAutoPostHalfDayPlaceholder"), rows: 6, value: halfDayText }), _jsx(Button, { disabled: !canAutoPost, onClick: handleAutoPost, children: t("actionsButtonAutoPost") })] }));
|
|
212
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-sm font-semibold", children: t("actionsButtonAutoPost") }), _jsx("p", { className: "text-muted-foreground text-sm", children: t("autoPostDescription") }), _jsx(EnhancedInput, { id: "autoPostDate", info: t("formAutoPostDateInfo"), label: t("formAutoPostDateLabel"), onChange: (e) => setAutoPostDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: autoPostDate }), _jsx(EnhancedTextarea, { id: "autoPostAbsent", info: t("formAutoPostAbsentInfo"), label: t("formAutoPostAbsentLabel"), onChange: (e) => setAbsentText(e.target.value), placeholder: t("formAutoPostAbsentPlaceholder"), rows: 6, value: absentText }), _jsx(EnhancedTextarea, { id: "autoPostLate", info: t("formAutoPostLateInfo"), label: t("formAutoPostLateLabel"), onChange: (e) => setLateText(e.target.value), placeholder: t("formAutoPostLatePlaceholder"), rows: 6, value: lateText }), _jsx(EnhancedTextarea, { id: "autoPostExcused", info: t("formAutoPostExcusedInfo"), label: t("formAutoPostExcusedLabel"), onChange: (e) => setExcusedText(e.target.value), placeholder: t("formAutoPostExcusedPlaceholder"), rows: 6, value: excusedText }), _jsx(EnhancedTextarea, { id: "autoPostHalfDay", info: t("formAutoPostHalfDayInfo"), label: t("formAutoPostHalfDayLabel"), onChange: (e) => setHalfDayText(e.target.value), placeholder: t("formAutoPostHalfDayPlaceholder"), rows: 6, value: halfDayText }), _jsx(Button, { disabled: !canAutoPost, onClick: handleAutoPost, children: t("actionsButtonAutoPost") })] }));
|
|
436
213
|
};
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"use client";
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
import { useMemo } from "react";
|
|
17
|
+
import { useTranslations } from "next-intl";
|
|
17
18
|
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
18
19
|
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
19
|
-
import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
|
|
20
20
|
import { useAttendanceModule, AttendanceProvider, ATTENDANCE_ACTION_TYPES, } from "./context";
|
|
21
21
|
import { AttendanceFilter } from "./filter";
|
|
22
22
|
import { AttendanceForm } from "./form";
|
|
@@ -24,39 +24,10 @@ import { AttendanceMoreActions } from "./more-actions";
|
|
|
24
24
|
import { AttendanceView } from "./view";
|
|
25
25
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
26
26
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
27
|
+
import { formatAttendanceDate } from "./date";
|
|
27
28
|
// ============================================================================
|
|
28
29
|
// TABLE COLUMN CONFIGURATION (static — no runtime deps)
|
|
29
30
|
// ============================================================================
|
|
30
|
-
const tableBodyCols = [
|
|
31
|
-
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
32
|
-
{
|
|
33
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
34
|
-
key: "date",
|
|
35
|
-
textFormatter: (_, row) => {
|
|
36
|
-
var _a, _b, _c, _d, _e;
|
|
37
|
-
const attendance = row;
|
|
38
|
-
console.log("attendance", attendance);
|
|
39
|
-
return (`${(_b = (_a = attendance.studentProfile) === null || _a === void 0 ? void 0 : _a.familyMember) === null || _b === void 0 ? void 0 : _b.firstName} ${(_d = (_c = attendance.studentProfile) === null || _c === void 0 ? void 0 : _c.familyMember) === null || _d === void 0 ? void 0 : _d.lastName} - ${(_e = attendance.studentProfile) === null || _e === void 0 ? void 0 : _e.computerNumber.split(":")[1]}` ||
|
|
40
|
-
"N/A");
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
45
|
-
key: "date",
|
|
46
|
-
textFormatter: (_, row) => {
|
|
47
|
-
const val = row.date;
|
|
48
|
-
return val ? formatDate(val, DATE_FORMATS.LOCALE_DATE) : "N/A";
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{ componentType: COMPONENT_TYPE.TEXT, key: "status" },
|
|
52
|
-
{
|
|
53
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
54
|
-
key: "remarks",
|
|
55
|
-
textFormatter: (value) => value || "N/A",
|
|
56
|
-
},
|
|
57
|
-
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
58
|
-
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
59
|
-
];
|
|
60
31
|
// ============================================================================
|
|
61
32
|
// COMPONENT INSTANCES (memoized — no runtime deps)
|
|
62
33
|
// ============================================================================
|
|
@@ -106,6 +77,49 @@ const createAttendanceConfig = ({ cancelLabel, dispatch, drawerFilterDescription
|
|
|
106
77
|
const GenericAttendancePage = createGenericModulePage();
|
|
107
78
|
const AttendancePageInner = (props) => {
|
|
108
79
|
const context = useAttendanceModule();
|
|
80
|
+
const t = useTranslations("attendance");
|
|
81
|
+
const statusLabels = useMemo(() => ({
|
|
82
|
+
PRESENT: t("formOptionPresent"),
|
|
83
|
+
ABSENT: t("formOptionAbsent"),
|
|
84
|
+
LATE: t("formOptionLate"),
|
|
85
|
+
EXCUSED: t("formOptionExcused"),
|
|
86
|
+
HALF_DAY: t("formOptionHalfDay"),
|
|
87
|
+
}), [t]);
|
|
88
|
+
const tableBodyCols = useMemo(() => [
|
|
89
|
+
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
90
|
+
{
|
|
91
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
92
|
+
key: "studentProfile",
|
|
93
|
+
textFormatter: (_, row) => {
|
|
94
|
+
var _a, _b, _c;
|
|
95
|
+
const profile = row.studentProfile;
|
|
96
|
+
const member = profile === null || profile === void 0 ? void 0 : profile.familyMember;
|
|
97
|
+
const name = `${(_a = member === null || member === void 0 ? void 0 : member.firstName) !== null && _a !== void 0 ? _a : ""} ${(_b = member === null || member === void 0 ? void 0 : member.lastName) !== null && _b !== void 0 ? _b : ""}`.trim();
|
|
98
|
+
const rawNumber = (_c = profile === null || profile === void 0 ? void 0 : profile.computerNumber) !== null && _c !== void 0 ? _c : "";
|
|
99
|
+
const number = rawNumber.split(":")[1] || rawNumber;
|
|
100
|
+
return ([name, number].filter(Boolean).join(" — ") ||
|
|
101
|
+
(profile === null || profile === void 0 ? void 0 : profile.studentCode) ||
|
|
102
|
+
"—");
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
107
|
+
key: "date",
|
|
108
|
+
textFormatter: (value) => formatAttendanceDate(value),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
112
|
+
key: "status",
|
|
113
|
+
textFormatter: (value) => { var _a; return (_a = statusLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : String(value !== null && value !== void 0 ? value : "—"); },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
117
|
+
key: "remarks",
|
|
118
|
+
textFormatter: (value) => value || "—",
|
|
119
|
+
},
|
|
120
|
+
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
121
|
+
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
122
|
+
], [statusLabels]);
|
|
109
123
|
const components = useMemo(() => createComponentInstances(), []);
|
|
110
124
|
const attendanceConfig = useMemo(() => createAttendanceConfig({
|
|
111
125
|
dispatch: context.dispatch,
|
|
@@ -2,12 +2,14 @@ import { z } from "zod";
|
|
|
2
2
|
import { ATTENDANCE_STATUS } from "../../type";
|
|
3
3
|
export declare const VALIDATION_KEYS: {
|
|
4
4
|
readonly date: "validationRequiredDate";
|
|
5
|
+
readonly invalidDate: "validationInvalidDate";
|
|
5
6
|
readonly status: "validationRequiredStatus";
|
|
7
|
+
readonly studentProfileId: "validationRequiredStudent";
|
|
6
8
|
};
|
|
7
9
|
export declare const attendanceFormValidation: z.ZodObject<{
|
|
8
10
|
date: z.ZodString;
|
|
9
11
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
10
12
|
remarks: z.ZodOptional<z.ZodString>;
|
|
11
13
|
status: z.ZodEnum<typeof ATTENDANCE_STATUS>;
|
|
12
|
-
studentProfileId: z.
|
|
14
|
+
studentProfileId: z.ZodString;
|
|
13
15
|
}, z.core.$strip>;
|
|
@@ -2,12 +2,17 @@ import { z } from "zod";
|
|
|
2
2
|
import { ATTENDANCE_STATUS } from "../../type";
|
|
3
3
|
export const VALIDATION_KEYS = {
|
|
4
4
|
date: "validationRequiredDate",
|
|
5
|
+
invalidDate: "validationInvalidDate",
|
|
5
6
|
status: "validationRequiredStatus",
|
|
7
|
+
studentProfileId: "validationRequiredStudent",
|
|
6
8
|
};
|
|
7
9
|
export const attendanceFormValidation = z.object({
|
|
8
|
-
date: z
|
|
10
|
+
date: z
|
|
11
|
+
.string()
|
|
12
|
+
.min(1, VALIDATION_KEYS.date)
|
|
13
|
+
.refine((value) => !Number.isNaN(new Date(value).getTime()), VALIDATION_KEYS.invalidDate),
|
|
9
14
|
enabled: z.boolean().optional(),
|
|
10
15
|
remarks: z.string().optional(),
|
|
11
16
|
status: z.nativeEnum(ATTENDANCE_STATUS, { error: VALIDATION_KEYS.status }),
|
|
12
|
-
studentProfileId: z.string().
|
|
17
|
+
studentProfileId: z.string().min(1, VALIDATION_KEYS.studentProfileId),
|
|
13
18
|
});
|
|
@@ -12,18 +12,27 @@ import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
|
12
12
|
import { CalendarDays, CheckCircle2, ClipboardList, FileText, User, XCircle, } from "lucide-react";
|
|
13
13
|
import { useTranslations } from "next-intl";
|
|
14
14
|
import { getCachedStudentProfileById } from "../student-profile/cache";
|
|
15
|
-
import {
|
|
15
|
+
import { formatAttendanceDate } from "./date";
|
|
16
16
|
export const AttendanceView = () => {
|
|
17
|
-
var _a, _b, _c, _d;
|
|
17
|
+
var _a, _b, _c, _d, _e, _f;
|
|
18
18
|
const { state } = useAttendanceModule();
|
|
19
|
-
const { date, enabled, remarks, status, studentProfileId } = state;
|
|
19
|
+
const { date, enabled, remarks, status, studentProfile, studentProfileId } = state;
|
|
20
20
|
const t = useTranslations("attendance");
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const statusLabels = {
|
|
22
|
+
PRESENT: t("formOptionPresent"),
|
|
23
|
+
ABSENT: t("formOptionAbsent"),
|
|
24
|
+
LATE: t("formOptionLate"),
|
|
25
|
+
EXCUSED: t("formOptionExcused"),
|
|
26
|
+
HALF_DAY: t("formOptionHalfDay"),
|
|
27
|
+
};
|
|
28
|
+
// The detail fetch includes the student; the cache is only a fallback for
|
|
29
|
+
// records opened from an older response.
|
|
30
|
+
const profile = studentProfile !== null && studentProfile !== void 0 ? studentProfile : getCachedStudentProfileById(studentProfileId);
|
|
31
|
+
const studentName = profile
|
|
32
|
+
? `${(_b = (_a = profile.familyMember) === null || _a === void 0 ? void 0 : _a.firstName) !== null && _b !== void 0 ? _b : ""} ${(_d = (_c = profile.familyMember) === null || _c === void 0 ? void 0 : _c.lastName) !== null && _d !== void 0 ? _d : ""}`.trim() ||
|
|
33
|
+
profile.studentCode
|
|
25
34
|
: studentProfileId || "—";
|
|
26
|
-
const formattedDate =
|
|
27
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(ClipboardList, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionAttendanceDetails") })] }), _jsx(CardDescription, { children: t("viewSectionAttendanceRecordDetails") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(User, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStudent") })] }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CalendarDays, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldDate") })] }), _jsx("p", { className: "text-base", children: formattedDate })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: "secondary", children: status
|
|
35
|
+
const formattedDate = formatAttendanceDate(date);
|
|
36
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(ClipboardList, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionAttendanceDetails") })] }), _jsx(CardDescription, { children: t("viewSectionAttendanceRecordDetails") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(User, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStudent") })] }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CalendarDays, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldDate") })] }), _jsx("p", { className: "text-base", children: formattedDate })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: "secondary", children: (_f = (_e = statusLabels[status]) !== null && _e !== void 0 ? _e : status) !== null && _f !== void 0 ? _f : "—" })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionAdditionalDetails") })] }), _jsx(CardDescription, { children: t("viewFieldOptionalNotes") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldRemarks") }), _jsx("p", { className: "text-base", children: remarks || "—" })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CheckCircle2, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewFieldStatusInfo") })] }), _jsx(CardDescription, { children: t("viewFieldRecordState") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: [enabled ? (_jsx(CheckCircle2, { className: "h-3 w-3" })) : (_jsx(XCircle, { className: "h-3 w-3" })), enabled ? t("badgeActive") : t("badgeInactive")] }) })] })] }));
|
|
28
37
|
};
|
|
29
38
|
AttendanceView.displayName = "AttendanceView";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
|
|
2
|
+
import { CampusBE } from "../../../type";
|
|
3
|
+
export declare const useCampusModule: () => {
|
|
4
|
+
applyFilters: () => void;
|
|
5
|
+
byIdLoading: boolean;
|
|
6
|
+
clearFilters: () => void;
|
|
7
|
+
clearSearch: () => void;
|
|
8
|
+
closeDrawer: () => void;
|
|
9
|
+
deleteLoading: boolean;
|
|
10
|
+
handleChange: (field: string, value: string | number | boolean | undefined | null) => void;
|
|
11
|
+
handleCreate: () => void;
|
|
12
|
+
handleDelete: (row?: TableRow) => void;
|
|
13
|
+
handleEdit: (row?: TableRow) => void;
|
|
14
|
+
handleFilters: () => void;
|
|
15
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
16
|
+
handlePageLimitChange: (k: string, value: object) => void;
|
|
17
|
+
handleSearch: (query: string) => void;
|
|
18
|
+
handleSubmit: () => void;
|
|
19
|
+
handleView: (row?: TableRow) => void;
|
|
20
|
+
headerActions: {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
handleOnClick: () => void;
|
|
23
|
+
label: string;
|
|
24
|
+
order: number;
|
|
25
|
+
}[];
|
|
26
|
+
listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
|
|
27
|
+
listLoading: boolean;
|
|
28
|
+
rowActions: RowAction[];
|
|
29
|
+
updateLoading: boolean;
|
|
30
|
+
handleCloseDrawer?: () => void;
|
|
31
|
+
state: {
|
|
32
|
+
items: CampusBE[];
|
|
33
|
+
count: number;
|
|
34
|
+
currentPage: number;
|
|
35
|
+
pageLimit: number;
|
|
36
|
+
searchQuery: string;
|
|
37
|
+
disableSaveButton: boolean;
|
|
38
|
+
drawer: string | null;
|
|
39
|
+
errors: Record<string, string>;
|
|
40
|
+
address: string | null;
|
|
41
|
+
city: string | null;
|
|
42
|
+
code: string;
|
|
43
|
+
country: string | null;
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
phone: string | null;
|
|
48
|
+
schoolId: string;
|
|
49
|
+
state: string | null;
|
|
50
|
+
filterEnabled: boolean | undefined;
|
|
51
|
+
appliedFilterEnabled: boolean | undefined;
|
|
52
|
+
classCount: number;
|
|
53
|
+
teacherCount: number;
|
|
54
|
+
studentCount: number;
|
|
55
|
+
};
|
|
56
|
+
dispatch: React.Dispatch<any>;
|
|
57
|
+
};
|