@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
@@ -0,0 +1,506 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from "react";
2
+ import { useTheme } from "next-themes";
3
+ import { useTranslations } from "next-intl";
4
+ import { isCreatedOrUpdated, validateForm, API_METHODS, fetchData, } from "@react-pakistan/util-functions";
5
+ import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
6
+ import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
7
+ import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
8
+ import { STUDENT_STATUS } from "../../../type";
9
+ import { formatNumber } from "@react-pakistan/util-functions/general/format-number";
10
+ import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
11
+ import { STUDENT_PROFILE_API_ROUTES, pageLimit } from "../constants";
12
+ import { studentProfileFormValidation } from "../validate";
13
+ import { getCachedStudentProfiles, invalidateStudentProfilesCache, } from "../cache";
14
+ import { getCachedWorkspaceSync } from "../../workspace/cache";
15
+ import { invalidateFamiliesCache } from "../../family/cache";
16
+ import { invalidateFamilyMembersCache } from "../../family-member/cache";
17
+ import { invalidateAdmissionsCache } from "../../admission/cache";
18
+ import { useStudentProfileContext, STUDENT_PROFILE_ACTION_TYPES, STUDENT_PROFILE_DRAWER, } from "./module-base";
19
+ export const useStudentProfileModule = () => {
20
+ var _a;
21
+ const context = useStudentProfileContext();
22
+ const { dispatch } = context;
23
+ const state = context.state;
24
+ const t = useTranslations("studentProfile");
25
+ const { theme } = useTheme();
26
+ const workspace = getCachedWorkspaceSync();
27
+ const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
28
+ const listFetchNowRef = useRef(null);
29
+ const debouncedQuery = useDebounce(state.searchQuery, 800);
30
+ const listParams = useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
31
+ ? { filterEnabled: String(state.filterEnabled) }
32
+ : {})), (state.filterGender ? { filterGender: state.filterGender } : {})), (state.filterStatus ? { filterStatus: state.filterStatus } : {}))), [
33
+ state.currentPage,
34
+ state.filterEnabled,
35
+ state.filterGender,
36
+ state.filterStatus,
37
+ state.pageLimit,
38
+ debouncedQuery,
39
+ schoolId,
40
+ ]);
41
+ const updateParams = useMemo(() => ({
42
+ avatar: state.avatar,
43
+ bloodGroup: state.bloodGroup,
44
+ dateOfBirth: state.dateOfBirth,
45
+ email: state.email,
46
+ emergencyPhone: formatNumber(state.emergencyPhone),
47
+ enabled: state.enabled,
48
+ familyMemberId: state.familyMemberId,
49
+ firstName: state.firstName,
50
+ gender: state.gender,
51
+ id: state.id,
52
+ lastName: state.lastName,
53
+ phone: formatNumber(state.phone),
54
+ status: state.status,
55
+ studentCode: state.studentCode,
56
+ }), [
57
+ state.avatar,
58
+ state.bloodGroup,
59
+ state.dateOfBirth,
60
+ state.email,
61
+ state.emergencyPhone,
62
+ state.enabled,
63
+ state.familyMemberId,
64
+ state.firstName,
65
+ state.gender,
66
+ state.id,
67
+ state.lastName,
68
+ state.phone,
69
+ state.status,
70
+ state.studentCode,
71
+ ]);
72
+ const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
73
+ const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
74
+ const isDefaultListState = state.currentPage === 1 &&
75
+ state.pageLimit === pageLimit &&
76
+ !debouncedQuery &&
77
+ state.filterEnabled === undefined &&
78
+ !state.filterGender &&
79
+ !state.filterStatus;
80
+ const showToast = useCallback((description, variant) => {
81
+ generateThemeToast({
82
+ description,
83
+ theme: theme,
84
+ variant,
85
+ });
86
+ }, [theme]);
87
+ const resetFormAndCloseDrawer = useCallback(() => {
88
+ dispatch({ type: STUDENT_PROFILE_ACTION_TYPES.RESET_FORM });
89
+ dispatch({
90
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
91
+ payload: { errors: {} },
92
+ });
93
+ dispatch({
94
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
95
+ payload: { disabled: false },
96
+ });
97
+ dispatch({
98
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
99
+ payload: { drawer: null },
100
+ });
101
+ }, [dispatch]);
102
+ const listCallback = useCallback(({ data, error }) => {
103
+ var _a, _b;
104
+ if (error) {
105
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
106
+ return;
107
+ }
108
+ if (data) {
109
+ const response = data;
110
+ dispatch({
111
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
112
+ payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
113
+ });
114
+ }
115
+ }, [dispatch, showToast, t]);
116
+ const updateCallback = useCallback(({ data, error }) => {
117
+ var _a;
118
+ if (error) {
119
+ showToast(t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
120
+ return;
121
+ }
122
+ if (data) {
123
+ const isCreated = isCreatedOrUpdated(data);
124
+ invalidateStudentProfilesCache();
125
+ invalidateFamiliesCache();
126
+ invalidateFamilyMembersCache();
127
+ showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
128
+ resetFormAndCloseDrawer();
129
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
130
+ }
131
+ }, [resetFormAndCloseDrawer, showToast, t]);
132
+ const byIdCallback = useCallback(({ data, error }) => {
133
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
134
+ if (error) {
135
+ showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
136
+ return;
137
+ }
138
+ if (data && typeof data === "object" && "id" in data) {
139
+ const sp = data;
140
+ const fm = sp.familyMember;
141
+ const family = fm === null || fm === void 0 ? void 0 : fm.family;
142
+ dispatch({
143
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_FORM_DATA,
144
+ payload: {
145
+ form: {
146
+ id: sp.id,
147
+ familyMemberId: sp.familyMemberId,
148
+ studentCode: sp.studentCode,
149
+ status: sp.status,
150
+ enabled: sp.enabled,
151
+ remarks: (_a = sp.remarks) !== null && _a !== void 0 ? _a : null,
152
+ firstName: (_b = fm === null || fm === void 0 ? void 0 : fm.firstName) !== null && _b !== void 0 ? _b : "",
153
+ lastName: (_c = fm === null || fm === void 0 ? void 0 : fm.lastName) !== null && _c !== void 0 ? _c : "",
154
+ dateOfBirth: (_d = fm === null || fm === void 0 ? void 0 : fm.dateOfBirth) !== null && _d !== void 0 ? _d : null,
155
+ gender: (_e = fm === null || fm === void 0 ? void 0 : fm.gender) !== null && _e !== void 0 ? _e : null,
156
+ bloodGroup: (_f = fm === null || fm === void 0 ? void 0 : fm.bloodGroup) !== null && _f !== void 0 ? _f : null,
157
+ phone: (_g = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.phone)) !== null && _g !== void 0 ? _g : null,
158
+ email: (_h = fm === null || fm === void 0 ? void 0 : fm.email) !== null && _h !== void 0 ? _h : null,
159
+ emergencyPhone: (_j = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.emergencyPhone)) !== null && _j !== void 0 ? _j : null,
160
+ avatar: (_k = fm === null || fm === void 0 ? void 0 : fm.avatar) !== null && _k !== void 0 ? _k : null,
161
+ familyId: (_l = fm === null || fm === void 0 ? void 0 : fm.familyId) !== null && _l !== void 0 ? _l : "",
162
+ address: (_m = family === null || family === void 0 ? void 0 : family.address) !== null && _m !== void 0 ? _m : null,
163
+ city: (_o = family === null || family === void 0 ? void 0 : family.city) !== null && _o !== void 0 ? _o : null,
164
+ state: (_p = family === null || family === void 0 ? void 0 : family.state) !== null && _p !== void 0 ? _p : null,
165
+ country: (_q = family === null || family === void 0 ? void 0 : family.country) !== null && _q !== void 0 ? _q : null,
166
+ postalCode: (_r = family === null || family === void 0 ? void 0 : family.postalCode) !== null && _r !== void 0 ? _r : null,
167
+ },
168
+ },
169
+ });
170
+ }
171
+ }, [dispatch, showToast, t]);
172
+ const deleteCallback = useCallback(({ data, error }) => {
173
+ var _a;
174
+ if (error) {
175
+ showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
176
+ return;
177
+ }
178
+ if (data) {
179
+ invalidateStudentProfilesCache();
180
+ showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
181
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
182
+ }
183
+ }, [showToast, t]);
184
+ const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
185
+ byIdCallback,
186
+ byIdParams,
187
+ deleteCallback,
188
+ deleteParams,
189
+ listCallback,
190
+ listParams,
191
+ listUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
192
+ searchQuery: debouncedQuery,
193
+ unitByIdUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
194
+ unitUrl: STUDENT_PROFILE_API_ROUTES.UNIT,
195
+ updateCallback,
196
+ updateParams,
197
+ headers: {
198
+ "Content-Type": "application/json",
199
+ "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
200
+ },
201
+ });
202
+ const handleChange = useCallback((field, value) => {
203
+ dispatch({
204
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
205
+ payload: { errors: {} },
206
+ });
207
+ dispatch({
208
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
209
+ payload: { disabled: false },
210
+ });
211
+ dispatch({
212
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
213
+ payload: { key: field, value },
214
+ });
215
+ }, [dispatch]);
216
+ const closeDrawer = useCallback(() => {
217
+ resetFormAndCloseDrawer();
218
+ }, [resetFormAndCloseDrawer]);
219
+ const handleCreate = useCallback(() => {
220
+ dispatch({
221
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
222
+ payload: { drawer: STUDENT_PROFILE_DRAWER.FORM_DRAWER },
223
+ });
224
+ }, [dispatch]);
225
+ const handleView = useCallback((row) => {
226
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
227
+ dispatch({
228
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
229
+ payload: { drawer: STUDENT_PROFILE_DRAWER.VIEW_DRAWER },
230
+ });
231
+ }, [byIdFetchNow, dispatch]);
232
+ const handleEdit = useCallback((row) => {
233
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
234
+ dispatch({
235
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
236
+ payload: { drawer: STUDENT_PROFILE_DRAWER.FORM_DRAWER },
237
+ });
238
+ }, [byIdFetchNow, dispatch]);
239
+ const handleDelete = useCallback((row) => {
240
+ if (!confirm(t("actionDeleteConfirmation")))
241
+ return;
242
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
243
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
244
+ });
245
+ }, [deleteFetchNow, t]);
246
+ const handleFilters = useCallback(() => {
247
+ dispatch({
248
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
249
+ payload: { drawer: STUDENT_PROFILE_DRAWER.FILTER_DRAWER },
250
+ });
251
+ }, [dispatch]);
252
+ const handleMoreActions = useCallback(() => {
253
+ dispatch({
254
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DRAWER,
255
+ payload: { drawer: STUDENT_PROFILE_DRAWER.MORE_ACTIONS_DRAWER },
256
+ });
257
+ }, [dispatch]);
258
+ const handlePageChange = useCallback((page) => {
259
+ const nextPage = typeof page === "number" ? page : state.currentPage + 1;
260
+ dispatch({
261
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
262
+ payload: { currentPage: nextPage },
263
+ });
264
+ }, [dispatch, state.currentPage]);
265
+ const handlePageLimitChange = useCallback((k, value) => {
266
+ const val = Object.assign({}, value);
267
+ dispatch({
268
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_PAGE_LIMIT,
269
+ payload: { pageLimit: Number(val.option) },
270
+ });
271
+ dispatch({
272
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
273
+ payload: { currentPage: 1 },
274
+ });
275
+ }, [dispatch]);
276
+ const handleSearch = useCallback((query) => {
277
+ dispatch({
278
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_SEARCH_QUERY,
279
+ payload: { searchQuery: query },
280
+ });
281
+ }, [dispatch]);
282
+ const clearSearch = useCallback(() => {
283
+ dispatch({
284
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_SEARCH_QUERY,
285
+ payload: { searchQuery: "" },
286
+ });
287
+ }, [dispatch]);
288
+ const handleAvatar = useCallback((files) => {
289
+ if (!files || files.length === 0)
290
+ return;
291
+ const file = files[0];
292
+ const blob = new Blob([file], { type: file.type });
293
+ const url = URL.createObjectURL(blob);
294
+ dispatch({
295
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
296
+ payload: { key: "avatar", value: url },
297
+ });
298
+ }, [dispatch]);
299
+ const applyFilters = useCallback(() => {
300
+ dispatch({
301
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
302
+ payload: { currentPage: 1 },
303
+ });
304
+ closeDrawer();
305
+ }, [dispatch, closeDrawer]);
306
+ const clearFilters = useCallback(() => {
307
+ dispatch({
308
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_FILTERS,
309
+ payload: {
310
+ filters: {
311
+ filterEnabled: undefined,
312
+ filterStatus: undefined,
313
+ filterGender: undefined,
314
+ },
315
+ },
316
+ });
317
+ dispatch({
318
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
319
+ payload: { currentPage: 1 },
320
+ });
321
+ }, [dispatch]);
322
+ const toggleStatus = useCallback((row) => {
323
+ updateFetchNow(undefined, {
324
+ body: JSON.stringify(Object.assign(Object.assign({}, row), { enabled: !(row === null || row === void 0 ? void 0 : row.enabled) })),
325
+ });
326
+ }, [updateFetchNow]);
327
+ const handleWithdrawStudent = useCallback(async () => {
328
+ if (!confirm(t("areYouSureYouWantToWithdrawThisStudent")))
329
+ return;
330
+ dispatch({
331
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
332
+ payload: { key: "status", value: STUDENT_STATUS.INACTIVE },
333
+ });
334
+ dispatch({
335
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_INPUT_FIELD,
336
+ payload: { key: "enabled", value: false },
337
+ });
338
+ invalidateStudentProfilesCache();
339
+ invalidateFamiliesCache();
340
+ invalidateFamilyMembersCache();
341
+ invalidateAdmissionsCache();
342
+ }, [dispatch, t]);
343
+ const handleReAdmitStudent = useCallback(async (row) => {
344
+ var _a;
345
+ if (!confirm(t("areYouSureYouWantToReAdmitThisStudent")))
346
+ return;
347
+ const { data, error } = await fetchData({
348
+ url: "/api/v1/readmit-student",
349
+ method: API_METHODS.POST,
350
+ headers: {
351
+ "Content-Type": "application/json",
352
+ "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
353
+ },
354
+ body: JSON.stringify({ studentProfileId: row === null || row === void 0 ? void 0 : row.id }),
355
+ });
356
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
357
+ invalidateStudentProfilesCache();
358
+ invalidateFamiliesCache();
359
+ invalidateFamilyMembersCache();
360
+ invalidateAdmissionsCache();
361
+ if (data) {
362
+ showToast(t("messagesReAdmitSuccess"), TOAST_VARIANT.SUCCESS);
363
+ }
364
+ if (error) {
365
+ showToast(t("messagesReAdmitFailed"), TOAST_VARIANT.ERROR);
366
+ }
367
+ }, [showToast, t]);
368
+ const handleSubmit = useCallback(() => {
369
+ dispatch({
370
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
371
+ payload: { disabled: true },
372
+ });
373
+ validateForm({
374
+ params: updateParams,
375
+ schema: studentProfileFormValidation,
376
+ successCallback: () => {
377
+ updateFetchNow(undefined, {
378
+ body: JSON.stringify(updateParams),
379
+ });
380
+ },
381
+ errorCallback: (errors) => {
382
+ dispatch({
383
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ERRORS,
384
+ payload: { errors },
385
+ });
386
+ dispatch({
387
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
388
+ payload: { disabled: false },
389
+ });
390
+ showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
391
+ },
392
+ });
393
+ }, [dispatch, updateParams, t, showToast, updateFetchNow]);
394
+ const headerActions = useMemo(() => [
395
+ {
396
+ enabled: false,
397
+ handleOnClick: handleMoreActions,
398
+ label: t("actionHeaderMoreActions"),
399
+ order: 1,
400
+ },
401
+ {
402
+ enabled: true,
403
+ handleOnClick: handleFilters,
404
+ label: t("actionHeaderFilters"),
405
+ order: 2,
406
+ },
407
+ {
408
+ enabled: false,
409
+ handleOnClick: handleCreate,
410
+ label: t("actionHeaderAddStudentProfile"),
411
+ order: 3,
412
+ },
413
+ ], [handleCreate, handleFilters, handleMoreActions, t]);
414
+ const rowActions = useMemo(() => [
415
+ {
416
+ enabled: true,
417
+ handleOnClick: handleView,
418
+ label: t("actionRowView"),
419
+ order: 1,
420
+ },
421
+ {
422
+ enabled: true,
423
+ handleOnClick: handleEdit,
424
+ label: t("actionRowEdit"),
425
+ order: 2,
426
+ },
427
+ {
428
+ enabled: false,
429
+ handleOnClick: handleDelete,
430
+ label: t("actionRowDelete"),
431
+ order: 3,
432
+ },
433
+ {
434
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === STUDENT_STATUS.ACTIVE,
435
+ handleOnClick: handleWithdrawStudent,
436
+ label: t("actionRowWithdrawStudent"),
437
+ order: 4,
438
+ variant: "destructive",
439
+ },
440
+ {
441
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === STUDENT_STATUS.INACTIVE,
442
+ handleOnClick: handleReAdmitStudent,
443
+ label: t("actionRowReAdmitStudent"),
444
+ order: 5,
445
+ },
446
+ ], [
447
+ handleDelete,
448
+ handleEdit,
449
+ handleView,
450
+ handleWithdrawStudent,
451
+ handleReAdmitStudent,
452
+ t,
453
+ ]);
454
+ useEffect(() => {
455
+ var _a;
456
+ if (!schoolId)
457
+ return;
458
+ if (isDefaultListState) {
459
+ (async () => {
460
+ try {
461
+ const { count, items } = await getCachedStudentProfiles({
462
+ params: listParams,
463
+ });
464
+ dispatch({
465
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
466
+ payload: { items: items || [], count: count || 0 },
467
+ });
468
+ }
469
+ catch (_a) {
470
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
471
+ }
472
+ })();
473
+ return;
474
+ }
475
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
476
+ }, [dispatch, isDefaultListState, listParams, schoolId, showToast, t]);
477
+ useEffect(() => {
478
+ listFetchNowRef.current = listFetchNow;
479
+ }, [listFetchNow]);
480
+ return Object.assign(Object.assign({}, context), { applyFilters,
481
+ byIdLoading,
482
+ clearFilters,
483
+ clearSearch,
484
+ closeDrawer,
485
+ deleteLoading,
486
+ handleAvatar,
487
+ handleChange,
488
+ handleCreate,
489
+ handleDelete,
490
+ handleEdit,
491
+ handleFilters,
492
+ handleMoreActions,
493
+ handlePageChange,
494
+ handlePageLimitChange,
495
+ handleReAdmitStudent,
496
+ handleSearch,
497
+ handleSubmit,
498
+ handleView,
499
+ handleWithdrawStudent,
500
+ headerActions,
501
+ listFetchNow,
502
+ listLoading,
503
+ rowActions,
504
+ toggleStatus,
505
+ updateLoading });
506
+ };