@appcorp/fusion-storybook 0.5.37 → 0.5.39

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.
@@ -12,9 +12,8 @@ import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-ut
12
12
  import { USER_API_ROUTES } from "../../../constants";
13
13
  import { userFormValidation } from "../validate";
14
14
  import { getCachedWorkspaceSync } from "../../workspace/cache";
15
- import { blobToWebP } from "webp-converter-browser";
16
- import { supabasePublicStorageUrl } from "../../../constants";
17
15
  import { toastNetworkError } from "../../../utils/toast-network-error";
16
+ import { uploadFile } from "../../../utils/upload-file";
18
17
  import { toE164Phone } from "../../../utils/to-e164-phone";
19
18
  import { useUserContext, USER_ACTION_TYPES, USER_DRAWER } from "../context";
20
19
  export const useUserModule = () => {
@@ -99,6 +98,7 @@ export const useUserModule = () => {
99
98
  payload: {
100
99
  form: {
101
100
  avatar: "",
101
+ avatarFile: null,
102
102
  email: "",
103
103
  enabled: true,
104
104
  id: "",
@@ -322,6 +322,10 @@ export const useUserModule = () => {
322
322
  type: USER_ACTION_TYPES.SET_INPUT_FIELD,
323
323
  payload: { key: "avatar", value: url },
324
324
  });
325
+ dispatch({
326
+ type: USER_ACTION_TYPES.SET_INPUT_FIELD,
327
+ payload: { key: "avatarFile", value: file },
328
+ });
325
329
  }, [dispatch]);
326
330
  const applyFilters = useCallback(() => {
327
331
  dispatch({
@@ -357,58 +361,33 @@ export const useUserModule = () => {
357
361
  // 1.4.7 NETWORK ACTIONS
358
362
  // ============================================================================
359
363
  const handleUploadImage = useCallback(async () => {
360
- var _a;
361
- if (!((_a = state.avatar) === null || _a === void 0 ? void 0 : _a.startsWith("blob:")))
364
+ if (!state.avatarFile)
362
365
  return {};
363
366
  if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
364
367
  toastNetworkError();
365
368
  return { failed: true };
366
369
  }
367
- // The Supabase user id does not exist yet on create — use a random path so
368
- // the upload never lands on an empty/overwritten key.
369
- const userKey = updateParams.id || crypto.randomUUID();
370
- const fileRef = `${workspace.id}/users/${userKey}/${crypto.randomUUID()}.webp`;
371
370
  try {
372
- const blob = await fetch(state.avatar).then((r) => r.blob());
373
- const webpBlob = await blobToWebP(blob, { quality: 0.8 });
374
- const arrayBuffer = await webpBlob.arrayBuffer();
375
- let binary = "";
376
- const bytes = new Uint8Array(arrayBuffer);
377
- const chunkSize = 0x8000;
378
- for (let i = 0; i < bytes.length; i += chunkSize) {
379
- const sub = bytes.subarray(i, i + chunkSize);
380
- for (let j = 0; j < sub.length; j++) {
381
- binary += String.fromCharCode(sub[j]);
382
- }
383
- }
384
- const base64 = btoa(binary);
385
- const res = await fetch("/api/uploads/avatar", {
386
- method: "POST",
387
- headers: { "Content-Type": "application/json" },
388
- body: JSON.stringify({
389
- fileBase64: base64,
390
- fileRef,
391
- contentType: webpBlob.type,
392
- }),
371
+ const uploaded = await uploadFile(state.avatarFile, {
372
+ workspaceId: workspace.id,
373
+ formName: "user",
374
+ maxSizeBytes: 0.25 * 1024 * 1024,
393
375
  });
394
- if (!res.ok)
395
- throw new Error("Upload failed");
396
- const responseData = await res.json();
397
- if (responseData === null || responseData === void 0 ? void 0 : responseData.path) {
398
- const url = `${supabasePublicStorageUrl}/${responseData.path}`;
399
- dispatch({
400
- type: USER_ACTION_TYPES.SET_INPUT_FIELD,
401
- payload: { key: "avatar", value: url },
402
- });
403
- return { url };
404
- }
376
+ dispatch({
377
+ type: USER_ACTION_TYPES.SET_INPUT_FIELD,
378
+ payload: { key: "avatar", value: uploaded.url },
379
+ });
380
+ dispatch({
381
+ type: USER_ACTION_TYPES.SET_INPUT_FIELD,
382
+ payload: { key: "avatarFile", value: null },
383
+ });
384
+ return { url: uploaded.url };
405
385
  }
406
- catch (_b) {
386
+ catch (_a) {
407
387
  toastNetworkError();
408
388
  return { failed: true };
409
389
  }
410
- return {};
411
- }, [state.avatar, dispatch, workspace === null || workspace === void 0 ? void 0 : workspace.id, updateParams.id]);
390
+ }, [state.avatarFile, dispatch, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
412
391
  const checkUserEmailExists = useCallback(async (emailParam) => {
413
392
  var _a, _b;
414
393
  const targetEmail = (typeof emailParam === "string" && emailParam) || state.email;
@@ -30,6 +30,7 @@ export declare const USER_ACTION_TYPES: {
30
30
  email: string;
31
31
  phone: string;
32
32
  avatar: string;
33
+ avatarFile: File | null;
33
34
  password: string;
34
35
  enabled: boolean;
35
36
  userRole: USER_ROLE | null;
@@ -48,6 +49,7 @@ export declare const USER_ACTION_TYPES: {
48
49
  email: string;
49
50
  phone: string;
50
51
  avatar: string;
52
+ avatarFile: File | null;
51
53
  password: string;
52
54
  enabled: boolean;
53
55
  userRole: USER_ROLE | null;
@@ -68,6 +70,7 @@ export declare const USER_ACTION_TYPES: {
68
70
  email: string;
69
71
  phone: string;
70
72
  avatar: string;
73
+ avatarFile: File | null;
71
74
  password: string;
72
75
  enabled: boolean;
73
76
  userRole: USER_ROLE | null;
@@ -86,6 +89,7 @@ export declare const USER_ACTION_TYPES: {
86
89
  email: string;
87
90
  phone: string;
88
91
  avatar: string;
92
+ avatarFile: File | null;
89
93
  password: string;
90
94
  enabled: boolean;
91
95
  userRole: USER_ROLE | null;
@@ -104,6 +108,7 @@ export declare const USER_ACTION_TYPES: {
104
108
  email: string;
105
109
  phone: string;
106
110
  avatar: string;
111
+ avatarFile: File | null;
107
112
  password: string;
108
113
  enabled: boolean;
109
114
  userRole: USER_ROLE | null;
@@ -53,6 +53,7 @@ const userConfig = {
53
53
  email: "",
54
54
  phone: "",
55
55
  avatar: "",
56
+ avatarFile: null,
56
57
  password: "",
57
58
  enabled: true,
58
59
  userRole: null,
@@ -30,6 +30,7 @@ export declare const WORKSPACE_ACTION_TYPES: {
30
30
  familiesCount: number;
31
31
  id: string;
32
32
  logo: string;
33
+ logoFile: File | null;
33
34
  name: string;
34
35
  plan: {
35
36
  currency?: string;
@@ -61,6 +62,7 @@ export declare const WORKSPACE_ACTION_TYPES: {
61
62
  familiesCount: number;
62
63
  id: string;
63
64
  logo: string;
65
+ logoFile: File | null;
64
66
  name: string;
65
67
  plan: {
66
68
  currency?: string;
@@ -94,6 +96,7 @@ export declare const WORKSPACE_ACTION_TYPES: {
94
96
  familiesCount: number;
95
97
  id: string;
96
98
  logo: string;
99
+ logoFile: File | null;
97
100
  name: string;
98
101
  plan: {
99
102
  currency?: string;
@@ -125,6 +128,7 @@ export declare const WORKSPACE_ACTION_TYPES: {
125
128
  familiesCount: number;
126
129
  id: string;
127
130
  logo: string;
131
+ logoFile: File | null;
128
132
  name: string;
129
133
  plan: {
130
134
  currency?: string;
@@ -156,6 +160,7 @@ export declare const WORKSPACE_ACTION_TYPES: {
156
160
  familiesCount: number;
157
161
  id: string;
158
162
  logo: string;
163
+ logoFile: File | null;
159
164
  name: string;
160
165
  plan: {
161
166
  currency?: string;
@@ -185,7 +190,7 @@ export declare const WorkspaceStateContextProvider: ({ children, subdomain, }: {
185
190
  subdomain?: string;
186
191
  }) => import("react").JSX.Element;
187
192
  export declare const useWorkspaceModule: () => {
188
- handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
193
+ handleChange: (field: string, value: string | number | boolean | File | null | undefined | Record<string, string>) => void;
189
194
  handleCloseDrawer: () => void;
190
195
  handleEdit: () => void;
191
196
  handleSubmit: () => void;
@@ -209,6 +214,7 @@ export declare const useWorkspaceModule: () => {
209
214
  familiesCount: number;
210
215
  id: string;
211
216
  logo: string;
217
+ logoFile: File | null;
212
218
  name: string;
213
219
  plan: {
214
220
  currency?: string;
@@ -29,6 +29,7 @@ import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-ut
29
29
  import { AUTH_API_ROUTES, WORKSPACE_API_ROUTES } from "../../constants";
30
30
  import { getCachedWorkspace, getCachedWorkspaceSync, setCachedWorkspace, } from "./cache";
31
31
  import { workspaceFormValidation } from "./validate";
32
+ import { uploadFile } from "../../utils/upload-file";
32
33
  // ============================================================================
33
34
  // 1.1 DRAWER TYPES
34
35
  // ============================================================================
@@ -58,6 +59,7 @@ const workspaceConfig = {
58
59
  familiesCount: 0,
59
60
  id: "",
60
61
  logo: "",
62
+ logoFile: null,
61
63
  name: "",
62
64
  plan: null,
63
65
  planEndDate: null,
@@ -314,10 +316,41 @@ export const useWorkspaceModule = () => {
314
316
  validateForm({
315
317
  params: updateParams,
316
318
  schema: workspaceFormValidation,
317
- successCallback: () => {
318
- updateFetchNow(undefined, {
319
- body: JSON.stringify(updateParams),
320
- });
319
+ successCallback: async () => {
320
+ try {
321
+ let logo = updateParams.logo;
322
+ if (state.logoFile) {
323
+ if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
324
+ throw new Error("Workspace context is not available");
325
+ }
326
+ const uploaded = await uploadFile(state.logoFile, {
327
+ workspaceId: workspace.id,
328
+ formName: "workspace",
329
+ maxSizeBytes: 2 * 1024 * 1024,
330
+ });
331
+ logo = uploaded.url;
332
+ dispatch({
333
+ type: WORKSPACE_ACTION_TYPES.SET_INPUT_FIELD,
334
+ payload: { key: "logo", value: logo },
335
+ });
336
+ dispatch({
337
+ type: WORKSPACE_ACTION_TYPES.SET_INPUT_FIELD,
338
+ payload: { key: "logoFile", value: null },
339
+ });
340
+ }
341
+ updateFetchNow(undefined, {
342
+ body: JSON.stringify(Object.assign(Object.assign({}, updateParams), { logo })),
343
+ });
344
+ }
345
+ catch (error) {
346
+ dispatch({
347
+ type: WORKSPACE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
348
+ payload: { disabled: false },
349
+ });
350
+ showToast(error instanceof Error
351
+ ? error.message
352
+ : t("messagesLogoUploadFailed"), TOAST_VARIANT.ERROR);
353
+ }
321
354
  },
322
355
  errorCallback: (errors) => {
323
356
  dispatch({
@@ -331,7 +364,15 @@ export const useWorkspaceModule = () => {
331
364
  showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
332
365
  },
333
366
  });
334
- }, [dispatch, updateParams, updateFetchNow, showToast, t]);
367
+ }, [
368
+ dispatch,
369
+ updateParams,
370
+ updateFetchNow,
371
+ showToast,
372
+ t,
373
+ state.logoFile,
374
+ workspace,
375
+ ]);
335
376
  // ============================================================================
336
377
  // 1.5.8 EFFECTS
337
378
  // ============================================================================
@@ -9,6 +9,7 @@ import { useState } from "react";
9
9
  import { useWorkspaceModule } from "./context";
10
10
  import { useTranslations } from "next-intl";
11
11
  import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
12
+ import { EnhancedDropzone } from "@appcorp/shadcn/components/enhanced-dropzone";
12
13
  import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
13
14
  import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
14
15
  import { getTranslatedError } from "../../utils/get-translated-error";
@@ -62,5 +63,14 @@ export const WorkspaceForm = () => {
62
63
  errors: state.errors,
63
64
  key: "subdomain",
64
65
  t,
65
- }), placeholder: t("formSubdomainPlaceholder"), required: true, info: t("formSubdomainUrlInfo", { subdomain: state.subdomain }), readOnly: true }), _jsx(EnhancedTextarea, { id: "description", label: t("formDescriptionLabel"), value: state.description || "", onChange: (e) => handleChange("description", e.target.value), error: state.errors.description, placeholder: t("formDescriptionPlaceholder"), rows: 3 }), _jsx(EnhancedInput, { id: "logo", label: t("formLogoLabel"), value: state.logo || "", onChange: (e) => handleChange("logo", e.target.value), error: state.errors.logo, placeholder: t("formLogoPlaceholder"), type: "url", readOnly: true }), planIdCombo, _jsxs("div", { className: "mt-6 border-t pt-6", children: [_jsxs("div", { className: "mb-4 flex items-center gap-2", children: [_jsx(Shield, { className: "text-primary h-5 w-5" }), _jsx("h3", { className: "text-lg font-semibold", children: t("formSectionSecrets") })] }), _jsx("p", { className: "text-muted-foreground mb-4 text-sm", children: t("formSecretsDescription") }), _jsx(SecretsEditor, { secrets: secrets, errors: state.errors, onChange: handleSecretChange, secretPlaceholder: t("formSecretPlaceholder") })] })] }));
66
+ }), placeholder: t("formSubdomainPlaceholder"), required: true, info: t("formSubdomainUrlInfo", { subdomain: state.subdomain }), readOnly: true }), _jsx(EnhancedTextarea, { id: "description", label: t("formDescriptionLabel"), value: state.description || "", onChange: (e) => handleChange("description", e.target.value), error: state.errors.description, placeholder: t("formDescriptionPlaceholder"), rows: 3 }), _jsx(EnhancedDropzone, { accept: ["image/*"], error: state.errors.logo, id: "logo", info: t("formLogoInfo"), label: t("formLogoLabel"), maxFiles: 1, maxSize: 2 * 1024 * 1024, onChange: (files) => {
67
+ if (!files.length)
68
+ return;
69
+ const file = files[0];
70
+ handleChange("logo", URL.createObjectURL(file));
71
+ handleChange("logoFile", file);
72
+ }, onRemoveRemote: () => {
73
+ handleChange("logo", "");
74
+ handleChange("logoFile", null);
75
+ }, value: state.logo ? [state.logo] : [] }), planIdCombo, _jsxs("div", { className: "mt-6 border-t pt-6", children: [_jsxs("div", { className: "mb-4 flex items-center gap-2", children: [_jsx(Shield, { className: "text-primary h-5 w-5" }), _jsx("h3", { className: "text-lg font-semibold", children: t("formSectionSecrets") })] }), _jsx("p", { className: "text-muted-foreground mb-4 text-sm", children: t("formSecretsDescription") }), _jsx(SecretsEditor, { secrets: secrets, errors: state.errors, onChange: handleSecretChange, secretPlaceholder: t("formSecretPlaceholder") })] })] }));
66
76
  };
package/constants.d.ts CHANGED
@@ -19,9 +19,6 @@ export declare const BULK_OPERATIONS_API_ROUTES: {
19
19
  export declare const ADMISSION_API_ROUTES: {
20
20
  readonly UNIT: "/api/v1/admission";
21
21
  };
22
- export declare const DOCUMENT_UPLOAD_API_ROUTES: {
23
- readonly UNIT: "/api/v1/document-upload";
24
- };
25
22
  export declare const STORAGE_WAKE_URL = "https://storage.edupilotpro.com/";
26
23
  export declare const CAMPUS_API_ROUTES: {
27
24
  readonly UNIT: "/api/v1/campus";
@@ -104,7 +101,6 @@ export declare const SUBJECT_API_ROUTES: {
104
101
  export declare const TEACHER_API_ROUTES: {
105
102
  readonly LIST: "/api/v1/teacher";
106
103
  readonly UNIT: "/api/v1/teacher";
107
- readonly AVATAR: "/api/v1/teacher-avatar";
108
104
  readonly BULK: "/api/v1/teacher/bulk";
109
105
  readonly BULK_STATUS: (jobId: string) => string;
110
106
  };
package/constants.js CHANGED
@@ -22,9 +22,6 @@ export const BULK_OPERATIONS_API_ROUTES = {
22
22
  export const ADMISSION_API_ROUTES = {
23
23
  UNIT: "/api/v1/admission",
24
24
  };
25
- export const DOCUMENT_UPLOAD_API_ROUTES = {
26
- UNIT: "/api/v1/document-upload",
27
- };
28
25
  export const STORAGE_WAKE_URL = "https://storage.edupilotpro.com/";
29
26
  export const CAMPUS_API_ROUTES = {
30
27
  UNIT: "/api/v1/campus",
@@ -107,7 +104,6 @@ export const SUBJECT_API_ROUTES = {
107
104
  export const TEACHER_API_ROUTES = {
108
105
  LIST: "/api/v1/teacher",
109
106
  UNIT: "/api/v1/teacher",
110
- AVATAR: "/api/v1/teacher-avatar",
111
107
  BULK: "/api/v1/teacher/bulk",
112
108
  BULK_STATUS: (jobId) => `/api/v1/teacher/bulk/${jobId}`,
113
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.5.37",
3
+ "version": "0.5.39",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",
@@ -65,6 +65,7 @@
65
65
  "@storybook/addon-onboarding": "^10.3.4",
66
66
  "@storybook/addon-vitest": "^10.3.4",
67
67
  "@storybook/nextjs-vite": "^10.3.4",
68
+ "@supabase/ssr": "^0",
68
69
  "@supabase/supabase-js": "^2.103.0",
69
70
  "@tailwindcss/forms": "^0.5.11",
70
71
  "@tailwindcss/postcss": "^4",