From f9abdd31cda1da8ac863993581a38ad1c61b16ba Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Thu, 26 Jun 2025 16:18:00 +0200 Subject: [PATCH] Fix some bugs - continue --- .../DepositDocumentComponent/index.tsx | 14 +++- .../Layouts/ClientDashboard/index.tsx | 13 ++-- .../Layouts/Folder/ViewDocuments/index.tsx | 71 ++++++++++++++++--- src/sdk/MessageBus.ts | 22 ++++-- 4 files changed, 98 insertions(+), 22 deletions(-) diff --git a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx index 2a71600c..e33f08fb 100644 --- a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx @@ -5,10 +5,12 @@ import { useCallback, useMemo, useState } from "react"; import classes from "./classes.module.scss"; import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; 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"; type IProps = { document: Document; @@ -59,15 +61,21 @@ export default function DepositDocumentComponent(props: IProps) { const fileData = { document: { - uid: document.uid + uid: document.uid! }, - file: fileBlob, + fileBlob: fileBlob, file_name: file.name, mimetype: file.type } const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; - FileService.createFile(fileData, validatorId).then(() => resolve()); + FileService.createFile(fileData, validatorId).then(() => { + DocumentService.getDocumentByUid(document.uid!).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentStatus.DEPOSITED }).then(() => resolve()); + } + }); + }); } }; reader.readAsArrayBuffer(file); diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index bdadb662..9c8e1554 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -42,7 +42,6 @@ export default function ClientDashboard(props: IProps) { const [customer, setCustomer] = useState(null); const [folder, setFolder] = useState(null); - const [file, setFile] = useState(null); const [documentsNotary, setDocumentsNotary] = useState([]); const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); @@ -96,11 +95,8 @@ export default function ClientDashboard(props: IProps) { setCustomer(customer); setFolder(folder); - setFile(file); - if (!file) { - setIsAuthModalOpen(true); - } + setIsAuthModalOpen(true); return { folder, customer }; @@ -178,6 +174,8 @@ export default function ClientDashboard(props: IProps) { .map((p: any) => p.processData) .filter((file: any) => file.isDeleted === 'false'); + // TODO: review - customerUid + for (const document of documents) { const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid); document.document_type = p.processData; @@ -224,6 +222,7 @@ export default function ClientDashboard(props: IProps) { setIsAddDocumentModalVisible(true); }, []); + /* const onDownloadFile = useCallback(() => { if (!file) { return; @@ -238,6 +237,7 @@ export default function ClientDashboard(props: IProps) { document.body.removeChild(a); URL.revokeObjectURL(url); }, [file]); + */ const renderBox = useCallback(() => { return ( @@ -267,6 +267,8 @@ export default function ClientDashboard(props: IProps) { Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)} + + {/* {file && ( + )} @@ -197,6 +201,7 @@ class ViewDocumentsClass extends BasePage { override async componentDidMount() { try { + /* TODO: review const document = await Documents.getInstance().getByUid(this.props.documentUid, { files: { where: { archived_at: null }, @@ -205,6 +210,29 @@ class ViewDocumentsClass extends BasePage { folder: true, depositor: true, }); + */ + + const document: any = await new Promise((resolve: (document: any) => void) => { + DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => { + if (process) { + const document: any = process.processData; + + const processes: any[] = await MessageBus.getInstance().getFiles(); + const process1: any = processes.find((process: any) => process.processData.document.get('uid') === document.uid); + + /* + const files: any[] = (await FileService.getFiles()) + .map((p: any) => p.processData) + .filter((file: any) => file.isDeleted === 'false'); + */ + + document.files = [process1.processData]; + + resolve(document); + } + }); + }); + this.setState( { document, @@ -226,7 +254,11 @@ class ViewDocumentsClass extends BasePage { private async getFilePreview(): Promise { try { - const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string); + // TODO: review + const file: any = this.state.selectedFile.fileBlob; + + const fileBlob: Blob = new Blob([file.data], { type: file.type }); + //const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string); this.setState({ fileBlob, @@ -236,6 +268,24 @@ class ViewDocumentsClass extends BasePage { } } + private downloadFile() { + // TODO: review + //if (!this.state.fileBlob) return; + const file: any = this.state.selectedFile.fileBlob; + + const blob = new Blob([file.data], { type: file.type }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = this.state.selectedFile.file_name; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + + } + + /* TODO: review private downloadFile() { if (!this.state.fileBlob) return; const url = window.URL.createObjectURL(this.state.fileBlob); @@ -248,6 +298,7 @@ class ViewDocumentsClass extends BasePage { a.click(); window.URL.revokeObjectURL(url); } + */ private getRandomPercentageForOcr() { // find diff @@ -315,8 +366,8 @@ class ViewDocumentsClass extends BasePage { Module.getInstance() .get() .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + - "?customerUid=" + - this.state.document?.depositor?.uid, + "?customerUid=" + + this.state.document?.depositor?.uid, ); } catch (e) { console.error(e); @@ -333,8 +384,8 @@ class ViewDocumentsClass extends BasePage { Module.getInstance() .get() .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + - "?customerUid=" + - this.state.document?.depositor?.uid, + "?customerUid=" + + this.state.document?.depositor?.uid, ); } catch (e) { console.error(e); diff --git a/src/sdk/MessageBus.ts b/src/sdk/MessageBus.ts index 3c39c120..c2300889 100644 --- a/src/sdk/MessageBus.ts +++ b/src/sdk/MessageBus.ts @@ -194,11 +194,25 @@ export default class MessageBus { continue; } - const isFile: boolean = process.states - .map((state: any) => state.keys) - .filter((keys: any) => keys['uid'] && keys['utype_ff']).length > 0; + const publicDataDecoded: { [key: string]: any } = {}; - if (!isFile) { + for (let stateId = 0; stateId < process.states.length - 1; stateId++) { + const state = process.states[stateId]; + if (!state) { + continue; + } + + const publicDataEncoded = state.public_data; + if (!publicDataEncoded) { + continue; + } + + for (const key of Object.keys(publicDataEncoded)) { + publicDataDecoded[key] = await this.getPublicData(publicDataEncoded[key]); + } + } + + if (publicDataDecoded['utype'] !== 'file') { continue; }