From ccc0a1620c24a287dfd3c39b73d14ac1931577d0 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Thu, 26 Jun 2025 13:08:36 +0200 Subject: [PATCH] Fix some bugs - continue --- .../Api/LeCoffreApi/sdk/CustomerService.ts | 13 +++ .../DefaultCustomerDashboard/index.tsx | 13 ++- .../ClientDashboard/ContactBox/index.tsx | 2 + .../Layouts/ClientDashboard/index.tsx | 96 +++++++++++++------ .../Folder/CreateCustomerNote/index.tsx | 21 +++- .../elements/AnchoringModal/index.tsx | 33 +++---- .../Layouts/Folder/UpdateClient/index.tsx | 69 +++---------- .../Folder/UpdateFolderMetadata/index.tsx | 12 +++ 8 files changed, 151 insertions(+), 108 deletions(-) diff --git a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts index 963822b8..006ed49b 100644 --- a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts +++ b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts @@ -92,4 +92,17 @@ export default class CustomerService { }).catch(reject); }); } + + public static updateCustomer(process: any, newData: any): Promise { + return new Promise((resolve: () => void, reject: (error: string) => void) => { + this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + const newStateId: string = processUpdated.diffs[0]?.state_id; + this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { + this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { + resolve(); + }).catch(reject); + }).catch(reject); + }).catch(reject); + }); + } } diff --git a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx index 8dfc3a60..89d8c1fe 100644 --- a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx @@ -8,6 +8,8 @@ import React, { useEffect, useState } from "react"; import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; + type IProps = IPropsDashboardWithList & {}; export default function DefaultCustomerDashboard(props: IProps) { @@ -19,6 +21,7 @@ export default function DefaultCustomerDashboard(props: IProps) { const jwt = JwtService.getInstance().decodeCustomerJwt(); if (!jwt) return; + /* Folders.getInstance() .get({ q: { @@ -42,6 +45,14 @@ export default function DefaultCustomerDashboard(props: IProps) { }, }) .then((folders) => setFolders(folders)); + */ + + FolderService.getFolders().then((processes: any[]) => { + if (processes.length > 0) { + const folders: any[] = processes.map((process: any) => process.processData); + setFolders(folders); + } + }); }, []); const onSelectedBlock = (block: IBlock) => { @@ -53,7 +64,7 @@ export default function DefaultCustomerDashboard(props: IProps) { .modules.pages.ClientDashboard.props.path.replace("[folderUid]", folder.uid ?? ""), ); }; - return ; + return ; function getBlocks(folders: OfficeFolder[]): IBlock[] { return folders.map((folder) => { diff --git a/src/front/Components/Layouts/ClientDashboard/ContactBox/index.tsx b/src/front/Components/Layouts/ClientDashboard/ContactBox/index.tsx index 0715e3d4..e84bfeea 100644 --- a/src/front/Components/Layouts/ClientDashboard/ContactBox/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ContactBox/index.tsx @@ -47,9 +47,11 @@ export default function ContactBox(props: IProps) { useEffect(() => { if (!folder?.office?.uid) return; + /* TODO: review OfficeRib.getInstance() .getRibStream(folder.office.uid) .then((blob) => setRibUrl(URL.createObjectURL(blob))); + */ }, [folder]); const downloadRib = useCallback(async () => { diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 856e3d63..0fd3be33 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -27,11 +27,12 @@ import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDoc import { v4 as uuidv4 } from "uuid"; -import MessageBus from "src/sdk/MessageBus"; - -import MapUtils from "src/sdk/MapUtils"; import AuthModal from "src/sdk/AuthModal"; -import FormModal from "./FormModal"; +//import FormModal from "./FormModal"; + +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"; type IProps = {}; @@ -48,40 +49,52 @@ export default function ClientDashboard(props: IProps) { const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); - const [isFormModalOpen, setIsFormModalOpen] = useState(false); + //const [isFormModalOpen, setIsFormModalOpen] = useState(false); const fetchFolderAndCustomer = useCallback(async () => { // TODO: review const { folder, customer, file } = await new Promise((resolve) => { - MessageBus.getInstance().isReady().then(() => { - setTimeout(() => { - MessageBus.getInstance().getFolders().then(async (folders) => { - const folder: any = folders.find((folder: any) => folder.processData.uid === folderUid as string); - if (folder) { - const customer = folder.processData.customers - .map((customer: any) => MapUtils.toJson(customer)) - .find((customer: any) => customer.uid === profileUid as string); + FolderService.getFolderByUid(folderUid as string).then((process: any) => { + if (process) { + const folder: any = process.processData; - const file = await new Promise((resolve: (file: any) => void) => { - MessageBus.getInstance().getFiles().then((files: any) => { - if (!files || files.length === 0) { - resolve(null); - } else { - const file: any = files.find((file: any) => file.processData.folderUid === folderUid as string && file.processData.profileUid === profileUid as string); - if (file) { - resolve(file); - } else { - resolve(null); - } - } - }).catch(() => resolve(null)); - }); + const customers: any[] = folder.customers; + const customer: any = customers.find((customer: any) => customer.uid === profileUid as string); + if (customer) { - resolve({ folder: folder.processData, customer, file: file ? file.processData : null }); - } - }); - }, 2500); + + resolve({ folder: folder, customer, file: null }); + } + } }); + + /* + MessageBus.getInstance().getFolders().then(async (folders) => { + const folder: any = folders.find((folder: any) => folder.processData.uid === folderUid as string); + if (folder) { + const customer = folder.processData.customers + .map((customer: any) => MapUtils.toJson(customer)) + .find((customer: any) => customer.uid === profileUid as string); + + const file = await new Promise((resolve: (file: any) => void) => { + MessageBus.getInstance().getFiles().then((files: any) => { + if (!files || files.length === 0) { + resolve(null); + } else { + const file: any = files.find((file: any) => file.processData.folderUid === folderUid as string && file.processData.profileUid === profileUid as string); + if (file) { + resolve(file); + } else { + resolve(null); + } + } + }).catch(() => resolve(null)); + }); + + resolve({ folder: folder.processData, customer, file: file ? file.processData : null }); + } + }); + */ }); setCustomer(customer); @@ -135,6 +148,7 @@ export default function ClientDashboard(props: IProps) { const fetchDocuments = useCallback( (customerUid: string | undefined) => { + /* const query: IGetDocumentsparams = { where: { depositor: { uid: customerUid }, folder_uid: folderUid as string }, include: { @@ -157,6 +171,20 @@ export default function ClientDashboard(props: IProps) { return Documents.getInstance() .get(query) .then((documents) => setDocuments(documents)); + */ + + return DocumentService.getDocuments().then(async (processes: any[]) => { + if (processes.length > 0) { + const documents: any[] = processes.map((process: any) => process.processData); + + for (const document of documents) { + const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid); + document.document_type = p.processData; + } + + setDocuments(documents); + } + }); }, [folderUid], ); @@ -336,12 +364,15 @@ export default function ClientDashboard(props: IProps) { isOpen={isAuthModalOpen} onClose={() => { setIsAuthModalOpen(false); + /* setTimeout(() => { setIsFormModalOpen(true); }, 500); + */ }} />} + {/* setIsFormModalOpen(false)} @@ -366,6 +397,7 @@ export default function ClientDashboard(props: IProps) { file: fileBlob } + / * MessageBus.getInstance().isReady().then(() => { MessageBus.getInstance().createFile(fileData, [], []).then((processCreated: any) => { MessageBus.getInstance().notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => { @@ -375,12 +407,14 @@ export default function ClientDashboard(props: IProps) { }); }); }); + * / } }; reader.readAsArrayBuffer(file); } }} /> + */} ); diff --git a/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx b/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx index 6920e548..4d64a7ff 100644 --- a/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx @@ -13,9 +13,10 @@ import BasePage from "../../Base"; import classes from "./classes.module.scss"; import Customer from "le-coffre-resources/dist/Customer"; import Note from "le-coffre-resources/dist/Customer/Note"; -import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders"; import Notes from "@Front/Api/LeCoffreApi/Customer/Notes/Notes"; -import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; + +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; +import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; type IProps = {}; @@ -76,9 +77,25 @@ class CreateCustomerNoteClass extends BasePage { } public override async componentDidMount() { + /* TODO: review // const note = await Notes.getInstance().getByUid(this.props.noteUid, query); const folder = await Folders.getInstance().getByUid(this.props.folderUid, { note: true }); const customer = await Customers.getInstance().getByUid(this.props.customerUid); + */ + + const folder: any = await FolderService.getFolderByUid(this.props.folderUid).then((process: any) => { + if (process) { + const folder: any = process.processData; + return folder; + } + }); + + const customer: any = await CustomerService.getCustomerByUid(this.props.customerUid).then((process: any) => { + if (process) { + const customer: any = process.processData; + return customer; + } + }); //get the note of the folder that has customer_uid = this.props.customer.uid // const folderNote = folder.notes?.find((note) => note.customer?.uid === this.props.customerUid); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx index f15c7d8f..e35b4cd5 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringModal/index.tsx @@ -6,7 +6,8 @@ import Image from "next/image"; import React, { useCallback, useState } from "react"; import classes from "./classes.module.scss"; -import MessageBus from "src/sdk/MessageBus"; + +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; type IProps = { isOpen: boolean; @@ -23,25 +24,17 @@ export default function AnchoringModal(props: IProps) { setIsAnchoring(true); // TODO: review - MessageBus.getInstance().isReady().then(() => { - MessageBus.getInstance().getFolders().then((folders: any) => { - const folder = folders.find((folder: any) => folder.processData.uid === folderUid); - if (folder) { - MessageBus.getInstance().updateProcess(folder.processId, { isArchived: 'true' }, [], null).then((processUpdated: any) => { - const newStateId: string = processUpdated.diffs[0]?.state_id; - MessageBus.getInstance().notifyUpdate(folder.processId, newStateId).then(() => { - MessageBus.getInstance().validateState(folder.processId, newStateId).then((_updatedProcess) => { - setIsAnchoring(false); + FolderService.getFolderByUid(folderUid as string).then((process: any) => { + if (process) { + FolderService.updateFolder(process, { status: '' }).then(() => { + setIsAnchoring(false); - onAnchorSuccess(); - if (onClose) { - onClose(); - } - }); - }); - }); - } - }); + onAnchorSuccess(); + if (onClose) { + onClose(); + } + }); + } }); /* @@ -50,7 +43,7 @@ export default function AnchoringModal(props: IProps) { setTimeout(resolve, timeoutDelay); }); setIsAnchoring(true); - + return OfficeFolderAnchors.getInstance() .post(folderUid) .then(() => timeoutPromise) diff --git a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx index b6e2670b..baddb59c 100644 --- a/src/front/Components/Layouts/Folder/UpdateClient/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateClient/index.tsx @@ -1,5 +1,4 @@ import backgroundImage from "@Assets/images/background_refonte.svg"; -import Customers from "@Front/Api/LeCoffreApi/Notary/Customers/Customers"; import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Form, { IBaseField } from "@Front/Components/DesignSystem/Form"; import TextField from "@Front/Components/DesignSystem/Form/TextField"; @@ -17,8 +16,7 @@ import { useRouter } from "next/router"; import { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; -import MessageBus from "src/sdk/MessageBus"; -import MapUtils from "src/sdk/MapUtils"; +import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; export default function UpdateClient() { const router = useRouter(); @@ -37,32 +35,14 @@ export default function UpdateClient() { useEffect(() => { const fetchCustomer = async () => { try { - // TODO: review - MessageBus.getInstance().isReady().then(() => { - MessageBus.getInstance().getFolders().then((folders: any) => { - const folder = folders.find((folder: any) => folder.processData.uid === folderUid as string); - if (folder) { - const customers: any[] = folder.processData.customers.map((customer: any) => MapUtils.toJson(customer)); - const customer: any = customers.find((customer: any) => customer.uid === customerUid as string); - if (customer) { - setCustomer(customer); - } + CustomerService.getCustomerByUid(customerUid as string).then((process: any) => { + if (process) { + const customer: any = process.processData; + if (customer) { + setCustomer(customer); } - }); + } }); - - /* - const customerData = await Customers.getInstance().getByUid(customerUid as string, { - contact: { - include: { - address: true, - }, - }, - }); - if (customerData) { - setCustomer(customerData); - } - */ } catch (error) { console.error("Failed to fetch customer", error); } @@ -89,34 +69,15 @@ export default function UpdateClient() { }); try { - // TODO: review - MessageBus.getInstance().isReady().then(() => { - MessageBus.getInstance().getFolders().then((folders: any) => { - const folder = folders.find((folder: any) => folder.processData.uid === folderUid as string); - if (folder) { - const customers: any[] = folder.processData.customers.map((customer: any) => MapUtils.toJson(customer)); - const customer: any = customers.find((customer: any) => customer.uid === customerUid as string); - if (customer) { - customer.contact = contact; // Update the contact - - MessageBus.getInstance().updateProcess(folder.processId, { customers: customers }, [], null).then((processUpdated: any) => { - const newStateId: string = processUpdated.diffs[0]?.state_id; - MessageBus.getInstance().notifyUpdate(folder.processId, newStateId).then(() => { - MessageBus.getInstance().validateState(folder.processId, newStateId).then((_stateValidated) => { - router.push(backwardPath); - }); - }); - }); - } - } - }); - }); - - /* await contact.validateOrReject?.({ groups: ["createCustomer"], forbidUnknownValues: false }); - await Customers.getInstance().put(customerUid as string, { contact }); - router.push(backwardPath); - */ + CustomerService.getCustomerByUid(customerUid as string).then((process: any) => { + if (process) { + // TODO: review - address + CustomerService.updateCustomer(process, { contact: contact }).then(() => { + router.push(backwardPath); + }); + } + }); } catch (validationErrors) { if (Array.isArray(validationErrors)) { setValidationError(validationErrors as ValidationError[]); diff --git a/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx b/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx index 8a23300d..9287bbb8 100644 --- a/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateFolderMetadata/index.tsx @@ -18,6 +18,8 @@ import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoub import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import { isArray } from "class-validator"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; + export default function UpdateFolderMetadata() { const router = useRouter(); @@ -63,6 +65,8 @@ export default function UpdateFolderMetadata() { useEffect(() => { if (!folderUid || isArray(folderUid)) return; + + /* TODO: review const query = { q: { deed: { include: { deed_type: true } }, @@ -73,6 +77,14 @@ export default function UpdateFolderMetadata() { Folders.getInstance() .getByUid(folderUid, query) .then((folder) => setSelectedFolder(folder)); + */ + + FolderService.getFolderByUid(folderUid).then((process: any) => { + if (process) { + const folder: any = process.processData; + setSelectedFolder(folder); + } + }); }, [folderUid]); const backwardPath = Module.getInstance()