@appcorp/fusion-storybook 0.1.56 → 0.1.57

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.
@@ -148,6 +148,13 @@ export declare const WORKSPACE_DRAWER: {
148
148
  readonly MORE_ACTIONS_DRAWER: string;
149
149
  readonly VIEW_DRAWER: string;
150
150
  };
151
+ type Plan = {
152
+ name: string;
153
+ id: string;
154
+ };
155
+ export declare const WorkspaceStateContextProvider: ({ children, }: {
156
+ children: React.ReactNode;
157
+ }) => import("react/jsx-runtime").JSX.Element;
151
158
  export declare const useWorkspaceModule: () => {
152
159
  state: {
153
160
  agreedCurrency: string;
@@ -177,10 +184,7 @@ export declare const useWorkspaceModule: () => {
177
184
  errors: Record<string, string>;
178
185
  };
179
186
  dispatch: import("react").Dispatch<any>;
180
- plans: {
181
- name: string;
182
- id: string;
183
- }[];
187
+ plans: Plan[];
184
188
  handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
185
189
  handleCloseDrawer: () => void;
186
190
  handleEdit: () => void;
@@ -188,3 +192,4 @@ export declare const useWorkspaceModule: () => {
188
192
  handleView: () => void;
189
193
  updateLoading: boolean;
190
194
  };
195
+ export {};
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
2
3
  /**
3
4
  * Workspace Module — business logic + API integration
4
5
  *
@@ -16,7 +17,7 @@
16
17
  * - `WorkspaceStateContextProvider` — provider component used by the page
17
18
  * - `useWorkspaceModule()` — hook that returns handlers and state
18
19
  */
19
- import { useCallback, useEffect, useMemo, useState } from "react";
20
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
20
21
  import { validateForm } from "@react-pakistan/util-functions";
21
22
  import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
22
23
  import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
@@ -80,12 +81,42 @@ export const WORKSPACE_DRAWER = {
80
81
  MORE_ACTIONS_DRAWER: "MORE_ACTIONS_DRAWER",
81
82
  VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
82
83
  };
84
+ const PlansContext = createContext([]);
85
+ export const WorkspaceStateContextProvider = ({ children, }) => {
86
+ const [plans, setPlans] = useState([]);
87
+ const t = useTranslations("workspace");
88
+ useEffect(() => {
89
+ const fetchPlans = async () => {
90
+ try {
91
+ const response = await fetch(AUTH_API_ROUTES.PLAN, {
92
+ method: "GET",
93
+ headers: {
94
+ "Content-Type": "application/json",
95
+ "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
96
+ },
97
+ });
98
+ if (response.ok) {
99
+ const data = await response.json();
100
+ setPlans((data.items || []));
101
+ }
102
+ }
103
+ catch (_a) {
104
+ generateThemeToast({
105
+ description: t("messagesFetchFailed"),
106
+ variant: TOAST_VARIANT.ERROR,
107
+ });
108
+ }
109
+ };
110
+ fetchPlans();
111
+ }, [t]);
112
+ return (_jsx(PlansContext.Provider, { value: plans, children: _jsx(WorkspaceProvider, { children: children }) }));
113
+ };
83
114
  // ============================================================================
84
115
  // ENHANCED WORKSPACE HOOK WITH API INTEGRATION
85
116
  // ============================================================================
86
117
  export const useWorkspaceModule = () => {
87
118
  const { state, dispatch } = useWorkspaceContext();
88
- const [plans, setPlans] = useState([]);
119
+ const plans = useContext(PlansContext);
89
120
  const workspace = getCachedWorkspaceSync();
90
121
  const t = useTranslations("workspace");
91
122
  // ============================================================================
@@ -251,6 +282,7 @@ export const useWorkspaceModule = () => {
251
282
  // EFFECTS
252
283
  // ============================================================================
253
284
  useEffect(() => {
285
+ console.log("Workspace data loaded into context:", workspace);
254
286
  if (workspace) {
255
287
  dispatch({
256
288
  type: WORKSPACE_ACTION_TYPES.SET_FORM_DATA,
@@ -258,28 +290,6 @@ export const useWorkspaceModule = () => {
258
290
  });
259
291
  }
260
292
  }, [dispatch, workspace]);
261
- // Fetch plans for the combobox
262
- useEffect(() => {
263
- const fetchPlans = async () => {
264
- try {
265
- const response = await fetch(AUTH_API_ROUTES.PLAN, {
266
- method: "GET",
267
- headers: {
268
- "Content-Type": "application/json",
269
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
270
- },
271
- });
272
- if (response.ok) {
273
- const data = await response.json();
274
- setPlans((data.items || []));
275
- }
276
- }
277
- catch (_a) {
278
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
279
- }
280
- };
281
- fetchPlans();
282
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
283
293
  // ============================================================================
284
294
  // RETURN
285
295
  // ============================================================================
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useWorkspaceModule, WorkspaceProvider } from "./context";
3
+ import { useWorkspaceModule, WorkspaceStateContextProvider } from "./context";
4
4
  import { WorkspaceView } from "./view";
5
5
  import { WorkspaceDrawer } from "./drawer";
6
6
  import { Button } from "@appcorp/shadcn/components/ui/button";
@@ -21,4 +21,4 @@ const WorkspaceInnerPage = ({ labelEdit, tableDescription, tableTitle, userRole,
21
21
  }
22
22
  return (_jsx("div", { className: "container mx-auto px-4 py-8", children: _jsxs("div", { className: "mx-auto max-w-6xl", children: [_jsxs("div", { className: "mb-8", children: [_jsx("h1", { className: "text-3xl font-bold text-gray-900", children: tableTitle }), _jsx("p", { className: "mt-2 text-gray-600", children: tableDescription })] }), _jsx("div", { className: "mb-6 flex justify-end", children: _jsxs(Button, { onClick: handleEdit, className: "flex items-center space-x-2", children: [_jsx(Edit, { className: "h-4 w-4" }), _jsx("span", { children: labelEdit })] }) }), _jsx(WorkspaceView, {}), _jsx(WorkspaceDrawer, {})] }) }));
23
23
  };
24
- export const WorkspacePage = (props) => (_jsx(WorkspaceProvider, { children: _jsx(WorkspaceInnerPage, Object.assign({}, props)) }));
24
+ export const WorkspacePage = (props) => (_jsx(WorkspaceStateContextProvider, { children: _jsx(WorkspaceInnerPage, Object.assign({}, props)) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",