@appcorp/fusion-storybook 0.2.1 → 0.2.3

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.
@@ -77,7 +77,8 @@ export const AdmissionForm = () => {
77
77
  },
78
78
  });
79
79
  }
80
- }, [id, dispatch, workspace]);
80
+ // eslint-disable-next-line react-hooks/exhaustive-deps
81
+ }, [id, dispatch]);
81
82
  return (_jsxs("div", { className: "grid grid-cols-1 gap-2 space-y-2", children: [_jsx("h4", { className: "m-0 p-0", children: t("formSectionStudentInformation") }), _jsxs("div", { className: "grid grid-cols-5 gap-4", children: [_jsx(EnhancedInput, { error: errors.firstName, id: "firstName", info: t("formFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("firstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, type: "text", value: firstName || "" }), _jsx(EnhancedInput, { error: errors.lastName, id: "lastName", info: t("formLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("lastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, type: "text", value: lastName || "" }), _jsx(EnhancedInput, { error: errors.studentIdNumber, id: "studentIdNumber", info: t("formStudentIdNumberInfo"), label: t("formStudentIdNumberLabel"), onChange: (e) => handleChange("studentIdNumber", e.target.value), placeholder: t("formStudentIdNumberPlaceholder"), required: true, type: "text", value: studentIdNumber || "" }), _jsx(EnhancedCombobox, { emptyText: t("formNoGenderOptionsEmpty"), error: errors.gender, id: "gender", info: t("formGenderInfo"), label: t("formGenderLabel"), required: true, onValueChange: (value) => handleChange("gender", value), options: [
82
83
  { label: t("formOptionMale"), value: GENDER.MALE },
83
84
  { label: t("formOptionFemale"), value: GENDER.FEMALE },
@@ -14,7 +14,7 @@
14
14
  */
15
15
  "use client";
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
- import { useMemo, useCallback } from "react";
17
+ import { useMemo } from "react";
18
18
  import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
19
19
  import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
20
20
  import { useAdmissionModule, AdmissionProvider, ADMISSION_DRAWER, ADMISSION_ACTION_TYPES, } from "./context";
@@ -46,15 +46,13 @@ const tableBodyCols = [
46
46
  // ============================================================================
47
47
  // COMPONENT FACTORY (creates JSX elements when config is created, not during render)
48
48
  // ============================================================================
49
- // Memoized component instances - created once and reused
50
- const componentInstancesCache = {
49
+ const createComponentInstances = () => ({
51
50
  filter: _jsx(AdmissionFilter, {}),
52
51
  form: _jsx(AdmissionForm, {}),
53
52
  moreActions: _jsx(AdmissionMoreActions, {}),
54
53
  view: _jsx(AdmissionView, {}),
55
- };
56
- const createComponentInstances = () => componentInstancesCache;
57
- const createAdmissionConfig = ({ cancelLabel, drawerTitle, labelActions, labelClass, labelEnabled, labelFirstName, labelId, labelLastName, labelRegistrationCode, labelStatus, saveLabel, searchPlaceholder, tableDescription, tableTitle, onClearFilters, }) => {
54
+ });
55
+ const createAdmissionConfig = ({ cancelLabel, dispatch, drawer, drawerTitle, labelActions, labelClass, labelEnabled, labelFirstName, labelId, labelLastName, labelRegistrationCode, labelStatus, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
58
56
  const components = createComponentInstances();
59
57
  return {
60
58
  moduleName: "admission",
@@ -78,8 +76,10 @@ const createAdmissionConfig = ({ cancelLabel, drawerTitle, labelActions, labelCl
78
76
  tableDescription,
79
77
  tableTitle,
80
78
  viewContent: components.view,
81
- size: "small",
82
- onClearFilters,
79
+ size: drawer === ADMISSION_DRAWER.FORM_DRAWER ? "full" : "small",
80
+ onClearFilters: () => {
81
+ dispatch({ type: ADMISSION_ACTION_TYPES.RESET_FORM });
82
+ },
83
83
  };
84
84
  };
85
85
  // ============================================================================
@@ -88,16 +88,10 @@ const createAdmissionConfig = ({ cancelLabel, drawerTitle, labelActions, labelCl
88
88
  const GenericAdmissionPage = createGenericModulePage();
89
89
  const AdmissionPageInner = (props) => {
90
90
  const context = useAdmissionModule();
91
- // Create a stable onClearFilters callback.
92
- // dispatch from useReducer is stable across renders, so we can safely use an empty dependency array
93
- // or only depend on dispatch (which never changes). Using empty array is safest.
94
- const handleClearFilters = useCallback(() => {
95
- context.dispatch({ type: ADMISSION_ACTION_TYPES.RESET_FORM });
96
- }, []);
97
- // Memoize config creation with translation props only.
98
- // The key insight: we create the config ONCE when translations change,
99
- // then apply drawer sizing as a separate, cheaper operation below.
100
- const baseConfig = useMemo(() => createAdmissionConfig({
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,
101
95
  cancelLabel: props.cancelLabel,
102
96
  drawerTitle: props.drawerTitle,
103
97
  labelActions: props.labelActions,
@@ -112,8 +106,9 @@ const AdmissionPageInner = (props) => {
112
106
  searchPlaceholder: props.searchPlaceholder,
113
107
  tableDescription: props.tableDescription,
114
108
  tableTitle: props.tableTitle,
115
- onClearFilters: handleClearFilters,
116
109
  }), [
110
+ context.dispatch,
111
+ context.state.drawer,
117
112
  props.cancelLabel,
118
113
  props.drawerTitle,
119
114
  props.labelActions,
@@ -128,24 +123,7 @@ const AdmissionPageInner = (props) => {
128
123
  props.searchPlaceholder,
129
124
  props.tableDescription,
130
125
  props.tableTitle,
131
- handleClearFilters,
132
126
  ]);
133
- // Apply drawer sizing without recreating the entire config.
134
- // We use a technique where we only update the size property and pass it separately,
135
- // ensuring GenericAdmissionPage gets a stable reference unless translation props change.
136
- const admissionConfig = useMemo(() => {
137
- const isFormDrawerOpen = context.state.drawer === ADMISSION_DRAWER.FORM_DRAWER;
138
- // Create a new config only if drawer state actually affects sizing
139
- // This prevents unnecessary recreations of the same-sized config
140
- if (isFormDrawerOpen && baseConfig.size === "full") {
141
- return baseConfig; // Already full size, no need to recreate
142
- }
143
- if (!isFormDrawerOpen && baseConfig.size === "small") {
144
- return baseConfig; // Already small size, no need to recreate
145
- }
146
- // Only recreate if size needs to change
147
- return Object.assign(Object.assign({}, baseConfig), { size: isFormDrawerOpen ? "full" : "small" });
148
- }, [baseConfig, context.state.drawer]);
149
127
  const hasPermission = resolveRbacPermissions({
150
128
  userRole: props.userRole,
151
129
  moduleName: "Admission",
@@ -432,13 +432,13 @@ export const useRbacModule = () => {
432
432
  order: 0,
433
433
  },
434
434
  {
435
- enabled: true,
435
+ enabled: false,
436
436
  handleOnClick: handleFilters,
437
437
  label: t("actionsButtonFilters"),
438
438
  order: 1,
439
439
  },
440
440
  {
441
- enabled: true,
441
+ enabled: false,
442
442
  handleOnClick: handleCreate,
443
443
  label: t("actionsButtonAddItem"),
444
444
  order: 2,
@@ -478,7 +478,10 @@ export const useRbacModule = () => {
478
478
  });
479
479
  dispatch({
480
480
  type: RBAC_ACTION_TYPES.SET_ITEMS,
481
- payload: { items: items || [], count: count || 0 },
481
+ payload: {
482
+ items: items.filter((item) => item.name !== "SUPER_ADMIN") || [],
483
+ count: count || 0,
484
+ },
482
485
  });
483
486
  }
484
487
  catch (_a) {
@@ -79,8 +79,8 @@ const createRbacConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, draw
79
79
  { label: tableColumnHeaderId, width: "5%" },
80
80
  { label: tableColumnHeaderName, width: "25%" },
81
81
  { label: tableColumnHeaderDescription, width: "35%" },
82
- { label: tableColumnHeaderPermissions, width: "25%" },
83
- { label: tableColumnHeaderActions, width: "10%" },
82
+ { label: tableColumnHeaderPermissions, width: "30%" },
83
+ { label: tableColumnHeaderActions, width: "5%" },
84
84
  ],
85
85
  tableDescription,
86
86
  tableTitle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",