From 20669e090e86bcc828ec28f794636842257cc8aa Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 30 Jun 2025 22:37:24 +0200 Subject: [PATCH] Use FileBlob and FileData everywhere --- src/common/Api/LeCoffreApi/sdk/FileService.ts | 5 +++-- src/front/Api/Entities/index.ts | 2 ++ .../ClientDashboard/DepositDocumentComponent/index.tsx | 5 +++-- .../Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx | 5 +++-- .../ClientView/DocumentTables/FilePreviewModal/index.tsx | 6 +++++- .../Components/Layouts/Folder/ViewDocuments/index.tsx | 7 +++++-- 6 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/front/Api/Entities/index.ts diff --git a/src/common/Api/LeCoffreApi/sdk/FileService.ts b/src/common/Api/LeCoffreApi/sdk/FileService.ts index 9b639cf9..b6dff078 100644 --- a/src/common/Api/LeCoffreApi/sdk/FileService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FileService.ts @@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid'; import MessageBus from 'src/sdk/MessageBus'; import User from 'src/sdk/User'; +import { FileData } from '../../../../front/Api/Entities/types'; export default class FileService { @@ -9,7 +10,7 @@ export default class FileService { private constructor() { } - public static createFile(fileData: any, validatorId: string): Promise { + public static createFile(fileData: FileData, validatorId: string): Promise { const ownerId = User.getInstance().getPairingId()!; const processData: any = { @@ -81,7 +82,7 @@ export default class FileService { return this.messageBus.getFileByUid(uid); } - public static updateFile(process: any, newData: any): Promise { + public static updateFile(process: any, newData: Partial & { isDeleted?: string }): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...newData }, [], null).then((processUpdated: any) => { const newStateId: string = processUpdated.diffs[0]?.state_id; diff --git a/src/front/Api/Entities/index.ts b/src/front/Api/Entities/index.ts new file mode 100644 index 00000000..e322dc9c --- /dev/null +++ b/src/front/Api/Entities/index.ts @@ -0,0 +1,2 @@ +export * from './types'; +export * from './rule'; \ No newline at end of file diff --git a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx index aa0f9063..3f476e10 100644 --- a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx @@ -9,6 +9,7 @@ import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import { FileBlob, FileData } from "@Front/Api/Entities/types"; type IProps = { document: any; @@ -39,12 +40,12 @@ export default function DepositDocumentComponent(props: IProps) { const arrayBuffer = event.target.result as ArrayBuffer; const uint8Array = new Uint8Array(arrayBuffer); - const fileBlob: any = { + const fileBlob: FileBlob = { type: file.type, data: uint8Array }; - const fileData: any = { + const fileData: FileData = { file_blob: fileBlob, file_name: file.name }; diff --git a/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx b/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx index 843ded9f..c2015d7b 100644 --- a/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx @@ -7,6 +7,7 @@ import { DocumentNotary } from "le-coffre-resources/dist/Notary"; import Image from "next/image"; import { NextRouter, useRouter } from "next/router"; import React from "react"; +import { FileBlob } from "@Front/Api/Entities/types"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; @@ -25,7 +26,7 @@ type IState = { isValidateModalVisible: boolean; refuseText: string; selectedFileIndex: number; - selectedFile: any; + selectedFile: { uid: string; file_name: string; file_blob: FileBlob } | null; documentNotary: DocumentNotary | null; fileBlob: Blob | null; isLoading: boolean; @@ -132,7 +133,7 @@ class ViewDocumentsNotaryClass extends BasePage { { documentNotary, selectedFileIndex: 0, - selectedFile: documentNotary.files![0]!, + selectedFile: documentNotary.files![0] as any, isLoading: false, }, () => { diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/FilePreviewModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/FilePreviewModal/index.tsx index 65da2374..8a07fe46 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/FilePreviewModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/FilePreviewModal/index.tsx @@ -1,8 +1,12 @@ import Modal from "@Front/Components/DesignSystem/Modal"; import React from "react"; +import { FileBlob } from "@Front/Api/Entities/types"; type IProps = { - file: any; + file: { + uid: string; + file_blob: FileBlob; + }; url: string; isOpen: boolean; onClose?: () => void; diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index 59ad2998..401b13d3 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -19,6 +19,7 @@ import MessageBox from "@Front/Components/Elements/MessageBox"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import { FileBlob } from "@Front/Api/Entities/types"; type IProps = {}; type IPropsClass = { @@ -32,7 +33,7 @@ type IState = { isValidateModalVisible: boolean; refuseText: string; selectedFileIndex: number; - selectedFile: any; // File | null; TODO: review + selectedFile: { uid: string; file_name: string; file_blob: FileBlob } | null; validatedPercentage: number; document: Document | null; fileBlob: Blob | null; @@ -237,6 +238,8 @@ class ViewDocumentsClass extends BasePage { private async getFilePreview(): Promise { try { + if (!this.state.selectedFile) return; + const fileBlob: Blob = new Blob([this.state.selectedFile.file_blob.data], { type: this.state.selectedFile.file_blob.type }); this.setState({ fileBlob, @@ -247,7 +250,7 @@ class ViewDocumentsClass extends BasePage { } private downloadFile() { - if (!this.state.fileBlob) return; + if (!this.state.fileBlob || !this.state.selectedFile) return; const url = URL.createObjectURL(this.state.fileBlob); const a = document.createElement('a');