From e4c440d6dfc8e9e251c874a8b94431da67c246d4 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Wed, 2 Jul 2025 13:41:39 +0200 Subject: [PATCH] Fix somes issues --- .../DepositOtherDocument/index.tsx | 88 ++++++++++++----- .../DefaultCustomerDashboard/index.tsx | 6 +- .../ReceivedDocuments/index.tsx | 96 +++++++++++++----- .../ViewDocumentsNotary/index.tsx | 33 +++++-- .../Layouts/ClientDashboard/index.tsx | 97 +++++++++---------- .../ClientView/DocumentTables/index.tsx | 4 +- .../Layouts/Folder/ViewDocuments/index.tsx | 2 +- src/sdk/MessageBus.ts | 4 + 8 files changed, 222 insertions(+), 108 deletions(-) diff --git a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx index 15f143a7..c6398dfa 100644 --- a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx @@ -14,10 +14,12 @@ import classNames from "classnames"; import Button, { EButtonstyletype, EButtonVariant } from "../Button"; import Confirm from "../OldModal/Confirm"; -import Documents from "@Front/Api/LeCoffreApi/Customer/Documents/Documents"; -import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; import Alert from "../OldModal/Alert"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; +import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; + type IProps = { onChange?: (files: File[]) => void; open: boolean; @@ -196,7 +198,7 @@ export default class DepositOtherDocument extends React.Component((resolve: (document: any) => void) => { + const documentTypeData: any = { + folder: { + uid: this.props.folder_uid, + }, + depositor: { + uid: this.props.customer_uid, + } + }; + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + + DocumentService.createDocument(documentTypeData, validatorId).then((processCreated: any) => { + if (processCreated) { + const document: any = processCreated.processData; + resolve(document); + } + }); }); } catch (e) { this.setState({ showFailedDocument: "Le dossier est vérifié aucune modification n'est acceptée", isLoading: false }); @@ -225,16 +239,46 @@ export default class DepositOtherDocument extends React.Component((resolve: () => void) => { + const reader = new FileReader(); + reader.onload = (event) => { + if (event.target?.result) { + const arrayBuffer = event.target.result as ArrayBuffer; + const uint8Array = new Uint8Array(arrayBuffer); + + const fileBlob: any = { + type: file.type, + data: uint8Array + }; + + const fileData: any = { + file_blob: fileBlob, + file_name: file.name + }; + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + + FileService.createFile(fileData, validatorId).then((processCreated: any) => { + const fileUid: string = processCreated.processData.uid; + + DocumentService.getDocumentByUid(documentCreated.uid).then((process: any) => { + if (process) { + const document: any = process.processData; + + let files: any[] = document.files; + if (!files) { + files = []; + } + files.push({ uid: fileUid }); + + DocumentService.updateDocument(process, { files: files, document_status: EDocumentStatus.DEPOSITED }).then(() => resolve()); + } + }); + }); + } + }; + reader.readAsArrayBuffer(file); + }); } this.setState({ diff --git a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx index 89d8c1fe..1b8d7b96 100644 --- a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx @@ -14,7 +14,7 @@ type IProps = IPropsDashboardWithList & {}; export default function DefaultCustomerDashboard(props: IProps) { const router = useRouter(); - const { folderUid } = router.query; + const { folderUid, profileUid } = router.query; const [folders, setFolders] = useState([]); useEffect(() => { @@ -61,7 +61,9 @@ export default function DefaultCustomerDashboard(props: IProps) { router.push( Module.getInstance() .get() - .modules.pages.ClientDashboard.props.path.replace("[folderUid]", folder.uid ?? ""), + .modules.pages.ClientDashboard.props.path + .replace("[folderUid]", folder.uid ?? "") + .replace("[profileUid]", profileUid as string ?? ""), ); }; return ; diff --git a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx index 001ea71a..c137971e 100644 --- a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx @@ -1,5 +1,3 @@ -import DocumentsNotary from "@Front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary"; -import FilesNotary from "@Front/Api/LeCoffreApi/Customer/FilesNotary/Files"; import Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; import IconButton from "@Front/Components/DesignSystem/IconButton"; import Table from "@Front/Components/DesignSystem/Table"; @@ -16,10 +14,14 @@ import { useRouter } from "next/router"; import React, { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; import Link from "next/link"; -import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders"; import Customer from "le-coffre-resources/dist/Customer"; import { DocumentNotary } from "le-coffre-resources/dist/Notary"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; + const header: readonly IHead[] = [ { key: "name", @@ -47,6 +49,26 @@ export default function ReceivedDocuments() { jwt = JwtService.getInstance().decodeCustomerJwt(); } + // TODO: review + LoaderService.getInstance().show(); + const folder: any = await new Promise((resolve: (folder: any) => void) => { + FolderService.getFolderByUid(folderUid as string).then((process: any) => { + if (process) { + const folder: any = process.processData; + resolve(folder); + } + }); + }); + + //const customer = folder?.customers?.find((customer) => customer.contact?.email === jwt?.email); + const customer = folder?.customers?.[0]; + if (!customer) throw new Error("Customer not found"); + + setCustomer(customer); + + return { folder, customer }; + + /* const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, @@ -76,32 +98,58 @@ export default function ReceivedDocuments() { setCustomer(customer); return { folder, customer }; + */ }, [folderUid]); useEffect(() => { fetchFolderAndCustomer(); + }, [folderUid]); // Ne dépend que de folderUid + + // Effet séparé pour charger les documents lorsque customer change + useEffect(() => { const customerUid = customer?.uid; if (!folderUid || !customerUid) return; - DocumentsNotary.getInstance() - .get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } }) - .then((documentsNotary) => setDocumentsNotary(documentsNotary)); - }, [folderUid, customer, fetchFolderAndCustomer]); - const onDownload = useCallback((doc: DocumentNotary) => { + DocumentService.getDocuments().then(async (processes: any[]) => { + if (processes.length > 0) { + let documents: any[] = processes.map((process: any) => process.processData); + + // FilterBy folder.uid & customer.uid + documents = documents.filter((document: any) => document.folder.uid === folderUid && document.customer && document.customer.uid === customerUid); + + for (const document of documents) { + if (document.files && document.files.length > 0) { + const files: any[] = []; + for (const file of document.files) { + files.push((await FileService.getFileByUid(file.uid)).processData); + } + document.files = files; + } + } + + setDocumentsNotary(documents); + LoaderService.getInstance().hide(); + } + }); + }, [folderUid, customer]); + + const onDownload = useCallback((doc: any) => { const file = doc.files?.[0]; - if (!file || !file?.uid || !doc.uid) return; + if (!file) return; - return FilesNotary.getInstance() - .download(file.uid, doc.uid) - .then((blob) => { - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = file.file_name ?? "file"; - a.click(); - URL.revokeObjectURL(url); - }) - .catch((e) => console.warn(e)); + return new Promise((resolve: () => void) => { + const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = file.file_name; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + + resolve(); + }).catch((e) => console.warn(e)); }, []); const onDownloadAll = useCallback(async () => { @@ -110,16 +158,14 @@ export default function ReceivedDocuments() { const zip = new JSZip(); const folder = zip.folder("documents") || zip; - const downloadPromises = documentsNotary.map(async (doc) => { + documentsNotary.map((doc: any) => { const file = doc.files?.[0]; - if (file && file.uid && doc.uid) { - const blob = await FilesNotary.getInstance().download(file.uid, doc.uid); + if (file) { + const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); folder.file(file.file_name ?? "file", blob); } }); - await Promise.all(downloadPromises); - zip.generateAsync({ type: "blob" }) .then((blob: any) => { saveAs(blob, "documents.zip"); diff --git a/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx b/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx index 843ded9f..89a6af09 100644 --- a/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ViewDocumentsNotary/index.tsx @@ -10,9 +10,12 @@ import React from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import DocumentsNotary from "@Front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary"; + import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate"; -import FilesNotary from "@Front/Api/LeCoffreApi/Customer/FilesNotary/Files"; + +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; type IProps = {}; type IPropsClass = { @@ -123,11 +126,26 @@ class ViewDocumentsNotaryClass extends BasePage { override async componentDidMount() { try { - const documentNotary = await DocumentsNotary.getInstance().getByUid(this.props.documentUid, { - files: true, - folder: true, - depositor: true, + LoaderService.getInstance().show(); + const documentNotary: any = await new Promise((resolve: (document: any) => void) => { + DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => { + if (process) { + const document: any = process.processData; + + if (document.files && document.files.length > 0) { + const files: any[] = []; + for (const file of document.files) { + files.push((await FileService.getFileByUid(file.uid)).processData); + } + document.files = files; + } + + resolve(document); + } + }); }); + LoaderService.getInstance().hide(); + this.setState( { documentNotary, @@ -149,8 +167,7 @@ class ViewDocumentsNotaryClass extends BasePage { private async getFilePreview(): Promise { try { - const fileBlob: Blob = await FilesNotary.getInstance().download(this.state.selectedFile?.uid as string, this.props.documentUid); - + const fileBlob: Blob = new Blob([this.state.selectedFile.file_blob.data], { type: this.state.selectedFile.file_blob.type }); this.setState({ fileBlob, }); diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 23fcb813..4b9eb1cc 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -10,7 +10,6 @@ import { DocumentNotary, OfficeFolder as OfficeFolderNotary } from "le-coffre-re import classes from "./classes.module.scss"; import { useRouter } from "next/router"; import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService"; -import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders"; import Tag, { ETagColor } from "@Front/Components/DesignSystem/Tag"; import DefaultCustomerDashboard from "@Front/Components/LayoutTemplates/DefaultCustomerDashboard"; @@ -21,7 +20,6 @@ import Module from "@Front/Config/Module"; import Separator, { ESeperatorColor, ESeperatorDirection } from "@Front/Components/DesignSystem/Separator"; import NotificationBox from "@Front/Components/DesignSystem/NotificationBox"; import ContactBox from "./ContactBox"; -import DocumentsNotary from "@Front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary"; import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary"; import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument"; @@ -31,6 +29,7 @@ import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; import FileService from "src/common/Api/LeCoffreApi/sdk/FileService"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; type IProps = {}; @@ -54,6 +53,7 @@ export default function ClientDashboard(props: IProps) { } // TODO: review + LoaderService.getInstance().show(); const { folder, customer } = await new Promise((resolve) => { FolderService.getFolderByUid(folderUid as string).then((process: any) => { if (process) { @@ -72,6 +72,7 @@ export default function ClientDashboard(props: IProps) { setFolder(folder); setIsAuthModalOpen(true); + LoaderService.getInstance().hide(); return { folder, customer }; @@ -111,52 +112,34 @@ export default function ClientDashboard(props: IProps) { const fetchDocuments = useCallback( async (customerUid: string | undefined) => { - /* TODO: review - const query: IGetDocumentsparams = { - where: { depositor: { uid: customerUid }, folder_uid: folderUid as string }, - include: { - files: true, - document_history: true, - document_type: true, - depositor: true, - folder: { - include: { - customers: { - include: { - contact: true, - }, - }, - }, - }, - }, - }; + LoaderService.getInstance().show(); + return new Promise((resolve: () => void) => { + DocumentService.getDocuments().then(async (processes: any[]) => { + if (processes.length > 0) { + let documents: any[] = processes.map((process: any) => process.processData); - return Documents.getInstance() - .get(query) - .then((documents) => setDocuments(documents)); - */ + // FilterBy folder.uid & depositor.uid + documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor && document.depositor.uid === customerUid); - return DocumentService.getDocuments().then(async (processes: any[]) => { - if (processes.length > 0) { - let documents: any[] = processes.map((process: any) => process.processData); - - // FilterBy folder_uid - documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor); - - for (const document of documents) { - document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData; - - if (document.files && document.files.length > 0) { - const files: any[] = []; - for (const file of document.files) { - files.push((await FileService.getFileByUid(file.uid)).processData); + for (const document of documents) { + if (document.document_type) { + document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData; } - document.files = files; - } - } - setDocuments(documents); - } + if (document.files && document.files.length > 0) { + const files: any[] = []; + for (const file of document.files) { + files.push((await FileService.getFileByUid(file.uid)).processData); + } + document.files = files; + } + } + + setDocuments(documents); + } + LoaderService.getInstance().hide(); + resolve(); + }); }); }, [folderUid], @@ -170,12 +153,28 @@ export default function ClientDashboard(props: IProps) { const customerUid = customer?.uid; if (!folderUid || !customerUid) return; - /* TODO: review - DocumentsNotary.getInstance() - .get({ where: { folder: { uid: folderUid }, customer: { uid: customerUid } }, include: { files: true } }) - .then((documentsNotary) => setDocumentsNotary(documentsNotary)); - */ + LoaderService.getInstance().show(); + DocumentService.getDocuments().then(async (processes: any[]) => { + if (processes.length > 0) { + let documents: any[] = processes.map((process: any) => process.processData); + // FilterBy folder.uid & customer.uid + documents = documents.filter((document: any) => document.folder.uid === folderUid && document.customer && document.customer.uid === customerUid); + + for (const document of documents) { + if (document.files && document.files.length > 0) { + const files: any[] = []; + for (const file of document.files) { + files.push((await FileService.getFileByUid(file.uid)).processData); + } + document.files = files; + } + } + + setDocumentsNotary(documents); + LoaderService.getInstance().hide(); + } + }); }, [folderUid, customer?.uid]); const documentsNotaryNotRead = useMemo( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx index 5f85bb8c..a639767d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -62,7 +62,9 @@ export default function DocumentTables(props: IProps) { documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor && document.depositor.uid === customerUid); for (const document of documents) { - document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData; + if (document.document_type) { + document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData; + } if (document.files && document.files.length > 0) { const files: any[] = []; diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index 59ad2998..dd3f5312 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -6,7 +6,7 @@ import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultNotaryDashboard from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; -import { Document, File } from "le-coffre-resources/dist/Notary"; +import { Document } from "le-coffre-resources/dist/Notary"; import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; import Image from "next/image"; import { NextRouter, useRouter } from "next/router"; diff --git a/src/sdk/MessageBus.ts b/src/sdk/MessageBus.ts index f97e2755..2d26952c 100644 --- a/src/sdk/MessageBus.ts +++ b/src/sdk/MessageBus.ts @@ -153,6 +153,10 @@ export default class MessageBus { continue; } + for (const key of Object.keys(publicDataDecoded)) { + processData[key] = publicDataDecoded[key]; + } + if (!file) { file = { processId,