@appcorp/fusion-storybook 0.5.37 → 0.5.40
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 +4 -1
- package/base-modules/admission/context/use-admission-module.js +63 -40
- 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/student-profile/context/use-student-profile-module.js +4 -0
- 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 +13 -37
- package/base-modules/workspace/context.js +47 -25
- package/base-modules/workspace/form.js +11 -1
- package/base-modules/workspace/view.js +12 -9
- package/constants.d.ts +0 -4
- package/constants.js +0 -4
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +2 -12
- package/utils/student-usage-api.d.ts +6 -0
- package/utils/student-usage-api.js +16 -0
- package/utils/student-usage.d.ts +20 -0
- package/utils/student-usage.js +40 -0
- 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
|
@@ -13,6 +13,7 @@ import { toE164Phone } from "../../../utils/to-e164-phone";
|
|
|
13
13
|
import { STUDENT_PROFILE_API_ROUTES } from "../../../constants";
|
|
14
14
|
import { studentProfileFormValidation } from "../validate";
|
|
15
15
|
import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
16
|
+
import { emitStudentUsageChanged } from "../../../utils/student-usage";
|
|
16
17
|
import { useStudentProfileContext, STUDENT_PROFILE_ACTION_TYPES, STUDENT_PROFILE_DRAWER, } from "./module-base";
|
|
17
18
|
export const useStudentProfileModule = () => {
|
|
18
19
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -184,6 +185,7 @@ export const useStudentProfileModule = () => {
|
|
|
184
185
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
185
186
|
resetFormAndCloseDrawer();
|
|
186
187
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
188
|
+
emitStudentUsageChanged();
|
|
187
189
|
}
|
|
188
190
|
}, [dispatch, resetFormAndCloseDrawer, showToast, t]);
|
|
189
191
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
@@ -236,6 +238,7 @@ export const useStudentProfileModule = () => {
|
|
|
236
238
|
if (data) {
|
|
237
239
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
238
240
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
241
|
+
emitStudentUsageChanged();
|
|
239
242
|
}
|
|
240
243
|
}, [showToast, t]);
|
|
241
244
|
const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
|
|
@@ -442,6 +445,7 @@ export const useStudentProfileModule = () => {
|
|
|
442
445
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
443
446
|
if (data) {
|
|
444
447
|
showToast(t("messagesReAdmitSuccess"), TOAST_VARIANT.SUCCESS);
|
|
448
|
+
emitStudentUsageChanged();
|
|
445
449
|
}
|
|
446
450
|
if (error) {
|
|
447
451
|
showToast(t("messagesReAdmitFailed"), TOAST_VARIANT.ERROR);
|
|
@@ -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;
|
|
@@ -22,14 +22,12 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
22
22
|
agreedPrice: number;
|
|
23
23
|
billingDate: null;
|
|
24
24
|
billingInterval: string;
|
|
25
|
-
classesCount: number;
|
|
26
|
-
coursesCount: number;
|
|
27
25
|
description: string;
|
|
28
26
|
dueDateLength: number;
|
|
29
27
|
enabled: boolean;
|
|
30
|
-
familiesCount: number;
|
|
31
28
|
id: string;
|
|
32
29
|
logo: string;
|
|
30
|
+
logoFile: File | null;
|
|
33
31
|
name: string;
|
|
34
32
|
plan: {
|
|
35
33
|
currency?: string;
|
|
@@ -40,11 +38,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
40
38
|
planId: string;
|
|
41
39
|
planStartDate: null;
|
|
42
40
|
secrets: {};
|
|
43
|
-
staffAccountsCount: number;
|
|
44
|
-
storageUsedMB: number;
|
|
45
41
|
studentsCount: number;
|
|
42
|
+
studentLimit: number | null;
|
|
46
43
|
subdomain: string;
|
|
47
|
-
teachersCount: number;
|
|
48
44
|
disableSaveButton: boolean;
|
|
49
45
|
drawer: null;
|
|
50
46
|
errors: Record<string, string>;
|
|
@@ -53,14 +49,12 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
53
49
|
agreedPrice: number;
|
|
54
50
|
billingDate: null;
|
|
55
51
|
billingInterval: string;
|
|
56
|
-
classesCount: number;
|
|
57
|
-
coursesCount: number;
|
|
58
52
|
description: string;
|
|
59
53
|
dueDateLength: number;
|
|
60
54
|
enabled: boolean;
|
|
61
|
-
familiesCount: number;
|
|
62
55
|
id: string;
|
|
63
56
|
logo: string;
|
|
57
|
+
logoFile: File | null;
|
|
64
58
|
name: string;
|
|
65
59
|
plan: {
|
|
66
60
|
currency?: string;
|
|
@@ -71,11 +65,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
71
65
|
planId: string;
|
|
72
66
|
planStartDate: null;
|
|
73
67
|
secrets: {};
|
|
74
|
-
staffAccountsCount: number;
|
|
75
|
-
storageUsedMB: number;
|
|
76
68
|
studentsCount: number;
|
|
69
|
+
studentLimit: number | null;
|
|
77
70
|
subdomain: string;
|
|
78
|
-
teachersCount: number;
|
|
79
71
|
disableSaveButton: boolean;
|
|
80
72
|
drawer: null;
|
|
81
73
|
errors: Record<string, string>;
|
|
@@ -86,14 +78,12 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
86
78
|
agreedPrice: number;
|
|
87
79
|
billingDate: null;
|
|
88
80
|
billingInterval: string;
|
|
89
|
-
classesCount: number;
|
|
90
|
-
coursesCount: number;
|
|
91
81
|
description: string;
|
|
92
82
|
dueDateLength: number;
|
|
93
83
|
enabled: boolean;
|
|
94
|
-
familiesCount: number;
|
|
95
84
|
id: string;
|
|
96
85
|
logo: string;
|
|
86
|
+
logoFile: File | null;
|
|
97
87
|
name: string;
|
|
98
88
|
plan: {
|
|
99
89
|
currency?: string;
|
|
@@ -104,11 +94,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
104
94
|
planId: string;
|
|
105
95
|
planStartDate: null;
|
|
106
96
|
secrets: {};
|
|
107
|
-
staffAccountsCount: number;
|
|
108
|
-
storageUsedMB: number;
|
|
109
97
|
studentsCount: number;
|
|
98
|
+
studentLimit: number | null;
|
|
110
99
|
subdomain: string;
|
|
111
|
-
teachersCount: number;
|
|
112
100
|
disableSaveButton: boolean;
|
|
113
101
|
drawer: null;
|
|
114
102
|
errors: Record<string, string>;
|
|
@@ -117,14 +105,12 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
117
105
|
agreedPrice: number;
|
|
118
106
|
billingDate: null;
|
|
119
107
|
billingInterval: string;
|
|
120
|
-
classesCount: number;
|
|
121
|
-
coursesCount: number;
|
|
122
108
|
description: string;
|
|
123
109
|
dueDateLength: number;
|
|
124
110
|
enabled: boolean;
|
|
125
|
-
familiesCount: number;
|
|
126
111
|
id: string;
|
|
127
112
|
logo: string;
|
|
113
|
+
logoFile: File | null;
|
|
128
114
|
name: string;
|
|
129
115
|
plan: {
|
|
130
116
|
currency?: string;
|
|
@@ -135,11 +121,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
135
121
|
planId: string;
|
|
136
122
|
planStartDate: null;
|
|
137
123
|
secrets: {};
|
|
138
|
-
staffAccountsCount: number;
|
|
139
|
-
storageUsedMB: number;
|
|
140
124
|
studentsCount: number;
|
|
125
|
+
studentLimit: number | null;
|
|
141
126
|
subdomain: string;
|
|
142
|
-
teachersCount: number;
|
|
143
127
|
disableSaveButton: boolean;
|
|
144
128
|
drawer: null;
|
|
145
129
|
errors: Record<string, string>;
|
|
@@ -148,14 +132,12 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
148
132
|
agreedPrice: number;
|
|
149
133
|
billingDate: null;
|
|
150
134
|
billingInterval: string;
|
|
151
|
-
classesCount: number;
|
|
152
|
-
coursesCount: number;
|
|
153
135
|
description: string;
|
|
154
136
|
dueDateLength: number;
|
|
155
137
|
enabled: boolean;
|
|
156
|
-
familiesCount: number;
|
|
157
138
|
id: string;
|
|
158
139
|
logo: string;
|
|
140
|
+
logoFile: File | null;
|
|
159
141
|
name: string;
|
|
160
142
|
plan: {
|
|
161
143
|
currency?: string;
|
|
@@ -166,11 +148,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
166
148
|
planId: string;
|
|
167
149
|
planStartDate: null;
|
|
168
150
|
secrets: {};
|
|
169
|
-
staffAccountsCount: number;
|
|
170
|
-
storageUsedMB: number;
|
|
171
151
|
studentsCount: number;
|
|
152
|
+
studentLimit: number | null;
|
|
172
153
|
subdomain: string;
|
|
173
|
-
teachersCount: number;
|
|
174
154
|
disableSaveButton: boolean;
|
|
175
155
|
drawer: null;
|
|
176
156
|
errors: Record<string, string>;
|
|
@@ -185,7 +165,7 @@ export declare const WorkspaceStateContextProvider: ({ children, subdomain, }: {
|
|
|
185
165
|
subdomain?: string;
|
|
186
166
|
}) => import("react").JSX.Element;
|
|
187
167
|
export declare const useWorkspaceModule: () => {
|
|
188
|
-
handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
|
|
168
|
+
handleChange: (field: string, value: string | number | boolean | File | null | undefined | Record<string, string>) => void;
|
|
189
169
|
handleCloseDrawer: () => void;
|
|
190
170
|
handleEdit: () => void;
|
|
191
171
|
handleSubmit: () => void;
|
|
@@ -201,14 +181,12 @@ export declare const useWorkspaceModule: () => {
|
|
|
201
181
|
agreedPrice: number;
|
|
202
182
|
billingDate: null;
|
|
203
183
|
billingInterval: string;
|
|
204
|
-
classesCount: number;
|
|
205
|
-
coursesCount: number;
|
|
206
184
|
description: string;
|
|
207
185
|
dueDateLength: number;
|
|
208
186
|
enabled: boolean;
|
|
209
|
-
familiesCount: number;
|
|
210
187
|
id: string;
|
|
211
188
|
logo: string;
|
|
189
|
+
logoFile: File | null;
|
|
212
190
|
name: string;
|
|
213
191
|
plan: {
|
|
214
192
|
currency?: string;
|
|
@@ -219,11 +197,9 @@ export declare const useWorkspaceModule: () => {
|
|
|
219
197
|
planId: string;
|
|
220
198
|
planStartDate: null;
|
|
221
199
|
secrets: {};
|
|
222
|
-
staffAccountsCount: number;
|
|
223
|
-
storageUsedMB: number;
|
|
224
200
|
studentsCount: number;
|
|
201
|
+
studentLimit: number | null;
|
|
225
202
|
subdomain: string;
|
|
226
|
-
teachersCount: number;
|
|
227
203
|
disableSaveButton: boolean;
|
|
228
204
|
drawer: null;
|
|
229
205
|
errors: Record<string, 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
|
// ============================================================================
|
|
@@ -50,25 +51,21 @@ const workspaceConfig = {
|
|
|
50
51
|
agreedPrice: 0,
|
|
51
52
|
billingDate: null,
|
|
52
53
|
billingInterval: "",
|
|
53
|
-
classesCount: 0,
|
|
54
|
-
coursesCount: 0,
|
|
55
54
|
description: "",
|
|
56
55
|
dueDateLength: 0,
|
|
57
56
|
enabled: true,
|
|
58
|
-
familiesCount: 0,
|
|
59
57
|
id: "",
|
|
60
58
|
logo: "",
|
|
59
|
+
logoFile: null,
|
|
61
60
|
name: "",
|
|
62
61
|
plan: null,
|
|
63
62
|
planEndDate: null,
|
|
64
63
|
planId: "",
|
|
65
64
|
planStartDate: null,
|
|
66
65
|
secrets: {},
|
|
67
|
-
staffAccountsCount: 0,
|
|
68
|
-
storageUsedMB: 0,
|
|
69
66
|
studentsCount: 0,
|
|
67
|
+
studentLimit: null,
|
|
70
68
|
subdomain: "",
|
|
71
|
-
teachersCount: 0,
|
|
72
69
|
// UI State
|
|
73
70
|
disableSaveButton: false,
|
|
74
71
|
drawer: null,
|
|
@@ -160,12 +157,9 @@ export const useWorkspaceModule = () => {
|
|
|
160
157
|
agreedPrice: state.agreedPrice,
|
|
161
158
|
billingDate: state.billingDate,
|
|
162
159
|
billingInterval: state.billingInterval,
|
|
163
|
-
classesCount: state.classesCount,
|
|
164
|
-
coursesCount: state.coursesCount,
|
|
165
160
|
description: state.description,
|
|
166
161
|
dueDateLength: state.dueDateLength,
|
|
167
162
|
enabled: state.enabled,
|
|
168
|
-
familiesCount: state.familiesCount,
|
|
169
163
|
id: state.id,
|
|
170
164
|
logo: state.logo,
|
|
171
165
|
name: state.name,
|
|
@@ -173,22 +167,15 @@ export const useWorkspaceModule = () => {
|
|
|
173
167
|
planId: state.planId,
|
|
174
168
|
planStartDate: state.planStartDate,
|
|
175
169
|
secrets: state.secrets,
|
|
176
|
-
staffAccountsCount: state.staffAccountsCount,
|
|
177
|
-
storageUsedMB: state.storageUsedMB,
|
|
178
|
-
studentsCount: state.studentsCount,
|
|
179
170
|
subdomain: state.subdomain,
|
|
180
|
-
teachersCount: state.teachersCount,
|
|
181
171
|
}), [
|
|
182
172
|
state.agreedCurrency,
|
|
183
173
|
state.agreedPrice,
|
|
184
174
|
state.billingDate,
|
|
185
175
|
state.billingInterval,
|
|
186
|
-
state.classesCount,
|
|
187
|
-
state.coursesCount,
|
|
188
176
|
state.description,
|
|
189
177
|
state.dueDateLength,
|
|
190
178
|
state.enabled,
|
|
191
|
-
state.familiesCount,
|
|
192
179
|
state.id,
|
|
193
180
|
state.logo,
|
|
194
181
|
state.name,
|
|
@@ -196,11 +183,7 @@ export const useWorkspaceModule = () => {
|
|
|
196
183
|
state.planId,
|
|
197
184
|
state.planStartDate,
|
|
198
185
|
state.secrets,
|
|
199
|
-
state.staffAccountsCount,
|
|
200
|
-
state.storageUsedMB,
|
|
201
|
-
state.studentsCount,
|
|
202
186
|
state.subdomain,
|
|
203
|
-
state.teachersCount,
|
|
204
187
|
]);
|
|
205
188
|
// ============================================================================
|
|
206
189
|
// 1.5.3 UTILITIES
|
|
@@ -314,10 +297,41 @@ export const useWorkspaceModule = () => {
|
|
|
314
297
|
validateForm({
|
|
315
298
|
params: updateParams,
|
|
316
299
|
schema: workspaceFormValidation,
|
|
317
|
-
successCallback: () => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
300
|
+
successCallback: async () => {
|
|
301
|
+
try {
|
|
302
|
+
let logo = updateParams.logo;
|
|
303
|
+
if (state.logoFile) {
|
|
304
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
|
|
305
|
+
throw new Error("Workspace context is not available");
|
|
306
|
+
}
|
|
307
|
+
const uploaded = await uploadFile(state.logoFile, {
|
|
308
|
+
workspaceId: workspace.id,
|
|
309
|
+
formName: "workspace",
|
|
310
|
+
maxSizeBytes: 2 * 1024 * 1024,
|
|
311
|
+
});
|
|
312
|
+
logo = uploaded.url;
|
|
313
|
+
dispatch({
|
|
314
|
+
type: WORKSPACE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
315
|
+
payload: { key: "logo", value: logo },
|
|
316
|
+
});
|
|
317
|
+
dispatch({
|
|
318
|
+
type: WORKSPACE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
319
|
+
payload: { key: "logoFile", value: null },
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
updateFetchNow(undefined, {
|
|
323
|
+
body: JSON.stringify(Object.assign(Object.assign({}, updateParams), { logo })),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
dispatch({
|
|
328
|
+
type: WORKSPACE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
329
|
+
payload: { disabled: false },
|
|
330
|
+
});
|
|
331
|
+
showToast(error instanceof Error
|
|
332
|
+
? error.message
|
|
333
|
+
: t("messagesLogoUploadFailed"), TOAST_VARIANT.ERROR);
|
|
334
|
+
}
|
|
321
335
|
},
|
|
322
336
|
errorCallback: (errors) => {
|
|
323
337
|
dispatch({
|
|
@@ -331,7 +345,15 @@ export const useWorkspaceModule = () => {
|
|
|
331
345
|
showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
|
|
332
346
|
},
|
|
333
347
|
});
|
|
334
|
-
}, [
|
|
348
|
+
}, [
|
|
349
|
+
dispatch,
|
|
350
|
+
updateParams,
|
|
351
|
+
updateFetchNow,
|
|
352
|
+
showToast,
|
|
353
|
+
t,
|
|
354
|
+
state.logoFile,
|
|
355
|
+
workspace,
|
|
356
|
+
]);
|
|
335
357
|
// ============================================================================
|
|
336
358
|
// 1.5.8 EFFECTS
|
|
337
359
|
// ============================================================================
|
|
@@ -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
|
};
|