@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.
@@ -37,7 +37,7 @@ export declare const useAdmissionModule: () => {
37
37
  listLoading: boolean;
38
38
  rowActions: RowAction[];
39
39
  updateLoading: boolean;
40
- uploadAdmissionDocuments: (files: File[], registrationCode: string, prefix?: string) => Promise<string[]>;
40
+ uploadAdmissionDocuments: (files: File[]) => Promise<string[]>;
41
41
  state: {
42
42
  items: AdmissionBE[];
43
43
  count: number;
@@ -11,12 +11,12 @@ import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
11
11
  import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
12
12
  import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
13
13
  import { ADMISSION_STATUS, GENDER, } from "../../../type";
14
- import { ADMISSION_API_ROUTES, DISCOUNT_CODE_API_ROUTES, DOCUMENT_UPLOAD_API_ROUTES, } from "../../../constants";
14
+ import { ADMISSION_API_ROUTES, DISCOUNT_CODE_API_ROUTES, } from "../../../constants";
15
15
  import { admissionFormValidation } from "../validate";
16
16
  import { getCachedWorkspaceSync } from "../../workspace/cache";
17
17
  import { downloadAdmissionFormPDF, } from "../../../utils/admission-pdf";
18
- import { fileToBase64 } from "../../../utils/file-to-base64";
19
18
  import { compressPdf, DocumentTooLargeError, isPdfFile, MAX_DOCUMENT_SIZE_BYTES, } from "../../../utils/compress-pdf";
19
+ import { uploadFiles } from "../../../utils/upload-file";
20
20
  import { wakeStorageServer } from "../../../utils/wake-storage";
21
21
  import { normalizeIdNumber } from "../../../utils/id-number";
22
22
  import { isGovernmentIdType, } from "../../../utils/government-id";
@@ -24,7 +24,7 @@ import { toE164Phone } from "../../../utils/to-e164-phone";
24
24
  import { Filter, Plus } from "lucide-react";
25
25
  import { ADMISSION_DRAWER, ADMISSION_ACTION_TYPES, useAdmissionContext, } from "../context";
26
26
  export const useAdmissionModule = () => {
27
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
28
28
  // ============================================================================
29
29
  // 1.4.1 STATE & CORE HOOKS
30
30
  // ============================================================================
@@ -330,11 +330,9 @@ export const useAdmissionModule = () => {
330
330
  (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
331
331
  }
332
332
  }, [showToast, t]);
333
- const uploadAdmissionDocuments = useCallback(async (files, registrationCode, prefix) => {
334
- var _a;
335
- const schoolId = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id;
336
- if (!schoolId) {
337
- throw new Error("School context is not available");
333
+ const uploadAdmissionDocuments = useCallback(async (files) => {
334
+ if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
335
+ throw new Error("Workspace context is not available");
338
336
  }
339
337
  const prepared = await Promise.all(files.map(async (file) => isPdfFile(file) ? await compressPdf(file) : file));
340
338
  for (const file of prepared) {
@@ -342,24 +340,13 @@ export const useAdmissionModule = () => {
342
340
  throw new DocumentTooLargeError(file.name, file.size);
343
341
  }
344
342
  }
345
- const payload = await Promise.all(prepared.map(async (file) => ({
346
- fileName: prefix ? `${prefix}-${file.name}` : file.name,
347
- contentType: file.type || "application/octet-stream",
348
- fileBase64: await fileToBase64(file),
349
- })));
350
- const { data, error } = await fetchData({
351
- url: DOCUMENT_UPLOAD_API_ROUTES.UNIT,
352
- method: API_METHODS.POST,
353
- headers: {
354
- "Content-Type": "application/json",
355
- },
356
- body: JSON.stringify({ schoolId, registrationCode, files: payload }),
343
+ const uploaded = await uploadFiles(prepared, {
344
+ workspaceId: workspace.id,
345
+ formName: "admission",
346
+ maxSizeBytes: MAX_DOCUMENT_SIZE_BYTES,
357
347
  });
358
- if (error || !(data === null || data === void 0 ? void 0 : data.urls)) {
359
- throw new Error("Upload failed");
360
- }
361
- return data.urls;
362
- }, [(_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id]);
348
+ return uploaded.map((file) => file.url);
349
+ }, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
363
350
  // ============================================================================
364
351
  // 1.4.5 API HOOKS
365
352
  // ============================================================================
@@ -431,7 +418,7 @@ export const useAdmissionModule = () => {
431
418
  schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
432
419
  }),
433
420
  });
434
- }, [t, deleteFetchNow, (_h = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _h === void 0 ? void 0 : _h.id]);
421
+ }, [t, deleteFetchNow, (_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id]);
435
422
  const handleRemoveDocument = useCallback(async (url) => {
436
423
  var _a;
437
424
  const next = (state.documents || []).filter((d) => d !== url);
@@ -461,7 +448,7 @@ export const useAdmissionModule = () => {
461
448
  }
462
449
  }, [
463
450
  dispatch,
464
- (_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id,
451
+ (_h = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _h === void 0 ? void 0 : _h.id,
465
452
  state.documents,
466
453
  state.id,
467
454
  state.classForAdmission,
@@ -619,7 +606,7 @@ export const useAdmissionModule = () => {
619
606
  status,
620
607
  }),
621
608
  });
622
- }, [updateFetchNow, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id]);
609
+ }, [updateFetchNow, (_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id]);
623
610
  const handleApprove = useCallback((row) => {
624
611
  handleUpdateStatus(row, ADMISSION_STATUS.APPROVED, t("messagesApproveConfirmation"));
625
612
  }, [handleUpdateStatus, t]);
@@ -657,7 +644,7 @@ export const useAdmissionModule = () => {
657
644
  if (data) {
658
645
  showToast(t("messagesAdmitSuccess"), TOAST_VARIANT.SUCCESS);
659
646
  }
660
- }, [t, showToast, (_l = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _l === void 0 ? void 0 : _l.id]);
647
+ }, [t, showToast, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id]);
661
648
  // ============================================================================
662
649
  // 1.4.7 NETWORK ACTIONS
663
650
  // ============================================================================
@@ -754,7 +741,7 @@ export const useAdmissionModule = () => {
754
741
  return;
755
742
  }
756
743
  showToast(t("messagesAnalyzeSuccess"), TOAST_VARIANT.SUCCESS);
757
- }, [(_m = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _m === void 0 ? void 0 : _m.id, t, showToast, byIdFetchNow, dispatch]);
744
+ }, [(_l = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _l === void 0 ? void 0 : _l.id, t, showToast, byIdFetchNow, dispatch]);
758
745
  const handleSubmit = useCallback(() => {
759
746
  dispatch({
760
747
  type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
@@ -769,25 +756,25 @@ export const useAdmissionModule = () => {
769
756
  const merged = state.documentsFiles.length
770
757
  ? [
771
758
  ...(state.documents || []),
772
- ...(await uploadAdmissionDocuments(state.documentsFiles, updateParams.registrationCode)),
759
+ ...(await uploadAdmissionDocuments(state.documentsFiles)),
773
760
  ]
774
761
  : state.documents || [];
775
762
  const studentIdImages = state.studentIdImagesFiles.length
776
763
  ? [
777
764
  ...(state.studentIdImages || []),
778
- ...(await uploadAdmissionDocuments(state.studentIdImagesFiles, updateParams.registrationCode, "student-id")),
765
+ ...(await uploadAdmissionDocuments(state.studentIdImagesFiles)),
779
766
  ]
780
767
  : state.studentIdImages || [];
781
768
  const fatherIdImages = state.fatherIdImagesFiles.length
782
769
  ? [
783
770
  ...(state.fatherIdImages || []),
784
- ...(await uploadAdmissionDocuments(state.fatherIdImagesFiles, updateParams.registrationCode, "father-id")),
771
+ ...(await uploadAdmissionDocuments(state.fatherIdImagesFiles)),
785
772
  ]
786
773
  : state.fatherIdImages || [];
787
774
  const motherIdImages = state.motherIdImagesFiles.length
788
775
  ? [
789
776
  ...(state.motherIdImages || []),
790
- ...(await uploadAdmissionDocuments(state.motherIdImagesFiles, updateParams.registrationCode, "mother-id")),
777
+ ...(await uploadAdmissionDocuments(state.motherIdImagesFiles)),
791
778
  ]
792
779
  : state.motherIdImages || [];
793
780
  const studentIdType = isGovernmentIdType(updateParams.studentIdType)
@@ -926,12 +913,12 @@ export const useAdmissionModule = () => {
926
913
  state.motherIdImages,
927
914
  state.motherIdImagesFiles,
928
915
  uploadAdmissionDocuments,
929
- (_o = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _o === void 0 ? void 0 : _o.id,
916
+ (_m = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _m === void 0 ? void 0 : _m.id,
930
917
  ]);
931
918
  // ============================================================================
932
919
  // 1.4.8 HEADER & ROW ACTIONS
933
920
  // ============================================================================
934
- const hasGeminiSecrets = Boolean(((_p = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _p === void 0 ? void 0 : _p.GEMINI_API_KEY) && ((_q = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _q === void 0 ? void 0 : _q.GEMINI_MODEL));
921
+ const hasGeminiSecrets = Boolean(((_o = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _o === void 0 ? void 0 : _o.GEMINI_API_KEY) && ((_p = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _p === void 0 ? void 0 : _p.GEMINI_MODEL));
935
922
  const headerActions = useMemo(() => [
936
923
  {
937
924
  enabled: true,
@@ -35,6 +35,7 @@ export declare const EXPENSE_ACTION_TYPES: {
35
35
  amount: number;
36
36
  approvedBy: string;
37
37
  attachments: string[];
38
+ attachmentsFiles: File[];
38
39
  category: EXPENSE_CATEGORY | "";
39
40
  description: string;
40
41
  enabled: boolean;
@@ -75,6 +76,7 @@ export declare const EXPENSE_ACTION_TYPES: {
75
76
  amount: number;
76
77
  approvedBy: string;
77
78
  attachments: string[];
79
+ attachmentsFiles: File[];
78
80
  category: EXPENSE_CATEGORY | "";
79
81
  description: string;
80
82
  enabled: boolean;
@@ -117,6 +119,7 @@ export declare const EXPENSE_ACTION_TYPES: {
117
119
  amount: number;
118
120
  approvedBy: string;
119
121
  attachments: string[];
122
+ attachmentsFiles: File[];
120
123
  category: EXPENSE_CATEGORY | "";
121
124
  description: string;
122
125
  enabled: boolean;
@@ -157,6 +160,7 @@ export declare const EXPENSE_ACTION_TYPES: {
157
160
  amount: number;
158
161
  approvedBy: string;
159
162
  attachments: string[];
163
+ attachmentsFiles: File[];
160
164
  category: EXPENSE_CATEGORY | "";
161
165
  description: string;
162
166
  enabled: boolean;
@@ -197,6 +201,7 @@ export declare const EXPENSE_ACTION_TYPES: {
197
201
  amount: number;
198
202
  approvedBy: string;
199
203
  attachments: string[];
204
+ attachmentsFiles: File[];
200
205
  category: EXPENSE_CATEGORY | "";
201
206
  description: string;
202
207
  enabled: boolean;
@@ -32,6 +32,7 @@ const expenseConfig = {
32
32
  amount: 0,
33
33
  approvedBy: "",
34
34
  attachments: [],
35
+ attachmentsFiles: [],
35
36
  category: "",
36
37
  description: "",
37
38
  enabled: true,
@@ -6,7 +6,7 @@ export declare const useExpenseModule: () => {
6
6
  clearSearch: () => void;
7
7
  closeDrawer: () => void;
8
8
  deleteLoading: boolean;
9
- handleChange: (field: string, value: string | number | boolean | string[] | undefined) => void;
9
+ handleChange: (field: string, value: string | number | boolean | string[] | File[] | undefined) => void;
10
10
  handleCreate: () => void;
11
11
  handleDelete: (row?: TableRow) => void;
12
12
  handleEdit: (row?: TableRow) => void;
@@ -39,6 +39,7 @@ export declare const useExpenseModule: () => {
39
39
  amount: number;
40
40
  approvedBy: string;
41
41
  attachments: string[];
42
+ attachmentsFiles: File[];
42
43
  category: import("../../../types").EXPENSE_CATEGORY | "";
43
44
  description: string;
44
45
  enabled: boolean;
@@ -5,6 +5,7 @@ import { useTranslations } from "next-intl";
5
5
  import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
6
6
  import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
7
7
  import { getCachedWorkspaceSync } from "../../workspace/cache";
8
+ import { uploadFiles } from "../../../utils/upload-file";
8
9
  import { expenseFormValidation } from "../validate";
9
10
  import { EXPENSE_ACTION_TYPES, EXPENSE_DRAWER, useExpenseContext, } from "./shared";
10
11
  import { useExpenseApiContext } from "./expense-api-provider";
@@ -87,6 +88,7 @@ export const useExpenseModule = () => {
87
88
  amount: 0,
88
89
  approvedBy: "",
89
90
  attachments: [],
91
+ attachmentsFiles: [],
90
92
  category: "",
91
93
  description: "",
92
94
  enabled: true,
@@ -224,10 +226,43 @@ export const useExpenseModule = () => {
224
226
  validateForm({
225
227
  params: updateParams,
226
228
  schema: expenseFormValidation,
227
- successCallback: () => {
228
- updateFetchNow(undefined, {
229
- body: JSON.stringify(updateParams),
230
- });
229
+ successCallback: async () => {
230
+ try {
231
+ let attachments = state.attachments || [];
232
+ if (state.attachmentsFiles.length > 0) {
233
+ if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
234
+ throw new Error("Workspace context is not available");
235
+ }
236
+ const uploaded = await uploadFiles(state.attachmentsFiles, {
237
+ workspaceId: workspace.id,
238
+ formName: "expense",
239
+ });
240
+ attachments = [
241
+ ...attachments.filter((url) => !url.startsWith("blob:")),
242
+ ...uploaded.map((file) => file.url),
243
+ ];
244
+ dispatch({
245
+ type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
246
+ payload: { key: "attachments", value: attachments },
247
+ });
248
+ dispatch({
249
+ type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
250
+ payload: { key: "attachmentsFiles", value: [] },
251
+ });
252
+ }
253
+ updateFetchNow(undefined, {
254
+ body: JSON.stringify(Object.assign(Object.assign({}, updateParams), { attachments })),
255
+ });
256
+ }
257
+ catch (error) {
258
+ dispatch({
259
+ type: EXPENSE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
260
+ payload: { disabled: false },
261
+ });
262
+ showToast(error instanceof Error
263
+ ? error.message
264
+ : t("messagesAttachmentsUploadFailed"), TOAST_VARIANT.ERROR);
265
+ }
231
266
  },
232
267
  errorCallback: (errors) => {
233
268
  dispatch({
@@ -241,7 +276,16 @@ export const useExpenseModule = () => {
241
276
  showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
242
277
  },
243
278
  });
244
- }, [dispatch, updateParams, updateFetchNow, t, showToast]);
279
+ }, [
280
+ dispatch,
281
+ updateParams,
282
+ updateFetchNow,
283
+ t,
284
+ showToast,
285
+ state.attachments,
286
+ state.attachmentsFiles,
287
+ workspace === null || workspace === void 0 ? void 0 : workspace.id,
288
+ ]);
245
289
  // ============================================================================
246
290
  // 1.4.6 HEADER & ROW ACTIONS
247
291
  // ============================================================================
@@ -66,8 +66,10 @@ export const ExpenseForm = () => {
66
66
  value: opt.value,
67
67
  label: paymentMethodLabelMap[opt.value] || opt.label,
68
68
  })), placeholder: t("formPaymentMethodPlaceholder"), searchPlaceholder: t("formPaymentMethodPlaceholder"), value: paymentMethod || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "paymentDate", t }), id: "paymentDate", info: t("formPaymentDateInfo"), label: t("formPaymentDateLabel"), onChange: (e) => handleChange("paymentDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: paymentDate || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "receiptNumber", t }), id: "receiptNumber", info: t("formReceiptNumberInfo"), label: t("formReceiptNumberLabel"), maxLength: 100, onChange: (e) => handleChange("receiptNumber", e.target.value), placeholder: t("formReceiptNumberPlaceholder"), type: "text", value: receiptNumber || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "transactionId", t }), id: "transactionId", info: t("formTransactionIdInfo"), label: t("formTransactionIdLabel"), maxLength: 100, onChange: (e) => handleChange("transactionId", e.target.value), placeholder: t("formTransactionIdPlaceholder"), type: "text", value: transactionId || "" })] })) : null, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", label: t("formRemarksLabel"), maxLength: 1000, onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 3, value: remarks || "" }), _jsx(EnhancedDropzone, { accept: ["image/*", "application/pdf"], error: getTranslatedError({ errors, key: "attachments", t }), id: "attachments", info: t("formAttachmentsInfo"), label: t("formAttachmentsLabel"), maxFiles: 10, onChange: (files) => {
69
- const urls = files.map((f) => URL.createObjectURL(f));
70
- handleChange("attachments", urls);
69
+ const remoteUrls = (attachments || []).filter((url) => !url.startsWith("blob:"));
70
+ const previewUrls = files.map((file) => URL.createObjectURL(file));
71
+ handleChange("attachments", [...remoteUrls, ...previewUrls]);
72
+ handleChange("attachmentsFiles", files);
71
73
  }, onRemoveRemote: (url) => {
72
74
  const newList = (attachments || []).filter((a) => a !== url);
73
75
  handleChange("attachments", newList);
@@ -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
- updateFetchNow(undefined, {
298
- body: JSON.stringify(updateParams),
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
- }, [dispatch, showToast, t, updateFetchNow, updateParams]);
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(EnhancedInput, { id: "logo", label: t("formLogoLabel"), value: logo || "", onChange: (e) => handleChange("logo", e.target.value), error: getTranslatedError({ errors, key: "logo", t }), placeholder: t("formLogoPlaceholder"), type: "url" }), _jsx(EnhancedCheckbox, { id: "enabled", label: t("formEnabledLabel"), checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
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 { processAvatarFile } from "./avatar-upload";
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
- // Process avatar file (validate, convert to WebP)
424
- const result = await processAvatarFile(file);
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 teacherId = state.id;
432
- if (!teacherId) {
433
- showToast(t("messagesAvatarSaveRequired"), TOAST_VARIANT.ERROR);
434
- uploadInProgressRef.current = false;
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: avatarUrl },
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, state.id, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
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,
@@ -45,6 +45,7 @@ export declare const useUserModule: () => {
45
45
  email: string;
46
46
  phone: string;
47
47
  avatar: string;
48
+ avatarFile: File | null;
48
49
  password: string;
49
50
  enabled: boolean;
50
51
  userRole: USER_ROLE | null;