@appcorp/fusion-storybook 0.5.36 → 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.
- package/base-modules/admission/context/use-admission-module.d.ts +1 -1
- package/base-modules/admission/context/use-admission-module.js +23 -36
- package/base-modules/admission/form.js +117 -54
- package/base-modules/expense/context/shared.d.ts +5 -0
- package/base-modules/expense/context/shared.js +1 -0
- package/base-modules/expense/context/use-expense-module.d.ts +2 -1
- package/base-modules/expense/context/use-expense-module.js +49 -5
- package/base-modules/expense/form.js +4 -2
- package/base-modules/school/context.d.ts +13 -7
- package/base-modules/school/context.js +46 -5
- package/base-modules/school/form.js +11 -1
- package/base-modules/teacher/context.js +9 -37
- package/base-modules/user/context/use-user-module.d.ts +1 -0
- package/base-modules/user/context/use-user-module.js +22 -43
- package/base-modules/user/context.d.ts +5 -0
- package/base-modules/user/context.js +1 -0
- package/base-modules/workspace/context.d.ts +7 -1
- package/base-modules/workspace/context.js +46 -5
- package/base-modules/workspace/form.js +11 -1
- package/constants.d.ts +0 -4
- package/constants.js +0 -4
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/upload-file.d.ts +42 -0
- package/utils/upload-file.js +116 -0
- package/base-modules/teacher/avatar-upload.d.ts +0 -36
- package/base-modules/teacher/avatar-upload.js +0 -104
- package/utils/file-to-base64.d.ts +0 -1
- package/utils/file-to-base64.js +0 -10
|
@@ -23,7 +23,8 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
23
23
|
email: null;
|
|
24
24
|
enabled: boolean;
|
|
25
25
|
id: string;
|
|
26
|
-
logo: null;
|
|
26
|
+
logo: string | null;
|
|
27
|
+
logoFile: File | null;
|
|
27
28
|
name: string;
|
|
28
29
|
phone: null;
|
|
29
30
|
postalCode: null;
|
|
@@ -43,7 +44,8 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
43
44
|
email: null;
|
|
44
45
|
enabled: boolean;
|
|
45
46
|
id: string;
|
|
46
|
-
logo: null;
|
|
47
|
+
logo: string | null;
|
|
48
|
+
logoFile: File | null;
|
|
47
49
|
name: string;
|
|
48
50
|
phone: null;
|
|
49
51
|
postalCode: null;
|
|
@@ -65,7 +67,8 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
65
67
|
email: null;
|
|
66
68
|
enabled: boolean;
|
|
67
69
|
id: string;
|
|
68
|
-
logo: null;
|
|
70
|
+
logo: string | null;
|
|
71
|
+
logoFile: File | null;
|
|
69
72
|
name: string;
|
|
70
73
|
phone: null;
|
|
71
74
|
postalCode: null;
|
|
@@ -85,7 +88,8 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
85
88
|
email: null;
|
|
86
89
|
enabled: boolean;
|
|
87
90
|
id: string;
|
|
88
|
-
logo: null;
|
|
91
|
+
logo: string | null;
|
|
92
|
+
logoFile: File | null;
|
|
89
93
|
name: string;
|
|
90
94
|
phone: null;
|
|
91
95
|
postalCode: null;
|
|
@@ -105,7 +109,8 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
105
109
|
email: null;
|
|
106
110
|
enabled: boolean;
|
|
107
111
|
id: string;
|
|
108
|
-
logo: null;
|
|
112
|
+
logo: string | null;
|
|
113
|
+
logoFile: File | null;
|
|
109
114
|
name: string;
|
|
110
115
|
phone: null;
|
|
111
116
|
postalCode: null;
|
|
@@ -119,7 +124,7 @@ export declare const SCHOOL_ACTION_TYPES: {
|
|
|
119
124
|
}>;
|
|
120
125
|
export declare const useSchoolModule: () => {
|
|
121
126
|
closeDrawer: () => void;
|
|
122
|
-
handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
|
|
127
|
+
handleChange: (field: string, value: string | number | boolean | File | null | undefined | Record<string, string>) => void;
|
|
123
128
|
handleEdit: () => void;
|
|
124
129
|
handleSubmit: () => void;
|
|
125
130
|
handleView: () => void;
|
|
@@ -143,7 +148,8 @@ export declare const useSchoolModule: () => {
|
|
|
143
148
|
email: null;
|
|
144
149
|
enabled: boolean;
|
|
145
150
|
id: string;
|
|
146
|
-
logo: null;
|
|
151
|
+
logo: string | null;
|
|
152
|
+
logoFile: File | null;
|
|
147
153
|
name: string;
|
|
148
154
|
phone: null;
|
|
149
155
|
postalCode: null;
|
|
@@ -30,6 +30,7 @@ import { invalidateSchoolCache } from "./cache";
|
|
|
30
30
|
import { schoolFormValidation } from "./validate";
|
|
31
31
|
import { getCachedWorkspaceSync, setCachedWorkspace } from "../workspace/cache";
|
|
32
32
|
import { toE164Phone } from "../../utils/to-e164-phone";
|
|
33
|
+
import { uploadFile } from "../../utils/upload-file";
|
|
33
34
|
// ============================================================================
|
|
34
35
|
// 1.1 DRAWER TYPES
|
|
35
36
|
// ============================================================================
|
|
@@ -55,6 +56,7 @@ const schoolConfig = {
|
|
|
55
56
|
enabled: true,
|
|
56
57
|
id: "",
|
|
57
58
|
logo: null,
|
|
59
|
+
logoFile: null,
|
|
58
60
|
name: "",
|
|
59
61
|
phone: null,
|
|
60
62
|
postalCode: null,
|
|
@@ -293,10 +295,41 @@ export const useSchoolModule = () => {
|
|
|
293
295
|
validateForm({
|
|
294
296
|
params: updateParams,
|
|
295
297
|
schema: schoolFormValidation,
|
|
296
|
-
successCallback: () => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
298
|
+
successCallback: async () => {
|
|
299
|
+
try {
|
|
300
|
+
let logo = updateParams.logo;
|
|
301
|
+
if (state.logoFile) {
|
|
302
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
|
|
303
|
+
throw new Error("Workspace context is not available");
|
|
304
|
+
}
|
|
305
|
+
const uploaded = await uploadFile(state.logoFile, {
|
|
306
|
+
workspaceId: workspace.id,
|
|
307
|
+
formName: "school",
|
|
308
|
+
maxSizeBytes: 2 * 1024 * 1024,
|
|
309
|
+
});
|
|
310
|
+
logo = uploaded.url;
|
|
311
|
+
dispatch({
|
|
312
|
+
type: SCHOOL_ACTION_TYPES.SET_INPUT_FIELD,
|
|
313
|
+
payload: { key: "logo", value: logo },
|
|
314
|
+
});
|
|
315
|
+
dispatch({
|
|
316
|
+
type: SCHOOL_ACTION_TYPES.SET_INPUT_FIELD,
|
|
317
|
+
payload: { key: "logoFile", value: null },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
updateFetchNow(undefined, {
|
|
321
|
+
body: JSON.stringify(Object.assign(Object.assign({}, updateParams), { logo })),
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
dispatch({
|
|
326
|
+
type: SCHOOL_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
327
|
+
payload: { disableSaveButton: false },
|
|
328
|
+
});
|
|
329
|
+
showToast(error instanceof Error
|
|
330
|
+
? error.message
|
|
331
|
+
: t("messagesLogoUploadFailed"), TOAST_VARIANT.ERROR);
|
|
332
|
+
}
|
|
300
333
|
},
|
|
301
334
|
errorCallback: (errors) => {
|
|
302
335
|
dispatch({
|
|
@@ -310,7 +343,15 @@ export const useSchoolModule = () => {
|
|
|
310
343
|
showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
|
|
311
344
|
},
|
|
312
345
|
});
|
|
313
|
-
}, [
|
|
346
|
+
}, [
|
|
347
|
+
dispatch,
|
|
348
|
+
showToast,
|
|
349
|
+
t,
|
|
350
|
+
updateFetchNow,
|
|
351
|
+
updateParams,
|
|
352
|
+
state.logoFile,
|
|
353
|
+
workspace === null || workspace === void 0 ? void 0 : workspace.id,
|
|
354
|
+
]);
|
|
314
355
|
// ============================================================================
|
|
315
356
|
// 1.4.8 HEADER & ROW ACTIONS
|
|
316
357
|
// ============================================================================
|
|
@@ -7,6 +7,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
*/
|
|
8
8
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
9
9
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
10
|
+
import { EnhancedDropzone } from "@appcorp/shadcn/components/enhanced-dropzone";
|
|
10
11
|
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
11
12
|
import { useSchoolModule } from "./context";
|
|
12
13
|
import { CURRENCY } from "../../type";
|
|
@@ -39,5 +40,14 @@ export const SchoolForm = () => {
|
|
|
39
40
|
// searchPlaceholder: t("formPrincipalSearchPlaceholder"),
|
|
40
41
|
// value: principalId || "",
|
|
41
42
|
// });
|
|
42
|
-
return (_jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "name", label: t("formNameLabel"), value: name, onChange: (e) => handleChange("name", e.target.value), error: getTranslatedError({ errors, key: "name", t }), placeholder: t("formNamePlaceholder"), required: true }), _jsx(EnhancedInput, { id: "code", label: t("formCodeLabel"), value: code, onChange: (e) => handleChange("code", e.target.value), error: getTranslatedError({ errors, key: "code", t }), placeholder: t("formCodePlaceholder"), required: true, info: t("formCodeInfo") }), currencyCombo, _jsx(EnhancedInput, { id: "address", label: t("formAddressLabel"), value: address || "", onChange: (e) => handleChange("address", e.target.value), error: getTranslatedError({ errors, key: "address", t }), placeholder: t("formAddressPlaceholder") }), _jsx(EnhancedInput, { id: "city", label: t("formCityLabel"), value: city || "", onChange: (e) => handleChange("city", e.target.value), error: getTranslatedError({ errors, key: "city", t }), placeholder: t("formCityPlaceholder") }), _jsx(EnhancedInput, { id: "state", label: t("formStateLabel"), value: stateField || "", onChange: (e) => handleChange("state", e.target.value), error: getTranslatedError({ errors, key: "state", t }), placeholder: t("formStatePlaceholder") }), _jsx(EnhancedInput, { id: "country", label: t("formCountryLabel"), value: country || "", onChange: (e) => handleChange("country", e.target.value), error: getTranslatedError({ errors, key: "country", t }), placeholder: t("formCountryPlaceholder") }), _jsx(EnhancedInput, { id: "postalCode", label: t("formPostalCodeLabel"), value: postalCode || "", onChange: (e) => handleChange("postalCode", e.target.value), error: getTranslatedError({ errors, key: "postalCode", t }), placeholder: t("formPostalCodePlaceholder") }), _jsx(PhoneInput, { id: "phone", label: t("formPhoneLabel"), value: phone || "", onChange: (value) => handleChange("phone", value), error: getTranslatedError({ errors, key: "phone", t }), placeholder: t("formPhonePlaceholder"), defaultCountry: country || "PK" }), _jsx(EnhancedInput, { id: "email", label: t("formEmailLabel"), value: email || "", onChange: (e) => handleChange("email", e.target.value), error: getTranslatedError({ errors, key: "email", t }), placeholder: t("formEmailPlaceholder"), type: "email" })] }), _jsx(EnhancedInput, { id: "website", label: t("formWebsiteLabel"), value: website || "", onChange: (e) => handleChange("website", e.target.value), error: getTranslatedError({ errors, key: "website", t }), placeholder: t("formWebsitePlaceholder"), type: "url" }), _jsx(
|
|
43
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "name", label: t("formNameLabel"), value: name, onChange: (e) => handleChange("name", e.target.value), error: getTranslatedError({ errors, key: "name", t }), placeholder: t("formNamePlaceholder"), required: true }), _jsx(EnhancedInput, { id: "code", label: t("formCodeLabel"), value: code, onChange: (e) => handleChange("code", e.target.value), error: getTranslatedError({ errors, key: "code", t }), placeholder: t("formCodePlaceholder"), required: true, info: t("formCodeInfo") }), currencyCombo, _jsx(EnhancedInput, { id: "address", label: t("formAddressLabel"), value: address || "", onChange: (e) => handleChange("address", e.target.value), error: getTranslatedError({ errors, key: "address", t }), placeholder: t("formAddressPlaceholder") }), _jsx(EnhancedInput, { id: "city", label: t("formCityLabel"), value: city || "", onChange: (e) => handleChange("city", e.target.value), error: getTranslatedError({ errors, key: "city", t }), placeholder: t("formCityPlaceholder") }), _jsx(EnhancedInput, { id: "state", label: t("formStateLabel"), value: stateField || "", onChange: (e) => handleChange("state", e.target.value), error: getTranslatedError({ errors, key: "state", t }), placeholder: t("formStatePlaceholder") }), _jsx(EnhancedInput, { id: "country", label: t("formCountryLabel"), value: country || "", onChange: (e) => handleChange("country", e.target.value), error: getTranslatedError({ errors, key: "country", t }), placeholder: t("formCountryPlaceholder") }), _jsx(EnhancedInput, { id: "postalCode", label: t("formPostalCodeLabel"), value: postalCode || "", onChange: (e) => handleChange("postalCode", e.target.value), error: getTranslatedError({ errors, key: "postalCode", t }), placeholder: t("formPostalCodePlaceholder") }), _jsx(PhoneInput, { id: "phone", label: t("formPhoneLabel"), value: phone || "", onChange: (value) => handleChange("phone", value), error: getTranslatedError({ errors, key: "phone", t }), placeholder: t("formPhonePlaceholder"), defaultCountry: country || "PK" }), _jsx(EnhancedInput, { id: "email", label: t("formEmailLabel"), value: email || "", onChange: (e) => handleChange("email", e.target.value), error: getTranslatedError({ errors, key: "email", t }), placeholder: t("formEmailPlaceholder"), type: "email" })] }), _jsx(EnhancedInput, { id: "website", label: t("formWebsiteLabel"), value: website || "", onChange: (e) => handleChange("website", e.target.value), error: getTranslatedError({ errors, key: "website", t }), placeholder: t("formWebsitePlaceholder"), type: "url" }), _jsx(EnhancedDropzone, { accept: ["image/*"], error: getTranslatedError({ errors, key: "logo", t }), id: "logo", info: t("formLogoInfo"), label: t("formLogoLabel"), maxFiles: 1, maxSize: 2 * 1024 * 1024, onChange: (files) => {
|
|
44
|
+
if (!files.length)
|
|
45
|
+
return;
|
|
46
|
+
const file = files[0];
|
|
47
|
+
handleChange("logo", URL.createObjectURL(file));
|
|
48
|
+
handleChange("logoFile", file);
|
|
49
|
+
}, onRemoveRemote: () => {
|
|
50
|
+
handleChange("logo", null);
|
|
51
|
+
handleChange("logoFile", null);
|
|
52
|
+
}, value: logo ? [logo] : [] }), _jsx(EnhancedCheckbox, { id: "enabled", label: t("formEnabledLabel"), checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
|
|
43
53
|
};
|
|
@@ -32,7 +32,7 @@ import { pageLimit } from "./constants";
|
|
|
32
32
|
import { TEACHER_API_ROUTES } from "../../constants";
|
|
33
33
|
import { teacherFormValidation } from "./validate";
|
|
34
34
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
35
|
-
import {
|
|
35
|
+
import { uploadFile } from "../../utils/upload-file";
|
|
36
36
|
// ============================================================================
|
|
37
37
|
// 1.1 DRAWER TYPES
|
|
38
38
|
// ============================================================================
|
|
@@ -420,46 +420,18 @@ export const useTeacherModule = () => {
|
|
|
420
420
|
return;
|
|
421
421
|
uploadInProgressRef.current = true;
|
|
422
422
|
lastUploadRef.current = { sig, ts: now };
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if ("type" in result) {
|
|
426
|
-
// Error result
|
|
427
|
-
const error = result;
|
|
428
|
-
showToast(error.message, TOAST_VARIANT.ERROR);
|
|
423
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
|
|
424
|
+
showToast(t("messagesAvatarUploadError"), TOAST_VARIANT.ERROR);
|
|
429
425
|
return;
|
|
430
426
|
}
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
// Upload to S3 via teacher-avatar endpoint
|
|
438
|
-
const response = await fetch(TEACHER_API_ROUTES.AVATAR, {
|
|
439
|
-
method: "POST",
|
|
440
|
-
headers: {
|
|
441
|
-
"Content-Type": "application/json",
|
|
442
|
-
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
443
|
-
},
|
|
444
|
-
body: JSON.stringify({
|
|
445
|
-
teacherId,
|
|
446
|
-
fileBase64: result.fileBase64,
|
|
447
|
-
contentType: result.contentType,
|
|
448
|
-
workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id,
|
|
449
|
-
}),
|
|
427
|
+
const uploaded = await uploadFile(file, {
|
|
428
|
+
workspaceId: workspace.id,
|
|
429
|
+
formName: "teacher",
|
|
430
|
+
maxSizeBytes: 100 * 1024,
|
|
450
431
|
});
|
|
451
|
-
if (!response.ok) {
|
|
452
|
-
const errorData = await response.json().catch(() => ({}));
|
|
453
|
-
const errorMessage = errorData.error || `Upload failed with status ${response.status}`;
|
|
454
|
-
showToast(errorMessage, TOAST_VARIANT.ERROR);
|
|
455
|
-
uploadInProgressRef.current = false;
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
const data = await response.json();
|
|
459
|
-
const avatarUrl = data.url;
|
|
460
432
|
dispatch({
|
|
461
433
|
type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
462
|
-
payload: { key: "avatar", value:
|
|
434
|
+
payload: { key: "avatar", value: uploaded.url },
|
|
463
435
|
});
|
|
464
436
|
showToast(t("messagesAvatarUploadSuccess"), TOAST_VARIANT.SUCCESS);
|
|
465
437
|
}
|
|
@@ -472,7 +444,7 @@ export const useTeacherModule = () => {
|
|
|
472
444
|
finally {
|
|
473
445
|
uploadInProgressRef.current = false;
|
|
474
446
|
}
|
|
475
|
-
}, [dispatch, showToast,
|
|
447
|
+
}, [dispatch, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
476
448
|
const applyFilters = useCallback(() => {
|
|
477
449
|
dispatch({
|
|
478
450
|
type: TEACHER_ACTION_TYPES.SET_FILTERS,
|
|
@@ -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
|
-
|
|
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
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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 (
|
|
386
|
+
catch (_a) {
|
|
407
387
|
toastNetworkError();
|
|
408
388
|
return { failed: true };
|
|
409
389
|
}
|
|
410
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
319
|
-
|
|
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
|
-
}, [
|
|
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(
|
|
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.
|
|
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",
|