@appcorp/fusion-storybook 0.5.39 → 0.6.1
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/attendance-register/documents/download.d.ts +2 -0
- package/attendance-register/documents/download.js +13 -0
- package/attendance-register/documents/image-text.d.ts +37 -0
- package/attendance-register/documents/image-text.js +103 -0
- package/attendance-register/documents/pdf.d.ts +40 -0
- package/attendance-register/documents/pdf.js +425 -0
- package/attendance-register/documents/zip-files.d.ts +2 -0
- package/attendance-register/documents/zip-files.js +5 -0
- package/attendance-register/documents/zip.d.ts +13 -0
- package/attendance-register/documents/zip.js +29 -0
- package/attendance-register/domain/calendar.d.ts +28 -0
- package/attendance-register/domain/calendar.js +150 -0
- package/attendance-register/domain/locale.d.ts +26 -0
- package/attendance-register/domain/locale.js +87 -0
- package/attendance-register/domain/register.d.ts +50 -0
- package/attendance-register/domain/register.js +116 -0
- package/attendance-register/domain/student-import.d.ts +51 -0
- package/attendance-register/domain/student-import.js +231 -0
- package/attendance-register/domain/week.d.ts +40 -0
- package/attendance-register/domain/week.js +90 -0
- package/attendance-register/index.d.ts +21 -0
- package/attendance-register/index.js +19 -0
- package/attendance-register/react/register-preview.d.ts +34 -0
- package/attendance-register/react/register-preview.js +88 -0
- package/attendance-register/react/use-attendance-register.d.ts +33 -0
- package/attendance-register/react/use-attendance-register.js +106 -0
- package/attendance-register/types.d.ts +90 -0
- package/attendance-register/types.js +22 -0
- package/base-modules/admission/context/use-admission-module.d.ts +3 -0
- package/base-modules/admission/context/use-admission-module.js +41 -5
- package/base-modules/attendance/page.d.ts +2 -0
- package/base-modules/attendance/page.js +21 -1
- package/base-modules/student-profile/context/use-student-profile-module.js +4 -0
- package/base-modules/workspace/context.d.ts +6 -36
- package/base-modules/workspace/context.js +1 -20
- package/base-modules/workspace/view.js +12 -9
- package/constants.d.ts +2 -0
- package/constants.js +2 -0
- package/package.json +3 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +2 -12
- package/utils/student-usage-api.d.ts +6 -0
- package/utils/student-usage-api.js +16 -0
- package/utils/student-usage.d.ts +20 -0
- package/utils/student-usage.js +40 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/** Browser-safe id generator shared by both apps. */
|
|
2
|
+
export function generateStudentId() {
|
|
3
|
+
const cryptoApi = globalThis.crypto;
|
|
4
|
+
if (cryptoApi && typeof cryptoApi.randomUUID === "function") {
|
|
5
|
+
return cryptoApi.randomUUID();
|
|
6
|
+
}
|
|
7
|
+
return `student-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
8
|
+
}
|
|
9
|
+
const HEADER_LABELS = new Set([
|
|
10
|
+
"name",
|
|
11
|
+
"student",
|
|
12
|
+
"student name",
|
|
13
|
+
"full name",
|
|
14
|
+
"first name",
|
|
15
|
+
"given name",
|
|
16
|
+
"last name",
|
|
17
|
+
"surname",
|
|
18
|
+
"family name",
|
|
19
|
+
"roll",
|
|
20
|
+
"roll no",
|
|
21
|
+
"roll number",
|
|
22
|
+
"admission no",
|
|
23
|
+
"admission number",
|
|
24
|
+
"student id",
|
|
25
|
+
"sr no",
|
|
26
|
+
"s no",
|
|
27
|
+
"s.no",
|
|
28
|
+
"#",
|
|
29
|
+
]);
|
|
30
|
+
const FIRST_NAME_HEADERS = new Set(["first name", "given name", "first"]);
|
|
31
|
+
const LAST_NAME_HEADERS = new Set(["last name", "surname", "family name", "last"]);
|
|
32
|
+
const FULL_NAME_HEADERS = new Set(["student name", "full name", "name", "student"]);
|
|
33
|
+
const ROLL_HEADERS = new Set(["roll", "roll no", "roll number", "sr no", "s no", "s.no", "#"]);
|
|
34
|
+
const ADMISSION_HEADERS = new Set([
|
|
35
|
+
"admission",
|
|
36
|
+
"admission no",
|
|
37
|
+
"admission number",
|
|
38
|
+
"student id",
|
|
39
|
+
"student code",
|
|
40
|
+
"registration no",
|
|
41
|
+
"id",
|
|
42
|
+
]);
|
|
43
|
+
function normalizeCell(value) {
|
|
44
|
+
return String(value !== null && value !== void 0 ? value : "")
|
|
45
|
+
.replace(/\uFEFF/g, "")
|
|
46
|
+
.replace(/\s+/g, " ")
|
|
47
|
+
.trim();
|
|
48
|
+
}
|
|
49
|
+
export function normalizeStudentName(name) {
|
|
50
|
+
return name.trim().replace(/\s+/g, " ").toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
function isHeaderCell(value) {
|
|
53
|
+
const header = value.toLowerCase().replace(/[.:]/g, "").trim();
|
|
54
|
+
return HEADER_LABELS.has(header);
|
|
55
|
+
}
|
|
56
|
+
function looksLikeHeader(row) {
|
|
57
|
+
return row.some((cell) => isHeaderCell(normalizeCell(cell)));
|
|
58
|
+
}
|
|
59
|
+
function findColumn(headers, labels) {
|
|
60
|
+
return headers.findIndex((header) => labels.has(header));
|
|
61
|
+
}
|
|
62
|
+
function looksNumeric(value) {
|
|
63
|
+
return /^\d+$/.test(value.trim());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Extracts students from parsed CSV/XLSX rows.
|
|
67
|
+
*
|
|
68
|
+
* Handles a name column, combined first/last columns, headerless files and
|
|
69
|
+
* files where the first column is a roll number. Admission numbers are read
|
|
70
|
+
* when present and are the identity used to allow two students with the same
|
|
71
|
+
* name.
|
|
72
|
+
*/
|
|
73
|
+
export function extractStudentRows(rows) {
|
|
74
|
+
var _a, _b, _c, _d, _e, _f;
|
|
75
|
+
const allRows = rows.map((row) => row.map((cell) => normalizeCell(cell)));
|
|
76
|
+
const cleanRows = allRows.filter((row) => row.some((cell) => cell.length > 0));
|
|
77
|
+
const emptyRows = allRows.length - cleanRows.length;
|
|
78
|
+
if (cleanRows.length === 0)
|
|
79
|
+
return { students: [], skipped: emptyRows };
|
|
80
|
+
const firstRow = cleanRows[0];
|
|
81
|
+
const hasHeader = looksLikeHeader(firstRow);
|
|
82
|
+
const headers = hasHeader
|
|
83
|
+
? firstRow.map((cell) => cell.toLowerCase().replace(/[.:]/g, "").trim())
|
|
84
|
+
: [];
|
|
85
|
+
const dataRows = hasHeader ? cleanRows.slice(1) : cleanRows;
|
|
86
|
+
let firstColumn = -1;
|
|
87
|
+
let lastColumn = -1;
|
|
88
|
+
let fullColumn = -1;
|
|
89
|
+
let rollColumn = -1;
|
|
90
|
+
let admissionColumn = -1;
|
|
91
|
+
if (hasHeader) {
|
|
92
|
+
firstColumn = findColumn(headers, FIRST_NAME_HEADERS);
|
|
93
|
+
lastColumn = findColumn(headers, LAST_NAME_HEADERS);
|
|
94
|
+
fullColumn = findColumn(headers, FULL_NAME_HEADERS);
|
|
95
|
+
rollColumn = findColumn(headers, ROLL_HEADERS);
|
|
96
|
+
admissionColumn = findColumn(headers, ADMISSION_HEADERS);
|
|
97
|
+
}
|
|
98
|
+
const students = [];
|
|
99
|
+
const seen = new Set();
|
|
100
|
+
let skipped = emptyRows;
|
|
101
|
+
for (const row of dataRows) {
|
|
102
|
+
let name = "";
|
|
103
|
+
if (firstColumn >= 0 && lastColumn >= 0) {
|
|
104
|
+
name = [row[firstColumn], row[lastColumn]].filter(Boolean).join(" ");
|
|
105
|
+
}
|
|
106
|
+
else if (fullColumn >= 0) {
|
|
107
|
+
name = (_a = row[fullColumn]) !== null && _a !== void 0 ? _a : "";
|
|
108
|
+
}
|
|
109
|
+
else if (lastColumn >= 0) {
|
|
110
|
+
name = (_b = row[lastColumn]) !== null && _b !== void 0 ? _b : "";
|
|
111
|
+
}
|
|
112
|
+
else if (hasHeader) {
|
|
113
|
+
const fallback = row.findIndex((cell) => cell.length > 0);
|
|
114
|
+
name = fallback >= 0 ? row[fallback] : "";
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Headerless files are usually "Name" or "Roll, Name". Prefer the
|
|
118
|
+
// second column when the first column is a number.
|
|
119
|
+
const first = (_c = row[0]) !== null && _c !== void 0 ? _c : "";
|
|
120
|
+
const second = (_d = row[1]) !== null && _d !== void 0 ? _d : "";
|
|
121
|
+
name = looksNumeric(first) && second ? second : first;
|
|
122
|
+
}
|
|
123
|
+
name = name.replace(/\s+/g, " ").trim();
|
|
124
|
+
if (!name) {
|
|
125
|
+
skipped += 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const admissionNumber = admissionColumn >= 0 ? normalizeCell(row[admissionColumn]) : "";
|
|
129
|
+
let rollNumber = rollColumn >= 0 ? normalizeCell(row[rollColumn]) : "";
|
|
130
|
+
if (!hasHeader) {
|
|
131
|
+
const first = (_e = row[0]) !== null && _e !== void 0 ? _e : "";
|
|
132
|
+
if (looksNumeric(first) && ((_f = row[1]) !== null && _f !== void 0 ? _f : ""))
|
|
133
|
+
rollNumber = first;
|
|
134
|
+
}
|
|
135
|
+
const key = admissionNumber
|
|
136
|
+
? `id:${admissionNumber.toLowerCase()}`
|
|
137
|
+
: normalizeStudentName(name);
|
|
138
|
+
if (seen.has(key)) {
|
|
139
|
+
skipped += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
seen.add(key);
|
|
143
|
+
students.push(Object.assign(Object.assign({ name }, (admissionNumber ? { admissionNumber } : {})), (rollNumber ? { rollNumber } : {})));
|
|
144
|
+
}
|
|
145
|
+
return { students, skipped };
|
|
146
|
+
}
|
|
147
|
+
/** Backwards-compatible name-only view of {@link extractStudentRows}. */
|
|
148
|
+
export function extractStudentNames(rows) {
|
|
149
|
+
const { students, skipped } = extractStudentRows(rows);
|
|
150
|
+
return { names: students.map((student) => student.name), skipped };
|
|
151
|
+
}
|
|
152
|
+
function identityKey(name, admissionNumber) {
|
|
153
|
+
const admission = admissionNumber === null || admissionNumber === void 0 ? void 0 : admissionNumber.trim().toLowerCase();
|
|
154
|
+
if (admission)
|
|
155
|
+
return `id:${admission}`;
|
|
156
|
+
return `name:${normalizeStudentName(name)}`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Merges new students into the current roster.
|
|
160
|
+
*
|
|
161
|
+
* Admission numbers are the identity when available, so two students can share
|
|
162
|
+
* a name. Name-only records still match by name to keep repeat imports from
|
|
163
|
+
* doubling the roster; pass `allowDuplicateNames` to override that.
|
|
164
|
+
*/
|
|
165
|
+
export function mergeStudents(existing, incoming, options = {}) {
|
|
166
|
+
var _a, _b, _c;
|
|
167
|
+
const allowDuplicateNames = (_a = options.allowDuplicateNames) !== null && _a !== void 0 ? _a : false;
|
|
168
|
+
const seen = new Set(existing.map((student) => identityKey(student.name, student.admissionNumber)));
|
|
169
|
+
const existingNames = new Set(existing.map((student) => normalizeStudentName(student.name)));
|
|
170
|
+
const numericRolls = existing
|
|
171
|
+
.map((student) => Number(student.rollNumber))
|
|
172
|
+
.filter((value) => Number.isFinite(value));
|
|
173
|
+
let nextRoll = (numericRolls.length > 0 ? Math.max(...numericRolls) : existing.length) + 1;
|
|
174
|
+
const students = [...existing];
|
|
175
|
+
let added = 0;
|
|
176
|
+
let duplicates = 0;
|
|
177
|
+
let updated = 0;
|
|
178
|
+
const duplicateNames = [];
|
|
179
|
+
for (const entry of incoming) {
|
|
180
|
+
const input = typeof entry === "string" ? { name: entry } : entry;
|
|
181
|
+
const name = input.name.replace(/\s+/g, " ").trim();
|
|
182
|
+
if (!name)
|
|
183
|
+
continue;
|
|
184
|
+
const admissionNumber = ((_b = input.admissionNumber) === null || _b === void 0 ? void 0 : _b.trim()) || undefined;
|
|
185
|
+
const normalizedName = normalizeStudentName(name);
|
|
186
|
+
const key = identityKey(name, admissionNumber);
|
|
187
|
+
// A re-import that adds IDs to a name-only roster should enrich, not fork.
|
|
188
|
+
if (admissionNumber && !seen.has(key)) {
|
|
189
|
+
const targetIndex = students.findIndex((student) => normalizeStudentName(student.name) === normalizedName && !student.admissionNumber);
|
|
190
|
+
if (targetIndex >= 0) {
|
|
191
|
+
students[targetIndex] = Object.assign(Object.assign({}, students[targetIndex]), { admissionNumber });
|
|
192
|
+
seen.add(key);
|
|
193
|
+
updated += 1;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Admission numbers must stay unique. Names only block a merge when the
|
|
198
|
+
// caller has not explicitly allowed duplicates.
|
|
199
|
+
const isDuplicate = admissionNumber
|
|
200
|
+
? seen.has(key)
|
|
201
|
+
: !allowDuplicateNames && (seen.has(key) || existingNames.has(normalizedName));
|
|
202
|
+
if (isDuplicate) {
|
|
203
|
+
duplicates += 1;
|
|
204
|
+
duplicateNames.push(name);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
let rollNumber = (_c = input.rollNumber) === null || _c === void 0 ? void 0 : _c.trim();
|
|
208
|
+
if (!rollNumber) {
|
|
209
|
+
rollNumber = String(nextRoll);
|
|
210
|
+
nextRoll += 1;
|
|
211
|
+
}
|
|
212
|
+
else if (/^\d+$/.test(rollNumber)) {
|
|
213
|
+
nextRoll = Math.max(nextRoll, Number(rollNumber) + 1);
|
|
214
|
+
}
|
|
215
|
+
students.push(Object.assign({ id: generateStudentId(), name,
|
|
216
|
+
rollNumber }, (admissionNumber ? { admissionNumber } : {})));
|
|
217
|
+
seen.add(key);
|
|
218
|
+
existingNames.add(normalizedName);
|
|
219
|
+
added += 1;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
students,
|
|
223
|
+
added,
|
|
224
|
+
duplicates,
|
|
225
|
+
updated,
|
|
226
|
+
duplicateNames: [...new Set(duplicateNames)],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
export function reindexStudents(students) {
|
|
230
|
+
return students.map((student, index) => (Object.assign(Object.assign({}, student), { rollNumber: String(index + 1) })));
|
|
231
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const WEEK_DAYS: readonly [{
|
|
2
|
+
readonly index: 0;
|
|
3
|
+
readonly short: "Sun";
|
|
4
|
+
readonly full: "Sunday";
|
|
5
|
+
}, {
|
|
6
|
+
readonly index: 1;
|
|
7
|
+
readonly short: "Mon";
|
|
8
|
+
readonly full: "Monday";
|
|
9
|
+
}, {
|
|
10
|
+
readonly index: 2;
|
|
11
|
+
readonly short: "Tue";
|
|
12
|
+
readonly full: "Tuesday";
|
|
13
|
+
}, {
|
|
14
|
+
readonly index: 3;
|
|
15
|
+
readonly short: "Wed";
|
|
16
|
+
readonly full: "Wednesday";
|
|
17
|
+
}, {
|
|
18
|
+
readonly index: 4;
|
|
19
|
+
readonly short: "Thu";
|
|
20
|
+
readonly full: "Thursday";
|
|
21
|
+
}, {
|
|
22
|
+
readonly index: 5;
|
|
23
|
+
readonly short: "Fri";
|
|
24
|
+
readonly full: "Friday";
|
|
25
|
+
}, {
|
|
26
|
+
readonly index: 6;
|
|
27
|
+
readonly short: "Sat";
|
|
28
|
+
readonly full: "Saturday";
|
|
29
|
+
}];
|
|
30
|
+
export interface WeekendPreset {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
days: number[];
|
|
34
|
+
}
|
|
35
|
+
export declare const WEEKEND_PRESETS: WeekendPreset[];
|
|
36
|
+
/** Best-effort weekend for a country code, always overridable by the user. */
|
|
37
|
+
export declare function getDefaultWeekendDays(country?: string): number[];
|
|
38
|
+
/** Keeps valid, unique weekday indices; missing input uses the country default. */
|
|
39
|
+
export declare function normalizeWeekendDays(value: unknown, country?: string): number[];
|
|
40
|
+
export declare function formatWeekendLabel(days: number[]): string;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weekday indices follow JavaScript's `Date.getDay()`: 0 = Sunday … 6 = Saturday.
|
|
3
|
+
*
|
|
4
|
+
* The country table is deliberately small and conservative: it only covers the
|
|
5
|
+
* systems where a Saturday–Sunday weekend would visibly mis-shade a register.
|
|
6
|
+
* Families of schools differ, so every value can be overridden in the UI.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_WEEKEND_DAYS } from "../types";
|
|
9
|
+
/** Gulf states and nearby systems with a Friday–Saturday weekend. */
|
|
10
|
+
const FRIDAY_SATURDAY = new Set([
|
|
11
|
+
"AE",
|
|
12
|
+
"SA",
|
|
13
|
+
"QA",
|
|
14
|
+
"KW",
|
|
15
|
+
"BH",
|
|
16
|
+
"OM",
|
|
17
|
+
"EG",
|
|
18
|
+
"JO",
|
|
19
|
+
"DZ",
|
|
20
|
+
"LY",
|
|
21
|
+
"IQ",
|
|
22
|
+
"YE",
|
|
23
|
+
"SD",
|
|
24
|
+
"SY",
|
|
25
|
+
"PS",
|
|
26
|
+
"IL",
|
|
27
|
+
"MV",
|
|
28
|
+
"BD",
|
|
29
|
+
]);
|
|
30
|
+
/** Countries where Friday is the weekly holiday. */
|
|
31
|
+
const FRIDAY_ONLY = new Set(["AF", "IR"]);
|
|
32
|
+
/** Countries where Saturday is the weekly holiday. */
|
|
33
|
+
const SATURDAY_ONLY = new Set(["NP"]);
|
|
34
|
+
/** Countries where Sunday is the only weekly holiday. */
|
|
35
|
+
const SUNDAY_ONLY = new Set(["PK"]);
|
|
36
|
+
export const WEEK_DAYS = [
|
|
37
|
+
{ index: 0, short: "Sun", full: "Sunday" },
|
|
38
|
+
{ index: 1, short: "Mon", full: "Monday" },
|
|
39
|
+
{ index: 2, short: "Tue", full: "Tuesday" },
|
|
40
|
+
{ index: 3, short: "Wed", full: "Wednesday" },
|
|
41
|
+
{ index: 4, short: "Thu", full: "Thursday" },
|
|
42
|
+
{ index: 5, short: "Fri", full: "Friday" },
|
|
43
|
+
{ index: 6, short: "Sat", full: "Saturday" },
|
|
44
|
+
];
|
|
45
|
+
const DAY_NAMES = WEEK_DAYS.map((day) => day.full);
|
|
46
|
+
const DAY_SHORT = WEEK_DAYS.map((day) => day.short);
|
|
47
|
+
export const WEEKEND_PRESETS = [
|
|
48
|
+
{ id: "sat-sun", label: "Sat & Sun", days: [0, 6] },
|
|
49
|
+
{ id: "fri-sat", label: "Fri & Sat", days: [5, 6] },
|
|
50
|
+
{ id: "fri-only", label: "Friday only", days: [5] },
|
|
51
|
+
{ id: "sun-only", label: "Sunday only", days: [0] },
|
|
52
|
+
{ id: "none", label: "Seven-day week", days: [] },
|
|
53
|
+
];
|
|
54
|
+
/** Best-effort weekend for a country code, always overridable by the user. */
|
|
55
|
+
export function getDefaultWeekendDays(country) {
|
|
56
|
+
const code = (country !== null && country !== void 0 ? country : "").trim().toUpperCase();
|
|
57
|
+
if (FRIDAY_SATURDAY.has(code))
|
|
58
|
+
return [5, 6];
|
|
59
|
+
if (FRIDAY_ONLY.has(code))
|
|
60
|
+
return [5];
|
|
61
|
+
if (SATURDAY_ONLY.has(code))
|
|
62
|
+
return [6];
|
|
63
|
+
if (SUNDAY_ONLY.has(code))
|
|
64
|
+
return [0];
|
|
65
|
+
return [...DEFAULT_WEEKEND_DAYS];
|
|
66
|
+
}
|
|
67
|
+
/** Keeps valid, unique weekday indices; missing input uses the country default. */
|
|
68
|
+
export function normalizeWeekendDays(value, country) {
|
|
69
|
+
if (!Array.isArray(value))
|
|
70
|
+
return getDefaultWeekendDays(country);
|
|
71
|
+
const days = new Set();
|
|
72
|
+
for (const entry of value) {
|
|
73
|
+
const day = typeof entry === "number" ? entry : Number(entry);
|
|
74
|
+
if (Number.isInteger(day) && day >= 0 && day <= 6)
|
|
75
|
+
days.add(day);
|
|
76
|
+
}
|
|
77
|
+
return [...days].sort((a, b) => a - b);
|
|
78
|
+
}
|
|
79
|
+
export function formatWeekendLabel(days) {
|
|
80
|
+
const sorted = normalizeWeekendDays(days, "");
|
|
81
|
+
if (sorted.length === 0)
|
|
82
|
+
return "No weekend";
|
|
83
|
+
if (sorted.length === 1)
|
|
84
|
+
return DAY_NAMES[sorted[0]];
|
|
85
|
+
if (sorted.length === 2 && sorted[0] === 0 && sorted[1] === 6)
|
|
86
|
+
return "Sat & Sun";
|
|
87
|
+
if (sorted.length === 2 && sorted[0] === 5 && sorted[1] === 6)
|
|
88
|
+
return "Fri & Sat";
|
|
89
|
+
return sorted.map((day) => DAY_SHORT[day]).join(" & ");
|
|
90
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared attendance-register engine.
|
|
3
|
+
*
|
|
4
|
+
* Pure domain logic, document generators and the headless register hook. Both
|
|
5
|
+
* schoolkit (public tool) and fusion-solution-pattern (paid SaaS) consume this
|
|
6
|
+
* entry point; persistence, contact gates and API access stay in each app.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./types";
|
|
9
|
+
export * from "./domain/calendar";
|
|
10
|
+
export * from "./domain/locale";
|
|
11
|
+
export * from "./domain/week";
|
|
12
|
+
export * from "./domain/register";
|
|
13
|
+
export * from "./domain/student-import";
|
|
14
|
+
export * from "./documents/pdf";
|
|
15
|
+
export * from "./documents/zip";
|
|
16
|
+
export * from "./documents/zip-files";
|
|
17
|
+
export * from "./documents/download";
|
|
18
|
+
export { useAttendanceRegister } from "./react/use-attendance-register";
|
|
19
|
+
export type { UseAttendanceRegisterOptions } from "./react/use-attendance-register";
|
|
20
|
+
export { RegisterPreview } from "./react/register-preview";
|
|
21
|
+
export type { RegisterPreviewLabels, RegisterPreviewProps, } from "./react/register-preview";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared attendance-register engine.
|
|
3
|
+
*
|
|
4
|
+
* Pure domain logic, document generators and the headless register hook. Both
|
|
5
|
+
* schoolkit (public tool) and fusion-solution-pattern (paid SaaS) consume this
|
|
6
|
+
* entry point; persistence, contact gates and API access stay in each app.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./types";
|
|
9
|
+
export * from "./domain/calendar";
|
|
10
|
+
export * from "./domain/locale";
|
|
11
|
+
export * from "./domain/week";
|
|
12
|
+
export * from "./domain/register";
|
|
13
|
+
export * from "./domain/student-import";
|
|
14
|
+
export * from "./documents/pdf";
|
|
15
|
+
export * from "./documents/zip";
|
|
16
|
+
export * from "./documents/zip-files";
|
|
17
|
+
export * from "./documents/download";
|
|
18
|
+
export { useAttendanceRegister } from "./react/use-attendance-register";
|
|
19
|
+
export { RegisterPreview } from "./react/register-preview";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { RegisterConfig } from "../types";
|
|
3
|
+
export interface RegisterPreviewLabels {
|
|
4
|
+
title: string;
|
|
5
|
+
close: string;
|
|
6
|
+
students: string;
|
|
7
|
+
days: string;
|
|
8
|
+
working: string;
|
|
9
|
+
weekends: string;
|
|
10
|
+
noSchool: string;
|
|
11
|
+
pages: string;
|
|
12
|
+
student: string;
|
|
13
|
+
present: string;
|
|
14
|
+
previewOnly: string;
|
|
15
|
+
backToEdit: string;
|
|
16
|
+
download: string;
|
|
17
|
+
generating: string;
|
|
18
|
+
empty: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RegisterPreviewProps {
|
|
21
|
+
open: boolean;
|
|
22
|
+
config: RegisterConfig;
|
|
23
|
+
canDownload?: boolean;
|
|
24
|
+
generating?: boolean;
|
|
25
|
+
onClose: () => void;
|
|
26
|
+
onDownload?: () => void;
|
|
27
|
+
/** Gate, legend or other caller-specific content shown above the actions. */
|
|
28
|
+
footer?: ReactNode;
|
|
29
|
+
labels?: Partial<RegisterPreviewLabels>;
|
|
30
|
+
/** CSS colour used for header cells and buttons. */
|
|
31
|
+
accent?: string;
|
|
32
|
+
showDownload?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function RegisterPreview({ open, config, canDownload, generating, onClose, onDownload, footer, labels: labelOverrides, accent, showDownload, }: RegisterPreviewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { Download, Eye, X } from "lucide-react";
|
|
5
|
+
import { MONTHS, } from "../types";
|
|
6
|
+
import { getDaysInMonth, getWeekGroups } from "../domain/calendar";
|
|
7
|
+
import { formatMonthName, formatMonthYear, isRtlLocale } from "../domain/locale";
|
|
8
|
+
import { getAttendanceMark, getNoSchoolSet, getRegisterSummary, isNonWorkingDay, } from "../domain/register";
|
|
9
|
+
const DEFAULT_LABELS = {
|
|
10
|
+
title: "Register preview",
|
|
11
|
+
close: "Close preview",
|
|
12
|
+
students: "Students",
|
|
13
|
+
days: "Days",
|
|
14
|
+
working: "Working",
|
|
15
|
+
weekends: "Weekends",
|
|
16
|
+
noSchool: "No school",
|
|
17
|
+
pages: "Pages",
|
|
18
|
+
student: "Student",
|
|
19
|
+
present: "Present",
|
|
20
|
+
previewOnly: "Preview only. Page breaks and print margins are applied in the PDF.",
|
|
21
|
+
backToEdit: "Back to edit",
|
|
22
|
+
download: "Download PDF",
|
|
23
|
+
generating: "Generating…",
|
|
24
|
+
empty: "Add students to preview the register.",
|
|
25
|
+
};
|
|
26
|
+
function SummaryBadge({ label, value }) {
|
|
27
|
+
return (_jsxs("div", { className: "rounded-lg border border-gray-200 bg-white px-3 py-2 dark:border-zinc-700 dark:bg-zinc-900", children: [_jsx("p", { className: "text-sm font-bold text-gray-900 dark:text-zinc-100", children: value }), _jsx("p", { className: "text-[10px] uppercase tracking-wide text-gray-500 dark:text-zinc-400", children: label })] }));
|
|
28
|
+
}
|
|
29
|
+
export function RegisterPreview({ open, config, canDownload = true, generating = false, onClose, onDownload, footer, labels: labelOverrides, accent = "#d97706", showDownload = true, }) {
|
|
30
|
+
const labels = Object.assign(Object.assign({}, DEFAULT_LABELS), labelOverrides);
|
|
31
|
+
const dialogRef = useRef(null);
|
|
32
|
+
const days = getDaysInMonth(config.month, config.year, config.weekendDays, config.locale);
|
|
33
|
+
const weeks = getWeekGroups(config.month, config.year, config.weekStartsOn, config.weekendDays, config.locale);
|
|
34
|
+
const summary = getRegisterSummary(config);
|
|
35
|
+
const noSchool = getNoSchoolSet(config);
|
|
36
|
+
const rtl = isRtlLocale(config.locale);
|
|
37
|
+
const accentStyle = { "--reg-accent": accent };
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const dialog = dialogRef.current;
|
|
40
|
+
if (!dialog)
|
|
41
|
+
return;
|
|
42
|
+
if (open && !dialog.open) {
|
|
43
|
+
if (typeof dialog.showModal === "function")
|
|
44
|
+
dialog.showModal();
|
|
45
|
+
else
|
|
46
|
+
dialog.setAttribute("open", "");
|
|
47
|
+
}
|
|
48
|
+
if (!open && dialog.open)
|
|
49
|
+
dialog.close();
|
|
50
|
+
}, [open]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const dialog = dialogRef.current;
|
|
53
|
+
if (!dialog)
|
|
54
|
+
return;
|
|
55
|
+
const handleClose = () => onClose();
|
|
56
|
+
dialog.addEventListener("close", handleClose);
|
|
57
|
+
return () => dialog.removeEventListener("close", handleClose);
|
|
58
|
+
}, [onClose]);
|
|
59
|
+
const handleDownload = () => {
|
|
60
|
+
if (!canDownload)
|
|
61
|
+
return;
|
|
62
|
+
onDownload === null || onDownload === void 0 ? void 0 : onDownload();
|
|
63
|
+
};
|
|
64
|
+
const headerCell = "bg-[var(--reg-accent)] text-white";
|
|
65
|
+
const nonWorkingHeader = "bg-gray-200 text-gray-700 dark:bg-zinc-700 dark:text-zinc-200";
|
|
66
|
+
const table = (columns, title) => (_jsxs("div", { className: "space-y-2", children: [title && _jsx("h3", { className: "text-sm font-semibold text-gray-900 dark:text-zinc-100", children: title }), _jsx("div", { className: "overflow-x-auto rounded-xl border border-gray-200 dark:border-zinc-700", children: _jsxs("table", { className: "min-w-full border-collapse text-[11px]", dir: rtl ? "rtl" : "ltr", children: [_jsx("thead", { className: "sticky top-0 z-30", children: _jsxs("tr", { children: [_jsx("th", { className: `sticky start-0 z-20 w-8 border border-gray-200 px-1 py-1.5 text-center font-semibold dark:border-zinc-600 ${headerCell}`, children: "#" }), _jsx("th", { className: `sticky start-8 z-20 min-w-[150px] border border-gray-200 px-2 py-1.5 text-start font-semibold dark:border-zinc-600 ${headerCell}`, children: labels.student }), columns.map((day, index) => {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const blank = day === null;
|
|
69
|
+
const nonWorking = blank || (day !== null && isNonWorkingDay(day, noSchool));
|
|
70
|
+
return (_jsxs("th", { className: `min-w-8 border px-1 py-1.5 text-center font-semibold ${nonWorking
|
|
71
|
+
? `border-gray-300 dark:border-zinc-600 ${nonWorkingHeader}`
|
|
72
|
+
: `border-[var(--reg-accent)] ${headerCell}`}`, children: [_jsx("span", { className: "block", children: (_a = day === null || day === void 0 ? void 0 : day.day) !== null && _a !== void 0 ? _a : "" }), _jsx("span", { className: "block text-[9px] font-normal opacity-80", children: (_b = day === null || day === void 0 ? void 0 : day.weekday) !== null && _b !== void 0 ? _b : "" })] }, `${(_c = day === null || day === void 0 ? void 0 : day.day) !== null && _c !== void 0 ? _c : "blank"}-${index}`));
|
|
73
|
+
}), _jsx("th", { className: `min-w-12 border border-gray-200 px-1 py-1.5 text-center font-semibold dark:border-zinc-600 ${headerCell}`, children: labels.present })] }) }), _jsxs("tbody", { children: [config.students.map((student) => (_jsxs("tr", { children: [_jsx("td", { className: "sticky start-0 z-10 border border-gray-200 bg-white px-1 py-1 text-center text-gray-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400", children: student.rollNumber }), _jsxs("td", { className: "sticky start-8 z-10 min-w-[150px] border border-gray-200 bg-white px-2 py-1 font-medium text-gray-800 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200", children: [_jsx("span", { className: "block max-w-[180px] truncate", children: student.name }), student.admissionNumber && (_jsxs("span", { className: "block text-[9px] font-normal text-gray-400", children: ["#", student.admissionNumber] }))] }), columns.map((day, index) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const blank = day === null;
|
|
76
|
+
const nonWorking = blank || (day !== null && isNonWorkingDay(day, noSchool));
|
|
77
|
+
const mark = day ? getAttendanceMark(config, student.id, day.day) : undefined;
|
|
78
|
+
return (_jsx("td", { className: `border px-1 py-1 text-center font-semibold ${nonWorking
|
|
79
|
+
? "border-gray-200 bg-gray-100 text-gray-400 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-500"
|
|
80
|
+
: "border-gray-200 bg-white text-gray-800 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200"}`, children: blank ? "" : nonWorking ? "—" : (mark !== null && mark !== void 0 ? mark : "") }, `${student.id}-${(_a = day === null || day === void 0 ? void 0 : day.day) !== null && _a !== void 0 ? _a : "blank"}-${index}`));
|
|
81
|
+
}), _jsx("td", { className: "border border-gray-200 bg-white px-1 py-1 dark:border-zinc-700 dark:bg-zinc-900" })] }, student.id))), config.students.length === 0 && (_jsx("tr", { children: _jsx("td", { colSpan: columns.length + 3, className: "border border-gray-200 px-3 py-4 text-center text-gray-500 dark:border-zinc-700 dark:text-zinc-400", children: labels.empty }) }))] })] }) })] }, title !== null && title !== void 0 ? title : "monthly"));
|
|
82
|
+
return (_jsx("dialog", { ref: dialogRef, "aria-labelledby": "attendance-preview-title", style: accentStyle, className: "m-auto max-h-[94dvh] w-[calc(100%-1rem)] max-w-6xl overflow-y-auto rounded-2xl border border-gray-200 bg-white p-0 text-gray-900 shadow-2xl backdrop:bg-black/50 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100", onClick: (event) => {
|
|
83
|
+
if (event.target === event.currentTarget)
|
|
84
|
+
onClose();
|
|
85
|
+
}, children: _jsxs("div", { className: "p-4 sm:p-6", children: [_jsxs("div", { className: "mb-4 flex items-start gap-3", children: [_jsx("span", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-[var(--reg-accent)]/15 text-[var(--reg-accent)]", children: _jsx(Eye, { size: 20 }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h2", { id: "attendance-preview-title", className: "text-lg font-bold", children: labels.title }), _jsxs("p", { className: "mt-0.5 truncate text-sm text-gray-500 dark:text-zinc-400", children: [config.schoolName || "School name", " \u00B7 ", config.className || "Class", config.section ? ` - ${config.section}` : "", " \u00B7", " ", formatMonthYear(MONTHS.indexOf(config.month), config.year, config.locale)] })] }), _jsx("button", { type: "button", onClick: onClose, "aria-label": labels.close, className: "inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-lg text-gray-400 hover:bg-gray-100 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-[var(--reg-accent)] dark:hover:bg-zinc-800 dark:hover:text-zinc-100", children: _jsx(X, { size: 18 }) })] }), _jsxs("div", { className: "mb-4 grid grid-cols-3 gap-2 sm:grid-cols-6", children: [_jsx(SummaryBadge, { label: labels.students, value: summary.totalStudents }), _jsx(SummaryBadge, { label: labels.days, value: summary.totalDays }), _jsx(SummaryBadge, { label: labels.working, value: summary.workingDays }), _jsx(SummaryBadge, { label: labels.weekends, value: summary.weekends }), _jsx(SummaryBadge, { label: labels.noSchool, value: summary.noSchoolDays }), _jsx(SummaryBadge, { label: labels.pages, value: summary.pageCount })] }), _jsx("div", { className: "max-h-[58vh] space-y-5 overflow-y-auto pr-1", children: config.layout === "monthly"
|
|
86
|
+
? table(days)
|
|
87
|
+
: weeks.map((week) => table(week.slots, `Week ${week.weekNumber} · ${week.startDay}–${week.endDay} ${formatMonthName(MONTHS.indexOf(config.month), config.locale)}`)) }), _jsx("p", { className: "mt-4 text-[11px] text-gray-500 dark:text-zinc-400", children: labels.previewOnly }), footer && _jsx("div", { className: "mt-4", children: footer }), _jsxs("div", { className: "mt-4 flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between", children: [_jsx("button", { type: "button", onClick: onClose, className: "inline-flex min-h-11 items-center justify-center rounded-lg border border-gray-200 bg-white px-4 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-[var(--reg-accent)] dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-200 dark:hover:bg-zinc-700", children: labels.backToEdit }), showDownload && (_jsx("button", { type: "button", onClick: handleDownload, disabled: generating, className: "inline-flex min-h-11 items-center justify-center gap-2 rounded-lg bg-[var(--reg-accent)] px-4 text-sm font-semibold text-white hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-[var(--reg-accent)] disabled:cursor-not-allowed disabled:opacity-50", children: generating ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-white border-t-transparent" }), labels.generating] })) : (_jsxs(_Fragment, { children: [_jsx(Download, { size: 16 }), " ", labels.download] })) }))] })] }) }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RegisterConfig, RegisterFormState, Student } from "../types";
|
|
2
|
+
export interface UseAttendanceRegisterOptions<T extends RegisterFormState> {
|
|
3
|
+
initialState: T | (() => T);
|
|
4
|
+
/** Persistence hook for callers such as schoolkit. */
|
|
5
|
+
onChange?: (state: T) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Headless register state shared by both apps. It owns only register concerns;
|
|
9
|
+
* contact details, analytics and API fetching stay in the consuming repo.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useAttendanceRegister<T extends RegisterFormState>({ initialState, onChange, }: UseAttendanceRegisterOptions<T>): {
|
|
12
|
+
state: T;
|
|
13
|
+
setState: import("react").Dispatch<import("react").SetStateAction<T>>;
|
|
14
|
+
updateField: <K extends keyof T>(key: K, value: T[K]) => void;
|
|
15
|
+
setStudents: (students: Student[]) => void;
|
|
16
|
+
removeStudent: (id: string) => void;
|
|
17
|
+
updateStudent: (id: string, patch: Partial<Omit<Student, "id">>) => void;
|
|
18
|
+
clearStudents: () => void;
|
|
19
|
+
resetRegister: () => void;
|
|
20
|
+
advanceMonth: () => {
|
|
21
|
+
month: string;
|
|
22
|
+
year: number;
|
|
23
|
+
};
|
|
24
|
+
days: import("..").AttendanceDay[];
|
|
25
|
+
weeks: import("..").WeekGroup[];
|
|
26
|
+
parsedNoSchool: import("..").ParsedNoSchoolDays;
|
|
27
|
+
workingDays: number;
|
|
28
|
+
config: RegisterConfig;
|
|
29
|
+
summary: import("..").RegisterSummary;
|
|
30
|
+
classLabel: string;
|
|
31
|
+
canExportLocal: boolean;
|
|
32
|
+
localError: string;
|
|
33
|
+
};
|