@appcorp/fusion-storybook 0.4.15 → 0.4.16

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.
@@ -32,7 +32,7 @@ export declare const useAdmissionModule: () => {
32
32
  listLoading: boolean;
33
33
  rowActions: RowAction[];
34
34
  updateLoading: boolean;
35
- uploadAdmissionDocuments: (files: File[]) => Promise<string[]>;
35
+ uploadAdmissionDocuments: (files: File[], registrationCode: string) => Promise<string[]>;
36
36
  state: {
37
37
  items: AdmissionBE[];
38
38
  count: number;
@@ -16,6 +16,8 @@ import { admissionFormValidation } from "../validate";
16
16
  import { getCachedWorkspaceSync } from "../../workspace/cache";
17
17
  import { downloadAdmissionFormPDF, } from "../../../utils/admission-pdf";
18
18
  import { fileToBase64 } from "../../../utils/file-to-base64";
19
+ import { compressPdf, DocumentTooLargeError, isPdfFile, MAX_DOCUMENT_SIZE_BYTES, } from "../../../utils/compress-pdf";
20
+ import { wakeStorageServer } from "../../../utils/wake-storage";
19
21
  import { normalizeIdNumber } from "../../../utils/id-number";
20
22
  import { toE164Phone } from "../../../utils/to-e164-phone";
21
23
  import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
@@ -293,13 +295,19 @@ export const useAdmissionModule = () => {
293
295
  (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
294
296
  }
295
297
  }, [showToast, t]);
296
- const uploadAdmissionDocuments = useCallback(async (files) => {
298
+ const uploadAdmissionDocuments = useCallback(async (files, registrationCode) => {
297
299
  var _a;
298
300
  const schoolId = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id;
299
301
  if (!schoolId) {
300
302
  throw new Error("School context is not available");
301
303
  }
302
- const payload = await Promise.all(files.map(async (file) => ({
304
+ const prepared = await Promise.all(files.map(async (file) => isPdfFile(file) ? await compressPdf(file) : file));
305
+ for (const file of prepared) {
306
+ if (file.size > MAX_DOCUMENT_SIZE_BYTES) {
307
+ throw new DocumentTooLargeError(file.name, file.size);
308
+ }
309
+ }
310
+ const payload = await Promise.all(prepared.map(async (file) => ({
303
311
  fileName: file.name,
304
312
  contentType: file.type || "application/octet-stream",
305
313
  fileBase64: await fileToBase64(file),
@@ -310,7 +318,7 @@ export const useAdmissionModule = () => {
310
318
  headers: {
311
319
  "Content-Type": "application/json",
312
320
  },
313
- body: JSON.stringify({ schoolId, files: payload }),
321
+ body: JSON.stringify({ schoolId, registrationCode, files: payload }),
314
322
  });
315
323
  if (error || !(data === null || data === void 0 ? void 0 : data.urls)) {
316
324
  throw new Error("Upload failed");
@@ -355,11 +363,12 @@ export const useAdmissionModule = () => {
355
363
  resetFormAndCloseDrawer();
356
364
  }, [resetFormAndCloseDrawer]);
357
365
  const handleCreate = useCallback(() => {
366
+ wakeStorageServer();
358
367
  dispatch({
359
368
  type: ADMISSION_ACTION_TYPES.SET_DRAWER,
360
369
  payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
361
370
  });
362
- }, [dispatch]);
371
+ }, [dispatch, wakeStorageServer]);
363
372
  const handleView = useCallback((row) => {
364
373
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
365
374
  dispatch({
@@ -368,12 +377,13 @@ export const useAdmissionModule = () => {
368
377
  });
369
378
  }, [dispatch, byIdFetchNow]);
370
379
  const handleEdit = useCallback((row) => {
380
+ wakeStorageServer();
371
381
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
372
382
  dispatch({
373
383
  type: ADMISSION_ACTION_TYPES.SET_DRAWER,
374
384
  payload: { drawer: ADMISSION_DRAWER.FORM_DRAWER },
375
385
  });
376
- }, [dispatch, byIdFetchNow]);
386
+ }, [dispatch, byIdFetchNow, wakeStorageServer]);
377
387
  const handleDelete = useCallback((row) => {
378
388
  if (!confirm(t("messagesDeleteConfirmation")))
379
389
  return;
@@ -638,7 +648,7 @@ export const useAdmissionModule = () => {
638
648
  const merged = state.documentsFiles.length
639
649
  ? [
640
650
  ...(state.documents || []),
641
- ...(await uploadAdmissionDocuments(state.documentsFiles)),
651
+ ...(await uploadAdmissionDocuments(state.documentsFiles, updateParams.registrationCode)),
642
652
  ]
643
653
  : state.documents || [];
644
654
  dispatch({
@@ -699,12 +709,14 @@ export const useAdmissionModule = () => {
699
709
  }),
700
710
  });
701
711
  }
702
- catch (_b) {
712
+ catch (error) {
703
713
  dispatch({
704
714
  type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
705
715
  payload: { disabled: false },
706
716
  });
707
- showToast(t("messagesDocumentsUploadFailed"), TOAST_VARIANT.ERROR);
717
+ showToast(t(error instanceof DocumentTooLargeError
718
+ ? "messagesDocumentTooLarge"
719
+ : "messagesDocumentsUploadFailed"), TOAST_VARIANT.ERROR);
708
720
  }
709
721
  },
710
722
  errorCallback: (errors) => {
package/constants.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare const ADMISSION_API_ROUTES: {
21
21
  export declare const DOCUMENT_UPLOAD_API_ROUTES: {
22
22
  readonly UNIT: "/api/v1/document-upload";
23
23
  };
24
+ export declare const STORAGE_WAKE_URL = "https://storage.edupilotpro.com/";
24
25
  export declare const CAMPUS_API_ROUTES: Record<string, string>;
25
26
  export declare const CLASS_API_ROUTES: {
26
27
  readonly UNIT: "/api/v1/class";
package/constants.js CHANGED
@@ -24,6 +24,7 @@ export const ADMISSION_API_ROUTES = {
24
24
  export const DOCUMENT_UPLOAD_API_ROUTES = {
25
25
  UNIT: "/api/v1/document-upload",
26
26
  };
27
+ export const STORAGE_WAKE_URL = "https://storage.edupilotpro.com/";
27
28
  export const CAMPUS_API_ROUTES = {
28
29
  UNIT: "/api/v1/campus",
29
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.4.15",
3
+ "version": "0.4.16",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",
@@ -42,6 +42,7 @@
42
42
  "@commitlint/cli": "^20.5.0",
43
43
  "@commitlint/config-conventional": "^20.5.0",
44
44
  "@playwright/test": "^1.59.1",
45
+ "@quicktoolsone/pdf-compress": "^2.0.0",
45
46
  "@radix-ui/react-avatar": "^1",
46
47
  "@radix-ui/react-checkbox": "^1",
47
48
  "@radix-ui/react-dialog": "^1",
@@ -106,6 +107,7 @@
106
107
  "ts-jest": "^29.4.9",
107
108
  "tw-animate-css": "^1.4.0",
108
109
  "typescript": "^5",
110
+ "undici": "^8.10.0",
109
111
  "uuid": "^13.0.0",
110
112
  "vaul": "^1.1.2",
111
113
  "vite": "^8.0.5",