@appcorp/fusion-storybook 0.2.13 → 0.2.14

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.
Files changed (48) hide show
  1. package/base-modules/admission/context/use-admission-module.d.ts +88 -0
  2. package/base-modules/admission/context/use-admission-module.js +771 -0
  3. package/base-modules/admission/context.d.ts +1 -87
  4. package/base-modules/admission/context.js +3 -769
  5. package/base-modules/campus/more-actions.js +0 -1
  6. package/base-modules/class/more-actions.js +1 -6
  7. package/base-modules/expense/more-actions.js +1 -6
  8. package/base-modules/fee-structure/more-actions.js +1 -6
  9. package/base-modules/student-fee/context/shared.d.ts +178 -0
  10. package/base-modules/student-fee/context/shared.js +59 -0
  11. package/base-modules/student-fee/context/use-student-fee-module.d.ts +64 -0
  12. package/base-modules/student-fee/context/use-student-fee-module.js +610 -0
  13. package/base-modules/student-fee/context.d.ts +21 -235
  14. package/base-modules/student-fee/context.js +2 -674
  15. package/base-modules/student-fee/more-actions.js +1 -6
  16. package/base-modules/student-profile/context/module-base.d.ts +187 -0
  17. package/base-modules/student-profile/context/module-base.js +50 -0
  18. package/base-modules/student-profile/context/use-student-profile-module.d.ts +70 -0
  19. package/base-modules/student-profile/context/use-student-profile-module.js +506 -0
  20. package/base-modules/student-profile/context.d.ts +20 -256
  21. package/base-modules/student-profile/context.js +2 -601
  22. package/base-modules/teacher/avatar-upload.js +1 -4
  23. package/base-modules/teacher/more-actions.js +1 -6
  24. package/base-modules/user/context/use-user-module.d.ts +53 -0
  25. package/base-modules/user/context/use-user-module.js +546 -0
  26. package/base-modules/user/context.d.ts +1 -52
  27. package/base-modules/user/context.js +5 -547
  28. package/base-modules/workspace-user/more-actions.js +1 -6
  29. package/components/module-error.d.ts +9 -0
  30. package/components/module-error.js +3 -0
  31. package/package.json +5 -4
  32. package/tsconfig.build.tsbuildinfo +1 -1
  33. package/type.d.ts +3 -1242
  34. package/type.js +3 -445
  35. package/types/academics.d.ts +264 -0
  36. package/types/academics.js +8 -0
  37. package/types/admission.d.ts +85 -0
  38. package/types/admission.js +6 -0
  39. package/types/communication.d.ts +165 -0
  40. package/types/communication.js +7 -0
  41. package/types/enums.d.ts +411 -0
  42. package/types/enums.js +442 -0
  43. package/types/finance.d.ts +126 -0
  44. package/types/finance.js +7 -0
  45. package/types/index.d.ts +12 -0
  46. package/types/index.js +12 -0
  47. package/types/user-management.d.ts +236 -0
  48. package/types/user-management.js +7 -0
@@ -18,27 +18,10 @@
18
18
  * - `ADMISSION_DRAWER` — drawer type constants
19
19
  * - `useAdmissionModule()` — hook that returns state, dispatch, and handlers
20
20
  */
21
- import { useCallback, useEffect, useMemo, useRef } from "react";
22
- import { useTheme } from "next-themes";
23
- import { useTranslations } from "next-intl";
24
- import { validateForm, isCreatedOrUpdated, API_METHODS, fetchData, } from "@react-pakistan/util-functions";
25
- import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
26
- import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
27
21
  import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
28
22
  import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
29
- import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
30
23
  import { ADMISSION_STATUS, GENDER, } from "../../type";
31
- import { ADMISSION_API_ROUTES, pageLimit } from "./constants";
32
- import { admissionFormValidation } from "./validate";
33
- import { getCachedAdmissions, invalidateAdmissionsCache } from "./cache";
34
- import { getCachedWorkspaceSync } from "../workspace/cache";
35
- import { generateAdmissionReceiptPDF, } from "../../utils/admission-pdf";
36
- import { formatNumber } from "@react-pakistan/util-functions/general/format-number";
37
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
38
- import { invalidateFamiliesCache } from "../family/cache";
39
- import { invalidateFamilyMembersCache } from "../family-member/cache";
40
- import { invalidateStudentProfilesCache } from "../student-profile/cache";
41
- import { Filter, Plus } from "lucide-react";
24
+ import { pageLimit } from "./constants";
42
25
  // ============================================================================
43
26
  // 1.1 DRAWER TYPES
44
27
  // ============================================================================
@@ -126,755 +109,6 @@ const admissionConfig = {
126
109
  // ============================================================================
127
110
  export const { actionTypes: ADMISSION_ACTION_TYPES, config: admissionModuleConfig, initialState: initialAdmissionState, Provider: AdmissionProvider, reducer: admissionReducer, useContext: useAdmissionContext, } = createGenericModule(admissionConfig);
128
111
  // ============================================================================
129
- // 1.4 ENHANCED ADMISSION HOOK WITH API INTEGRATION
112
+ // 1.4 EXPORT ENHANCED HOOK
130
113
  // ============================================================================
131
- export const useAdmissionModule = () => {
132
- var _a, _b, _c, _d, _e, _f;
133
- // ============================================================================
134
- // 1.4.1 STATE & CORE HOOKS
135
- // ============================================================================
136
- const context = useAdmissionContext();
137
- const { dispatch } = context;
138
- const state = context.state;
139
- const t = useTranslations("admission");
140
- const { theme } = useTheme();
141
- const workspace = getCachedWorkspaceSync();
142
- const listFetchNowRef = useRef(null);
143
- const debouncedQuery = useDebounce(state.searchQuery, 800);
144
- // ============================================================================
145
- // 1.4.2 API PARAMETERS
146
- // ============================================================================
147
- const listParams = useMemo(() => {
148
- var _a;
149
- 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.filterEnabled !== undefined
150
- ? { filterEnabled: String(state.filterEnabled) }
151
- : {})), (state.filterAdmissionStatus
152
- ? { filterAdmissionStatus: state.filterAdmissionStatus }
153
- : {})), (state.filterStartDate
154
- ? { filterStartDate: state.filterStartDate }
155
- : {})), (state.filterEndDate ? { filterEndDate: state.filterEndDate } : {})));
156
- }, [
157
- state.currentPage,
158
- state.filterAdmissionStatus,
159
- state.filterEnabled,
160
- state.filterEndDate,
161
- state.filterStartDate,
162
- state.pageLimit,
163
- debouncedQuery,
164
- (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
165
- ]);
166
- const updateParams = useMemo(() => {
167
- var _a, _b, _c, _d;
168
- return ({
169
- address: state.address || "",
170
- admissionNotes: state.admissionNotes || "",
171
- admissionStatus: state.status || ADMISSION_STATUS.PENDING,
172
- studentIdNumber: state.studentIdNumber || "",
173
- city: state.city || "",
174
- classForAdmission: state.classForAdmission || "",
175
- country: state.country || "",
176
- discountCode: state.discountCode || "",
177
- dob: state.dob || null,
178
- emergencyContact: state.emergencyContact || "",
179
- enabled: (_a = state.enabled) !== null && _a !== void 0 ? _a : true,
180
- fatherIdNumber: state.fatherIdNumber || "",
181
- fatherFirstName: state.fatherFirstName || "",
182
- fatherLastName: state.fatherLastName || "",
183
- fatherMobile: formatNumber(state.fatherMobile),
184
- fatherOccupation: state.fatherOccupation || "",
185
- fatherOrganization: state.fatherOrganization || "",
186
- firstName: state.firstName || "",
187
- gender: state.gender || null,
188
- hafiz: (_b = state.hafiz) !== null && _b !== void 0 ? _b : false,
189
- id: state.id || "",
190
- lastName: state.lastName || "",
191
- motherIdNumber: state.motherIdNumber || "",
192
- motherFirstName: state.motherFirstName || "",
193
- motherLastName: state.motherLastName || "",
194
- motherMobile: formatNumber(state.motherMobile),
195
- notes: state.notes || "",
196
- orphan: (_c = state.orphan) !== null && _c !== void 0 ? _c : false,
197
- postalCode: state.postalCode || "",
198
- previousSchool: state.previousSchool || "",
199
- registrationCode: state.registrationCode || "",
200
- schoolId: ((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id) || "",
201
- siblings: state.siblings || "",
202
- state: state.state || "",
203
- });
204
- }, [
205
- state.address,
206
- state.admissionNotes,
207
- state.status,
208
- state.studentIdNumber,
209
- state.city,
210
- state.classForAdmission,
211
- state.country,
212
- state.discountCode,
213
- state.dob,
214
- state.emergencyContact,
215
- state.enabled,
216
- state.fatherIdNumber,
217
- state.fatherFirstName,
218
- state.fatherLastName,
219
- state.fatherMobile,
220
- state.fatherOccupation,
221
- state.fatherOrganization,
222
- state.firstName,
223
- state.gender,
224
- state.hafiz,
225
- state.id,
226
- state.lastName,
227
- state.motherIdNumber,
228
- state.motherFirstName,
229
- state.motherLastName,
230
- state.motherMobile,
231
- state.notes,
232
- state.orphan,
233
- state.postalCode,
234
- state.previousSchool,
235
- state.registrationCode,
236
- state.siblings,
237
- state.state,
238
- (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id,
239
- ]);
240
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
241
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
242
- const isDefaultListState = state.currentPage === 1 &&
243
- state.pageLimit === pageLimit &&
244
- !debouncedQuery &&
245
- state.filterAdmissionStatus === undefined &&
246
- state.filterStartDate === undefined &&
247
- state.filterEndDate === undefined;
248
- // ============================================================================
249
- // 1.4.3 UTILITIES
250
- // ============================================================================
251
- const showToast = useCallback((description, variant) => {
252
- generateThemeToast({
253
- description,
254
- theme: theme,
255
- variant,
256
- });
257
- }, [theme]);
258
- const setField = useCallback((key, value) => {
259
- var _a;
260
- let formatted = value === null
261
- ? undefined
262
- : value;
263
- if ((key === "fatherMobile" || key === "motherMobile") &&
264
- typeof value === "string") {
265
- formatted = (_a = formatPhoneDisplay(value)) !== null && _a !== void 0 ? _a : value;
266
- }
267
- dispatch({
268
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
269
- payload: { key, value: formatted || value },
270
- });
271
- }, [dispatch]);
272
- const resetFormAndCloseDrawer = useCallback(() => {
273
- dispatch({ type: ADMISSION_ACTION_TYPES.RESET_FORM });
274
- dispatch({
275
- type: ADMISSION_ACTION_TYPES.SET_ERRORS,
276
- payload: { errors: {} },
277
- });
278
- dispatch({
279
- type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
280
- payload: { disabled: false },
281
- });
282
- dispatch({
283
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
284
- payload: { drawer: null },
285
- });
286
- }, [dispatch]);
287
- // ============================================================================
288
- // 1.4.4 API CALLBACKS
289
- // ============================================================================
290
- const listCallback = useCallback(({ data, error }) => {
291
- if (error) {
292
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
293
- return;
294
- }
295
- if (data) {
296
- dispatch({
297
- type: ADMISSION_ACTION_TYPES.SET_ITEMS,
298
- payload: { items: data.items || [], count: data.count || 0 },
299
- });
300
- }
301
- }, [dispatch, showToast, t]);
302
- const updateCallback = useCallback(({ data, error }) => {
303
- var _a;
304
- const isCreated = isCreatedOrUpdated(data);
305
- if (error) {
306
- showToast(isCreated ? t("messagesCreateFailed") : t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
307
- return;
308
- }
309
- if (data) {
310
- invalidateAdmissionsCache();
311
- showToast(t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
312
- resetFormAndCloseDrawer();
313
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
314
- }
315
- }, [resetFormAndCloseDrawer, showToast, t]);
316
- const byIdCallback = useCallback(({ data, error }) => {
317
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
318
- if (error) {
319
- showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
320
- return;
321
- }
322
- if (data) {
323
- const admission = data;
324
- if ((_a = admission === null || admission === void 0 ? void 0 : admission.fatherDetails) === null || _a === void 0 ? void 0 : _a.emergencyContact) {
325
- setField("emergencyContact", "Father");
326
- }
327
- if ((_b = admission === null || admission === void 0 ? void 0 : admission.motherDetails) === null || _b === void 0 ? void 0 : _b.emergencyContact) {
328
- setField("emergencyContact", "Mother");
329
- }
330
- setField("id", admission.id);
331
- setField("firstName", (_c = admission.studentDetails) === null || _c === void 0 ? void 0 : _c.firstName);
332
- setField("lastName", (_d = admission.studentDetails) === null || _d === void 0 ? void 0 : _d.lastName);
333
- setField("studentIdNumber", (_e = admission.studentDetails) === null || _e === void 0 ? void 0 : _e.studentIdNumber);
334
- // Normalise gender to match GENDER enum values (e.g. 'Male' → 'MALE')
335
- const rawGender = (_f = admission.studentDetails) === null || _f === void 0 ? void 0 : _f.gender;
336
- let normalizedGender = null;
337
- if (typeof rawGender === "string" && rawGender.length > 0) {
338
- const upper = rawGender.toUpperCase();
339
- normalizedGender = Object.values(GENDER).includes(upper)
340
- ? upper
341
- : rawGender;
342
- }
343
- setField("gender", normalizedGender);
344
- setField("dob", (_g = admission.studentDetails) === null || _g === void 0 ? void 0 : _g.dob);
345
- setField("registrationCode", (_h = admission.studentDetails) === null || _h === void 0 ? void 0 : _h.registrationCode);
346
- setField("discountCode", (_j = admission.studentDetails) === null || _j === void 0 ? void 0 : _j.discountCode);
347
- setField("hafiz", (_k = admission.studentDetails) === null || _k === void 0 ? void 0 : _k.hafiz);
348
- setField("orphan", (_l = admission.studentDetails) === null || _l === void 0 ? void 0 : _l.orphan);
349
- setField("fatherFirstName", (_m = admission.fatherDetails) === null || _m === void 0 ? void 0 : _m.fatherFirstName);
350
- setField("fatherLastName", (_o = admission.fatherDetails) === null || _o === void 0 ? void 0 : _o.fatherLastName);
351
- setField("fatherIdNumber", (_p = admission.fatherDetails) === null || _p === void 0 ? void 0 : _p.fatherIdNumber);
352
- setField("fatherMobile", (_r = formatPhoneDisplay((_q = admission.fatherDetails) === null || _q === void 0 ? void 0 : _q.fatherMobile)) !== null && _r !== void 0 ? _r : (_s = admission.fatherDetails) === null || _s === void 0 ? void 0 : _s.fatherMobile);
353
- setField("fatherOccupation", (_t = admission.fatherDetails) === null || _t === void 0 ? void 0 : _t.fatherOccupation);
354
- setField("fatherOrganization", (_u = admission.fatherDetails) === null || _u === void 0 ? void 0 : _u.fatherOrganization);
355
- setField("motherFirstName", (_v = admission.motherDetails) === null || _v === void 0 ? void 0 : _v.motherFirstName);
356
- setField("motherLastName", (_w = admission.motherDetails) === null || _w === void 0 ? void 0 : _w.motherLastName);
357
- setField("motherIdNumber", (_x = admission.motherDetails) === null || _x === void 0 ? void 0 : _x.motherIdNumber);
358
- setField("motherMobile", (_z = formatPhoneDisplay((_y = admission.motherDetails) === null || _y === void 0 ? void 0 : _y.motherMobile)) !== null && _z !== void 0 ? _z : (_0 = admission.motherDetails) === null || _0 === void 0 ? void 0 : _0.motherMobile);
359
- setField("address", (_1 = admission.homeDetails) === null || _1 === void 0 ? void 0 : _1.address);
360
- setField("city", (_2 = admission.homeDetails) === null || _2 === void 0 ? void 0 : _2.city);
361
- setField("country", (_3 = admission.homeDetails) === null || _3 === void 0 ? void 0 : _3.country);
362
- setField("postalCode", (_4 = admission.homeDetails) === null || _4 === void 0 ? void 0 : _4.postalCode);
363
- setField("state", (_5 = admission.homeDetails) === null || _5 === void 0 ? void 0 : _5.state);
364
- setField("notes", (_6 = admission.officeUse) === null || _6 === void 0 ? void 0 : _6.notes);
365
- setField("admissionNotes", (_7 = admission.officeUse) === null || _7 === void 0 ? void 0 : _7.admissionNotes);
366
- setField("previousSchool", (_8 = admission.admissionDetails) === null || _8 === void 0 ? void 0 : _8.previousSchool);
367
- setField("siblings", (_9 = admission.admissionDetails) === null || _9 === void 0 ? void 0 : _9.siblings);
368
- setField("classForAdmission", (_10 = admission.admissionDetails) === null || _10 === void 0 ? void 0 : _10.classForAdmission);
369
- setField("status", admission.status || ADMISSION_STATUS.PENDING);
370
- setField("enabled", (_11 = admission.enabled) !== null && _11 !== void 0 ? _11 : true);
371
- // Populate AI analysis if present
372
- const aiAnalysis = (_12 = admission
373
- .aiAnalysis) !== null && _12 !== void 0 ? _12 : null;
374
- dispatch({
375
- type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
376
- payload: { form: { aiAnalysis } },
377
- });
378
- }
379
- }, [dispatch, showToast, t, setField]);
380
- const deleteCallback = useCallback(({ data, error }) => {
381
- var _a;
382
- if (error) {
383
- showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
384
- return;
385
- }
386
- if (data) {
387
- invalidateAdmissionsCache();
388
- showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
389
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
390
- }
391
- }, [showToast, t]);
392
- // ============================================================================
393
- // 1.4.5 API HOOKS
394
- // ============================================================================
395
- const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
396
- byIdCallback,
397
- byIdParams,
398
- deleteCallback,
399
- deleteParams,
400
- listCallback,
401
- listParams,
402
- listUrl: ADMISSION_API_ROUTES.UNIT,
403
- searchQuery: debouncedQuery,
404
- unitByIdUrl: ADMISSION_API_ROUTES.UNIT,
405
- unitUrl: ADMISSION_API_ROUTES.UNIT,
406
- updateCallback,
407
- updateParams,
408
- headers: {
409
- "Content-Type": "application/json",
410
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
411
- },
412
- });
413
- // ============================================================================
414
- // 1.4.6 HANDLERS
415
- // ============================================================================
416
- const handleChange = useCallback((field, value) => {
417
- dispatch({
418
- type: ADMISSION_ACTION_TYPES.SET_ERRORS,
419
- payload: { errors: {} },
420
- });
421
- dispatch({
422
- type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
423
- payload: { disabled: false },
424
- });
425
- setField(field, value);
426
- }, [setField, dispatch]);
427
- const handleCloseDrawer = useCallback(() => {
428
- resetFormAndCloseDrawer();
429
- }, [resetFormAndCloseDrawer]);
430
- const handleCreate = useCallback(() => {
431
- dispatch({
432
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
433
- payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
434
- });
435
- }, [dispatch]);
436
- const handleView = useCallback((row) => {
437
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
438
- dispatch({
439
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
440
- payload: { drawer: ADMISSION_DRAWER.VIEW_DRAWER },
441
- });
442
- }, [dispatch, byIdFetchNow]);
443
- const handleEdit = useCallback((row) => {
444
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
445
- dispatch({
446
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
447
- payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
448
- });
449
- }, [dispatch, byIdFetchNow]);
450
- const handleDelete = useCallback((row) => {
451
- if (!confirm(t("actionDeleteConfirmation")))
452
- return;
453
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
454
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
455
- });
456
- }, [t, deleteFetchNow]);
457
- const handleFilters = useCallback(() => {
458
- dispatch({
459
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
460
- payload: { drawer: ADMISSION_DRAWER.FILTER_DRAWER },
461
- });
462
- }, [dispatch]);
463
- const handlePageChange = useCallback((page) => {
464
- const nextPage = typeof page === "number" ? page : state.currentPage + 1;
465
- dispatch({
466
- type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
467
- payload: { currentPage: nextPage },
468
- });
469
- }, [dispatch, state.currentPage]);
470
- const handlePageLimitChange = useCallback((k, value) => {
471
- const val = Object.assign({}, value);
472
- dispatch({
473
- type: ADMISSION_ACTION_TYPES.SET_PAGE_LIMIT,
474
- payload: { pageLimit: Number(val.option) },
475
- });
476
- dispatch({
477
- type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
478
- payload: { currentPage: 1 },
479
- });
480
- }, [dispatch]);
481
- const handleSearch = useCallback((query) => {
482
- dispatch({
483
- type: ADMISSION_ACTION_TYPES.SET_SEARCH_QUERY,
484
- payload: { searchQuery: query },
485
- });
486
- }, [dispatch]);
487
- const handleSetStartDate = useCallback((startDate) => {
488
- dispatch({
489
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
490
- payload: { key: "filterStartDate", value: startDate },
491
- });
492
- }, [dispatch]);
493
- const handleSetEndDate = useCallback((endDate) => {
494
- dispatch({
495
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
496
- payload: { key: "filterEndDate", value: endDate },
497
- });
498
- }, [dispatch]);
499
- const clearFilters = useCallback(() => {
500
- dispatch({
501
- type: ADMISSION_ACTION_TYPES.SET_FILTERS,
502
- payload: {
503
- filters: {
504
- filterEnabled: undefined,
505
- filterAdmissionStatus: undefined,
506
- filterStartDate: undefined,
507
- filterEndDate: undefined,
508
- appliedFilterEnabled: undefined,
509
- appliedFilterAdmissionStatus: undefined,
510
- appliedFilterStartDate: undefined,
511
- appliedFilterEndDate: undefined,
512
- },
513
- },
514
- });
515
- dispatch({
516
- type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
517
- payload: { currentPage: 1 },
518
- });
519
- }, [dispatch]);
520
- const handlePrint = useCallback(async (row) => {
521
- var _a, _b, _c, _d, _e;
522
- if (!row)
523
- return;
524
- const logoBase64Res = await fetch(`/api/v1/auth/image-url-to-base64`, {
525
- method: API_METHODS.POST,
526
- body: JSON.stringify({ url: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.logo }),
527
- headers: {
528
- "Content-Type": "application/json",
529
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
530
- },
531
- });
532
- const logoBase64 = await logoBase64Res.json();
533
- try {
534
- const rowRecord = row;
535
- const studentDetails = rowRecord.studentDetails || {};
536
- const admissionDetails = rowRecord.admissionDetails || {};
537
- const fatherDetails = rowRecord.fatherDetails || {};
538
- const motherDetails = rowRecord.motherDetails || {};
539
- const homeDetails = rowRecord.homeDetails || {};
540
- const pdfData = {
541
- firstName: studentDetails.firstName || "",
542
- lastName: studentDetails.lastName || "",
543
- studentIdNumber: studentDetails.studentIdNumber || "",
544
- gender: studentDetails.gender || "",
545
- dob: studentDetails.dob || "",
546
- registrationCode: studentDetails.registrationCode || "",
547
- discountCode: studentDetails.discountCode,
548
- fatherFirstName: fatherDetails.fatherFirstName || "",
549
- fatherLastName: fatherDetails.fatherLastName || "",
550
- fatherIdNumber: fatherDetails.fatherIdNumber || "",
551
- fatherMobile: fatherDetails.fatherMobile || "",
552
- fatherOccupation: fatherDetails.fatherOccupation,
553
- fatherOrganization: fatherDetails.fatherOrganization,
554
- motherFirstName: motherDetails.motherFirstName || "",
555
- motherLastName: motherDetails.motherLastName || "",
556
- motherIdNumber: motherDetails.motherIdNumber || "",
557
- motherMobile: motherDetails.motherMobile || "",
558
- address: homeDetails.address || "",
559
- city: homeDetails.city || "",
560
- state: homeDetails.state || "",
561
- country: homeDetails.country || "",
562
- classForAdmission: admissionDetails.classForAdmission || "",
563
- previousSchool: admissionDetails.previousSchool,
564
- siblings: admissionDetails.siblings,
565
- notes: admissionDetails.notes,
566
- admissionNotes: admissionDetails.admissionNotes,
567
- schoolName: ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.name) || undefined,
568
- schoolAddress: ((_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.address) || undefined,
569
- schoolPhone: ((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.phone) || undefined,
570
- schoolEmail: ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.email) || undefined,
571
- submissionDate: (row === null || row === void 0 ? void 0 : row.createdAt)
572
- ? new Date(row === null || row === void 0 ? void 0 : row.createdAt).toLocaleDateString()
573
- : undefined,
574
- admissionStatus: admissionDetails.admissionStatus,
575
- logo: logoBase64.base64,
576
- };
577
- await generateAdmissionReceiptPDF(pdfData);
578
- }
579
- catch (_f) {
580
- showToast(t("messagesPrintFailed"), TOAST_VARIANT.ERROR);
581
- }
582
- }, [workspace, t, showToast]);
583
- const handleAddStudent = useCallback(async (row) => {
584
- var _a;
585
- const tableRow = row;
586
- const { data, error } = await fetchData({
587
- url: "/api/v1/admit-student",
588
- method: API_METHODS.POST,
589
- headers: {
590
- "Content-Type": "application/json",
591
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
592
- },
593
- body: JSON.stringify({ admissionId: tableRow === null || tableRow === void 0 ? void 0 : tableRow.id }),
594
- });
595
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
596
- invalidateAdmissionsCache();
597
- invalidateFamiliesCache();
598
- invalidateFamilyMembersCache();
599
- invalidateStudentProfilesCache();
600
- if (data) {
601
- showToast(t("messagesAdmitSuccess"), TOAST_VARIANT.SUCCESS);
602
- }
603
- if (error) {
604
- showToast(t("messagesAdmitFailed"), TOAST_VARIANT.ERROR);
605
- }
606
- }, [t, showToast]);
607
- // ============================================================================
608
- // 1.4.7 NETWORK ACTIONS
609
- // ============================================================================
610
- const handleAnalyze = useCallback(async (row) => {
611
- var _a, _b, _c, _d;
612
- const tableRow = row;
613
- if (!(tableRow === null || tableRow === void 0 ? void 0 : tableRow.id))
614
- return;
615
- const schoolId = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id;
616
- if (!schoolId)
617
- return;
618
- dispatch({
619
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
620
- payload: { key: "analyzeLoading", value: true },
621
- });
622
- dispatch({
623
- type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
624
- payload: { form: { analyzeError: null } },
625
- });
626
- // Open view drawer so user can watch progress
627
- await (byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: tableRow.id } }));
628
- dispatch({
629
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
630
- payload: { drawer: ADMISSION_DRAWER.VIEW_DRAWER },
631
- });
632
- const { data, error } = await fetchData({
633
- url: `/api/v1/admission/analyze`,
634
- method: API_METHODS.POST,
635
- headers: {
636
- "Content-Type": "application/json",
637
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
638
- },
639
- body: JSON.stringify({ id: tableRow.id, schoolId }),
640
- });
641
- dispatch({
642
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
643
- payload: { key: "analyzeLoading", value: false },
644
- });
645
- if (error) {
646
- dispatch({
647
- type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
648
- payload: { form: { analyzeError: t("messagesAnalyzeFailed") } },
649
- });
650
- showToast(t("messagesAnalyzeFailed"), TOAST_VARIANT.ERROR);
651
- return;
652
- }
653
- const result = data;
654
- if (result === null || result === void 0 ? void 0 : result.aiAnalysis) {
655
- dispatch({
656
- type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
657
- payload: { form: { aiAnalysis: result.aiAnalysis } },
658
- });
659
- }
660
- invalidateAdmissionsCache();
661
- (_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
662
- generateThemeToast({
663
- description: `${t("messagesAnalyzeSuccess")} ${(_c = result === null || result === void 0 ? void 0 : result.score) !== null && _c !== void 0 ? _c : "N/A"} — ${(_d = result === null || result === void 0 ? void 0 : result.status) !== null && _d !== void 0 ? _d : ""}`,
664
- variant: TOAST_VARIANT.SUCCESS,
665
- });
666
- }, [(_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id, t, showToast, byIdFetchNow, dispatch]);
667
- const handleSubmit = useCallback(() => {
668
- dispatch({
669
- type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
670
- payload: { disabled: true },
671
- });
672
- validateForm({
673
- params: updateParams,
674
- schema: admissionFormValidation,
675
- successCallback: () => {
676
- var _a;
677
- updateFetchNow(undefined, {
678
- body: JSON.stringify({
679
- schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
680
- admissionDetails: {
681
- classForAdmission: updateParams.classForAdmission,
682
- previousSchool: updateParams.previousSchool,
683
- siblings: updateParams.siblings,
684
- },
685
- fatherDetails: {
686
- fatherIdNumber: updateParams.fatherIdNumber,
687
- fatherFirstName: updateParams.fatherFirstName,
688
- fatherLastName: updateParams.fatherLastName,
689
- fatherMobile: updateParams.fatherMobile,
690
- fatherOccupation: updateParams.fatherOccupation,
691
- fatherOrganization: updateParams.fatherOrganization,
692
- emergencyContact: updateParams.emergencyContact === "Father",
693
- },
694
- motherDetails: {
695
- motherIdNumber: updateParams.motherIdNumber || "",
696
- motherFirstName: updateParams.motherFirstName || "N/A",
697
- motherLastName: updateParams.motherLastName || "N/A",
698
- motherMobile: updateParams.motherMobile,
699
- emergencyContact: updateParams.emergencyContact === "Mother",
700
- },
701
- homeDetails: {
702
- address: updateParams.address,
703
- city: updateParams.city,
704
- country: updateParams.country,
705
- postalCode: updateParams.postalCode,
706
- state: updateParams.state,
707
- },
708
- officeUse: {
709
- notes: updateParams.notes,
710
- admissionNotes: updateParams.admissionNotes,
711
- },
712
- studentDetails: {
713
- studentIdNumber: updateParams.studentIdNumber,
714
- discountCode: updateParams.discountCode,
715
- dob: updateParams.dob,
716
- firstName: updateParams.firstName,
717
- gender: updateParams.gender,
718
- hafiz: updateParams.hafiz,
719
- lastName: updateParams.lastName,
720
- orphan: updateParams.orphan,
721
- registrationCode: updateParams.registrationCode,
722
- },
723
- }),
724
- });
725
- },
726
- errorCallback: (errors) => {
727
- dispatch({
728
- type: ADMISSION_ACTION_TYPES.SET_ERRORS,
729
- payload: { errors },
730
- });
731
- dispatch({
732
- type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
733
- payload: { disabled: false },
734
- });
735
- showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
736
- },
737
- });
738
- }, [
739
- dispatch,
740
- updateParams,
741
- t,
742
- showToast,
743
- updateFetchNow,
744
- (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id,
745
- ]);
746
- // ============================================================================
747
- // 1.4.8 HEADER & ROW ACTIONS
748
- // ============================================================================
749
- const hasGeminiSecrets = Boolean(((_e = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _e === void 0 ? void 0 : _e.GEMINI_API_KEY) && ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _f === void 0 ? void 0 : _f.GEMINI_MODEL));
750
- const headerActions = useMemo(() => [
751
- {
752
- enabled: true,
753
- handleOnClick: handleFilters,
754
- label: t("actionHeaderFilters"),
755
- order: 1,
756
- icon: Filter,
757
- },
758
- {
759
- enabled: true,
760
- handleOnClick: handleCreate,
761
- label: t("actionHeaderAddAdmission"),
762
- order: 2,
763
- icon: Plus,
764
- },
765
- ], [handleFilters, handleCreate, t]);
766
- const rowActions = useMemo(() => [
767
- {
768
- enabled: true,
769
- handleOnClick: handleView,
770
- label: t("actionRowView"),
771
- order: 1,
772
- },
773
- {
774
- enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
775
- handleOnClick: handleEdit,
776
- label: t("actionRowEdit"),
777
- order: 2,
778
- },
779
- {
780
- enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
781
- handleOnClick: handleDelete,
782
- label: t("actionRowDelete"),
783
- order: 3,
784
- variant: "destructive",
785
- },
786
- {
787
- enabled: true,
788
- handleOnClick: handlePrint,
789
- label: t("actionRowPrintPdf"),
790
- order: 4,
791
- },
792
- {
793
- enabled: (row) => hasGeminiSecrets &&
794
- (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
795
- handleOnClick: handleAnalyze,
796
- label: t("actionRowAnalyzeWithAi"),
797
- order: 5,
798
- },
799
- {
800
- enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) !== ADMISSION_STATUS.APPROVED,
801
- handleOnClick: handleAddStudent,
802
- label: t("actionRowAddStudent"),
803
- order: 6,
804
- },
805
- ], [
806
- handleView,
807
- handleEdit,
808
- handleDelete,
809
- handlePrint,
810
- handleAnalyze,
811
- handleAddStudent,
812
- hasGeminiSecrets,
813
- t,
814
- ]);
815
- const applyFilters = useCallback(() => {
816
- dispatch({
817
- type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
818
- payload: { currentPage: 1 },
819
- });
820
- handleCloseDrawer();
821
- }, [dispatch, handleCloseDrawer]);
822
- // ============================================================================
823
- // 1.4.9 EFFECTS
824
- // ============================================================================
825
- // Initial load + re-fetch on page/search/filter change via cache
826
- useEffect(() => {
827
- var _a;
828
- if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
829
- return;
830
- if (isDefaultListState) {
831
- (async () => {
832
- try {
833
- const { count, items } = await getCachedAdmissions({
834
- params: listParams,
835
- });
836
- dispatch({
837
- type: ADMISSION_ACTION_TYPES.SET_ITEMS,
838
- payload: { items: items || [], count: count || 0 },
839
- });
840
- }
841
- catch (_a) {
842
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
843
- }
844
- })();
845
- return;
846
- }
847
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
848
- }, [dispatch, isDefaultListState, listParams, workspace === null || workspace === void 0 ? void 0 : workspace.id, t, showToast]);
849
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
850
- useEffect(() => {
851
- listFetchNowRef.current = listFetchNow;
852
- }, [listFetchNow]);
853
- // ============================================================================
854
- // 1.4.10 RETURN
855
- // ============================================================================
856
- return Object.assign(Object.assign({}, context), { applyFilters,
857
- byIdLoading,
858
- clearFilters,
859
- deleteLoading,
860
- handleAddStudent,
861
- handleAnalyze,
862
- handleChange,
863
- handleCloseDrawer,
864
- handleCreate,
865
- handleDelete,
866
- handleEdit,
867
- handleFilters,
868
- handlePageChange,
869
- handlePageLimitChange,
870
- handlePrint,
871
- handleSearch,
872
- handleSetEndDate,
873
- handleSetStartDate,
874
- handleSubmit,
875
- handleView,
876
- headerActions,
877
- listLoading,
878
- rowActions,
879
- updateLoading });
880
- };
114
+ export { useAdmissionModule } from "./context/use-admission-module";