@appcorp/fusion-storybook 0.5.25 → 0.5.27
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/subject/context.d.ts +7 -0
- package/base-modules/subject/context.js +68 -33
- package/base-modules/subject/form.js +1 -1
- package/base-modules/subject/more-actions.js +34 -13
- package/base-modules/subject/page.js +2 -2
- package/base-modules/subject/validate.js +2 -6
- package/base-modules/subject/view.js +1 -3
- package/base-modules/teacher/context.d.ts +6 -0
- package/base-modules/teacher/context.js +59 -33
- package/base-modules/teacher/date.d.ts +6 -0
- package/base-modules/teacher/date.js +13 -0
- package/base-modules/teacher/form.js +6 -25
- package/base-modules/teacher/more-actions.js +34 -13
- package/base-modules/teacher/validate.js +6 -7
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +5 -3
|
@@ -83,7 +83,8 @@ const teacherConfig = {
|
|
|
83
83
|
teacherCode: "",
|
|
84
84
|
userId: null,
|
|
85
85
|
// Filter State
|
|
86
|
-
filterEnabled:
|
|
86
|
+
filterEnabled: true,
|
|
87
|
+
appliedFilterEnabled: true,
|
|
87
88
|
},
|
|
88
89
|
};
|
|
89
90
|
// ============================================================================
|
|
@@ -99,7 +100,7 @@ export const useTeacherModule = () => {
|
|
|
99
100
|
// 1.4.1 STATE & CORE HOOKS
|
|
100
101
|
// ============================================================================
|
|
101
102
|
const context = useTeacherContext();
|
|
102
|
-
const { dispatch } = context;
|
|
103
|
+
const { dispatch, handleCloseDrawer } = context;
|
|
103
104
|
const state = context.state;
|
|
104
105
|
const t = useTranslations("teacher");
|
|
105
106
|
const { theme } = useTheme();
|
|
@@ -112,11 +113,11 @@ export const useTeacherModule = () => {
|
|
|
112
113
|
// ============================================================================
|
|
113
114
|
// 1.4.2 API PARAMETERS
|
|
114
115
|
// ============================================================================
|
|
115
|
-
const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.
|
|
116
|
-
? { filterEnabled: String(state.
|
|
116
|
+
const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
|
|
117
|
+
? { filterEnabled: String(state.appliedFilterEnabled) }
|
|
117
118
|
: {}))), [
|
|
119
|
+
state.appliedFilterEnabled,
|
|
118
120
|
state.currentPage,
|
|
119
|
-
state.filterEnabled,
|
|
120
121
|
state.pageLimit,
|
|
121
122
|
debouncedQuery,
|
|
122
123
|
schoolId,
|
|
@@ -145,8 +146,8 @@ export const useTeacherModule = () => {
|
|
|
145
146
|
teacherCode: state.teacherCode,
|
|
146
147
|
userId: state.userId,
|
|
147
148
|
}), [state, schoolId]);
|
|
148
|
-
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
149
|
-
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
149
|
+
const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
150
|
+
const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
150
151
|
// ============================================================================
|
|
151
152
|
// 1.4.3 UTILITIES
|
|
152
153
|
// ============================================================================
|
|
@@ -158,7 +159,15 @@ export const useTeacherModule = () => {
|
|
|
158
159
|
});
|
|
159
160
|
}, [theme]);
|
|
160
161
|
const resetFormAndCloseDrawer = useCallback(() => {
|
|
162
|
+
const applied = state.appliedFilterEnabled;
|
|
163
|
+
const staged = state.filterEnabled;
|
|
161
164
|
dispatch({ type: TEACHER_ACTION_TYPES.RESET_FORM });
|
|
165
|
+
dispatch({
|
|
166
|
+
type: TEACHER_ACTION_TYPES.SET_FILTERS,
|
|
167
|
+
payload: {
|
|
168
|
+
filters: { appliedFilterEnabled: applied, filterEnabled: staged },
|
|
169
|
+
},
|
|
170
|
+
});
|
|
162
171
|
dispatch({
|
|
163
172
|
type: TEACHER_ACTION_TYPES.SET_ERRORS,
|
|
164
173
|
payload: { errors: {} },
|
|
@@ -171,7 +180,7 @@ export const useTeacherModule = () => {
|
|
|
171
180
|
type: TEACHER_ACTION_TYPES.SET_DRAWER,
|
|
172
181
|
payload: { drawer: null },
|
|
173
182
|
});
|
|
174
|
-
}, [dispatch]);
|
|
183
|
+
}, [dispatch, state.appliedFilterEnabled, state.filterEnabled]);
|
|
175
184
|
const resetRecordFormState = useCallback(() => {
|
|
176
185
|
dispatch({
|
|
177
186
|
type: TEACHER_ACTION_TYPES.SET_ERRORS,
|
|
@@ -194,7 +203,6 @@ export const useTeacherModule = () => {
|
|
|
194
203
|
emergencyPhone: "",
|
|
195
204
|
enabled: true,
|
|
196
205
|
experience: null,
|
|
197
|
-
filterEnabled: undefined,
|
|
198
206
|
firstName: "",
|
|
199
207
|
gender: GENDER.MALE,
|
|
200
208
|
id: "",
|
|
@@ -215,36 +223,42 @@ export const useTeacherModule = () => {
|
|
|
215
223
|
// ============================================================================
|
|
216
224
|
// 1.4.4 API CALLBACKS
|
|
217
225
|
// ============================================================================
|
|
226
|
+
const apiError = (data) => data === null || data === void 0 ? void 0 : data.error;
|
|
218
227
|
const listCallback = useCallback(({ data, error }) => {
|
|
219
|
-
var _a, _b;
|
|
228
|
+
var _a, _b, _c;
|
|
220
229
|
if (error) {
|
|
221
|
-
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
230
|
+
showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
222
231
|
return;
|
|
223
232
|
}
|
|
224
233
|
if (data) {
|
|
225
234
|
const response = data;
|
|
226
235
|
dispatch({
|
|
227
236
|
type: TEACHER_ACTION_TYPES.SET_ITEMS,
|
|
228
|
-
payload: { items: (
|
|
237
|
+
payload: { items: (_b = response.items) !== null && _b !== void 0 ? _b : [], count: (_c = response.count) !== null && _c !== void 0 ? _c : 0 },
|
|
229
238
|
});
|
|
230
239
|
}
|
|
231
240
|
}, [dispatch, showToast, t]);
|
|
232
241
|
const updateCallback = useCallback(({ data, error }) => {
|
|
233
|
-
var _a;
|
|
242
|
+
var _a, _b;
|
|
234
243
|
if (error) {
|
|
235
|
-
|
|
244
|
+
dispatch({
|
|
245
|
+
type: TEACHER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
246
|
+
payload: { disabled: false },
|
|
247
|
+
});
|
|
248
|
+
showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
|
|
236
249
|
return;
|
|
237
250
|
}
|
|
238
251
|
if (data) {
|
|
239
252
|
const isCreated = isCreatedOrUpdated(data);
|
|
240
253
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
241
254
|
resetFormAndCloseDrawer();
|
|
242
|
-
(
|
|
255
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
243
256
|
}
|
|
244
|
-
}, [resetFormAndCloseDrawer, showToast, t]);
|
|
257
|
+
}, [dispatch, resetFormAndCloseDrawer, showToast, t]);
|
|
245
258
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
259
|
+
var _a;
|
|
246
260
|
if (error) {
|
|
247
|
-
showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
261
|
+
showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
248
262
|
return;
|
|
249
263
|
}
|
|
250
264
|
if (data) {
|
|
@@ -252,20 +266,20 @@ export const useTeacherModule = () => {
|
|
|
252
266
|
dispatch({
|
|
253
267
|
type: TEACHER_ACTION_TYPES.SET_FORM_DATA,
|
|
254
268
|
payload: {
|
|
255
|
-
form: Object.assign(Object.assign({}, teacher), { phone: teacher.phone || "", emergencyPhone: teacher.emergencyPhone || ""
|
|
269
|
+
form: Object.assign(Object.assign({}, teacher), { phone: teacher.phone || "", emergencyPhone: teacher.emergencyPhone || "" }),
|
|
256
270
|
},
|
|
257
271
|
});
|
|
258
272
|
}
|
|
259
273
|
}, [dispatch, showToast, t]);
|
|
260
274
|
const deleteCallback = useCallback(({ data, error }) => {
|
|
261
|
-
var _a;
|
|
275
|
+
var _a, _b;
|
|
262
276
|
if (error) {
|
|
263
|
-
showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
|
|
277
|
+
showToast((_a = apiError(data)) !== null && _a !== void 0 ? _a : t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
|
|
264
278
|
return;
|
|
265
279
|
}
|
|
266
280
|
if (data) {
|
|
267
281
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
268
|
-
(
|
|
282
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
269
283
|
}
|
|
270
284
|
}, [showToast, t]);
|
|
271
285
|
// ============================================================================
|
|
@@ -310,11 +324,12 @@ export const useTeacherModule = () => {
|
|
|
310
324
|
resetFormAndCloseDrawer();
|
|
311
325
|
}, [resetFormAndCloseDrawer]);
|
|
312
326
|
const handleCreate = useCallback(() => {
|
|
327
|
+
resetRecordFormState();
|
|
313
328
|
dispatch({
|
|
314
329
|
type: TEACHER_ACTION_TYPES.SET_DRAWER,
|
|
315
330
|
payload: { drawer: TEACHER_DRAWER.FORM_DRAWER },
|
|
316
331
|
});
|
|
317
|
-
}, [dispatch]);
|
|
332
|
+
}, [dispatch, resetRecordFormState]);
|
|
318
333
|
const handleView = useCallback((row) => {
|
|
319
334
|
resetRecordFormState();
|
|
320
335
|
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
@@ -335,9 +350,9 @@ export const useTeacherModule = () => {
|
|
|
335
350
|
if (!confirm(t("messagesDeleteConfirmation")))
|
|
336
351
|
return;
|
|
337
352
|
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
338
|
-
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
|
|
353
|
+
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
|
|
339
354
|
});
|
|
340
|
-
}, [deleteFetchNow, t]);
|
|
355
|
+
}, [deleteFetchNow, schoolId, t]);
|
|
341
356
|
const handleFilters = useCallback(() => {
|
|
342
357
|
dispatch({
|
|
343
358
|
type: TEACHER_ACTION_TYPES.SET_DRAWER,
|
|
@@ -459,27 +474,38 @@ export const useTeacherModule = () => {
|
|
|
459
474
|
}
|
|
460
475
|
}, [dispatch, showToast, state.id, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
461
476
|
const applyFilters = useCallback(() => {
|
|
477
|
+
dispatch({
|
|
478
|
+
type: TEACHER_ACTION_TYPES.SET_FILTERS,
|
|
479
|
+
payload: { filters: { appliedFilterEnabled: state.filterEnabled } },
|
|
480
|
+
});
|
|
462
481
|
dispatch({
|
|
463
482
|
type: TEACHER_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
464
483
|
payload: { currentPage: 1 },
|
|
465
484
|
});
|
|
466
|
-
|
|
467
|
-
}, [dispatch,
|
|
485
|
+
handleCloseDrawer === null || handleCloseDrawer === void 0 ? void 0 : handleCloseDrawer();
|
|
486
|
+
}, [dispatch, handleCloseDrawer, state.filterEnabled]);
|
|
468
487
|
const clearFilters = useCallback(() => {
|
|
469
488
|
dispatch({
|
|
470
489
|
type: TEACHER_ACTION_TYPES.SET_FILTERS,
|
|
471
|
-
payload: {
|
|
490
|
+
payload: {
|
|
491
|
+
filters: { filterEnabled: undefined, appliedFilterEnabled: undefined },
|
|
492
|
+
},
|
|
472
493
|
});
|
|
473
494
|
dispatch({
|
|
474
495
|
type: TEACHER_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
475
496
|
payload: { currentPage: 1 },
|
|
476
497
|
});
|
|
477
|
-
|
|
498
|
+
handleCloseDrawer === null || handleCloseDrawer === void 0 ? void 0 : handleCloseDrawer();
|
|
499
|
+
}, [dispatch, handleCloseDrawer]);
|
|
478
500
|
const toggleStatus = useCallback((row) => {
|
|
479
501
|
updateFetchNow(undefined, {
|
|
480
|
-
body: JSON.stringify(
|
|
502
|
+
body: JSON.stringify({
|
|
503
|
+
id: row === null || row === void 0 ? void 0 : row.id,
|
|
504
|
+
schoolId,
|
|
505
|
+
enabled: !(row === null || row === void 0 ? void 0 : row.enabled),
|
|
506
|
+
}),
|
|
481
507
|
});
|
|
482
|
-
}, [updateFetchNow]);
|
|
508
|
+
}, [schoolId, updateFetchNow]);
|
|
483
509
|
// ============================================================================
|
|
484
510
|
// 1.4.7 SUBMIT
|
|
485
511
|
// ============================================================================
|
|
@@ -540,20 +566,20 @@ export const useTeacherModule = () => {
|
|
|
540
566
|
order: 1,
|
|
541
567
|
},
|
|
542
568
|
{
|
|
543
|
-
enabled:
|
|
569
|
+
enabled: true,
|
|
544
570
|
handleOnClick: handleEdit,
|
|
545
571
|
label: t("actionsButtonEdit"),
|
|
546
572
|
order: 2,
|
|
547
573
|
},
|
|
548
574
|
{
|
|
549
|
-
enabled:
|
|
575
|
+
enabled: true,
|
|
550
576
|
handleOnClick: handleDelete,
|
|
551
577
|
label: t("actionsButtonDelete"),
|
|
552
578
|
order: 3,
|
|
553
579
|
variant: "destructive",
|
|
554
580
|
},
|
|
555
581
|
{
|
|
556
|
-
enabled:
|
|
582
|
+
enabled: true,
|
|
557
583
|
handleOnClick: toggleStatus,
|
|
558
584
|
label: t("actionsButtonToggleStatus"),
|
|
559
585
|
order: 4,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teacher dates are calendar days stored at UTC midnight. Formatting them with
|
|
3
|
+
* the local timezone shifts the day in negative-offset zones.
|
|
4
|
+
*/
|
|
5
|
+
/** `YYYY-MM-DD` for `<input type="date">`; empty string when invalid. */
|
|
6
|
+
export declare const toDateInput: (value?: string | Date | null) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teacher dates are calendar days stored at UTC midnight. Formatting them with
|
|
3
|
+
* the local timezone shifts the day in negative-offset zones.
|
|
4
|
+
*/
|
|
5
|
+
/** `YYYY-MM-DD` for `<input type="date">`; empty string when invalid. */
|
|
6
|
+
export const toDateInput = (value) => {
|
|
7
|
+
if (!value)
|
|
8
|
+
return "";
|
|
9
|
+
const date = new Date(value);
|
|
10
|
+
if (Number.isNaN(date.getTime()))
|
|
11
|
+
return "";
|
|
12
|
+
return date.toISOString().slice(0, 10);
|
|
13
|
+
};
|
|
@@ -3,12 +3,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
4
4
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
5
5
|
import { EnhancedDropzone } from "@appcorp/shadcn/components/enhanced-dropzone";
|
|
6
|
-
import {
|
|
6
|
+
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
7
7
|
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
8
8
|
import { useTranslations } from "next-intl";
|
|
9
9
|
import { useTeacherModule } from "./context";
|
|
10
10
|
import { GENDER_OPTIONS } from "./constants";
|
|
11
|
-
import {
|
|
11
|
+
import { toDateInput } from "./date";
|
|
12
12
|
import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
|
|
13
13
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
14
14
|
export const TeacherForm = () => {
|
|
@@ -16,37 +16,18 @@ export const TeacherForm = () => {
|
|
|
16
16
|
const genderLabelMap = {
|
|
17
17
|
MALE: t("formOptionMale"),
|
|
18
18
|
FEMALE: t("formOptionFemale"),
|
|
19
|
+
OTHER: t("formOptionOther"),
|
|
19
20
|
PREFER_NOT_TO_SAY: t("formOptionPreferNotToSay"),
|
|
20
21
|
};
|
|
21
22
|
const context = useTeacherModule();
|
|
22
23
|
const { address, avatar, bio, city, country, dateOfBirth, emergencyPhone, enabled, errors, experience, firstName, gender, joiningDate, lastName, phone, postalCode, qualification, specialization, } = context.state;
|
|
23
24
|
const stateValue = context.state.state;
|
|
24
25
|
const { handleChange, handleAvatarUpload } = context;
|
|
25
|
-
const {
|
|
26
|
-
id: "gender",
|
|
27
|
-
info: t("formGenderInfo"),
|
|
28
|
-
label: t("formGenderLabel"),
|
|
29
|
-
onValueChange: (value) => handleChange("gender", value || null),
|
|
30
|
-
options: GENDER_OPTIONS.map((opt) => ({
|
|
26
|
+
const genderCombo = (_jsx(EnhancedCombobox, { emptyText: t("formGenderPlaceholder"), error: getTranslatedError({ errors, key: "gender", t }), id: "gender", info: t("formGenderInfo"), label: t("formGenderLabel"), onValueChange: (value) => handleChange("gender", value || null), options: GENDER_OPTIONS.map((opt) => ({
|
|
31
27
|
value: opt.value,
|
|
32
28
|
label: genderLabelMap[opt.value] || opt.label,
|
|
33
|
-
})),
|
|
34
|
-
|
|
35
|
-
searchEndpoint: TEACHER_API_ROUTES.UNIT,
|
|
36
|
-
formatSearchResult: (item) => {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
return ({
|
|
39
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
40
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
value: gender || "",
|
|
44
|
-
});
|
|
45
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "firstName", t }), id: "firstName", info: t("formFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("firstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, value: firstName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "lastName", t }), id: "lastName", info: t("formLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("lastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, value: lastName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "joiningDate", t }), id: "joiningDate", info: t("formJoiningDateInfo"), label: t("formJoiningDateLabel"), onChange: (e) => handleChange("joiningDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, required: true, type: "date", value: joiningDate
|
|
46
|
-
? new Date(joiningDate).toISOString().split("T")[0]
|
|
47
|
-
: "" }), genderCombo, _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dateOfBirth", t }), id: "dateOfBirth", info: t("formDateOfBirthInfo"), label: t("formDateOfBirthLabel"), onChange: (e) => handleChange("dateOfBirth", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: dateOfBirth
|
|
48
|
-
? new Date(dateOfBirth).toISOString().split("T")[0]
|
|
49
|
-
: "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (e) => {
|
|
29
|
+
})), placeholder: t("formGenderPlaceholder"), value: gender || "" }));
|
|
30
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "firstName", t }), id: "firstName", info: t("formFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("firstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, value: firstName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "lastName", t }), id: "lastName", info: t("formLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("lastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, value: lastName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "joiningDate", t }), id: "joiningDate", info: t("formJoiningDateInfo"), label: t("formJoiningDateLabel"), onChange: (e) => handleChange("joiningDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, required: true, type: "date", value: toDateInput(joiningDate) }), genderCombo, _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dateOfBirth", t }), id: "dateOfBirth", info: t("formDateOfBirthInfo"), label: t("formDateOfBirthLabel"), onChange: (e) => handleChange("dateOfBirth", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: toDateInput(dateOfBirth) }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (e) => {
|
|
50
31
|
var _a;
|
|
51
32
|
return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
|
|
52
33
|
}, placeholder: t("formPhonePlaceholder"), type: "tel", value: phone || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "emergencyPhone", t }), id: "emergencyPhone", info: t("formEmergencyPhoneInfo"), label: t("formEmergencyPhoneLabel"), onChange: (e) => {
|
|
@@ -11,19 +11,42 @@ import { pageLimit } from "./constants";
|
|
|
11
11
|
import { TEACHER_API_ROUTES } from "../../constants";
|
|
12
12
|
import { TEACHER_ACTION_TYPES, useTeacherContext } from "./context";
|
|
13
13
|
import { useRef, useEffect, useCallback } from "react";
|
|
14
|
-
|
|
14
|
+
/** Read at call time — never cache a workspace captured at module load. */
|
|
15
|
+
const currentSchoolId = () => { var _a, _b; return ((_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.id) || ""; };
|
|
15
16
|
const POLL_INTERVAL_MS = 2000;
|
|
16
17
|
const POLL_TIMEOUT_MS = 300000;
|
|
18
|
+
const EXPORT_PAGE_LIMIT = 200;
|
|
19
|
+
const EXPORT_MAX_PAGES = 50;
|
|
17
20
|
const handleGetAllRecords = async (schoolId, pageLimit) => {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
const take = Math.min(pageLimit, EXPORT_PAGE_LIMIT);
|
|
23
|
+
const items = [];
|
|
24
|
+
for (let page = 1; page <= EXPORT_MAX_PAGES; page++) {
|
|
25
|
+
const params = new URLSearchParams({
|
|
26
|
+
currentPage: String(page),
|
|
27
|
+
pageLimit: String(take),
|
|
28
|
+
schoolId,
|
|
29
|
+
});
|
|
30
|
+
const response = await fetch(`${TEACHER_API_ROUTES.UNIT}?${params.toString()}`);
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const body = (await response.json().catch(() => ({})));
|
|
33
|
+
throw new Error((_a = body.error) !== null && _a !== void 0 ? _a : `Export failed (${response.status})`);
|
|
34
|
+
}
|
|
35
|
+
const result = (await response.json());
|
|
36
|
+
const pageItems = (_b = result.items) !== null && _b !== void 0 ? _b : [];
|
|
37
|
+
items.push(...pageItems);
|
|
38
|
+
if (take <= 1 ||
|
|
39
|
+
pageItems.length < take ||
|
|
40
|
+
items.length >= ((_c = result.count) !== null && _c !== void 0 ? _c : items.length)) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const csv = await converter.json2csv(items, {});
|
|
21
45
|
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
22
46
|
await downloadFromUrl(blob, "teacher.csv");
|
|
23
47
|
};
|
|
24
48
|
async function submitBulkJob(csvData, method, signal) {
|
|
25
|
-
|
|
26
|
-
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
49
|
+
const schoolId = currentSchoolId();
|
|
27
50
|
if (!schoolId)
|
|
28
51
|
throw new Error("School ID not found");
|
|
29
52
|
// const apiKey = process.env.NEXT_PUBLIC_API_KEY;
|
|
@@ -100,7 +123,7 @@ export const TeacherMoreActions = () => {
|
|
|
100
123
|
};
|
|
101
124
|
}, []);
|
|
102
125
|
const handleBulkFlow = useCallback(async (files, method) => {
|
|
103
|
-
var _a, _b, _c, _d
|
|
126
|
+
var _a, _b, _c, _d;
|
|
104
127
|
const closeDrawer = () => {
|
|
105
128
|
dispatch({
|
|
106
129
|
type: TEACHER_ACTION_TYPES.SET_DRAWER,
|
|
@@ -196,7 +219,7 @@ export const TeacherMoreActions = () => {
|
|
|
196
219
|
else {
|
|
197
220
|
showSuccessToast(t("messagesBulkSuccess"));
|
|
198
221
|
}
|
|
199
|
-
const schoolId = (
|
|
222
|
+
const schoolId = currentSchoolId();
|
|
200
223
|
fetch(`${TEACHER_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
201
224
|
headers: {
|
|
202
225
|
"Content-Type": "application/json",
|
|
@@ -221,7 +244,7 @@ export const TeacherMoreActions = () => {
|
|
|
221
244
|
}
|
|
222
245
|
else {
|
|
223
246
|
const r = status.results;
|
|
224
|
-
const detail = ((
|
|
247
|
+
const detail = ((_d = r === null || r === void 0 ? void 0 : r.errors) === null || _d === void 0 ? void 0 : _d.length)
|
|
225
248
|
? formatErrorSummary(t, r.errors)
|
|
226
249
|
: t("unknownError");
|
|
227
250
|
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
@@ -243,8 +266,7 @@ export const TeacherMoreActions = () => {
|
|
|
243
266
|
id: "1",
|
|
244
267
|
title: t("moreActionsDownloadEmptyCsvTemplate"),
|
|
245
268
|
handleOnClick: async () => {
|
|
246
|
-
|
|
247
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
|
|
269
|
+
await handleGetAllRecords(currentSchoolId(), 1);
|
|
248
270
|
},
|
|
249
271
|
},
|
|
250
272
|
{ id: "2", title: t("moreActionsAddYourDataToTheCsv") },
|
|
@@ -258,8 +280,7 @@ export const TeacherMoreActions = () => {
|
|
|
258
280
|
id: "1",
|
|
259
281
|
title: t("moreActionsDownloadPopulatedCsvTemplate"),
|
|
260
282
|
handleOnClick: async () => {
|
|
261
|
-
|
|
262
|
-
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
|
|
283
|
+
await handleGetAllRecords(currentSchoolId(), EXPORT_PAGE_LIMIT);
|
|
263
284
|
},
|
|
264
285
|
},
|
|
265
286
|
{ id: "2", title: t("moreActionsUpdateYourDataToTheCsv") },
|
|
@@ -26,22 +26,21 @@ export const teacherFormValidation = z.object({
|
|
|
26
26
|
.string()
|
|
27
27
|
.nullable()
|
|
28
28
|
.optional()
|
|
29
|
-
.transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
|
|
29
|
+
.transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
|
|
30
30
|
campusId: z.string().optional().nullable(),
|
|
31
|
-
experience: z.number().optional().nullable(),
|
|
32
|
-
firstName: z.string().min(1, VALIDATION_KEYS.firstName),
|
|
33
|
-
gender: z
|
|
34
|
-
.preprocess((val) => (val === "" ? undefined : val), z
|
|
31
|
+
experience: z.number().int().min(0).max(80).optional().nullable(),
|
|
32
|
+
firstName: z.string().trim().min(1, VALIDATION_KEYS.firstName).max(100),
|
|
33
|
+
gender: z.preprocess((val) => (val === "" ? undefined : val), z
|
|
35
34
|
.enum(["MALE", "FEMALE", "OTHER", "PREFER_NOT_TO_SAY"])
|
|
36
35
|
.optional()
|
|
37
36
|
.nullable()),
|
|
38
37
|
joiningDate: z.string().optional(),
|
|
39
|
-
lastName: z.string().min(1, VALIDATION_KEYS.lastName),
|
|
38
|
+
lastName: z.string().trim().min(1, VALIDATION_KEYS.lastName).max(100),
|
|
40
39
|
phone: z
|
|
41
40
|
.string()
|
|
42
41
|
.nullable()
|
|
43
42
|
.optional()
|
|
44
|
-
.transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
|
|
43
|
+
.transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
|
|
45
44
|
postalCode: z.string().optional().nullable(),
|
|
46
45
|
qualification: z.string().optional().nullable(),
|
|
47
46
|
specialization: z.string().optional().nullable(),
|