@appcorp/fusion-storybook 0.5.15 → 0.5.17

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.
@@ -31,6 +31,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
31
31
  enrollmentDate: string;
32
32
  errors: Record<string, string>;
33
33
  filterEnabled: boolean | undefined;
34
+ appliedFilterEnabled: boolean | undefined;
34
35
  id: string;
35
36
  sectionId: string;
36
37
  studentProfileId: string;
@@ -50,6 +51,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
50
51
  enrollmentDate: string;
51
52
  errors: Record<string, string>;
52
53
  filterEnabled: boolean | undefined;
54
+ appliedFilterEnabled: boolean | undefined;
53
55
  id: string;
54
56
  sectionId: string;
55
57
  studentProfileId: string;
@@ -71,6 +73,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
71
73
  enrollmentDate: string;
72
74
  errors: Record<string, string>;
73
75
  filterEnabled: boolean | undefined;
76
+ appliedFilterEnabled: boolean | undefined;
74
77
  id: string;
75
78
  sectionId: string;
76
79
  studentProfileId: string;
@@ -90,6 +93,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
90
93
  enrollmentDate: string;
91
94
  errors: Record<string, string>;
92
95
  filterEnabled: boolean | undefined;
96
+ appliedFilterEnabled: boolean | undefined;
93
97
  id: string;
94
98
  sectionId: string;
95
99
  studentProfileId: string;
@@ -109,6 +113,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
109
113
  enrollmentDate: string;
110
114
  errors: Record<string, string>;
111
115
  filterEnabled: boolean | undefined;
116
+ appliedFilterEnabled: boolean | undefined;
112
117
  id: string;
113
118
  sectionId: string;
114
119
  studentProfileId: string;
@@ -158,6 +163,7 @@ export declare const useEnrollmentModule: () => {
158
163
  enrollmentDate: string;
159
164
  errors: Record<string, string>;
160
165
  filterEnabled: boolean | undefined;
166
+ appliedFilterEnabled: boolean | undefined;
161
167
  id: string;
162
168
  sectionId: string;
163
169
  studentProfileId: string;
@@ -1,4 +1,15 @@
1
1
  "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  /**
3
14
  * Enrollment Module — business logic + API integration
4
15
  *
@@ -30,6 +41,7 @@ import { ENROLLMENT_API_ROUTES } from "../../constants";
30
41
  import { enrollmentFormValidation } from "./validate";
31
42
  import { TOAST_VARIANT, generateThemeToast, } from "@appcorp/shadcn/lib/toast-utils";
32
43
  import { getCachedWorkspaceSync } from "../workspace/cache";
44
+ import { toDateInput } from "./date";
33
45
  // ============================================================================
34
46
  // 1.1 DRAWER TYPES
35
47
  // ============================================================================
@@ -57,9 +69,12 @@ const enrollmentConfig = {
57
69
  // Form State
58
70
  classId: "",
59
71
  enabled: true,
60
- enrollmentDate: new Date().toISOString().split("T")[0],
72
+ enrollmentDate: toDateInput(new Date()),
61
73
  errors: {},
62
- filterEnabled: undefined,
74
+ // Staged filter: the drawer edits `filterEnabled`; Apply copies it to
75
+ // `appliedFilterEnabled`, which drives the request.
76
+ filterEnabled: true,
77
+ appliedFilterEnabled: true,
63
78
  id: "",
64
79
  sectionId: "",
65
80
  studentProfileId: "",
@@ -93,11 +108,11 @@ export const useEnrollmentModule = () => {
93
108
  // ==========================================================================
94
109
  // 1.4.2 API PARAMETERS
95
110
  // ==========================================================================
96
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
97
- ? { filterEnabled: String(state.filterEnabled) }
111
+ const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
112
+ ? { filterEnabled: String(state.appliedFilterEnabled) }
98
113
  : {}))), [
114
+ state.appliedFilterEnabled,
99
115
  state.currentPage,
100
- state.filterEnabled,
101
116
  state.pageLimit,
102
117
  schoolId,
103
118
  debouncedQuery,
@@ -111,8 +126,9 @@ export const useEnrollmentModule = () => {
111
126
  schoolId,
112
127
  studentProfileId: state.studentProfileId,
113
128
  }), [state, schoolId]);
114
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
115
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
129
+ // Single-record calls must carry the tenant.
130
+ const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
131
+ const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
116
132
  // ==========================================================================
117
133
  // 1.4.3 UTILITIES
118
134
  // ==========================================================================
@@ -123,8 +139,24 @@ export const useEnrollmentModule = () => {
123
139
  variant,
124
140
  });
125
141
  }, [theme]);
126
- const resetFormAndCloseDrawer = useCallback(() => {
127
- dispatch({ type: ENROLLMENT_ACTION_TYPES.RESET_FORM });
142
+ /** Clear the form without touching the applied filter. */
143
+ const resetFormFields = useCallback(() => {
144
+ dispatch({
145
+ type: ENROLLMENT_ACTION_TYPES.SET_FORM_DATA,
146
+ payload: {
147
+ form: {
148
+ class: undefined,
149
+ classId: "",
150
+ enabled: true,
151
+ enrollmentDate: toDateInput(new Date()),
152
+ id: "",
153
+ section: undefined,
154
+ sectionId: "",
155
+ studentProfile: undefined,
156
+ studentProfileId: "",
157
+ },
158
+ },
159
+ });
128
160
  dispatch({
129
161
  type: ENROLLMENT_ACTION_TYPES.SET_ERRORS,
130
162
  payload: { errors: {} },
@@ -133,11 +165,14 @@ export const useEnrollmentModule = () => {
133
165
  type: ENROLLMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
134
166
  payload: { disabled: false },
135
167
  });
168
+ }, [dispatch]);
169
+ const resetFormAndCloseDrawer = useCallback(() => {
170
+ resetFormFields();
136
171
  dispatch({
137
172
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
138
173
  payload: { drawer: null },
139
174
  });
140
- }, [dispatch]);
175
+ }, [dispatch, resetFormFields]);
141
176
  // ==========================================================================
142
177
  // 1.4.4 API CALLBACKS
143
178
  // ==========================================================================
@@ -159,7 +194,6 @@ export const useEnrollmentModule = () => {
159
194
  }
160
195
  }, [dispatch, showToast, t]);
161
196
  const updateCallback = useCallback(({ data, error }) => {
162
- var _a;
163
197
  if (error) {
164
198
  showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
165
199
  return;
@@ -168,7 +202,7 @@ export const useEnrollmentModule = () => {
168
202
  showToast(isCreatedOrUpdated(data)
169
203
  ? t("messagesEnrollmentCreated")
170
204
  : t("messagesEnrollmentUpdated"), TOAST_VARIANT.SUCCESS);
171
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
205
+ // `useModuleEntityV2` schedules the list refresh.
172
206
  resetFormAndCloseDrawer();
173
207
  }
174
208
  }, [resetFormAndCloseDrawer, showToast, t]);
@@ -178,21 +212,24 @@ export const useEnrollmentModule = () => {
178
212
  return;
179
213
  }
180
214
  if (data) {
215
+ const record = data;
181
216
  dispatch({
182
217
  type: ENROLLMENT_ACTION_TYPES.SET_FORM_DATA,
183
- payload: { form: Object.assign(Object.assign({}, data), { filterEnabled: undefined }) },
218
+ payload: {
219
+ form: Object.assign(Object.assign({}, record), {
220
+ // ISO → the `YYYY-MM-DD` a date input expects.
221
+ enrollmentDate: toDateInput(record.enrollmentDate) }),
222
+ },
184
223
  });
185
224
  }
186
225
  }, [dispatch, showToast, t]);
187
226
  const deleteCallback = useCallback(({ data, error }) => {
188
- var _a;
189
227
  if (error) {
190
228
  showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
191
229
  return;
192
230
  }
193
231
  if (data) {
194
232
  showToast(t("messagesEnrollmentDeleted"), TOAST_VARIANT.SUCCESS);
195
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
196
233
  }
197
234
  }, [showToast, t]);
198
235
  // ==========================================================================
@@ -269,11 +306,13 @@ export const useEnrollmentModule = () => {
269
306
  });
270
307
  }, [dispatch]);
271
308
  const handleCreate = useCallback(() => {
309
+ // Never carry a previous record's id/values into a new entry.
310
+ resetFormFields();
272
311
  dispatch({
273
312
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
274
313
  payload: { drawer: ENROLLMENT_DRAWER.FORM_DRAWER },
275
314
  });
276
- }, [dispatch]);
315
+ }, [dispatch, resetFormFields]);
277
316
  const handleView = useCallback((row) => {
278
317
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
279
318
  dispatch({
@@ -292,9 +331,9 @@ export const useEnrollmentModule = () => {
292
331
  if (!confirm(t("messagesDeleteConfirmation")))
293
332
  return;
294
333
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
295
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
334
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
296
335
  });
297
- }, [t, deleteFetchNow]);
336
+ }, [t, deleteFetchNow, schoolId]);
298
337
  const handleFilters = useCallback(() => {
299
338
  dispatch({
300
339
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
@@ -308,10 +347,8 @@ export const useEnrollmentModule = () => {
308
347
  });
309
348
  }, [dispatch]);
310
349
  const clearFilters = useCallback(() => {
311
- dispatch({
312
- type: ENROLLMENT_ACTION_TYPES.SET_FILTERS,
313
- payload: { filters: { filterEnabled: undefined } },
314
- });
350
+ // RESET_FORM restores the default filter (enabled only).
351
+ dispatch({ type: ENROLLMENT_ACTION_TYPES.RESET_FORM });
315
352
  dispatch({
316
353
  type: ENROLLMENT_ACTION_TYPES.SET_CURRENT_PAGE,
317
354
  payload: { currentPage: 1 },
@@ -329,8 +366,9 @@ export const useEnrollmentModule = () => {
329
366
  params: updateParams,
330
367
  schema: enrollmentFormValidation,
331
368
  successCallback: () => {
369
+ const { id } = updateParams, createParams = __rest(updateParams, ["id"]);
332
370
  updateFetchNow(undefined, {
333
- body: JSON.stringify(updateParams),
371
+ body: JSON.stringify(id ? updateParams : createParams),
334
372
  });
335
373
  },
336
374
  errorCallback: (errors) => {
@@ -383,7 +421,7 @@ export const useEnrollmentModule = () => {
383
421
  order: 1,
384
422
  },
385
423
  {
386
- enabled: false,
424
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
387
425
  handleOnClick: handleDelete,
388
426
  label: t("actionsButtonDelete"),
389
427
  order: 3,
@@ -391,12 +429,18 @@ export const useEnrollmentModule = () => {
391
429
  },
392
430
  ], [handleDelete, handleEdit, handleView, t]);
393
431
  const applyFilters = useCallback(() => {
432
+ dispatch({
433
+ type: ENROLLMENT_ACTION_TYPES.SET_FILTERS,
434
+ payload: {
435
+ filters: { appliedFilterEnabled: state.filterEnabled },
436
+ },
437
+ });
394
438
  dispatch({
395
439
  type: ENROLLMENT_ACTION_TYPES.SET_CURRENT_PAGE,
396
440
  payload: { currentPage: 1 },
397
441
  });
398
442
  closeDrawer();
399
- }, [dispatch, closeDrawer]);
443
+ }, [dispatch, closeDrawer, state.filterEnabled]);
400
444
  // ==========================================================================
401
445
  // 1.4.9 EFFECTS
402
446
  // ==========================================================================
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Enrollment dates are stored at UTC midnight by the API. 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;
7
+ /** Locale date without the timezone shift. */
8
+ export declare const formatEnrollmentDate: (value?: string | Date | null) => string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Enrollment dates are stored at UTC midnight by the API. 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
+ };
14
+ /** Locale date without the timezone shift. */
15
+ export const formatEnrollmentDate = (value) => {
16
+ const day = toDateInput(value);
17
+ if (!day)
18
+ return "—";
19
+ const [year, month, date] = day.split("-").map(Number);
20
+ return new Date(Date.UTC(year, month - 1, date)).toLocaleDateString(undefined, { timeZone: "UTC" });
21
+ };
@@ -19,7 +19,7 @@ export const EnrollmentFilter = () => {
19
19
  : state.filterEnabled
20
20
  ? "true"
21
21
  : "false";
22
- return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("filterOptionEnabled"), name: "filterEnabled", value: filterEnabledValue, options: [
22
+ return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
23
23
  { label: t("filterOptionAll"), value: "undefined" },
24
24
  { label: t("filterOptionEnabled"), value: "true" },
25
25
  { label: t("filterOptionDisabled"), value: "false" },
@@ -14,33 +14,46 @@ import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
14
14
  import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
15
15
  import { Separator } from "@appcorp/shadcn/components/ui/separator";
16
16
  import { API_METHODS } from "@react-pakistan/util-functions/constants/api-methods";
17
- import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
18
17
  import { useEnrollmentModule } from "./context";
19
18
  import { CLASS_API_ROUTES, SECTION_API_ROUTES, STUDENT_PROFILE_API_ROUTES, } from "../../constants";
20
19
  import { useTranslations } from "next-intl";
21
20
  import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
22
- import { useEffect } from "react";
21
+ import { useEffect, useMemo } from "react";
23
22
  import { getTranslatedError } from "../../utils/get-translated-error";
24
23
  import { getCachedWorkspaceSync } from "../workspace/cache";
24
+ import { toDateInput } from "./date";
25
25
  // ============================================================================
26
26
  // COMPONENT
27
27
  // ============================================================================
28
28
  export const EnrollmentForm = () => {
29
29
  var _a, _b, _c, _d;
30
- const { state: { classId, enabled, enrollmentDate, errors, sectionId, studentProfileId, }, handleChange, } = useEnrollmentModule();
30
+ const { state, handleChange } = useEnrollmentModule();
31
+ const { class: selectedClass, classId, enabled, enrollmentDate, errors, section: selectedSection, sectionId, studentProfile: selectedStudent, studentProfileId, } = state;
31
32
  const workspace = getCachedWorkspaceSync();
32
33
  const t = useTranslations("enrollment");
33
34
  const { fetchNow: studentProfileFetchNow, data: studentProfileData } = useFetch(STUDENT_PROFILE_API_ROUTES.UNIT, {
34
35
  method: API_METHODS.GET,
35
- params: { schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id },
36
+ params: {
37
+ schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
38
+ filterEnabled: "true",
39
+ pageLimit: 200,
40
+ },
36
41
  });
37
42
  const { fetchNow: classFetchNow, data: classData } = useFetch(CLASS_API_ROUTES.UNIT, {
38
43
  method: API_METHODS.GET,
39
- params: { schoolId: (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id },
44
+ params: {
45
+ schoolId: (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id,
46
+ filterEnabled: "true",
47
+ pageLimit: 200,
48
+ },
40
49
  });
41
50
  const { fetchNow: sectionFetchNow, data: sectionData } = useFetch(SECTION_API_ROUTES.UNIT, {
42
51
  method: API_METHODS.GET,
43
- params: { schoolId: (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id },
52
+ params: {
53
+ schoolId: (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id,
54
+ filterEnabled: "true",
55
+ pageLimit: 200,
56
+ },
44
57
  });
45
58
  useEffect(() => {
46
59
  if (workspace === null || workspace === void 0 ? void 0 : workspace.id) {
@@ -50,19 +63,45 @@ export const EnrollmentForm = () => {
50
63
  }
51
64
  // eslint-disable-next-line react-hooks/exhaustive-deps
52
65
  }, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
66
+ const studentOptions = useMemo(() => {
67
+ const items = ((studentProfileData === null || studentProfileData === void 0 ? void 0 : studentProfileData.items) || []).slice();
68
+ if (selectedStudent &&
69
+ !items.some((item) => item.id === selectedStudent.id)) {
70
+ items.unshift(selectedStudent);
71
+ }
72
+ return items.map((item) => {
73
+ var _a, _b, _c, _d, _e;
74
+ return ({
75
+ value: item.id,
76
+ label: `${(_b = (_a = item.familyMember) === null || _a === void 0 ? void 0 : _a.firstName) !== null && _b !== void 0 ? _b : ""} ${(_d = (_c = item.familyMember) === null || _c === void 0 ? void 0 : _c.lastName) !== null && _d !== void 0 ? _d : ""} - ${((_e = item.computerNumber) !== null && _e !== void 0 ? _e : "").split(":")[1] || item.computerNumber || ""}`,
77
+ });
78
+ });
79
+ }, [studentProfileData, selectedStudent]);
80
+ const classOptions = useMemo(() => {
81
+ const items = ((classData === null || classData === void 0 ? void 0 : classData.items) || []).slice();
82
+ if (selectedClass && !items.some((item) => item.id === selectedClass.id)) {
83
+ items.unshift(selectedClass);
84
+ }
85
+ return items.map((item) => ({
86
+ value: item.id,
87
+ label: `${item.name} (${item.code})`,
88
+ }));
89
+ }, [classData, selectedClass]);
90
+ const sectionOptions = useMemo(() => {
91
+ const items = ((sectionData === null || sectionData === void 0 ? void 0 : sectionData.items) || []).slice();
92
+ if (selectedSection &&
93
+ !items.some((item) => item.id === selectedSection.id)) {
94
+ items.unshift(selectedSection);
95
+ }
96
+ return items.map((item) => ({ value: item.id, label: item.name }));
97
+ }, [sectionData, selectedSection]);
53
98
  const { enhancedComboboxElement: studentProfileIdCombo } = useEnhancedCombobox({
54
99
  emptyText: t("formNoStudentEmpty"),
55
100
  id: "studentProfileId",
56
101
  info: t("formStudentInfo"),
57
102
  label: t("formStudentLabel"),
58
103
  onValueChange: (value) => handleChange("studentProfileId", value),
59
- options: ((studentProfileData === null || studentProfileData === void 0 ? void 0 : studentProfileData.items) || []).map((s) => {
60
- var _a, _b, _c;
61
- return ({
62
- value: s.id,
63
- label: `${(_a = s.familyMember) === null || _a === void 0 ? void 0 : _a.firstName} ${(_b = s.familyMember) === null || _b === void 0 ? void 0 : _b.lastName} - ${((_c = s.computerNumber) !== null && _c !== void 0 ? _c : "").split(":")[1] || s.computerNumber || ""}`,
64
- });
65
- }),
104
+ options: studentOptions,
66
105
  placeholder: t("formStudentPlaceholder"),
67
106
  required: true,
68
107
  searchEndpoint: STUDENT_PROFILE_API_ROUTES.UNIT,
@@ -84,10 +123,7 @@ export const EnrollmentForm = () => {
84
123
  info: t("formClassInfo"),
85
124
  label: t("formClassLabel"),
86
125
  onValueChange: (value) => handleChange("classId", value),
87
- options: ((classData === null || classData === void 0 ? void 0 : classData.items) || []).map((c) => ({
88
- value: c.id,
89
- label: `${c.name} (${c.code})`,
90
- })),
126
+ options: classOptions,
91
127
  placeholder: t("formClassPlaceholder"),
92
128
  required: true,
93
129
  searchEndpoint: CLASS_API_ROUTES.UNIT,
@@ -107,10 +143,7 @@ export const EnrollmentForm = () => {
107
143
  info: t("formSectionInfo"),
108
144
  label: t("formSectionLabel"),
109
145
  onValueChange: (value) => handleChange("sectionId", value),
110
- options: ((sectionData === null || sectionData === void 0 ? void 0 : sectionData.items) || []).map((s) => ({
111
- value: s.id,
112
- label: s.name,
113
- })),
146
+ options: sectionOptions,
114
147
  placeholder: t("formSectionPlaceholder"),
115
148
  required: true,
116
149
  searchEndpoint: SECTION_API_ROUTES.UNIT,
@@ -124,7 +157,5 @@ export const EnrollmentForm = () => {
124
157
  },
125
158
  value: sectionId || "",
126
159
  });
127
- return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "enrollmentDate", t }), id: "enrollmentDate", info: t("formEnrollmentDateInfo"), label: t("formEnrollmentDateLabel"), onChange: (e) => handleChange("enrollmentDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, placeholder: t("formEnrollmentDatePlaceholder"), required: true, type: "date", value: enrollmentDate
128
- ? formatDate(enrollmentDate, DATE_FORMATS.YYYY_MM_DD)
129
- : "" }), _jsx(Separator, {}), studentProfileIdCombo, classIdCombo, sectionIdCombo, _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formActiveEnrollmentInfo"), label: t("formActiveEnrollmentLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }));
160
+ return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "enrollmentDate", t }), id: "enrollmentDate", info: t("formEnrollmentDateInfo"), label: t("formEnrollmentDateLabel"), onChange: (e) => handleChange("enrollmentDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, placeholder: t("formEnrollmentDatePlaceholder"), required: true, type: "date", value: toDateInput(enrollmentDate) }), _jsx(Separator, {}), studentProfileIdCombo, classIdCombo, sectionIdCombo, _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formActiveEnrollmentInfo"), label: t("formActiveEnrollmentLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }));
130
161
  };
@@ -10,18 +10,54 @@ import { pageLimit } from "./constants";
10
10
  import { ENROLLMENT_API_ROUTES } from "../../constants";
11
11
  import { ENROLLMENT_ACTION_TYPES, useEnrollmentContext } from "./context";
12
12
  import { useRef, useEffect, useCallback } from "react";
13
- const workspace = getCachedWorkspaceSync();
14
13
  const POLL_INTERVAL_MS = 2000;
15
14
  const POLL_TIMEOUT_MS = 300000;
16
- const handleGetAllRecords = async (schoolId, pageLimit) => {
17
- const response = await fetch(`${ENROLLMENT_API_ROUTES.UNIT}?pageLimit=${pageLimit}&currentPage=1&schoolId=${schoolId}`);
18
- const result = await response.json();
19
- const csv = await converter.json2csv(result.items || [], {});
15
+ const TEMPLATE_HEADERS = [
16
+ "id",
17
+ "studentProfileId",
18
+ "classId",
19
+ "sectionId",
20
+ "enrollmentDate",
21
+ "enabled",
22
+ ];
23
+ const CREATE_TEMPLATE_HEADERS = [
24
+ "studentProfileId",
25
+ "classId",
26
+ "sectionId",
27
+ "enrollmentDate",
28
+ "enabled",
29
+ ];
30
+ const toCsvRow = (row) => {
31
+ var _a, _b, _c, _d;
32
+ return ({
33
+ id: (_a = row.id) !== null && _a !== void 0 ? _a : "",
34
+ studentProfileId: (_b = row.studentProfileId) !== null && _b !== void 0 ? _b : "",
35
+ classId: (_c = row.classId) !== null && _c !== void 0 ? _c : "",
36
+ sectionId: (_d = row.sectionId) !== null && _d !== void 0 ? _d : "",
37
+ enrollmentDate: row.enrollmentDate
38
+ ? new Date(String(row.enrollmentDate)).toISOString().slice(0, 10)
39
+ : "",
40
+ enabled: row.enabled === false ? "false" : "true",
41
+ });
42
+ };
43
+ const downloadCsv = async (csv, filename) => {
20
44
  const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
21
- await downloadFromUrl(blob, "enrollment.csv");
45
+ await downloadFromUrl(blob, filename);
46
+ };
47
+ const downloadCreateTemplate = async () => {
48
+ await downloadCsv(CREATE_TEMPLATE_HEADERS.join(",") + "\n", "enrollment-template.csv");
49
+ };
50
+ const downloadUpdateTemplate = async (schoolId) => {
51
+ var _a;
52
+ const response = await fetch(`${ENROLLMENT_API_ROUTES.UNIT}?pageLimit=1000&currentPage=1&schoolId=${schoolId}`);
53
+ const result = (await response.json());
54
+ const rows = ((_a = result.items) !== null && _a !== void 0 ? _a : []).map(toCsvRow);
55
+ const csv = await converter.json2csv(rows, { keys: TEMPLATE_HEADERS });
56
+ await downloadCsv(csv, "enrollment.csv");
22
57
  };
23
58
  async function submitBulkJob(csvData, method, signal) {
24
59
  var _a;
60
+ const workspace = getCachedWorkspaceSync();
25
61
  const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
26
62
  if (!schoolId)
27
63
  throw new Error("School ID not found");
@@ -80,7 +116,9 @@ function formatErrorSummary(t, errors) {
80
116
  return lines.join("\n");
81
117
  }
82
118
  export const EnrollmentMoreActions = () => {
119
+ var _a;
83
120
  const t = useTranslations("enrollment");
121
+ const workspace = getCachedWorkspaceSync();
84
122
  const { dispatch } = useEnrollmentContext();
85
123
  const abortRef = useRef(null);
86
124
  // Abort any in-flight polling on unmount
@@ -229,7 +267,7 @@ export const EnrollmentMoreActions = () => {
229
267
  error: error instanceof Error ? error.message : t("unknownError"),
230
268
  }));
231
269
  }
232
- }, [dispatch, t]);
270
+ }, [dispatch, t, (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id]);
233
271
  const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
234
272
  const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
235
273
  const create = [
@@ -237,8 +275,7 @@ export const EnrollmentMoreActions = () => {
237
275
  id: "1",
238
276
  title: t("downloadEmptyCsvTemplate"),
239
277
  handleOnClick: async () => {
240
- var _a;
241
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
278
+ await downloadCreateTemplate();
242
279
  },
243
280
  },
244
281
  { id: "2", title: t("addYourDataToTheCsv") },
@@ -253,7 +290,7 @@ export const EnrollmentMoreActions = () => {
253
290
  title: t("downloadPopulatedCsvTemplate"),
254
291
  handleOnClick: async () => {
255
292
  var _a;
256
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 5000);
293
+ await downloadUpdateTemplate(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "");
257
294
  },
258
295
  },
259
296
  { id: "2", title: t("updateYourDataInTheCsv") },
@@ -16,15 +16,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { useMemo } from "react";
17
17
  import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
18
18
  import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
19
- import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
20
19
  import { VALUE_DELIMITER } from "@react-pakistan/util-functions/constants/select-value-delimiter";
21
- import { useEnrollmentModule, EnrollmentProvider, ENROLLMENT_ACTION_TYPES, } from "./context";
20
+ import { useEnrollmentModule, EnrollmentProvider } from "./context";
22
21
  import { EnrollmentFilter } from "./filter";
23
22
  import { EnrollmentForm } from "./form";
24
23
  import { EnrollmentMoreActions } from "./more-actions";
25
24
  import { EnrollmentView } from "./view";
26
25
  import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
27
26
  import { RbacNoAccess } from "../../components/rbac-no-access";
27
+ import { formatEnrollmentDate } from "./date";
28
28
  // ============================================================================
29
29
  // TABLE COLUMN CONFIGURATION (static — no runtime deps)
30
30
  // ============================================================================
@@ -34,9 +34,11 @@ const tableBodyCols = [
34
34
  componentType: COMPONENT_TYPE.TEXT,
35
35
  key: "studentProfile",
36
36
  textFormatter: (_, row) => {
37
- var _a, _b, _c, _d, _e, _f;
37
+ var _a, _b, _c, _d, _e;
38
38
  const cn = (_b = (_a = row.studentProfile) === null || _a === void 0 ? void 0 : _a.computerNumber) !== null && _b !== void 0 ? _b : "";
39
- return `${(_d = (_c = row.studentProfile) === null || _c === void 0 ? void 0 : _c.familyMember) === null || _d === void 0 ? void 0 : _d.firstName} ${(_f = (_e = row.studentProfile) === null || _e === void 0 ? void 0 : _e.familyMember) === null || _f === void 0 ? void 0 : _f.lastName} - ${cn.split(VALUE_DELIMITER.COLON)[1] || cn}`;
39
+ const member = (_c = row.studentProfile) === null || _c === void 0 ? void 0 : _c.familyMember;
40
+ const name = `${(_d = member === null || member === void 0 ? void 0 : member.firstName) !== null && _d !== void 0 ? _d : ""} ${(_e = member === null || member === void 0 ? void 0 : member.lastName) !== null && _e !== void 0 ? _e : ""}`.trim();
41
+ return `${name || "—"} - ${cn.split(VALUE_DELIMITER.COLON)[1] || cn || "—"}`;
40
42
  },
41
43
  },
42
44
  {
@@ -55,10 +57,7 @@ const tableBodyCols = [
55
57
  {
56
58
  componentType: COMPONENT_TYPE.TEXT,
57
59
  key: "enrollmentDate",
58
- textFormatter: (_, row) => {
59
- const val = row.enrollmentDate;
60
- return val ? formatDate(val, DATE_FORMATS.LOCALE_DATE) : "N/A";
61
- },
60
+ textFormatter: (_, row) => formatEnrollmentDate(row.enrollmentDate),
62
61
  },
63
62
  { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
64
63
  { componentType: COMPONENT_TYPE.ACTIONS },
@@ -72,7 +71,7 @@ const createComponentInstances = () => ({
72
71
  moreActions: _jsx(EnrollmentMoreActions, {}),
73
72
  view: _jsx(EnrollmentView, {}),
74
73
  });
75
- const createEnrollmentConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderClass, tableColumnHeaderEnabled, tableColumnHeaderEnrollmentDate, tableColumnHeaderId, tableColumnHeaderSection, tableColumnHeaderStudent, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
74
+ const createEnrollmentConfig = ({ onClearFilters, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderClass, tableColumnHeaderEnabled, tableColumnHeaderEnrollmentDate, tableColumnHeaderId, tableColumnHeaderSection, tableColumnHeaderStudent, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
76
75
  const components = createComponentInstances();
77
76
  return {
78
77
  moduleName: "enrollment",
@@ -102,9 +101,7 @@ const createEnrollmentConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave
102
101
  tableDescription,
103
102
  tableTitle,
104
103
  viewContent: components.view,
105
- onClearFilters: () => {
106
- dispatch({ type: ENROLLMENT_ACTION_TYPES.RESET_FORM });
107
- },
104
+ onClearFilters: onClearFilters,
108
105
  };
109
106
  };
110
107
  // ============================================================================
@@ -114,7 +111,7 @@ const GenericEnrollmentPage = createGenericModulePage();
114
111
  const EnrollmentPageInner = (props) => {
115
112
  const context = useEnrollmentModule();
116
113
  const enrollmentConfig = useMemo(() => createEnrollmentConfig({
117
- dispatch: context.dispatch,
114
+ onClearFilters: context.clearFilters,
118
115
  drawerButtonCancel: props.drawerButtonCancel,
119
116
  drawerButtonSave: props.drawerButtonSave,
120
117
  drawerFormTitle: props.drawerFormTitle,
@@ -136,7 +133,7 @@ const EnrollmentPageInner = (props) => {
136
133
  tableSearchPlaceholder: props.tableSearchPlaceholder,
137
134
  tableTitle: props.tableTitle,
138
135
  }), [
139
- context.dispatch,
136
+ context.clearFilters,
140
137
  props.drawerButtonCancel,
141
138
  props.drawerButtonSave,
142
139
  props.drawerFormTitle,
@@ -9,6 +9,7 @@ export declare const VALIDATION_KEYS: {
9
9
  readonly studentProfileIdRequired: "validationEnrollmentStudentProfileIdRequired";
10
10
  readonly sectionIdRequired: "validationEnrollmentSectionIdRequired";
11
11
  readonly enrollmentDateRequired: "validationEnrollmentEnrollmentDateRequired";
12
+ readonly invalidDate: "validationEnrollmentInvalidDate";
12
13
  };
13
14
  export declare const enrollmentFormValidation: z.ZodObject<{
14
15
  classId: z.ZodString;