@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.
- 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/campus/more-actions.js +0 -1
- package/base-modules/class/more-actions.js +1 -6
- 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/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 +264 -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
|
@@ -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
|
-
|
|
21
|
-
|
|
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";
|
|
@@ -43,7 +43,7 @@ export async function convertToWebPFormat(file) {
|
|
|
43
43
|
return webpBlob;
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
46
|
-
console.
|
|
46
|
+
console.error("webp conversion error", error);
|
|
47
47
|
const errorMessage = error instanceof Error
|
|
48
48
|
? error.message
|
|
49
49
|
: "Unknown error during WebP conversion";
|
|
@@ -80,9 +80,6 @@ export async function processAvatarFile(file) {
|
|
|
80
80
|
}
|
|
81
81
|
// Convert to WebP
|
|
82
82
|
const conversionResult = await convertToWebPFormat(file);
|
|
83
|
-
console.log("type" in conversionResult
|
|
84
|
-
? `type: ${conversionResult.type}`
|
|
85
|
-
: "no type field in result");
|
|
86
83
|
// if ("type" in conversionResult) {
|
|
87
84
|
// // It's an error
|
|
88
85
|
// return conversionResult as AvatarUploadError;
|
|
@@ -27,7 +27,6 @@ export const TeacherMoreActions = () => {
|
|
|
27
27
|
{
|
|
28
28
|
id: "3",
|
|
29
29
|
title: t("moreActionsUploadTheCompletedCsvToTheSystem"),
|
|
30
|
-
handleOnClick: () => console.log("clicked"),
|
|
31
30
|
},
|
|
32
31
|
];
|
|
33
32
|
const update = [
|
|
@@ -40,11 +39,7 @@ export const TeacherMoreActions = () => {
|
|
|
40
39
|
},
|
|
41
40
|
},
|
|
42
41
|
{ id: "2", title: t("moreActionsUpdateYourDataToTheCsv") },
|
|
43
|
-
{
|
|
44
|
-
id: "3",
|
|
45
|
-
title: t("moreActionsUploadTheCompletedCsvToTheSystem"),
|
|
46
|
-
handleOnClick: () => console.log("clicked"),
|
|
47
|
-
},
|
|
42
|
+
{ id: "3", title: t("moreActionsUploadTheCompletedCsvToTheSystem") },
|
|
48
43
|
];
|
|
49
44
|
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Timeline, { events: create, heading: t("moreActionsBulkCreate") }), _jsx(Timeline, { events: update, heading: t("moreActionsBulkUpdate") })] }));
|
|
50
45
|
};
|