@appcorp/fusion-storybook 0.5.7 → 0.5.11
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/admission/context/use-admission-module.d.ts +10 -1
- package/base-modules/admission/context/use-admission-module.js +207 -69
- package/base-modules/admission/context.d.ts +20 -0
- package/base-modules/admission/context.js +8 -2
- package/base-modules/admission/filter.js +5 -20
- package/base-modules/admission/form.js +11 -32
- package/base-modules/admission/page.js +36 -19
- package/base-modules/admission/validate.d.ts +23 -1
- package/base-modules/admission/validate.js +58 -21
- package/base-modules/admission/view.js +27 -4
- 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/constants.d.ts +0 -4
- package/constants.js +0 -4
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/base-modules/admission/more-actions.d.ts +0 -1
- package/base-modules/admission/more-actions.js +0 -291
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { AdmissionAIBE, AdmissionBE } from "../../../type";
|
|
1
|
+
import { AdmissionAIBE, AdmissionBE, DiscountCodeBE } from "../../../type";
|
|
2
2
|
import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
|
|
3
3
|
export declare const useAdmissionModule: () => {
|
|
4
4
|
applyFilters: () => void;
|
|
5
5
|
byIdLoading: boolean;
|
|
6
6
|
clearFilters: () => void;
|
|
7
7
|
deleteLoading: boolean;
|
|
8
|
+
discountCodes: DiscountCodeBE[];
|
|
8
9
|
handleAddStudent: (row?: unknown) => Promise<void>;
|
|
9
10
|
handleAnalyze: (row?: unknown) => Promise<void>;
|
|
11
|
+
handleApprove: (row?: unknown) => void;
|
|
12
|
+
handleCancelAdmission: (row?: unknown) => void;
|
|
10
13
|
handleChange: (field: string, value: string | number | boolean | undefined | null) => void;
|
|
11
14
|
handleCloseDrawer: () => void;
|
|
12
15
|
handleCreate: () => void;
|
|
@@ -17,10 +20,12 @@ export declare const useAdmissionModule: () => {
|
|
|
17
20
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
18
21
|
handlePrint: (row?: TableRow) => Promise<void>;
|
|
19
22
|
handleRemoveDocument: (url: string) => Promise<void>;
|
|
23
|
+
handleReject: (row?: unknown) => void;
|
|
20
24
|
handleSearch: (query: string) => void;
|
|
21
25
|
handleSetEndDate: (endDate: string) => void;
|
|
22
26
|
handleSetStartDate: (startDate: string) => void;
|
|
23
27
|
handleSubmit: () => void;
|
|
28
|
+
handleUpdateStatus: (row: TableRow | undefined, status: string, confirmation: string) => void;
|
|
24
29
|
handleView: (row?: TableRow) => void;
|
|
25
30
|
headerActions: {
|
|
26
31
|
enabled: boolean;
|
|
@@ -87,6 +92,10 @@ export declare const useAdmissionModule: () => {
|
|
|
87
92
|
filterAdmissionStatus: string | undefined;
|
|
88
93
|
filterStartDate: string | undefined;
|
|
89
94
|
filterEndDate: string | undefined;
|
|
95
|
+
appliedFilterEnabled: boolean | undefined;
|
|
96
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
97
|
+
appliedFilterStartDate: string | undefined;
|
|
98
|
+
appliedFilterEndDate: string | undefined;
|
|
90
99
|
};
|
|
91
100
|
dispatch: React.Dispatch<any>;
|
|
92
101
|
};
|
|
@@ -24,7 +24,7 @@ import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/forma
|
|
|
24
24
|
import { Filter, Plus } from "lucide-react";
|
|
25
25
|
import { ADMISSION_DRAWER, ADMISSION_ACTION_TYPES, useAdmissionContext, } from "../context";
|
|
26
26
|
export const useAdmissionModule = () => {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
28
28
|
// ============================================================================
|
|
29
29
|
// 1.4.1 STATE & CORE HOOKS
|
|
30
30
|
// ============================================================================
|
|
@@ -36,36 +36,38 @@ export const useAdmissionModule = () => {
|
|
|
36
36
|
const workspace = getCachedWorkspaceSync();
|
|
37
37
|
const listFetchNowRef = useRef(null);
|
|
38
38
|
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
39
|
+
// Discount codes are school-scoped; fetch once (not per render) so both the
|
|
40
|
+
// form combobox and the PDF code lookup have data.
|
|
39
41
|
const { data: discountCodesData } = useFetch(DISCOUNT_CODE_API_ROUTES.UNIT, {
|
|
40
|
-
params: {
|
|
42
|
+
params: { schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id },
|
|
41
43
|
method: API_METHODS.GET,
|
|
44
|
+
autoFetch: true,
|
|
42
45
|
});
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const data = discountCodesData === null || discountCodesData === void 0 ? void 0 : discountCodesData.data;
|
|
46
|
-
return new Map((_a = data === null || data === void 0 ? void 0 : data.items.map((dc) => [dc.id, dc])) !== null && _a !== void 0 ? _a : []);
|
|
47
|
-
}, [discountCodesData]);
|
|
46
|
+
const discountCodes = useMemo(() => { var _a; return (_a = discountCodesData === null || discountCodesData === void 0 ? void 0 : discountCodesData.items) !== null && _a !== void 0 ? _a : []; }, [discountCodesData]);
|
|
47
|
+
const discountCodeMap = useMemo(() => new Map(discountCodes.map((dc) => [dc.id, dc])), [discountCodes]);
|
|
48
48
|
// ============================================================================
|
|
49
49
|
// 1.4.2 API PARAMETERS
|
|
50
50
|
// ============================================================================
|
|
51
51
|
const listParams = useMemo(() => {
|
|
52
52
|
var _a;
|
|
53
|
-
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "" }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.
|
|
54
|
-
? { filterEnabled: String(state.
|
|
55
|
-
: {})), (state.
|
|
56
|
-
? { filterAdmissionStatus: state.
|
|
57
|
-
: {})), (state.
|
|
58
|
-
? { filterStartDate: state.
|
|
59
|
-
: {})), (state.
|
|
53
|
+
return (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "" }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
|
|
54
|
+
? { filterEnabled: String(state.appliedFilterEnabled) }
|
|
55
|
+
: {})), (state.appliedFilterAdmissionStatus
|
|
56
|
+
? { filterAdmissionStatus: state.appliedFilterAdmissionStatus }
|
|
57
|
+
: {})), (state.appliedFilterStartDate
|
|
58
|
+
? { filterStartDate: state.appliedFilterStartDate }
|
|
59
|
+
: {})), (state.appliedFilterEndDate
|
|
60
|
+
? { filterEndDate: state.appliedFilterEndDate }
|
|
61
|
+
: {})));
|
|
60
62
|
}, [
|
|
63
|
+
state.appliedFilterAdmissionStatus,
|
|
64
|
+
state.appliedFilterEnabled,
|
|
65
|
+
state.appliedFilterEndDate,
|
|
66
|
+
state.appliedFilterStartDate,
|
|
61
67
|
state.currentPage,
|
|
62
|
-
state.filterAdmissionStatus,
|
|
63
|
-
state.filterEnabled,
|
|
64
|
-
state.filterEndDate,
|
|
65
|
-
state.filterStartDate,
|
|
66
68
|
state.pageLimit,
|
|
67
69
|
debouncedQuery,
|
|
68
|
-
(
|
|
70
|
+
(_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id,
|
|
69
71
|
]);
|
|
70
72
|
const updateParams = useMemo(() => {
|
|
71
73
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -141,11 +143,13 @@ export const useAdmissionModule = () => {
|
|
|
141
143
|
state.state,
|
|
142
144
|
state.status,
|
|
143
145
|
state.studentIdNumber,
|
|
144
|
-
(
|
|
145
|
-
(
|
|
146
|
+
(_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.country,
|
|
147
|
+
(_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id,
|
|
146
148
|
]);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
// Single-record calls must carry the tenant: the API/tenant guard cannot
|
|
150
|
+
// scope an id-only request.
|
|
151
|
+
const byIdParams = useMemo(() => { var _a; return ({ id: state.id, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id }); }, [state.id, (_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id]);
|
|
152
|
+
const deleteParams = useMemo(() => { var _a; return ({ id: state.id, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id }); }, [state.id, (_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id]);
|
|
149
153
|
// ============================================================================
|
|
150
154
|
// 1.4.3 UTILITIES
|
|
151
155
|
// ============================================================================
|
|
@@ -324,7 +328,7 @@ export const useAdmissionModule = () => {
|
|
|
324
328
|
throw new Error("Upload failed");
|
|
325
329
|
}
|
|
326
330
|
return data.urls;
|
|
327
|
-
}, [(
|
|
331
|
+
}, [(_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id]);
|
|
328
332
|
// ============================================================================
|
|
329
333
|
// 1.4.5 API HOOKS
|
|
330
334
|
// ============================================================================
|
|
@@ -364,11 +368,13 @@ export const useAdmissionModule = () => {
|
|
|
364
368
|
}, [resetFormAndCloseDrawer]);
|
|
365
369
|
const handleCreate = useCallback(() => {
|
|
366
370
|
wakeStorageServer();
|
|
371
|
+
// Never carry a previous edit's id/values into a new application.
|
|
372
|
+
dispatch({ type: ADMISSION_ACTION_TYPES.RESET_FORM });
|
|
367
373
|
dispatch({
|
|
368
374
|
type: ADMISSION_ACTION_TYPES.SET_DRAWER,
|
|
369
375
|
payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
|
|
370
376
|
});
|
|
371
|
-
}, [dispatch
|
|
377
|
+
}, [dispatch]);
|
|
372
378
|
const handleView = useCallback((row) => {
|
|
373
379
|
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
374
380
|
dispatch({
|
|
@@ -383,14 +389,18 @@ export const useAdmissionModule = () => {
|
|
|
383
389
|
type: ADMISSION_ACTION_TYPES.SET_DRAWER,
|
|
384
390
|
payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
|
|
385
391
|
});
|
|
386
|
-
}, [dispatch, byIdFetchNow
|
|
392
|
+
}, [dispatch, byIdFetchNow]);
|
|
387
393
|
const handleDelete = useCallback((row) => {
|
|
394
|
+
var _a;
|
|
388
395
|
if (!confirm(t("messagesDeleteConfirmation")))
|
|
389
396
|
return;
|
|
390
397
|
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
391
|
-
body: JSON.stringify({
|
|
398
|
+
body: JSON.stringify({
|
|
399
|
+
id: row === null || row === void 0 ? void 0 : row.id,
|
|
400
|
+
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
401
|
+
}),
|
|
392
402
|
});
|
|
393
|
-
}, [t, deleteFetchNow]);
|
|
403
|
+
}, [t, deleteFetchNow, (_h = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _h === void 0 ? void 0 : _h.id]);
|
|
394
404
|
const handleRemoveDocument = useCallback(async (url) => {
|
|
395
405
|
var _a;
|
|
396
406
|
const next = (state.documents || []).filter((d) => d !== url);
|
|
@@ -420,7 +430,7 @@ export const useAdmissionModule = () => {
|
|
|
420
430
|
}
|
|
421
431
|
}, [
|
|
422
432
|
dispatch,
|
|
423
|
-
(
|
|
433
|
+
(_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id,
|
|
424
434
|
state.documents,
|
|
425
435
|
state.id,
|
|
426
436
|
state.classForAdmission,
|
|
@@ -491,18 +501,24 @@ export const useAdmissionModule = () => {
|
|
|
491
501
|
});
|
|
492
502
|
}, [dispatch]);
|
|
493
503
|
const handlePrint = useCallback(async (row) => {
|
|
494
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
504
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
495
505
|
if (!row)
|
|
496
506
|
return;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
507
|
+
let logoBase64 = {};
|
|
508
|
+
if ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.logo) {
|
|
509
|
+
try {
|
|
510
|
+
const logoBase64Res = await fetch(`/api/v1/auth/image-url-to-base64`, {
|
|
511
|
+
method: API_METHODS.POST,
|
|
512
|
+
body: JSON.stringify({ url: workspace.school.logo }),
|
|
513
|
+
headers: { "Content-Type": "application/json" },
|
|
514
|
+
});
|
|
515
|
+
if (logoBase64Res.ok)
|
|
516
|
+
logoBase64 = await logoBase64Res.json();
|
|
517
|
+
}
|
|
518
|
+
catch (_j) {
|
|
519
|
+
// The form still renders without a logo.
|
|
520
|
+
}
|
|
521
|
+
}
|
|
506
522
|
try {
|
|
507
523
|
const rowRecord = row;
|
|
508
524
|
const studentDetails = rowRecord.studentDetails || {};
|
|
@@ -510,6 +526,7 @@ export const useAdmissionModule = () => {
|
|
|
510
526
|
const fatherDetails = rowRecord.fatherDetails || {};
|
|
511
527
|
const motherDetails = rowRecord.motherDetails || {};
|
|
512
528
|
const homeDetails = rowRecord.homeDetails || {};
|
|
529
|
+
const officeUse = rowRecord.officeUse || {};
|
|
513
530
|
const pdfData = {
|
|
514
531
|
firstName: studentDetails.firstName || "",
|
|
515
532
|
lastName: studentDetails.lastName || "",
|
|
@@ -537,8 +554,8 @@ export const useAdmissionModule = () => {
|
|
|
537
554
|
classForAdmission: admissionDetails.classForAdmission || "",
|
|
538
555
|
previousSchool: admissionDetails.previousSchool,
|
|
539
556
|
siblings: admissionDetails.siblings,
|
|
540
|
-
notes:
|
|
541
|
-
admissionNotes:
|
|
557
|
+
notes: officeUse.notes,
|
|
558
|
+
admissionNotes: officeUse.admissionNotes,
|
|
542
559
|
schoolName: ((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.name) || undefined,
|
|
543
560
|
schoolAddress: ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.address) || undefined,
|
|
544
561
|
schoolPhone: ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.phone) || undefined,
|
|
@@ -546,40 +563,72 @@ export const useAdmissionModule = () => {
|
|
|
546
563
|
submissionDate: (row === null || row === void 0 ? void 0 : row.createdAt)
|
|
547
564
|
? new Date(row === null || row === void 0 ? void 0 : row.createdAt).toLocaleDateString()
|
|
548
565
|
: undefined,
|
|
549
|
-
admissionStatus:
|
|
566
|
+
admissionStatus: String((_h = row === null || row === void 0 ? void 0 : row.status) !== null && _h !== void 0 ? _h : ""),
|
|
550
567
|
logo: logoBase64.base64,
|
|
551
568
|
};
|
|
552
569
|
await downloadAdmissionFormPDF(pdfData);
|
|
553
570
|
}
|
|
554
|
-
catch (
|
|
571
|
+
catch (_k) {
|
|
555
572
|
showToast(t("messagesPrintFailed"), TOAST_VARIANT.ERROR);
|
|
556
573
|
}
|
|
557
574
|
}, [workspace, discountCodeMap, t, showToast]);
|
|
558
|
-
const
|
|
575
|
+
const handleUpdateStatus = useCallback((row, status, confirmation) => {
|
|
559
576
|
var _a;
|
|
577
|
+
if (!(row === null || row === void 0 ? void 0 : row.id))
|
|
578
|
+
return;
|
|
579
|
+
if (!confirm(confirmation))
|
|
580
|
+
return;
|
|
581
|
+
updateFetchNow(undefined, {
|
|
582
|
+
body: JSON.stringify({
|
|
583
|
+
id: row.id,
|
|
584
|
+
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
585
|
+
status,
|
|
586
|
+
}),
|
|
587
|
+
});
|
|
588
|
+
}, [updateFetchNow, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id]);
|
|
589
|
+
const handleApprove = useCallback((row) => {
|
|
590
|
+
handleUpdateStatus(row, ADMISSION_STATUS.APPROVED, t("messagesApproveConfirmation"));
|
|
591
|
+
}, [handleUpdateStatus, t]);
|
|
592
|
+
const handleReject = useCallback((row) => {
|
|
593
|
+
handleUpdateStatus(row, ADMISSION_STATUS.REJECTED, t("messagesRejectConfirmation"));
|
|
594
|
+
}, [handleUpdateStatus, t]);
|
|
595
|
+
const handleCancelAdmission = useCallback((row) => {
|
|
596
|
+
handleUpdateStatus(row, ADMISSION_STATUS.CANCELLED, t("messagesCancelConfirmation"));
|
|
597
|
+
}, [handleUpdateStatus, t]);
|
|
598
|
+
const handleAddStudent = useCallback(async (row) => {
|
|
599
|
+
var _a, _b;
|
|
560
600
|
const tableRow = row;
|
|
601
|
+
if (!(tableRow === null || tableRow === void 0 ? void 0 : tableRow.id))
|
|
602
|
+
return;
|
|
603
|
+
if (!confirm(t("messagesAdmitConfirmation")))
|
|
604
|
+
return;
|
|
561
605
|
const { data, error } = await fetchData({
|
|
562
606
|
url: "/api/v1/admit-student",
|
|
563
607
|
method: API_METHODS.POST,
|
|
564
608
|
headers: {
|
|
565
609
|
"Content-Type": "application/json",
|
|
566
|
-
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
567
610
|
},
|
|
568
|
-
body: JSON.stringify({
|
|
611
|
+
body: JSON.stringify({
|
|
612
|
+
admissionId: tableRow.id,
|
|
613
|
+
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
614
|
+
}),
|
|
569
615
|
});
|
|
570
|
-
(
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
616
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
617
|
+
// `fetchData` returns the error body as `data` on failure — check the
|
|
618
|
+
// error first so we never show both toasts.
|
|
574
619
|
if (error) {
|
|
575
620
|
showToast(t("messagesAdmitFailed"), TOAST_VARIANT.ERROR);
|
|
621
|
+
return;
|
|
576
622
|
}
|
|
577
|
-
|
|
623
|
+
if (data) {
|
|
624
|
+
showToast(t("messagesAdmitSuccess"), TOAST_VARIANT.SUCCESS);
|
|
625
|
+
}
|
|
626
|
+
}, [t, showToast, (_l = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _l === void 0 ? void 0 : _l.id]);
|
|
578
627
|
// ============================================================================
|
|
579
628
|
// 1.4.7 NETWORK ACTIONS
|
|
580
629
|
// ============================================================================
|
|
581
630
|
const handleAnalyze = useCallback(async (row) => {
|
|
582
|
-
var _a, _b
|
|
631
|
+
var _a, _b;
|
|
583
632
|
const tableRow = row;
|
|
584
633
|
if (!(tableRow === null || tableRow === void 0 ? void 0 : tableRow.id))
|
|
585
634
|
return;
|
|
@@ -627,13 +676,51 @@ export const useAdmissionModule = () => {
|
|
|
627
676
|
type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
|
|
628
677
|
payload: { form: { aiAnalysis: result.aiAnalysis } },
|
|
629
678
|
});
|
|
679
|
+
showToast(t("messagesAnalyzeSuccess"), TOAST_VARIANT.SUCCESS);
|
|
680
|
+
return;
|
|
630
681
|
}
|
|
631
|
-
|
|
682
|
+
// 202: the worker is scoring in the background. Poll the record until the
|
|
683
|
+
// analysis is persisted (bounded) so the drawer updates itself.
|
|
632
684
|
generateThemeToast({
|
|
633
|
-
description:
|
|
634
|
-
variant: TOAST_VARIANT.
|
|
685
|
+
description: t("messagesAnalyzeQueued"),
|
|
686
|
+
variant: TOAST_VARIANT.INFO,
|
|
687
|
+
});
|
|
688
|
+
const startedAt = Date.now();
|
|
689
|
+
const pollUntil = startedAt + 60000;
|
|
690
|
+
let found = false;
|
|
691
|
+
while (Date.now() < pollUntil) {
|
|
692
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
693
|
+
const { data: freshData, error: freshError } = await fetchData({
|
|
694
|
+
url: `${ADMISSION_API_ROUTES.UNIT}?id=${encodeURIComponent(tableRow.id)}&schoolId=${encodeURIComponent(schoolId)}`,
|
|
695
|
+
method: API_METHODS.GET,
|
|
696
|
+
});
|
|
697
|
+
if (freshError)
|
|
698
|
+
continue;
|
|
699
|
+
const freshAi = freshData === null || freshData === void 0 ? void 0 : freshData.aiAnalysis;
|
|
700
|
+
if (freshAi) {
|
|
701
|
+
dispatch({
|
|
702
|
+
type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
|
|
703
|
+
payload: { form: { aiAnalysis: freshAi } },
|
|
704
|
+
});
|
|
705
|
+
found = true;
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
dispatch({
|
|
710
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
711
|
+
payload: { key: "analyzeLoading", value: false },
|
|
635
712
|
});
|
|
636
|
-
|
|
713
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
714
|
+
if (!found) {
|
|
715
|
+
dispatch({
|
|
716
|
+
type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
|
|
717
|
+
payload: { form: { analyzeError: t("messagesAnalyzeTimeout") } },
|
|
718
|
+
});
|
|
719
|
+
showToast(t("messagesAnalyzeTimeout"), TOAST_VARIANT.ERROR);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
showToast(t("messagesAnalyzeSuccess"), TOAST_VARIANT.SUCCESS);
|
|
723
|
+
}, [(_m = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _m === void 0 ? void 0 : _m.id, t, showToast, byIdFetchNow, dispatch]);
|
|
637
724
|
const handleSubmit = useCallback(() => {
|
|
638
725
|
dispatch({
|
|
639
726
|
type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
@@ -661,6 +748,8 @@ export const useAdmissionModule = () => {
|
|
|
661
748
|
});
|
|
662
749
|
updateFetchNow(undefined, {
|
|
663
750
|
body: JSON.stringify({
|
|
751
|
+
// Without the id the API would create a duplicate on every edit.
|
|
752
|
+
id: updateParams.id,
|
|
664
753
|
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
665
754
|
admissionDetails: {
|
|
666
755
|
classForAdmission: updateParams.classForAdmission,
|
|
@@ -740,12 +829,12 @@ export const useAdmissionModule = () => {
|
|
|
740
829
|
state.documents,
|
|
741
830
|
state.documentsFiles,
|
|
742
831
|
uploadAdmissionDocuments,
|
|
743
|
-
(
|
|
832
|
+
(_o = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _o === void 0 ? void 0 : _o.id,
|
|
744
833
|
]);
|
|
745
834
|
// ============================================================================
|
|
746
835
|
// 1.4.8 HEADER & ROW ACTIONS
|
|
747
836
|
// ============================================================================
|
|
748
|
-
const hasGeminiSecrets = Boolean(((
|
|
837
|
+
const hasGeminiSecrets = Boolean(((_p = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _p === void 0 ? void 0 : _p.GEMINI_API_KEY) && ((_q = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _q === void 0 ? void 0 : _q.GEMINI_MODEL));
|
|
749
838
|
const headerActions = useMemo(() => [
|
|
750
839
|
{
|
|
751
840
|
enabled: true,
|
|
@@ -777,47 +866,91 @@ export const useAdmissionModule = () => {
|
|
|
777
866
|
},
|
|
778
867
|
{
|
|
779
868
|
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
|
|
780
|
-
handleOnClick:
|
|
781
|
-
label: t("
|
|
869
|
+
handleOnClick: handleApprove,
|
|
870
|
+
label: t("actionsButtonApprove"),
|
|
782
871
|
order: 3,
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
|
|
875
|
+
handleOnClick: handleReject,
|
|
876
|
+
label: t("actionsButtonReject"),
|
|
877
|
+
order: 4,
|
|
783
878
|
variant: "destructive",
|
|
784
879
|
},
|
|
880
|
+
{
|
|
881
|
+
enabled: (row) => {
|
|
882
|
+
const status = row === null || row === void 0 ? void 0 : row.status;
|
|
883
|
+
return (status === ADMISSION_STATUS.PENDING ||
|
|
884
|
+
status === ADMISSION_STATUS.APPROVED);
|
|
885
|
+
},
|
|
886
|
+
handleOnClick: handleCancelAdmission,
|
|
887
|
+
label: t("actionsButtonCancelAdmission"),
|
|
888
|
+
order: 5,
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.APPROVED,
|
|
892
|
+
handleOnClick: handleAddStudent,
|
|
893
|
+
label: t("actionsButtonAddStudent"),
|
|
894
|
+
order: 6,
|
|
895
|
+
},
|
|
785
896
|
{
|
|
786
897
|
enabled: true,
|
|
787
898
|
handleOnClick: handlePrint,
|
|
788
899
|
label: t("actionsButtonPrintPdf"),
|
|
789
|
-
order:
|
|
900
|
+
order: 7,
|
|
790
901
|
},
|
|
791
902
|
{
|
|
792
903
|
enabled: (row) => hasGeminiSecrets &&
|
|
793
904
|
(row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
|
|
794
905
|
handleOnClick: handleAnalyze,
|
|
795
906
|
label: t("actionsButtonAnalyzeWithAi"),
|
|
796
|
-
order:
|
|
907
|
+
order: 8,
|
|
797
908
|
},
|
|
798
909
|
{
|
|
799
|
-
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status)
|
|
800
|
-
handleOnClick:
|
|
801
|
-
label: t("
|
|
802
|
-
order:
|
|
910
|
+
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
|
|
911
|
+
handleOnClick: handleDelete,
|
|
912
|
+
label: t("actionsButtonDelete"),
|
|
913
|
+
order: 9,
|
|
914
|
+
variant: "destructive",
|
|
803
915
|
},
|
|
804
916
|
], [
|
|
805
917
|
handleView,
|
|
806
918
|
handleEdit,
|
|
807
|
-
|
|
919
|
+
handleApprove,
|
|
920
|
+
handleReject,
|
|
921
|
+
handleCancelAdmission,
|
|
922
|
+
handleAddStudent,
|
|
808
923
|
handlePrint,
|
|
809
924
|
handleAnalyze,
|
|
810
|
-
|
|
925
|
+
handleDelete,
|
|
811
926
|
hasGeminiSecrets,
|
|
812
927
|
t,
|
|
813
928
|
]);
|
|
814
929
|
const applyFilters = useCallback(() => {
|
|
930
|
+
dispatch({
|
|
931
|
+
type: ADMISSION_ACTION_TYPES.SET_FILTERS,
|
|
932
|
+
payload: {
|
|
933
|
+
filters: {
|
|
934
|
+
appliedFilterEnabled: state.filterEnabled,
|
|
935
|
+
appliedFilterAdmissionStatus: state.filterAdmissionStatus,
|
|
936
|
+
appliedFilterStartDate: state.filterStartDate,
|
|
937
|
+
appliedFilterEndDate: state.filterEndDate,
|
|
938
|
+
},
|
|
939
|
+
},
|
|
940
|
+
});
|
|
815
941
|
dispatch({
|
|
816
942
|
type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
817
943
|
payload: { currentPage: 1 },
|
|
818
944
|
});
|
|
819
945
|
handleCloseDrawer();
|
|
820
|
-
}, [
|
|
946
|
+
}, [
|
|
947
|
+
dispatch,
|
|
948
|
+
handleCloseDrawer,
|
|
949
|
+
state.filterAdmissionStatus,
|
|
950
|
+
state.filterEnabled,
|
|
951
|
+
state.filterEndDate,
|
|
952
|
+
state.filterStartDate,
|
|
953
|
+
]);
|
|
821
954
|
// ============================================================================
|
|
822
955
|
// 1.4.9 EFFECTS
|
|
823
956
|
// ============================================================================
|
|
@@ -837,8 +970,11 @@ export const useAdmissionModule = () => {
|
|
|
837
970
|
byIdLoading,
|
|
838
971
|
clearFilters,
|
|
839
972
|
deleteLoading,
|
|
973
|
+
discountCodes,
|
|
840
974
|
handleAddStudent,
|
|
841
975
|
handleAnalyze,
|
|
976
|
+
handleApprove,
|
|
977
|
+
handleCancelAdmission,
|
|
842
978
|
handleChange,
|
|
843
979
|
handleCloseDrawer,
|
|
844
980
|
handleCreate,
|
|
@@ -849,10 +985,12 @@ export const useAdmissionModule = () => {
|
|
|
849
985
|
handlePageLimitChange,
|
|
850
986
|
handlePrint,
|
|
851
987
|
handleRemoveDocument,
|
|
988
|
+
handleReject,
|
|
852
989
|
handleSearch,
|
|
853
990
|
handleSetEndDate,
|
|
854
991
|
handleSetStartDate,
|
|
855
992
|
handleSubmit,
|
|
993
|
+
handleUpdateStatus,
|
|
856
994
|
handleView,
|
|
857
995
|
headerActions,
|
|
858
996
|
listLoading,
|
|
@@ -71,6 +71,10 @@ export declare const ADMISSION_ACTION_TYPES: {
|
|
|
71
71
|
filterAdmissionStatus: string | undefined;
|
|
72
72
|
filterStartDate: string | undefined;
|
|
73
73
|
filterEndDate: string | undefined;
|
|
74
|
+
appliedFilterEnabled: boolean | undefined;
|
|
75
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
76
|
+
appliedFilterStartDate: string | undefined;
|
|
77
|
+
appliedFilterEndDate: string | undefined;
|
|
74
78
|
}>, initialAdmissionState: {
|
|
75
79
|
items: AdmissionBE[];
|
|
76
80
|
count: number;
|
|
@@ -125,6 +129,10 @@ export declare const ADMISSION_ACTION_TYPES: {
|
|
|
125
129
|
filterAdmissionStatus: string | undefined;
|
|
126
130
|
filterStartDate: string | undefined;
|
|
127
131
|
filterEndDate: string | undefined;
|
|
132
|
+
appliedFilterEnabled: boolean | undefined;
|
|
133
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
134
|
+
appliedFilterStartDate: string | undefined;
|
|
135
|
+
appliedFilterEndDate: string | undefined;
|
|
128
136
|
}, AdmissionProvider: import("react").FC<{
|
|
129
137
|
children: React.ReactNode;
|
|
130
138
|
}>, admissionReducer: (state: {
|
|
@@ -181,6 +189,10 @@ export declare const ADMISSION_ACTION_TYPES: {
|
|
|
181
189
|
filterAdmissionStatus: string | undefined;
|
|
182
190
|
filterStartDate: string | undefined;
|
|
183
191
|
filterEndDate: string | undefined;
|
|
192
|
+
appliedFilterEnabled: boolean | undefined;
|
|
193
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
194
|
+
appliedFilterStartDate: string | undefined;
|
|
195
|
+
appliedFilterEndDate: string | undefined;
|
|
184
196
|
}, action: any) => {
|
|
185
197
|
items: AdmissionBE[];
|
|
186
198
|
count: number;
|
|
@@ -235,6 +247,10 @@ export declare const ADMISSION_ACTION_TYPES: {
|
|
|
235
247
|
filterAdmissionStatus: string | undefined;
|
|
236
248
|
filterStartDate: string | undefined;
|
|
237
249
|
filterEndDate: string | undefined;
|
|
250
|
+
appliedFilterEnabled: boolean | undefined;
|
|
251
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
252
|
+
appliedFilterStartDate: string | undefined;
|
|
253
|
+
appliedFilterEndDate: string | undefined;
|
|
238
254
|
}, useAdmissionContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
|
|
239
255
|
items: AdmissionBE[];
|
|
240
256
|
count: number;
|
|
@@ -289,5 +305,9 @@ export declare const ADMISSION_ACTION_TYPES: {
|
|
|
289
305
|
filterAdmissionStatus: string | undefined;
|
|
290
306
|
filterStartDate: string | undefined;
|
|
291
307
|
filterEndDate: string | undefined;
|
|
308
|
+
appliedFilterEnabled: boolean | undefined;
|
|
309
|
+
appliedFilterAdmissionStatus: string | undefined;
|
|
310
|
+
appliedFilterStartDate: string | undefined;
|
|
311
|
+
appliedFilterEndDate: string | undefined;
|
|
292
312
|
}>;
|
|
293
313
|
export { useAdmissionModule } from "./context/use-admission-module";
|
|
@@ -99,11 +99,17 @@ const admissionConfig = {
|
|
|
99
99
|
aiAnalysis: null,
|
|
100
100
|
analyzeLoading: false,
|
|
101
101
|
analyzeError: null,
|
|
102
|
-
// Filter
|
|
103
|
-
|
|
102
|
+
// Filter state is staged: the drawer edits `filter*`, Apply copies them to
|
|
103
|
+
// `applied*`, and only `applied*` drives the request (no refetch per
|
|
104
|
+
// keystroke). Soft-deleted records are hidden by default.
|
|
105
|
+
filterEnabled: true,
|
|
104
106
|
filterAdmissionStatus: undefined,
|
|
105
107
|
filterStartDate: undefined,
|
|
106
108
|
filterEndDate: undefined,
|
|
109
|
+
appliedFilterEnabled: true,
|
|
110
|
+
appliedFilterAdmissionStatus: undefined,
|
|
111
|
+
appliedFilterStartDate: undefined,
|
|
112
|
+
appliedFilterEndDate: undefined,
|
|
107
113
|
},
|
|
108
114
|
drawerTypes: DRAWER_TYPES,
|
|
109
115
|
};
|
|
@@ -6,11 +6,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
* Filter UI for admission records. Uses the module state pattern:
|
|
7
7
|
* `const { state, handleChange, handleSetStartDate, handleSetEndDate } = useAdmissionModule()`
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
10
10
|
import { EnhancedRadio } from "@appcorp/shadcn/components/enhanced-radio";
|
|
11
11
|
import { useTranslations } from "next-intl";
|
|
12
12
|
import { ADMISSION_STATUS_OPTIONS } from "./constants";
|
|
13
|
-
import { ADMISSION_API_ROUTES } from "../../constants";
|
|
14
13
|
import { useAdmissionModule } from "./context";
|
|
15
14
|
export const AdmissionFilter = () => {
|
|
16
15
|
const { state, handleChange, handleSetStartDate, handleSetEndDate } = useAdmissionModule();
|
|
@@ -28,26 +27,12 @@ export const AdmissionFilter = () => {
|
|
|
28
27
|
: filterEnabled
|
|
29
28
|
? "true"
|
|
30
29
|
: "false";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
info: t("drawerFilterAdmissionStatusInfo"),
|
|
35
|
-
options: ADMISSION_STATUS_OPTIONS.map((opt) => ({
|
|
30
|
+
// Static options: the status list is a fixed enum. A remote search here
|
|
31
|
+
// would replace the options with admission rows.
|
|
32
|
+
const filterAdmissionStatusCombo = (_jsx(EnhancedCombobox, { id: "filterAdmissionStatus", info: t("drawerFilterAdmissionStatusInfo"), label: t("drawerFilterAdmissionStatusLabel"), onValueChange: (value) => handleChange("filterAdmissionStatus", value), options: ADMISSION_STATUS_OPTIONS.map((opt) => ({
|
|
36
33
|
value: opt.value,
|
|
37
34
|
label: admissionStatusLabelMap[opt.value] || opt.label,
|
|
38
|
-
})),
|
|
39
|
-
value: filterAdmissionStatus || "",
|
|
40
|
-
onValueChange: (value) => handleChange("filterAdmissionStatus", value),
|
|
41
|
-
searchEndpoint: ADMISSION_API_ROUTES.UNIT,
|
|
42
|
-
placeholder: "",
|
|
43
|
-
formatSearchResult: (item) => {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
return ({
|
|
46
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
47
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
});
|
|
35
|
+
})), placeholder: "", value: filterAdmissionStatus || "" }));
|
|
51
36
|
return (_jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [filterAdmissionStatusCombo, _jsxs("div", { children: [_jsx("label", { htmlFor: "startDate", className: "text-foreground mb-1 block text-sm font-medium", children: t("drawerFilterStartDateLabel") }), _jsx("input", { id: "startDate", type: "date", value: filterStartDate || "", onChange: (e) => handleSetStartDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, className: "border-input bg-background text-foreground focus:ring-ring w-full rounded-md border px-3 py-2 focus:border-transparent focus:ring-2 focus:outline-none" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "endDate", className: "text-foreground mb-1 block text-sm font-medium", children: t("drawerFilterEndDateLabel") }), _jsx("input", { id: "endDate", type: "date", value: filterEndDate || "", onChange: (e) => handleSetEndDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, className: "border-input bg-background text-foreground focus:ring-ring w-full rounded-md border px-3 py-2 focus:border-transparent focus:ring-2 focus:outline-none" })] }), _jsx(EnhancedRadio, { label: t("filterOptionEnabled"), name: "filterEnabled", value: filterEnabledValue, options: [
|
|
52
37
|
{ label: t("filterOptionAll"), value: "undefined" },
|
|
53
38
|
{ label: t("filterOptionEnabled"), value: "true" },
|