@appcorp/fusion-storybook 0.2.12 → 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 (173) 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/admission/filter.d.ts +1 -1
  6. package/base-modules/admission/form.d.ts +1 -1
  7. package/base-modules/admission/more-actions.d.ts +1 -1
  8. package/base-modules/admission/page.d.ts +8 -1
  9. package/base-modules/admission/page.js +25 -4
  10. package/base-modules/admission/view.d.ts +1 -1
  11. package/base-modules/attendance/form.d.ts +1 -1
  12. package/base-modules/attendance/page.d.ts +8 -1
  13. package/base-modules/attendance/page.js +25 -4
  14. package/base-modules/attendance/view.d.ts +1 -1
  15. package/base-modules/campus/filter.d.ts +1 -1
  16. package/base-modules/campus/form.d.ts +1 -1
  17. package/base-modules/campus/more-actions.d.ts +1 -1
  18. package/base-modules/campus/more-actions.js +0 -1
  19. package/base-modules/campus/page.d.ts +8 -1
  20. package/base-modules/campus/page.js +25 -4
  21. package/base-modules/campus/view.d.ts +1 -1
  22. package/base-modules/class/filter.d.ts +1 -1
  23. package/base-modules/class/form.d.ts +1 -1
  24. package/base-modules/class/more-actions.d.ts +1 -1
  25. package/base-modules/class/more-actions.js +1 -6
  26. package/base-modules/class/page.d.ts +8 -1
  27. package/base-modules/class/page.js +25 -4
  28. package/base-modules/class/view.d.ts +1 -1
  29. package/base-modules/course/filter.d.ts +1 -1
  30. package/base-modules/course/form.d.ts +1 -1
  31. package/base-modules/course/more-actions.d.ts +1 -1
  32. package/base-modules/course/page.d.ts +8 -1
  33. package/base-modules/course/page.js +25 -4
  34. package/base-modules/course/view.d.ts +1 -1
  35. package/base-modules/discount-code/filter.d.ts +2 -1
  36. package/base-modules/discount-code/form.d.ts +1 -1
  37. package/base-modules/discount-code/page.d.ts +8 -1
  38. package/base-modules/discount-code/page.js +25 -4
  39. package/base-modules/discount-code/view.d.ts +1 -1
  40. package/base-modules/enrollment/filter.d.ts +1 -1
  41. package/base-modules/enrollment/form.d.ts +1 -1
  42. package/base-modules/enrollment/more-actions.d.ts +1 -1
  43. package/base-modules/enrollment/page.d.ts +8 -1
  44. package/base-modules/enrollment/page.js +25 -4
  45. package/base-modules/enrollment/view.d.ts +1 -1
  46. package/base-modules/expense/filter.d.ts +1 -1
  47. package/base-modules/expense/form.d.ts +1 -1
  48. package/base-modules/expense/more-actions.d.ts +1 -1
  49. package/base-modules/expense/more-actions.js +1 -6
  50. package/base-modules/expense/page.d.ts +8 -1
  51. package/base-modules/expense/page.js +25 -4
  52. package/base-modules/expense/view.d.ts +1 -1
  53. package/base-modules/family/filter.d.ts +1 -1
  54. package/base-modules/family/form.d.ts +1 -1
  55. package/base-modules/family/more-actions.d.ts +1 -1
  56. package/base-modules/family/page.d.ts +8 -1
  57. package/base-modules/family/page.js +25 -4
  58. package/base-modules/family/view.d.ts +1 -1
  59. package/base-modules/family-member/filter.d.ts +1 -1
  60. package/base-modules/family-member/form.d.ts +1 -1
  61. package/base-modules/family-member/more-actions.d.ts +1 -1
  62. package/base-modules/family-member/page.d.ts +8 -1
  63. package/base-modules/family-member/page.js +25 -4
  64. package/base-modules/family-member/view.d.ts +1 -1
  65. package/base-modules/fee-structure/filter.d.ts +1 -1
  66. package/base-modules/fee-structure/form.d.ts +1 -1
  67. package/base-modules/fee-structure/more-actions.d.ts +1 -1
  68. package/base-modules/fee-structure/more-actions.js +1 -6
  69. package/base-modules/fee-structure/page.d.ts +8 -1
  70. package/base-modules/fee-structure/page.js +25 -4
  71. package/base-modules/fee-structure/view.d.ts +1 -1
  72. package/base-modules/rbac/assign-permissions.d.ts +1 -1
  73. package/base-modules/rbac/filter.d.ts +1 -1
  74. package/base-modules/rbac/form.d.ts +1 -1
  75. package/base-modules/rbac/more-actions.d.ts +1 -1
  76. package/base-modules/rbac/page.d.ts +8 -1
  77. package/base-modules/rbac/page.js +25 -4
  78. package/base-modules/rbac/view.d.ts +7 -1
  79. package/base-modules/school/drawer.d.ts +1 -1
  80. package/base-modules/school/filter.d.ts +1 -1
  81. package/base-modules/school/form.d.ts +1 -1
  82. package/base-modules/school/more-actions.d.ts +1 -1
  83. package/base-modules/school/view.d.ts +1 -1
  84. package/base-modules/section/filter.d.ts +1 -1
  85. package/base-modules/section/form.d.ts +1 -1
  86. package/base-modules/section/more-actions.d.ts +1 -1
  87. package/base-modules/section/page.d.ts +8 -1
  88. package/base-modules/section/page.js +25 -4
  89. package/base-modules/section/view.d.ts +1 -1
  90. package/base-modules/student-fee/context/shared.d.ts +178 -0
  91. package/base-modules/student-fee/context/shared.js +59 -0
  92. package/base-modules/student-fee/context/use-student-fee-module.d.ts +64 -0
  93. package/base-modules/student-fee/context/use-student-fee-module.js +610 -0
  94. package/base-modules/student-fee/context.d.ts +21 -235
  95. package/base-modules/student-fee/context.js +2 -674
  96. package/base-modules/student-fee/filter.d.ts +1 -1
  97. package/base-modules/student-fee/form.d.ts +1 -1
  98. package/base-modules/student-fee/more-actions.d.ts +1 -1
  99. package/base-modules/student-fee/more-actions.js +1 -6
  100. package/base-modules/student-fee/page.d.ts +8 -1
  101. package/base-modules/student-fee/page.js +25 -4
  102. package/base-modules/student-fee/view.d.ts +1 -1
  103. package/base-modules/student-profile/context/module-base.d.ts +187 -0
  104. package/base-modules/student-profile/context/module-base.js +50 -0
  105. package/base-modules/student-profile/context/use-student-profile-module.d.ts +70 -0
  106. package/base-modules/student-profile/context/use-student-profile-module.js +506 -0
  107. package/base-modules/student-profile/context.d.ts +20 -256
  108. package/base-modules/student-profile/context.js +2 -601
  109. package/base-modules/student-profile/filter.d.ts +1 -1
  110. package/base-modules/student-profile/form.d.ts +1 -1
  111. package/base-modules/student-profile/more-actions.d.ts +1 -1
  112. package/base-modules/student-profile/page.d.ts +8 -1
  113. package/base-modules/student-profile/page.js +25 -4
  114. package/base-modules/student-profile/view.d.ts +1 -1
  115. package/base-modules/subject/filter.d.ts +1 -1
  116. package/base-modules/subject/form.d.ts +1 -1
  117. package/base-modules/subject/more-actions.d.ts +1 -1
  118. package/base-modules/subject/page.d.ts +8 -1
  119. package/base-modules/subject/page.js +25 -4
  120. package/base-modules/subject/view.d.ts +1 -1
  121. package/base-modules/teacher/avatar-upload.js +1 -4
  122. package/base-modules/teacher/filter.d.ts +1 -1
  123. package/base-modules/teacher/form.d.ts +1 -1
  124. package/base-modules/teacher/more-actions.d.ts +1 -1
  125. package/base-modules/teacher/more-actions.js +1 -6
  126. package/base-modules/teacher/page.d.ts +8 -1
  127. package/base-modules/teacher/page.js +25 -4
  128. package/base-modules/teacher/view.d.ts +1 -1
  129. package/base-modules/user/context/use-user-module.d.ts +53 -0
  130. package/base-modules/user/context/use-user-module.js +546 -0
  131. package/base-modules/user/context.d.ts +1 -52
  132. package/base-modules/user/context.js +5 -547
  133. package/base-modules/user/drawer.d.ts +1 -1
  134. package/base-modules/user/filter.d.ts +1 -1
  135. package/base-modules/user/form.d.ts +1 -1
  136. package/base-modules/user/more-actions.d.ts +1 -1
  137. package/base-modules/user/page.d.ts +8 -1
  138. package/base-modules/user/page.js +25 -4
  139. package/base-modules/user/view.d.ts +1 -1
  140. package/base-modules/workspace/context.d.ts +1 -1
  141. package/base-modules/workspace/drawer.d.ts +1 -1
  142. package/base-modules/workspace/filter.d.ts +1 -1
  143. package/base-modules/workspace/form.d.ts +1 -1
  144. package/base-modules/workspace/more-actions.d.ts +1 -1
  145. package/base-modules/workspace/view.d.ts +1 -1
  146. package/base-modules/workspace-user/filter.d.ts +1 -1
  147. package/base-modules/workspace-user/form.d.ts +1 -1
  148. package/base-modules/workspace-user/more-actions.d.ts +1 -1
  149. package/base-modules/workspace-user/more-actions.js +1 -6
  150. package/base-modules/workspace-user/page.d.ts +8 -1
  151. package/base-modules/workspace-user/page.js +25 -4
  152. package/base-modules/workspace-user/view.d.ts +1 -1
  153. package/components/module-error.d.ts +9 -0
  154. package/components/module-error.js +3 -0
  155. package/components/timeline.d.ts +1 -1
  156. package/package.json +6 -5
  157. package/tsconfig.build.tsbuildinfo +1 -1
  158. package/type.d.ts +3 -1242
  159. package/type.js +3 -445
  160. package/types/academics.d.ts +264 -0
  161. package/types/academics.js +8 -0
  162. package/types/admission.d.ts +85 -0
  163. package/types/admission.js +6 -0
  164. package/types/communication.d.ts +165 -0
  165. package/types/communication.js +7 -0
  166. package/types/enums.d.ts +411 -0
  167. package/types/enums.js +442 -0
  168. package/types/finance.d.ts +126 -0
  169. package/types/finance.js +7 -0
  170. package/types/index.d.ts +12 -0
  171. package/types/index.js +12 -0
  172. package/types/user-management.d.ts +236 -0
  173. package/types/user-management.js +7 -0
@@ -17,604 +17,5 @@
17
17
  * - `STUDENT_PROFILE_DRAWER` — drawer type constants
18
18
  * - `useStudentProfileModule()` — hook that returns state, dispatch, and handlers
19
19
  */
20
- import { useCallback, useEffect, useMemo, useRef } from "react";
21
- import { useTheme } from "next-themes";
22
- import { useTranslations } from "next-intl";
23
- import { isCreatedOrUpdated, validateForm, API_METHODS, fetchData, } from "@react-pakistan/util-functions";
24
- import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
25
- import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
26
- import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
27
- import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
28
- import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
29
- import { STUDENT_STATUS } from "../../type";
30
- import { formatNumber } from "@react-pakistan/util-functions/general/format-number";
31
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
32
- import { STUDENT_PROFILE_API_ROUTES, pageLimit } from "./constants";
33
- import { studentProfileFormValidation } from "./validate";
34
- import { getCachedStudentProfiles, invalidateStudentProfilesCache, } from "./cache";
35
- import { getCachedWorkspaceSync } from "../workspace/cache";
36
- import { invalidateFamiliesCache } from "../family/cache";
37
- import { invalidateFamilyMembersCache } from "../family-member/cache";
38
- import { invalidateAdmissionsCache } from "../admission/cache";
39
- // ============================================================================
40
- // 1.1 DRAWER TYPES
41
- // ============================================================================
42
- export const STUDENT_PROFILE_DRAWER = {
43
- FILTER_DRAWER: DRAWER_TYPES.FILTER_DRAWER,
44
- FORM_DRAWER: DRAWER_TYPES.FORM_DRAWER,
45
- MORE_ACTIONS_DRAWER: DRAWER_TYPES.MORE_ACTIONS_DRAWER,
46
- VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
47
- };
48
- const studentProfileConfig = {
49
- name: "StudentProfile",
50
- displayName: "Student Profile",
51
- drawerTypes: DRAWER_TYPES,
52
- initialState: {
53
- // List data
54
- items: [],
55
- count: 0,
56
- // Search & Pagination
57
- currentPage: 1,
58
- pageLimit,
59
- searchQuery: "",
60
- // UI State
61
- disableSaveButton: false,
62
- drawer: null,
63
- errors: {},
64
- // Form State
65
- id: "",
66
- familyMemberId: "",
67
- studentCode: "",
68
- status: STUDENT_STATUS.ACTIVE,
69
- enabled: true,
70
- remarks: "",
71
- // FamilyMember fields (nested)
72
- firstName: "",
73
- lastName: "",
74
- dateOfBirth: "",
75
- gender: "",
76
- bloodGroup: "",
77
- phone: "",
78
- email: "",
79
- emergencyPhone: "",
80
- avatar: "",
81
- // Family fields (nested)
82
- familyId: "",
83
- address: "",
84
- city: "",
85
- state: "",
86
- country: "",
87
- postalCode: "",
88
- // Filter State
89
- filterEnabled: undefined,
90
- filterGender: undefined,
91
- filterStatus: undefined,
92
- },
93
- };
94
- // ============================================================================
95
- // 1.3 CREATE STUDENT PROFILE MODULE
96
- // ============================================================================
97
- export const { actionTypes: STUDENT_PROFILE_ACTION_TYPES, config: studentProfileModuleConfig, initialState: initialStudentProfileState, Provider: StudentProfileProvider, reducer: studentProfileReducer, useContext: useStudentProfileContext, } = createGenericModule(studentProfileConfig);
98
- // ============================================================================
99
- // 1.4 ENHANCED STUDENT PROFILE HOOK WITH API INTEGRATION
100
- // ============================================================================
101
- export const useStudentProfileModule = () => {
102
- var _a;
103
- // ============================================================================
104
- // 1.4.1 STATE & CORE HOOKS
105
- // ============================================================================
106
- const context = useStudentProfileContext();
107
- const { dispatch } = context;
108
- const state = context.state;
109
- const t = useTranslations("studentProfile");
110
- const { theme } = useTheme();
111
- const workspace = getCachedWorkspaceSync();
112
- const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
113
- const listFetchNowRef = useRef(null);
114
- const debouncedQuery = useDebounce(state.searchQuery, 800);
115
- // ============================================================================
116
- // 1.4.2 API PARAMETERS
117
- // ============================================================================
118
- const listParams = useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
119
- ? { filterEnabled: String(state.filterEnabled) }
120
- : {})), (state.filterGender ? { filterGender: state.filterGender } : {})), (state.filterStatus ? { filterStatus: state.filterStatus } : {}))), [
121
- state.currentPage,
122
- state.filterEnabled,
123
- state.filterGender,
124
- state.filterStatus,
125
- state.pageLimit,
126
- debouncedQuery,
127
- schoolId,
128
- ]);
129
- const updateParams = useMemo(() => ({
130
- avatar: state.avatar,
131
- bloodGroup: state.bloodGroup,
132
- dateOfBirth: state.dateOfBirth,
133
- email: state.email,
134
- emergencyPhone: formatNumber(state.emergencyPhone),
135
- enabled: state.enabled,
136
- familyMemberId: state.familyMemberId,
137
- firstName: state.firstName,
138
- gender: state.gender,
139
- id: state.id,
140
- lastName: state.lastName,
141
- phone: formatNumber(state.phone),
142
- status: state.status,
143
- studentCode: state.studentCode,
144
- }), [
145
- state.avatar,
146
- state.bloodGroup,
147
- state.dateOfBirth,
148
- state.email,
149
- state.emergencyPhone,
150
- state.enabled,
151
- state.familyMemberId,
152
- state.firstName,
153
- state.gender,
154
- state.id,
155
- state.lastName,
156
- state.phone,
157
- state.status,
158
- state.studentCode,
159
- ]);
160
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
161
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
162
- const isDefaultListState = state.currentPage === 1 &&
163
- state.pageLimit === pageLimit &&
164
- !debouncedQuery &&
165
- state.filterEnabled === undefined &&
166
- !state.filterGender &&
167
- !state.filterStatus;
168
- // ============================================================================
169
- // 1.4.3 UTILITIES
170
- // ============================================================================
171
- const showToast = useCallback((description, variant) => {
172
- generateThemeToast({
173
- description,
174
- theme: theme,
175
- variant,
176
- });
177
- }, [theme]);
178
- const resetFormAndCloseDrawer = useCallback(() => {
179
- dispatch({ type: STUDENT_PROFILE_ACTION_TYPES.RESET_FORM });
180
- dispatch({
181
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
182
- payload: { errors: {} },
183
- });
184
- dispatch({
185
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
186
- payload: { disabled: false },
187
- });
188
- dispatch({
189
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
190
- payload: { drawer: null },
191
- });
192
- }, [dispatch]);
193
- // ============================================================================
194
- // 1.4.4 API CALLBACKS
195
- // ============================================================================
196
- const listCallback = useCallback(({ data, error }) => {
197
- var _a, _b;
198
- if (error) {
199
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
200
- return;
201
- }
202
- if (data) {
203
- const response = data;
204
- dispatch({
205
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
206
- payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
207
- });
208
- }
209
- }, [dispatch, showToast, t]);
210
- const updateCallback = useCallback(({ data, error }) => {
211
- var _a;
212
- if (error) {
213
- showToast(t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
214
- return;
215
- }
216
- if (data) {
217
- const isCreated = isCreatedOrUpdated(data);
218
- invalidateStudentProfilesCache();
219
- invalidateFamiliesCache();
220
- invalidateFamilyMembersCache();
221
- showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
222
- resetFormAndCloseDrawer();
223
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
224
- }
225
- }, [resetFormAndCloseDrawer, showToast, t]);
226
- const byIdCallback = useCallback(({ data, error }) => {
227
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
228
- if (error) {
229
- showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
230
- return;
231
- }
232
- if (data && typeof data === "object" && "id" in data) {
233
- const sp = data;
234
- const fm = sp.familyMember;
235
- const family = fm === null || fm === void 0 ? void 0 : fm.family;
236
- dispatch({
237
- type: STUDENT_PROFILE_ACTION_TYPES.SET_FORM_DATA,
238
- payload: {
239
- form: {
240
- id: sp.id,
241
- familyMemberId: sp.familyMemberId,
242
- studentCode: sp.studentCode,
243
- status: sp.status,
244
- enabled: sp.enabled,
245
- remarks: (_a = sp.remarks) !== null && _a !== void 0 ? _a : null,
246
- firstName: (_b = fm === null || fm === void 0 ? void 0 : fm.firstName) !== null && _b !== void 0 ? _b : "",
247
- lastName: (_c = fm === null || fm === void 0 ? void 0 : fm.lastName) !== null && _c !== void 0 ? _c : "",
248
- dateOfBirth: (_d = fm === null || fm === void 0 ? void 0 : fm.dateOfBirth) !== null && _d !== void 0 ? _d : null,
249
- gender: (_e = fm === null || fm === void 0 ? void 0 : fm.gender) !== null && _e !== void 0 ? _e : null,
250
- bloodGroup: (_f = fm === null || fm === void 0 ? void 0 : fm.bloodGroup) !== null && _f !== void 0 ? _f : null,
251
- phone: (_g = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.phone)) !== null && _g !== void 0 ? _g : null,
252
- email: (_h = fm === null || fm === void 0 ? void 0 : fm.email) !== null && _h !== void 0 ? _h : null,
253
- emergencyPhone: (_j = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.emergencyPhone)) !== null && _j !== void 0 ? _j : null,
254
- avatar: (_k = fm === null || fm === void 0 ? void 0 : fm.avatar) !== null && _k !== void 0 ? _k : null,
255
- familyId: (_l = fm === null || fm === void 0 ? void 0 : fm.familyId) !== null && _l !== void 0 ? _l : "",
256
- address: (_m = family === null || family === void 0 ? void 0 : family.address) !== null && _m !== void 0 ? _m : null,
257
- city: (_o = family === null || family === void 0 ? void 0 : family.city) !== null && _o !== void 0 ? _o : null,
258
- state: (_p = family === null || family === void 0 ? void 0 : family.state) !== null && _p !== void 0 ? _p : null,
259
- country: (_q = family === null || family === void 0 ? void 0 : family.country) !== null && _q !== void 0 ? _q : null,
260
- postalCode: (_r = family === null || family === void 0 ? void 0 : family.postalCode) !== null && _r !== void 0 ? _r : null,
261
- },
262
- },
263
- });
264
- }
265
- }, [dispatch, showToast, t]);
266
- const deleteCallback = useCallback(({ data, error }) => {
267
- var _a;
268
- if (error) {
269
- showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
270
- return;
271
- }
272
- if (data) {
273
- invalidateStudentProfilesCache();
274
- showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
275
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
276
- }
277
- }, [showToast, t]);
278
- // ============================================================================
279
- // 1.4.5 API HOOKS
280
- // ============================================================================
281
- const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
282
- byIdCallback,
283
- byIdParams,
284
- deleteCallback,
285
- deleteParams,
286
- listCallback,
287
- listParams,
288
- listUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
289
- searchQuery: debouncedQuery,
290
- unitByIdUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
291
- unitUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
292
- updateCallback,
293
- updateParams,
294
- headers: {
295
- "Content-Type": "application/json",
296
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
297
- },
298
- });
299
- // ============================================================================
300
- // 1.4.6 HANDLERS
301
- // ============================================================================
302
- const handleChange = useCallback((field, value) => {
303
- dispatch({
304
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
305
- payload: { errors: {} },
306
- });
307
- dispatch({
308
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
309
- payload: { disabled: false },
310
- });
311
- dispatch({
312
- type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
313
- payload: { key: field, value },
314
- });
315
- }, [dispatch]);
316
- const closeDrawer = useCallback(() => {
317
- resetFormAndCloseDrawer();
318
- }, [resetFormAndCloseDrawer]);
319
- const handleCreate = useCallback(() => {
320
- dispatch({
321
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
322
- payload: { drawer: STUDENT_PROFILE_DRAWER.FORM_DRAWER },
323
- });
324
- }, [dispatch]);
325
- const handleView = useCallback((row) => {
326
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
327
- dispatch({
328
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
329
- payload: { drawer: STUDENT_PROFILE_DRAWER.VIEW_DRAWER },
330
- });
331
- }, [byIdFetchNow, dispatch]);
332
- const handleEdit = useCallback((row) => {
333
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
334
- dispatch({
335
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
336
- payload: { drawer: STUDENT_PROFILE_DRAWER.FORM_DRAWER },
337
- });
338
- }, [byIdFetchNow, dispatch]);
339
- const handleDelete = useCallback((row) => {
340
- if (!confirm(t("actionDeleteConfirmation")))
341
- return;
342
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
343
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
344
- });
345
- }, [deleteFetchNow, t]);
346
- const handleFilters = useCallback(() => {
347
- dispatch({
348
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
349
- payload: { drawer: STUDENT_PROFILE_DRAWER.FILTER_DRAWER },
350
- });
351
- }, [dispatch]);
352
- const handleMoreActions = useCallback(() => {
353
- dispatch({
354
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
355
- payload: { drawer: STUDENT_PROFILE_DRAWER.MORE_ACTIONS_DRAWER },
356
- });
357
- }, [dispatch]);
358
- const handlePageChange = useCallback((page) => {
359
- const nextPage = typeof page === "number" ? page : state.currentPage + 1;
360
- dispatch({
361
- type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
362
- payload: { currentPage: nextPage },
363
- });
364
- }, [dispatch, state.currentPage]);
365
- const handlePageLimitChange = useCallback((k, value) => {
366
- const val = Object.assign({}, value);
367
- dispatch({
368
- type: STUDENT_PROFILE_ACTION_TYPES.SET_PAGE_LIMIT,
369
- payload: { pageLimit: Number(val.option) },
370
- });
371
- dispatch({
372
- type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
373
- payload: { currentPage: 1 },
374
- });
375
- }, [dispatch]);
376
- const handleSearch = useCallback((query) => {
377
- dispatch({
378
- type: STUDENT_PROFILE_ACTION_TYPES.SET_SEARCH_QUERY,
379
- payload: { searchQuery: query },
380
- });
381
- }, [dispatch]);
382
- const clearSearch = useCallback(() => {
383
- dispatch({
384
- type: STUDENT_PROFILE_ACTION_TYPES.SET_SEARCH_QUERY,
385
- payload: { searchQuery: "" },
386
- });
387
- }, [dispatch]);
388
- const handleAvatar = useCallback((files) => {
389
- if (!files || files.length === 0)
390
- return;
391
- const file = files[0];
392
- const blob = new Blob([file], { type: file.type });
393
- const url = URL.createObjectURL(blob);
394
- dispatch({
395
- type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
396
- payload: { key: "avatar", value: url },
397
- });
398
- }, [dispatch]);
399
- const applyFilters = useCallback(() => {
400
- dispatch({
401
- type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
402
- payload: { currentPage: 1 },
403
- });
404
- closeDrawer();
405
- }, [dispatch, closeDrawer]);
406
- const clearFilters = useCallback(() => {
407
- dispatch({
408
- type: STUDENT_PROFILE_ACTION_TYPES.SET_FILTERS,
409
- payload: {
410
- filters: {
411
- filterEnabled: undefined,
412
- filterStatus: undefined,
413
- filterGender: undefined,
414
- },
415
- },
416
- });
417
- dispatch({
418
- type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
419
- payload: { currentPage: 1 },
420
- });
421
- }, [dispatch]);
422
- const toggleStatus = useCallback((row) => {
423
- updateFetchNow(undefined, {
424
- body: JSON.stringify(Object.assign(Object.assign({}, row), { enabled: !(row === null || row === void 0 ? void 0 : row.enabled) })),
425
- });
426
- }, [updateFetchNow]);
427
- const handleWithdrawStudent = useCallback(async () => {
428
- if (!confirm(t("areYouSureYouWantToWithdrawThisStudent")))
429
- return;
430
- dispatch({
431
- type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
432
- payload: { key: "status", value: STUDENT_STATUS.INACTIVE },
433
- });
434
- dispatch({
435
- type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
436
- payload: { key: "enabled", value: false },
437
- });
438
- invalidateStudentProfilesCache();
439
- invalidateFamiliesCache();
440
- invalidateFamilyMembersCache();
441
- invalidateAdmissionsCache();
442
- }, [dispatch, t]);
443
- const handleReAdmitStudent = useCallback(async (row) => {
444
- var _a;
445
- if (!confirm(t("areYouSureYouWantToReAdmitThisStudent")))
446
- return;
447
- const { data, error } = await fetchData({
448
- url: "/api/v1/readmit-student",
449
- method: API_METHODS.POST,
450
- headers: {
451
- "Content-Type": "application/json",
452
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
453
- },
454
- body: JSON.stringify({ studentProfileId: row === null || row === void 0 ? void 0 : row.id }),
455
- });
456
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
457
- invalidateStudentProfilesCache();
458
- invalidateFamiliesCache();
459
- invalidateFamilyMembersCache();
460
- invalidateAdmissionsCache();
461
- if (data) {
462
- showToast(t("messagesReAdmitSuccess"), TOAST_VARIANT.SUCCESS);
463
- }
464
- if (error) {
465
- showToast(t("messagesReAdmitFailed"), TOAST_VARIANT.ERROR);
466
- }
467
- }, [showToast, t]);
468
- // ============================================================================
469
- // 1.4.7 SUBMIT
470
- // ============================================================================
471
- const handleSubmit = useCallback(() => {
472
- dispatch({
473
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
474
- payload: { disabled: true },
475
- });
476
- validateForm({
477
- params: updateParams,
478
- schema: studentProfileFormValidation,
479
- successCallback: () => {
480
- updateFetchNow(undefined, {
481
- body: JSON.stringify(updateParams),
482
- });
483
- },
484
- errorCallback: (errors) => {
485
- dispatch({
486
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
487
- payload: { errors },
488
- });
489
- dispatch({
490
- type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
491
- payload: { disabled: false },
492
- });
493
- showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
494
- },
495
- });
496
- }, [dispatch, updateParams, t, showToast, updateFetchNow]);
497
- // ============================================================================
498
- // 1.4.8 HEADER & ROW ACTIONS
499
- // ============================================================================
500
- const headerActions = useMemo(() => [
501
- {
502
- enabled: false,
503
- handleOnClick: handleMoreActions,
504
- label: t("actionHeaderMoreActions"),
505
- order: 1,
506
- },
507
- {
508
- enabled: true,
509
- handleOnClick: handleFilters,
510
- label: t("actionHeaderFilters"),
511
- order: 2,
512
- },
513
- {
514
- enabled: false,
515
- handleOnClick: handleCreate,
516
- label: t("actionHeaderAddStudentProfile"),
517
- order: 3,
518
- },
519
- ], [handleCreate, handleFilters, handleMoreActions, t]);
520
- const rowActions = useMemo(() => [
521
- {
522
- enabled: true,
523
- handleOnClick: handleView,
524
- label: t("actionRowView"),
525
- order: 1,
526
- },
527
- {
528
- enabled: true,
529
- handleOnClick: handleEdit,
530
- label: t("actionRowEdit"),
531
- order: 2,
532
- },
533
- {
534
- enabled: false,
535
- handleOnClick: handleDelete,
536
- label: t("actionRowDelete"),
537
- order: 3,
538
- },
539
- {
540
- enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === STUDENT_STATUS.ACTIVE,
541
- handleOnClick: handleWithdrawStudent,
542
- label: t("actionRowWithdrawStudent"),
543
- order: 4,
544
- variant: "destructive",
545
- },
546
- {
547
- enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === STUDENT_STATUS.INACTIVE,
548
- handleOnClick: handleReAdmitStudent,
549
- label: t("actionRowReAdmitStudent"),
550
- order: 5,
551
- },
552
- ], [
553
- handleDelete,
554
- handleEdit,
555
- handleView,
556
- handleWithdrawStudent,
557
- handleReAdmitStudent,
558
- t,
559
- ]);
560
- // ============================================================================
561
- // 1.4.9 EFFECTS
562
- // ============================================================================
563
- // Initial load + re-fetch on page/search/filter change via cache
564
- useEffect(() => {
565
- var _a;
566
- if (!schoolId)
567
- return;
568
- if (isDefaultListState) {
569
- (async () => {
570
- try {
571
- const { count, items } = await getCachedStudentProfiles({
572
- params: listParams,
573
- });
574
- dispatch({
575
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
576
- payload: { items: items || [], count: count || 0 },
577
- });
578
- }
579
- catch (_a) {
580
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
581
- }
582
- })();
583
- return;
584
- }
585
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
586
- }, [dispatch, isDefaultListState, listParams, schoolId, showToast, t]);
587
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
588
- useEffect(() => {
589
- listFetchNowRef.current = listFetchNow;
590
- }, [listFetchNow]);
591
- // ============================================================================
592
- // 1.4.10 RETURN
593
- // ============================================================================
594
- return Object.assign(Object.assign({}, context), { applyFilters,
595
- byIdLoading,
596
- clearFilters,
597
- clearSearch,
598
- closeDrawer,
599
- deleteLoading,
600
- handleAvatar,
601
- handleChange,
602
- handleCreate,
603
- handleDelete,
604
- handleEdit,
605
- handleFilters,
606
- handleMoreActions,
607
- handlePageChange,
608
- handlePageLimitChange,
609
- handleReAdmitStudent,
610
- handleSearch,
611
- handleSubmit,
612
- handleView,
613
- handleWithdrawStudent,
614
- headerActions,
615
- listFetchNow,
616
- listLoading,
617
- rowActions,
618
- toggleStatus,
619
- updateLoading });
620
- };
20
+ export { STUDENT_PROFILE_DRAWER, STUDENT_PROFILE_ACTION_TYPES, studentProfileModuleConfig, initialStudentProfileState, StudentProfileProvider, studentProfileReducer, useStudentProfileContext, } from "./context/module-base";
21
+ export { useStudentProfileModule } from "./context/use-student-profile-module";
@@ -1 +1 @@
1
- export declare const StudentProfileFilter: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const StudentProfileFilter: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const StudentProfileForm: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const StudentProfileForm: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const StudentProfileMoreActions: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const StudentProfileMoreActions: () => import("react").JSX.Element;
@@ -19,7 +19,14 @@ import { FC } from "react";
19
19
  import { USER_ROLE } from "../../type";
20
20
  interface Props {
21
21
  cancelLabel: string;
22
- drawerTitle: string;
22
+ drawerFilterDescription: string;
23
+ drawerFilterTitle: string;
24
+ drawerFormDescription: string;
25
+ drawerFormTitle: string;
26
+ drawerMoreActionsDescription: string;
27
+ drawerMoreActionsTitle: string;
28
+ drawerViewDescription: string;
29
+ drawerViewTitle: string;
23
30
  labelActions: string;
24
31
  labelEnabled: string;
25
32
  labelFirstName: string;