@appcorp/fusion-storybook 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,7 +128,7 @@ export const { actionTypes: ADMISSION_ACTION_TYPES, config: admissionModuleConfi
128
128
  // ENHANCED ADMISSION HOOK WITH API INTEGRATION
129
129
  // ============================================================================
130
130
  export const useAdmissionModule = () => {
131
- var _a, _b, _c, _d, _e;
131
+ var _a, _b, _c, _d, _e, _f;
132
132
  const context = useAdmissionContext();
133
133
  const t = useTranslations("admission");
134
134
  const workspace = getCachedWorkspaceSync();
@@ -195,10 +195,85 @@ export const useAdmissionModule = () => {
195
195
  siblings: context.state.siblings || "",
196
196
  state: context.state.state || "",
197
197
  });
198
- }, [context.state, (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id]);
198
+ }, [
199
+ context.state.address,
200
+ context.state.admissionNotes,
201
+ context.state.status,
202
+ context.state.bForm,
203
+ context.state.city,
204
+ context.state.classForAdmission,
205
+ context.state.country,
206
+ context.state.discountCode,
207
+ context.state.dob,
208
+ context.state.emergencyContact,
209
+ context.state.enabled,
210
+ context.state.fatherCnic,
211
+ context.state.fatherFirstName,
212
+ context.state.fatherLastName,
213
+ context.state.fatherMobile,
214
+ context.state.fatherOccupation,
215
+ context.state.fatherOrganization,
216
+ context.state.firstName,
217
+ context.state.gender,
218
+ context.state.hafiz,
219
+ context.state.id,
220
+ context.state.lastName,
221
+ context.state.motherCnic,
222
+ context.state.motherFirstName,
223
+ context.state.motherLastName,
224
+ context.state.motherMobile,
225
+ context.state.notes,
226
+ context.state.orphan,
227
+ context.state.postalCode,
228
+ context.state.previousSchool,
229
+ context.state.registrationCode,
230
+ context.state.siblings,
231
+ context.state.state,
232
+ (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id,
233
+ ]);
199
234
  const byIdParams = useMemo(() => ({ id: context.state.id }), [context.state.id]);
200
235
  const deleteParams = useMemo(() => ({ id: context.state.id }), [context.state.id]);
201
236
  // ============================================================================
237
+ // UTILITIES
238
+ // ============================================================================
239
+ const showToast = useCallback((message, variant) => {
240
+ generateThemeToast({ description: message, variant });
241
+ }, []);
242
+ const setField = useCallback((key, value) => {
243
+ var _a, _b, _c;
244
+ let formatted = value === null
245
+ ? undefined
246
+ : value;
247
+ if ((key === "bForm" || key === "fatherCnic" || key === "motherCnic") &&
248
+ typeof value === "string" &&
249
+ value.length === 13) {
250
+ formatted = (_a = formatCnic(value)) !== null && _a !== void 0 ? _a : value;
251
+ }
252
+ if ((key === "fatherMobile" || key === "motherMobile") &&
253
+ typeof value === "string" &&
254
+ value.length >= 13) {
255
+ formatted = (_c = (_b = formatPhone(value, "PK")) === null || _b === void 0 ? void 0 : _b.international) !== null && _c !== void 0 ? _c : value;
256
+ }
257
+ context.dispatch({
258
+ type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
259
+ payload: { key, value: formatted || value },
260
+ });
261
+ }, [context]);
262
+ const resetFormAndCloseDrawer = useCallback(() => {
263
+ context.dispatch({
264
+ type: ADMISSION_ACTION_TYPES.SET_ERRORS,
265
+ payload: { errors: {} },
266
+ });
267
+ context.dispatch({
268
+ type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
269
+ payload: { disabled: false },
270
+ });
271
+ context.dispatch({
272
+ type: ADMISSION_ACTION_TYPES.SET_DRAWER,
273
+ payload: { drawer: null },
274
+ });
275
+ }, [context]);
276
+ // ============================================================================
202
277
  // API CALLBACKS
203
278
  // ============================================================================
204
279
  const listCallback = ({ data, error }) => {
@@ -227,19 +302,25 @@ export const useAdmissionModule = () => {
227
302
  }
228
303
  };
229
304
  const byIdCallback = ({ data, error }) => {
230
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
305
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
231
306
  if (error) {
232
307
  showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
233
308
  return;
234
309
  }
235
310
  if (data) {
236
311
  const admission = data;
312
+ if ((_a = admission === null || admission === void 0 ? void 0 : admission.fatherDetails) === null || _a === void 0 ? void 0 : _a.emergencyContact) {
313
+ setField("emergencyContact", "Father");
314
+ }
315
+ if ((_b = admission === null || admission === void 0 ? void 0 : admission.motherDetails) === null || _b === void 0 ? void 0 : _b.emergencyContact) {
316
+ setField("emergencyContact", "Mother");
317
+ }
237
318
  setField("id", admission.id);
238
- setField("firstName", (_a = admission.studentDetails) === null || _a === void 0 ? void 0 : _a.firstName);
239
- setField("lastName", (_b = admission.studentDetails) === null || _b === void 0 ? void 0 : _b.lastName);
240
- setField("bForm", (_c = admission.studentDetails) === null || _c === void 0 ? void 0 : _c.bForm);
319
+ setField("firstName", (_c = admission.studentDetails) === null || _c === void 0 ? void 0 : _c.firstName);
320
+ setField("lastName", (_d = admission.studentDetails) === null || _d === void 0 ? void 0 : _d.lastName);
321
+ setField("bForm", (_e = admission.studentDetails) === null || _e === void 0 ? void 0 : _e.bForm);
241
322
  // Normalise gender to match GENDER enum values (e.g. 'Male' → 'MALE')
242
- const rawGender = (_d = admission.studentDetails) === null || _d === void 0 ? void 0 : _d.gender;
323
+ const rawGender = (_f = admission.studentDetails) === null || _f === void 0 ? void 0 : _f.gender;
243
324
  let normalizedGender = null;
244
325
  if (typeof rawGender === "string" && rawGender.length > 0) {
245
326
  const upper = rawGender.toUpperCase();
@@ -248,36 +329,36 @@ export const useAdmissionModule = () => {
248
329
  : rawGender;
249
330
  }
250
331
  setField("gender", normalizedGender);
251
- setField("dob", (_e = admission.studentDetails) === null || _e === void 0 ? void 0 : _e.dob);
252
- setField("registrationCode", (_f = admission.studentDetails) === null || _f === void 0 ? void 0 : _f.registrationCode);
253
- setField("discountCode", (_g = admission.studentDetails) === null || _g === void 0 ? void 0 : _g.discountCode);
254
- setField("hafiz", (_h = admission.studentDetails) === null || _h === void 0 ? void 0 : _h.hafiz);
255
- setField("orphan", (_j = admission.studentDetails) === null || _j === void 0 ? void 0 : _j.orphan);
256
- setField("fatherFirstName", (_k = admission.fatherDetails) === null || _k === void 0 ? void 0 : _k.fatherFirstName);
257
- setField("fatherLastName", (_l = admission.fatherDetails) === null || _l === void 0 ? void 0 : _l.fatherLastName);
258
- setField("fatherCnic", (_m = admission.fatherDetails) === null || _m === void 0 ? void 0 : _m.fatherCnic);
259
- setField("fatherMobile", (_o = admission.fatherDetails) === null || _o === void 0 ? void 0 : _o.fatherMobile);
260
- setField("fatherOccupation", (_p = admission.fatherDetails) === null || _p === void 0 ? void 0 : _p.fatherOccupation);
261
- setField("fatherOrganization", (_q = admission.fatherDetails) === null || _q === void 0 ? void 0 : _q.fatherOrganization);
262
- setField("motherFirstName", (_r = admission.motherDetails) === null || _r === void 0 ? void 0 : _r.motherFirstName);
263
- setField("motherLastName", (_s = admission.motherDetails) === null || _s === void 0 ? void 0 : _s.motherLastName);
264
- setField("motherCnic", (_t = admission.motherDetails) === null || _t === void 0 ? void 0 : _t.motherCnic);
265
- setField("motherMobile", (_u = admission.motherDetails) === null || _u === void 0 ? void 0 : _u.motherMobile);
266
- setField("address", (_v = admission.homeDetails) === null || _v === void 0 ? void 0 : _v.address);
267
- setField("city", (_w = admission.homeDetails) === null || _w === void 0 ? void 0 : _w.city);
268
- setField("country", (_x = admission.homeDetails) === null || _x === void 0 ? void 0 : _x.country);
269
- setField("postalCode", (_y = admission.homeDetails) === null || _y === void 0 ? void 0 : _y.postalCode);
270
- setField("state", (_z = admission.homeDetails) === null || _z === void 0 ? void 0 : _z.state);
271
- setField("notes", (_0 = admission.officeUse) === null || _0 === void 0 ? void 0 : _0.notes);
272
- setField("admissionNotes", (_1 = admission.officeUse) === null || _1 === void 0 ? void 0 : _1.admissionNotes);
273
- setField("previousSchool", (_2 = admission.admissionDetails) === null || _2 === void 0 ? void 0 : _2.previousSchool);
274
- setField("siblings", (_3 = admission.admissionDetails) === null || _3 === void 0 ? void 0 : _3.siblings);
275
- setField("classForAdmission", (_4 = admission.admissionDetails) === null || _4 === void 0 ? void 0 : _4.classForAdmission);
332
+ setField("dob", (_g = admission.studentDetails) === null || _g === void 0 ? void 0 : _g.dob);
333
+ setField("registrationCode", (_h = admission.studentDetails) === null || _h === void 0 ? void 0 : _h.registrationCode);
334
+ setField("discountCode", (_j = admission.studentDetails) === null || _j === void 0 ? void 0 : _j.discountCode);
335
+ setField("hafiz", (_k = admission.studentDetails) === null || _k === void 0 ? void 0 : _k.hafiz);
336
+ setField("orphan", (_l = admission.studentDetails) === null || _l === void 0 ? void 0 : _l.orphan);
337
+ setField("fatherFirstName", (_m = admission.fatherDetails) === null || _m === void 0 ? void 0 : _m.fatherFirstName);
338
+ setField("fatherLastName", (_o = admission.fatherDetails) === null || _o === void 0 ? void 0 : _o.fatherLastName);
339
+ setField("fatherCnic", (_p = admission.fatherDetails) === null || _p === void 0 ? void 0 : _p.fatherCnic);
340
+ setField("fatherMobile", (_q = admission.fatherDetails) === null || _q === void 0 ? void 0 : _q.fatherMobile);
341
+ setField("fatherOccupation", (_r = admission.fatherDetails) === null || _r === void 0 ? void 0 : _r.fatherOccupation);
342
+ setField("fatherOrganization", (_s = admission.fatherDetails) === null || _s === void 0 ? void 0 : _s.fatherOrganization);
343
+ setField("motherFirstName", (_t = admission.motherDetails) === null || _t === void 0 ? void 0 : _t.motherFirstName);
344
+ setField("motherLastName", (_u = admission.motherDetails) === null || _u === void 0 ? void 0 : _u.motherLastName);
345
+ setField("motherCnic", (_v = admission.motherDetails) === null || _v === void 0 ? void 0 : _v.motherCnic);
346
+ setField("motherMobile", (_w = admission.motherDetails) === null || _w === void 0 ? void 0 : _w.motherMobile);
347
+ setField("address", (_x = admission.homeDetails) === null || _x === void 0 ? void 0 : _x.address);
348
+ setField("city", (_y = admission.homeDetails) === null || _y === void 0 ? void 0 : _y.city);
349
+ setField("country", (_z = admission.homeDetails) === null || _z === void 0 ? void 0 : _z.country);
350
+ setField("postalCode", (_0 = admission.homeDetails) === null || _0 === void 0 ? void 0 : _0.postalCode);
351
+ setField("state", (_1 = admission.homeDetails) === null || _1 === void 0 ? void 0 : _1.state);
352
+ setField("notes", (_2 = admission.officeUse) === null || _2 === void 0 ? void 0 : _2.notes);
353
+ setField("admissionNotes", (_3 = admission.officeUse) === null || _3 === void 0 ? void 0 : _3.admissionNotes);
354
+ setField("previousSchool", (_4 = admission.admissionDetails) === null || _4 === void 0 ? void 0 : _4.previousSchool);
355
+ setField("siblings", (_5 = admission.admissionDetails) === null || _5 === void 0 ? void 0 : _5.siblings);
356
+ setField("classForAdmission", (_6 = admission.admissionDetails) === null || _6 === void 0 ? void 0 : _6.classForAdmission);
276
357
  setField("status", admission.status || ADMISSION_STATUS.PENDING);
277
- setField("enabled", (_5 = admission.enabled) !== null && _5 !== void 0 ? _5 : true);
358
+ setField("enabled", (_7 = admission.enabled) !== null && _7 !== void 0 ? _7 : true);
278
359
  // Populate AI analysis if present
279
- const aiAnalysis = (_6 = admission
280
- .aiAnalysis) !== null && _6 !== void 0 ? _6 : null;
360
+ const aiAnalysis = (_8 = admission
361
+ .aiAnalysis) !== null && _8 !== void 0 ? _8 : null;
281
362
  context.dispatch({
282
363
  type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
283
364
  payload: { form: { aiAnalysis } },
@@ -317,46 +398,6 @@ export const useAdmissionModule = () => {
317
398
  },
318
399
  });
319
400
  // ============================================================================
320
- // UTILITIES
321
- // ============================================================================
322
- const showToast = useCallback((message, variant) => {
323
- generateThemeToast({ description: message, variant });
324
- }, []);
325
- const resetFormAndCloseDrawer = useCallback(() => {
326
- context.dispatch({
327
- type: ADMISSION_ACTION_TYPES.SET_ERRORS,
328
- payload: { errors: {} },
329
- });
330
- context.dispatch({
331
- type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
332
- payload: { disabled: false },
333
- });
334
- context.dispatch({
335
- type: ADMISSION_ACTION_TYPES.SET_DRAWER,
336
- payload: { drawer: null },
337
- });
338
- }, [context]);
339
- const setField = useCallback((key, value) => {
340
- var _a, _b, _c;
341
- let formatted = value === null
342
- ? undefined
343
- : value;
344
- if ((key === "bForm" || key === "fatherCnic" || key === "motherCnic") &&
345
- typeof value === "string" &&
346
- value.length === 13) {
347
- formatted = (_a = formatCnic(value)) !== null && _a !== void 0 ? _a : value;
348
- }
349
- if ((key === "fatherMobile" || key === "motherMobile") &&
350
- typeof value === "string" &&
351
- value.length >= 13) {
352
- formatted = (_c = (_b = formatPhone(value, "PK")) === null || _b === void 0 ? void 0 : _b.international) !== null && _c !== void 0 ? _c : value;
353
- }
354
- context.dispatch({
355
- type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
356
- payload: { key, value: formatted || value },
357
- });
358
- }, [context]);
359
- // ============================================================================
360
401
  // HANDLERS
361
402
  // ============================================================================
362
403
  const handleChange = useCallback((field, value) => {
@@ -612,8 +653,54 @@ export const useAdmissionModule = () => {
612
653
  params: updateParams,
613
654
  schema: admissionFormValidation,
614
655
  successCallback: () => {
656
+ var _a;
615
657
  updateFetchNow(undefined, {
616
- body: JSON.stringify(updateParams),
658
+ body: JSON.stringify({
659
+ schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
660
+ admissionDetails: {
661
+ classForAdmission: updateParams.classForAdmission,
662
+ previousSchool: updateParams.previousSchool,
663
+ siblings: updateParams.siblings,
664
+ },
665
+ fatherDetails: {
666
+ fatherCnic: updateParams.fatherCnic,
667
+ fatherFirstName: updateParams.fatherFirstName,
668
+ fatherLastName: updateParams.fatherLastName,
669
+ fatherMobile: updateParams.fatherMobile,
670
+ fatherOccupation: updateParams.fatherOccupation,
671
+ fatherOrganization: updateParams.fatherOrganization,
672
+ emergencyContact: updateParams.emergencyContact === "Father",
673
+ },
674
+ motherDetails: {
675
+ motherCnic: updateParams.motherCnic,
676
+ motherFirstName: updateParams.motherFirstName,
677
+ motherLastName: updateParams.motherLastName,
678
+ motherMobile: updateParams.motherMobile,
679
+ emergencyContact: updateParams.emergencyContact === "Mother",
680
+ },
681
+ homeDetails: {
682
+ address: updateParams.address,
683
+ city: updateParams.city,
684
+ country: updateParams.country,
685
+ postalCode: updateParams.postalCode,
686
+ state: updateParams.state,
687
+ },
688
+ officeUse: {
689
+ notes: updateParams.notes,
690
+ admissionNotes: updateParams.admissionNotes,
691
+ },
692
+ studentDetails: {
693
+ bForm: updateParams.bForm,
694
+ discountCode: updateParams.discountCode,
695
+ dob: updateParams.dob,
696
+ firstName: updateParams.firstName,
697
+ gender: updateParams.gender,
698
+ hafiz: updateParams.hafiz,
699
+ lastName: updateParams.lastName,
700
+ orphan: updateParams.orphan,
701
+ registrationCode: updateParams.registrationCode,
702
+ },
703
+ }),
617
704
  });
618
705
  },
619
706
  errorCallback: (errors) => {
@@ -628,11 +715,18 @@ export const useAdmissionModule = () => {
628
715
  showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
629
716
  },
630
717
  });
631
- }, [context, updateParams, t, showToast, updateFetchNow]);
718
+ }, [
719
+ context,
720
+ updateParams,
721
+ t,
722
+ showToast,
723
+ updateFetchNow,
724
+ (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id,
725
+ ]);
632
726
  // ============================================================================
633
727
  // HEADER & ROW ACTIONS
634
728
  // ============================================================================
635
- const hasGeminiSecrets = Boolean(((_d = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _d === void 0 ? void 0 : _d.GEMINI_API_KEY) && ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _e === void 0 ? void 0 : _e.GEMINI_MODEL));
729
+ const hasGeminiSecrets = Boolean(((_e = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _e === void 0 ? void 0 : _e.GEMINI_API_KEY) && ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _f === void 0 ? void 0 : _f.GEMINI_MODEL));
636
730
  const headerActions = useMemo(() => [
637
731
  {
638
732
  enabled: true,
@@ -88,16 +88,50 @@ const GenericAdmissionPage = createGenericModulePage();
88
88
  // ============================================================================
89
89
  const AdmissionPageInner = (props) => {
90
90
  const context = useAdmissionModule();
91
- // Memoize config creation
92
- const admissionConfig = useMemo(() => createAdmissionConfig(Object.assign({ dispatch: context.dispatch, drawer: context.state.drawer }, props)), [context.dispatch, context.state.drawer, props]);
93
- // Memoize permission check to avoid recalculation on every render
94
- const hasPermission = useMemo(() => resolveRbacPermissions({
91
+ // Memoize config creation - destructure props to avoid object reference changes
92
+ const admissionConfig = useMemo(() => createAdmissionConfig({
93
+ dispatch: context.dispatch,
94
+ drawer: context.state.drawer,
95
+ cancelLabel: props.cancelLabel,
96
+ drawerTitle: props.drawerTitle,
97
+ labelActions: props.labelActions,
98
+ labelClass: props.labelClass,
99
+ labelEnabled: props.labelEnabled,
100
+ labelFirstName: props.labelFirstName,
101
+ labelId: props.labelId,
102
+ labelLastName: props.labelLastName,
103
+ labelRegistrationCode: props.labelRegistrationCode,
104
+ labelStatus: props.labelStatus,
105
+ saveLabel: props.saveLabel,
106
+ searchPlaceholder: props.searchPlaceholder,
107
+ tableDescription: props.tableDescription,
108
+ tableTitle: props.tableTitle,
109
+ }), [
110
+ context.dispatch,
111
+ context.state.drawer,
112
+ props.cancelLabel,
113
+ props.drawerTitle,
114
+ props.labelActions,
115
+ props.labelClass,
116
+ props.labelEnabled,
117
+ props.labelFirstName,
118
+ props.labelId,
119
+ props.labelLastName,
120
+ props.labelRegistrationCode,
121
+ props.labelStatus,
122
+ props.saveLabel,
123
+ props.searchPlaceholder,
124
+ props.tableDescription,
125
+ props.tableTitle,
126
+ ]);
127
+ const hasPermission = resolveRbacPermissions({
95
128
  userRole: props.userRole,
96
129
  moduleName: "Admission",
97
- }), [props.userRole]);
130
+ });
98
131
  if (!hasPermission) {
99
132
  return _jsx(RbacNoAccess, { moduleName: "Admission" });
100
133
  }
134
+ console.log("Rendering AdmissionPageInner with config:", admissionConfig);
101
135
  return (_jsx("div", { className: "p-4", children: _jsx(GenericAdmissionPage, { overrideConfig: admissionConfig, context: context, tableBodyCols: tableBodyCols }) }));
102
136
  };
103
137
  export const AdmissionPage = (props) => (_jsx(AdmissionProvider, { children: _jsx(AdmissionPageInner, Object.assign({}, props)) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",