@appcorp/fusion-storybook 0.2.9 → 0.2.11
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.
|
@@ -43,6 +43,7 @@ export async function convertToWebPFormat(file) {
|
|
|
43
43
|
return webpBlob;
|
|
44
44
|
}
|
|
45
45
|
catch (error) {
|
|
46
|
+
console.log("webp conversion error", error);
|
|
46
47
|
const errorMessage = error instanceof Error
|
|
47
48
|
? error.message
|
|
48
49
|
: "Unknown error during WebP conversion";
|
|
@@ -79,10 +80,13 @@ export async function processAvatarFile(file) {
|
|
|
79
80
|
}
|
|
80
81
|
// Convert to WebP
|
|
81
82
|
const conversionResult = await convertToWebPFormat(file);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
console.log("type" in conversionResult
|
|
84
|
+
? `type: ${conversionResult.type}`
|
|
85
|
+
: "no type field in result");
|
|
86
|
+
// if ("type" in conversionResult) {
|
|
87
|
+
// // It's an error
|
|
88
|
+
// return conversionResult as AvatarUploadError;
|
|
89
|
+
// }
|
|
86
90
|
// Convert blob to base64
|
|
87
91
|
try {
|
|
88
92
|
const fileBase64 = await blobToBase64(conversionResult);
|
|
@@ -27,13 +27,12 @@ import { createGenericModule } from "@react-pakistan/util-functions/factory/gene
|
|
|
27
27
|
import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
28
28
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
29
29
|
import { GENDER } from "../../type";
|
|
30
|
-
import { formatNumber } from "@react-pakistan/util-functions/general/format-number";
|
|
31
|
-
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
32
30
|
import { TEACHER_API_ROUTES, pageLimit } from "./constants";
|
|
33
31
|
import { teacherFormValidation } from "./validate";
|
|
34
32
|
import { getCachedTeachers, invalidateTeachersCache } from "./cache";
|
|
35
33
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
36
34
|
import { processAvatarFile } from "./avatar-upload";
|
|
35
|
+
import { v4 as uuidv4 } from "uuid";
|
|
37
36
|
// ============================================================================
|
|
38
37
|
// 1.1 DRAWER TYPES
|
|
39
38
|
// ============================================================================
|
|
@@ -127,7 +126,7 @@ export const useTeacherModule = () => {
|
|
|
127
126
|
city: state.city,
|
|
128
127
|
country: state.country,
|
|
129
128
|
dateOfBirth: state.dateOfBirth,
|
|
130
|
-
emergencyPhone:
|
|
129
|
+
emergencyPhone: state.emergencyPhone,
|
|
131
130
|
enabled: state.enabled,
|
|
132
131
|
experience: state.experience,
|
|
133
132
|
firstName: state.firstName,
|
|
@@ -135,7 +134,7 @@ export const useTeacherModule = () => {
|
|
|
135
134
|
id: state.id,
|
|
136
135
|
joiningDate: state.joiningDate,
|
|
137
136
|
lastName: state.lastName,
|
|
138
|
-
phone:
|
|
137
|
+
phone: state.phone,
|
|
139
138
|
postalCode: state.postalCode,
|
|
140
139
|
qualification: state.qualification,
|
|
141
140
|
schoolId,
|
|
@@ -216,9 +215,7 @@ export const useTeacherModule = () => {
|
|
|
216
215
|
dispatch({
|
|
217
216
|
type: TEACHER_ACTION_TYPES.SET_FORM_DATA,
|
|
218
217
|
payload: {
|
|
219
|
-
form: Object.assign(Object.assign({}, teacher), { phone:
|
|
220
|
-
formatPhoneDisplay(teacher.emergencyPhone)) ||
|
|
221
|
-
"", filterEnabled: undefined }),
|
|
218
|
+
form: Object.assign(Object.assign({}, teacher), { phone: teacher.phone || "", emergencyPhone: teacher.emergencyPhone || "", filterEnabled: undefined }),
|
|
222
219
|
},
|
|
223
220
|
});
|
|
224
221
|
}
|
|
@@ -359,30 +356,29 @@ export const useTeacherModule = () => {
|
|
|
359
356
|
const handleAvatarUpload = useCallback(async (file) => {
|
|
360
357
|
try {
|
|
361
358
|
// Set uploading state
|
|
362
|
-
dispatch({
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
});
|
|
359
|
+
// dispatch({
|
|
360
|
+
// type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
361
|
+
// payload: { key: "avatarUploading", value: true },
|
|
362
|
+
// });
|
|
366
363
|
// Process avatar file (validate, convert to WebP)
|
|
367
364
|
const result = await processAvatarFile(file);
|
|
368
365
|
if ("type" in result) {
|
|
369
366
|
// Error result
|
|
370
367
|
const error = result;
|
|
371
368
|
showToast(error.message, TOAST_VARIANT.ERROR);
|
|
372
|
-
dispatch({
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
});
|
|
369
|
+
// dispatch({
|
|
370
|
+
// type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
371
|
+
// payload: { key: "avatarUploading", value: false },
|
|
372
|
+
// });
|
|
376
373
|
return;
|
|
377
374
|
}
|
|
378
|
-
|
|
379
|
-
const teacherId = state.id;
|
|
375
|
+
const teacherId = uuidv4();
|
|
380
376
|
if (!teacherId) {
|
|
381
377
|
showToast("Please save the teacher record first before uploading an avatar", TOAST_VARIANT.ERROR);
|
|
382
|
-
dispatch({
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
});
|
|
378
|
+
// dispatch({
|
|
379
|
+
// type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
380
|
+
// payload: { key: "avatarUploading", value: false },
|
|
381
|
+
// });
|
|
386
382
|
return;
|
|
387
383
|
}
|
|
388
384
|
// Upload to S3 via teacher-avatar endpoint
|
|
@@ -396,16 +392,17 @@ export const useTeacherModule = () => {
|
|
|
396
392
|
teacherId,
|
|
397
393
|
fileBase64: result.fileBase64,
|
|
398
394
|
contentType: result.contentType,
|
|
395
|
+
workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id,
|
|
399
396
|
}),
|
|
400
397
|
});
|
|
401
398
|
if (!response.ok) {
|
|
402
399
|
const errorData = await response.json().catch(() => ({}));
|
|
403
400
|
const errorMessage = errorData.error || `Upload failed with status ${response.status}`;
|
|
404
401
|
showToast(errorMessage, TOAST_VARIANT.ERROR);
|
|
405
|
-
dispatch({
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
});
|
|
402
|
+
// dispatch({
|
|
403
|
+
// type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
404
|
+
// payload: { key: "avatarUploading", value: false },
|
|
405
|
+
// });
|
|
409
406
|
return;
|
|
410
407
|
}
|
|
411
408
|
const data = await response.json();
|
|
@@ -424,12 +421,12 @@ export const useTeacherModule = () => {
|
|
|
424
421
|
showToast(errorMessage, TOAST_VARIANT.ERROR);
|
|
425
422
|
}
|
|
426
423
|
finally {
|
|
427
|
-
dispatch({
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
});
|
|
424
|
+
// dispatch({
|
|
425
|
+
// type: TEACHER_ACTION_TYPES.SET_INPUT_FIELD,
|
|
426
|
+
// payload: { key: "avatarUploading", value: false },
|
|
427
|
+
// });
|
|
431
428
|
}
|
|
432
|
-
}, [
|
|
429
|
+
}, [dispatch, showToast, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
433
430
|
const applyFilters = useCallback(() => {
|
|
434
431
|
dispatch({
|
|
435
432
|
type: TEACHER_ACTION_TYPES.SET_CURRENT_PAGE,
|