@appcorp/fusion-storybook 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-modules/admission/context/use-admission-module.d.ts +88 -0
- package/base-modules/admission/context/use-admission-module.js +771 -0
- package/base-modules/admission/context.d.ts +1 -87
- package/base-modules/admission/context.js +3 -769
- package/base-modules/attendance/more-actions.js +7 -2
- package/base-modules/campus/more-actions.js +0 -1
- package/base-modules/class/more-actions.js +1 -6
- package/base-modules/enrollment/context.d.ts +1 -13
- package/base-modules/enrollment/context.js +0 -3
- package/base-modules/enrollment/form.js +2 -6
- package/base-modules/enrollment/page.d.ts +0 -1
- package/base-modules/enrollment/page.js +5 -13
- package/base-modules/enrollment/validate.d.ts +0 -1
- package/base-modules/enrollment/validate.js +0 -1
- package/base-modules/enrollment/view.js +4 -7
- package/base-modules/expense/more-actions.js +1 -6
- package/base-modules/fee-structure/more-actions.js +1 -6
- package/base-modules/student-fee/context/shared.d.ts +178 -0
- package/base-modules/student-fee/context/shared.js +59 -0
- package/base-modules/student-fee/context/use-student-fee-module.d.ts +64 -0
- package/base-modules/student-fee/context/use-student-fee-module.js +610 -0
- package/base-modules/student-fee/context.d.ts +21 -235
- package/base-modules/student-fee/context.js +2 -674
- package/base-modules/student-fee/more-actions.js +1 -6
- package/base-modules/student-profile/constants.js +7 -3
- package/base-modules/student-profile/context/module-base.d.ts +187 -0
- package/base-modules/student-profile/context/module-base.js +50 -0
- package/base-modules/student-profile/context/use-student-profile-module.d.ts +70 -0
- package/base-modules/student-profile/context/use-student-profile-module.js +506 -0
- package/base-modules/student-profile/context.d.ts +20 -256
- package/base-modules/student-profile/context.js +2 -601
- package/base-modules/teacher/avatar-upload.js +1 -4
- package/base-modules/teacher/more-actions.js +1 -6
- package/base-modules/user/context/use-user-module.d.ts +53 -0
- package/base-modules/user/context/use-user-module.js +546 -0
- package/base-modules/user/context.d.ts +1 -52
- package/base-modules/user/context.js +5 -547
- package/base-modules/workspace-user/more-actions.js +1 -6
- package/components/module-error.d.ts +9 -0
- package/components/module-error.js +3 -0
- package/package.json +5 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.d.ts +3 -1242
- package/type.js +3 -445
- package/types/academics.d.ts +262 -0
- package/types/academics.js +8 -0
- package/types/admission.d.ts +85 -0
- package/types/admission.js +6 -0
- package/types/communication.d.ts +165 -0
- package/types/communication.js +7 -0
- package/types/enums.d.ts +411 -0
- package/types/enums.js +442 -0
- package/types/finance.d.ts +126 -0
- package/types/finance.js +7 -0
- package/types/index.d.ts +12 -0
- package/types/index.js +12 -0
- package/types/user-management.d.ts +236 -0
- 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
|
+
};
|