From 39c14ff490398e59bed0b593ba38a25607d19941 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Fri, 27 Jun 2025 01:26:39 +0200 Subject: [PATCH] Fix some bugs - continue --- .../Api/LeCoffreApi/sdk/CustomerService.ts | 7 +- .../Api/LeCoffreApi/sdk/DeedTypeService.ts | 7 +- .../Api/LeCoffreApi/sdk/DocumentService.ts | 7 +- .../LeCoffreApi/sdk/DocumentTypeService.ts | 7 +- src/common/Api/LeCoffreApi/sdk/FileService.ts | 7 +- .../Api/LeCoffreApi/sdk/FolderService.ts | 7 +- src/common/Api/LeCoffreApi/sdk/NoteService.ts | 110 ++++++++++++++ .../DepositDocumentComponent/index.tsx | 17 +-- .../Layouts/ClientDashboard/FormModal.tsx | 94 ------------ .../Layouts/ClientDashboard/index.tsx | 134 ++---------------- .../DeedTypes/DeedTypesInformations/index.tsx | 17 +-- .../Folder/CreateCustomerNote/index.tsx | 24 ++-- .../ClientView/ClientBox/index.tsx | 31 ++-- .../DeleteAskedDocumentModal/index.tsx | 13 +- .../ClientView/DocumentTables/index.tsx | 56 ++++---- .../FolderInformation/ClientView/index.tsx | 36 +++-- .../NoClientView/DeleteFolderModal/index.tsx | 19 ++- .../Folder/FolderInformation/index.tsx | 18 ++- .../Folder/UpdateCustomerNote/index.tsx | 47 +++--- .../Layouts/Folder/ViewDocuments/index.tsx | 80 +++++------ src/sdk/MessageBus.ts | 83 ----------- 21 files changed, 335 insertions(+), 486 deletions(-) create mode 100644 src/common/Api/LeCoffreApi/sdk/NoteService.ts delete mode 100644 src/front/Components/Layouts/ClientDashboard/FormModal.tsx diff --git a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts index dd427f48..37d9051e 100644 --- a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts +++ b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts @@ -25,6 +25,7 @@ export default class CustomerService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -78,12 +79,12 @@ export default class CustomerService { } public static getCustomers(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'customer'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'customer' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getCustomerByUid(uid: string): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'customer').then((processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'customer' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then((processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -96,7 +97,7 @@ export default class CustomerService { 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) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts index 96ceb87b..2e9a32ab 100644 --- a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts @@ -27,6 +27,7 @@ export default class DeedTypeService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -80,12 +81,12 @@ export default class DeedTypeService { } public static getDeedTypes(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'deedType'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'deedType' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getDeedTypeByUid(uid: string, includeDocumentTypes: boolean = true): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'deedType').then(async (processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'deedType' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then(async (processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -112,7 +113,7 @@ export default class DeedTypeService { public static updateDeedType(process: any, newData: any): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { - this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts index 13a195cc..5726ca23 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts @@ -25,6 +25,7 @@ export default class DocumentService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -78,12 +79,12 @@ export default class DocumentService { } public static getDocuments(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'document'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'document' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getDocumentByUid(uid: string): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'document').then((processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'document' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then((processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -96,7 +97,7 @@ export default class DocumentService { public static updateDocument(process: any, newData: any): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { - this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts index 7c167cc4..13846c2a 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts @@ -25,6 +25,7 @@ export default class DocumentTypeService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -78,12 +79,12 @@ export default class DocumentTypeService { } public static getDocumentTypes(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'documentType'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'documentType' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getDocumentTypeByUid(uid: string): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'documentType').then((processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'documentType' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then((processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -96,7 +97,7 @@ export default class DocumentTypeService { public static updateDocumentType(process: any, newData: any): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { - this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/FileService.ts b/src/common/Api/LeCoffreApi/sdk/FileService.ts index cd9cdcd0..317de209 100644 --- a/src/common/Api/LeCoffreApi/sdk/FileService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FileService.ts @@ -25,6 +25,7 @@ export default class FileService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -78,12 +79,12 @@ export default class FileService { } public static getFiles(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'file'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'file' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getFileByUid(uid: string): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'file').then(async (processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'file' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then(async (processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -96,7 +97,7 @@ export default class FileService { public static updateFile(process: any, newData: any): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { - this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/FolderService.ts b/src/common/Api/LeCoffreApi/sdk/FolderService.ts index bdedd1f5..74e0bb92 100644 --- a/src/common/Api/LeCoffreApi/sdk/FolderService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FolderService.ts @@ -28,6 +28,7 @@ export default class FolderService { const privateFields: string[] = Object.keys(processData); privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); const roles: any = { demiurge: { @@ -87,12 +88,12 @@ export default class FolderService { } public static getFolders(): Promise { - return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'folder'); + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'folder' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); } public static getFolderByUid(uid: string, includeCustomers: boolean = true, includeDeedType: boolean = true): Promise { return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { - this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'folder').then(async (processes: any[]) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'folder' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then(async (processes: any[]) => { if (processes.length === 0) { resolve(null); } else { @@ -124,7 +125,7 @@ export default class FolderService { public static updateFolder(process: any, newData: any): Promise { return new Promise((resolve: () => void, reject: (error: string) => void) => { - this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + this.messageBus.updateProcess(process.processId, { updated_at: new Date().toISOString(), ...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) => { diff --git a/src/common/Api/LeCoffreApi/sdk/NoteService.ts b/src/common/Api/LeCoffreApi/sdk/NoteService.ts new file mode 100644 index 00000000..623fb781 --- /dev/null +++ b/src/common/Api/LeCoffreApi/sdk/NoteService.ts @@ -0,0 +1,110 @@ + +import { v4 as uuidv4 } from 'uuid'; + +import MessageBus from 'src/sdk/MessageBus'; +import User from 'src/sdk/User'; + +export default class NoteService { + + private static readonly messageBus: MessageBus = MessageBus.getInstance(); + + private constructor() { } + + public static createNote(noteData: any, validatorId: string): Promise { + const ownerId = User.getInstance().getPairingId()!; + + const processData: any = { + uid: uuidv4(), + utype: 'note', + isDeleted: 'false', + created_at: new Date().toISOString(), + updated_at: new Date().toISOString(), + ...noteData, + }; + + const privateFields: string[] = Object.keys(processData); + privateFields.splice(privateFields.indexOf('uid'), 1); + privateFields.splice(privateFields.indexOf('utype'), 1); + privateFields.splice(privateFields.indexOf('isDeleted'), 1); + + const roles: any = { + demiurge: { + members: [...[ownerId], validatorId], + validation_rules: [], + storages: [] + }, + owner: { + members: [ownerId], + validation_rules: [ + { + quorum: 0.5, + fields: [...privateFields, 'roles', 'uid', 'utype'], + min_sig_member: 1, + }, + ], + storages: [] + }, + validator: { + members: [validatorId], + validation_rules: [ + { + quorum: 0.5, + fields: ['idCertified', 'roles'], + min_sig_member: 1, + }, + { + quorum: 0.0, + fields: [...privateFields], + min_sig_member: 0, + }, + ], + storages: [] + }, + apophis: { + members: [ownerId], + validation_rules: [], + storages: [] + } + }; + + return new Promise((resolve: (processCreated: any) => void, reject: (error: string) => void) => { + this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => { + this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => { + this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => { + resolve(processCreated); + }).catch(reject); + }).catch(reject); + }).catch(reject); + }); + } + + public static getNotes(): Promise { + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'note' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false'); + } + + public static getNoteByUid(uid: string): Promise { + return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'note' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then((processes: any[]) => { + if (processes.length === 0) { + resolve(null); + } else { + const process: any = processes[0]; + resolve(process); + } + }).catch(reject); + }); + } + + public static updateNote(process: any, newData: any): 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; + 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/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx index e33f08fb..3c2d6118 100644 --- a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx @@ -4,7 +4,6 @@ import { Document } from "le-coffre-resources/dist/Customer"; 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"; @@ -93,21 +92,19 @@ export default function DepositDocumentComponent(props: IProps) { (resolve: () => void) => { FileService.getFileByUid(filedUid).then((process: any) => { if (process) { - FileService.updateFile(process, { isDeleted: 'true' }).then(() => resolve()); + FileService.updateFile(process, { isDeleted: 'true' }).then(() => { + DocumentService.getDocumentByUid(document.uid!).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentStatus.ASKED }).then(() => resolve()); + } + }); + }); } }); }) .then(onChange) .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" })) .catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message })); - - /* TODO: review - return Files.getInstance() - .delete(filedUid) - .then(onChange) - .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" })) - .catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message })); - */ }, [onChange], ); diff --git a/src/front/Components/Layouts/ClientDashboard/FormModal.tsx b/src/front/Components/Layouts/ClientDashboard/FormModal.tsx deleted file mode 100644 index 5e1ef676..00000000 --- a/src/front/Components/Layouts/ClientDashboard/FormModal.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import React, { useEffect, useState, useRef } from 'react'; -import Modal from '@Front/Components/DesignSystem/Modal'; -import Typography, { ETypo } from '@Front/Components/DesignSystem/Typography'; -import Button, { EButtonstyletype, EButtonVariant } from '@Front/Components/DesignSystem/Button'; - -interface FormModalProps { - isOpen: boolean; - onClose: () => void; - onSubmit: (file: File) => void; -} - -export default function FormModal({ isOpen, onClose, onSubmit }: FormModalProps) { - const [selectedFile, setSelectedFile] = useState(null); - const fileInputRef = useRef(null); - - useEffect(() => { - if (!isOpen) { - setSelectedFile(null); - if (fileInputRef.current) { - fileInputRef.current.value = ''; - } - } - }, [isOpen]); - - const handleFileChange = (e: React.ChangeEvent) => { - const files = e.target.files; - if (files && files.length > 0 && files[0] instanceof File) { - setSelectedFile(files[0]); - } - }; - - const handleButtonClick = () => { - if (fileInputRef.current) { - fileInputRef.current.click(); - } - }; - - return ( - -
-
- - Document - -
- - - {selectedFile && ( -
- - {selectedFile.name} - -
- )} -
-
- -
- - -
-
-
- ); -} diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 9c8e1554..6cd797d9 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -26,7 +26,6 @@ import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentN import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument"; import AuthModal from "src/sdk/AuthModal"; -//import FormModal from "./FormModal"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; @@ -47,11 +46,15 @@ export default function ClientDashboard(props: IProps) { const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); - //const [isFormModalOpen, setIsFormModalOpen] = useState(false); const fetchFolderAndCustomer = useCallback(async () => { + let jwt: ICustomerJwtPayload | undefined; + if (typeof document !== "undefined") { + jwt = JwtService.getInstance().decodeCustomerJwt(); + } + // TODO: review - const { folder, customer, file } = await new Promise((resolve) => { + const { folder, customer } = await new Promise((resolve) => { FolderService.getFolderByUid(folderUid as string).then((process: any) => { if (process) { const folder: any = process.processData; @@ -63,34 +66,6 @@ export default function ClientDashboard(props: IProps) { } } }); - - /* - 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); @@ -101,11 +76,6 @@ export default function ClientDashboard(props: IProps) { return { folder, customer }; /* - let jwt: ICustomerJwtPayload | undefined; - if (typeof document !== "undefined") { - jwt = JwtService.getInstance().decodeCustomerJwt(); - } - const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, @@ -140,7 +110,7 @@ export default function ClientDashboard(props: IProps) { }, [folderUid]); const fetchDocuments = useCallback( - (customerUid: string | undefined) => { + async (customerUid: string | undefined) => { /* const query: IGetDocumentsparams = { where: { depositor: { uid: customerUid }, folder_uid: folderUid as string }, @@ -166,15 +136,14 @@ export default function ClientDashboard(props: IProps) { .then((documents) => setDocuments(documents)); */ + const files: any[] = (await FileService.getFiles()).map((p: any) => p.processData); + return DocumentService.getDocuments().then(async (processes: any[]) => { if (processes.length > 0) { - const documents: any[] = processes.map((process: any) => process.processData); + let documents: any[] = processes.map((process: any) => process.processData); - const files: any[] = (await FileService.getFiles()) - .map((p: any) => p.processData) - .filter((file: any) => file.isDeleted === 'false'); - - // TODO: review - customerUid + // FilterBy folder_uid + documents = documents.filter((document: any) => document.folder.uid === folderUid); for (const document of documents) { const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid); @@ -222,23 +191,6 @@ export default function ClientDashboard(props: IProps) { setIsAddDocumentModalVisible(true); }, []); - /* - const onDownloadFile = useCallback(() => { - if (!file) { - return; - } - const blob = new Blob([file.file.data], { type: file.file.type }); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = 'document.pdf'; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - }, [file]); - */ - const renderBox = useCallback(() => { return ( Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)} - - {/* - {file && ( - - )} - */} -
@@ -372,57 +311,8 @@ export default function ClientDashboard(props: IProps) { isOpen={isAuthModalOpen} onClose={() => { setIsAuthModalOpen(false); - /* - setTimeout(() => { - setIsFormModalOpen(true); - }, 500); - */ }} />} - - {/* - setIsFormModalOpen(false)} - onSubmit={(file: any) => { - if (file) { - 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 = { - type: file.type, - data: uint8Array - }; - - const fileData = { - uid: uuidv4(), - utype_ff: 'file', - folderUid: folderUid as string, - profileUid: profileUid as string, - 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(() => { - MessageBus.getInstance().validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => { - setIsFormModalOpen(false); - }); - }); - }); - }); - * / - } - }; - reader.readAsArrayBuffer(file); - } - }} - /> - */}
); diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 457f6d8f..e55ad29c 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -1,6 +1,5 @@ import ChevronIcon from "@Assets/Icons/chevron.svg"; import PenICon from "@Assets/Icons/pen.svg"; -import DeedTypes from "@Front/Api/LeCoffreApi/Notary/DeedTypes/DeedTypes"; import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/DropdownOption"; import Form from "@Front/Components/DesignSystem/Form"; @@ -51,14 +50,13 @@ export default function DeedTypesInformations(props: IProps) { }, []); const deleteDeedType = useCallback(async () => { - await DeedTypes.getInstance().put( - deedTypeUid as string, - DeedType.hydrate({ - uid: deedTypeUid as string, - archived_at: new Date(), - }), - ); - router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path); + DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => { + if (process) { + DeedTypeService.updateDeedType(process, { archived_at: new Date().toISOString() }).then(() => { + router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path); + }); + } + }); }, [deedTypeUid, router]); useEffect(() => { @@ -119,7 +117,6 @@ export default function DeedTypesInformations(props: IProps) { DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => { closeSaveModal(); }); - } }); }, [closeSaveModal, deedTypeUid, selectedDocuments]); diff --git a/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx b/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx index 4d64a7ff..ea17b9a4 100644 --- a/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateCustomerNote/index.tsx @@ -13,10 +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 Notes from "@Front/Api/LeCoffreApi/Customer/Notes/Notes"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; +import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService"; type IProps = {}; @@ -108,14 +108,22 @@ class CreateCustomerNoteClass extends BasePage { if (!this.state.folder || !this.state.customer) { throw new Error("Folder or customer not found"); } - const note = { - content: values["content"], - folder: this.state.folder, - customer: this.state.customer, - }; - await Notes.getInstance().post(note); - this.props.router.push(this.backwardPath); + // TODO: review + const noteData: any = { + content: values["content"], + folder: { + uid: this.state.folder.uid + }, + customer: { + uid: this.state.customer.uid + } + }; + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + + NoteService.createNote(noteData, validatorId).then(() => { + this.props.router.push(this.backwardPath); + }); } catch (error) { console.error(error); } diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/ClientBox/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/ClientBox/index.tsx index b456b35f..80c54530 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/ClientBox/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/ClientBox/index.tsx @@ -12,7 +12,8 @@ import { useCallback } from "react"; import { AnchorStatus } from "../.."; import classes from "./classes.module.scss"; import DeleteCustomerModal from "./DeleteCustomerModal"; -import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; + +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; type IProps = { customer: Customer; @@ -35,17 +36,25 @@ export default function ClientBox(props: IProps) { }, [customer.uid, folderUid]); const handleDelete = useCallback( - async (customerUid: string) => { - console.log(customer); - const documents = await Documents.getInstance().get({ where: { depositor_uid: customerUid, folder_uid: folderUid } }); - console.log(documents); + (customerUid: string) => { + DocumentService.getDocuments().then((processes: any[]) => { + if (processes.length > 0) { + let documents: any[] = processes.map((process: any) => process.processData); - if (documents && documents.length > 0) { - closeDeleteModal(); - openErrorModal(); - return; - } - props.onDelete(customerUid); + // FilterBy depositor_uid & folder_uid + documents = documents.filter((document: any) => document.depositor.uid === customerUid && document.folder.uid === folderUid); + + if (documents && documents.length > 0) { + closeDeleteModal(); + openErrorModal(); + return; + } + + props.onDelete(customerUid); + } else { + props.onDelete(customerUid); + } + }); }, [closeDeleteModal, customer.documents, openErrorModal, props, customer, folderUid], ); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx index e43a3e1d..86c332df 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteAskedDocumentModal/index.tsx @@ -1,9 +1,10 @@ -import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; import Modal from "@Front/Components/DesignSystem/Modal"; import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import React, { useCallback } from "react"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; + type IProps = { documentUid: string; isOpen: boolean; @@ -16,8 +17,14 @@ export default function DeleteAskedDocumentModal(props: IProps) { const onDelete = useCallback( () => - Documents.getInstance() - .delete(documentUid) + new Promise( + (resolve: () => void) => { + DocumentService.getDocumentByUid(documentUid).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { isDeleted: 'true' }).then(() => resolve()); + } + }); + }) .then(() => onDeleteSuccess(documentUid)) .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." })) .then(onClose) 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 26dd236c..421d3cfe 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -25,6 +25,8 @@ import DeleteSentDocumentModal from "./DeleteSentDocumentModal"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; +import MessageBus from "src/sdk/MessageBus"; + type IProps = { customerUid: string; folderUid: string; @@ -54,7 +56,9 @@ export default function DocumentTables(props: IProps) { const deleteSentDocumentModal = useOpenable(); const fetchDocuments = useCallback( - () => + () => { + setDocuments([]); + DocumentService.getDocuments().then(async (processes: any[]) => { if (processes.length > 0) { let documents: any[] = processes.map((process: any) => process.processData); @@ -62,24 +66,26 @@ export default function DocumentTables(props: IProps) { // FilterBy folder.uid & depositor.uid documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor.uid === customerUid); + const ps: any[] = await MessageBus.getInstance().getFiles(); + for (const document of documents) { const documentTypeUid: string = document.document_type.uid; - const p: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid); - document.document_type = p.processData; + const p1: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid); + document.document_type = p1.processData; + + const p2: any = ps.find((p2: any) => p2.processData.document.get('uid') === document.uid); + if (p2) { + document.files = [p2.processData]; + } } setDocuments(documents); + } else { + setDocuments([]); } }) - /* - Documents.getInstance() - .get({ - where: { folder: { uid: folderUid }, depositor: { uid: customerUid } }, - include: { files: true, document_type: true }, - }) - .then(setDocuments) - .catch(console.warn)*/, + }, [customerUid, folderUid], ); @@ -116,21 +122,23 @@ export default function DocumentTables(props: IProps) { [deleteSentDocumentModal], ); - const onDownload = useCallback((doc: Document) => { + const onDownload = useCallback((doc: any /* Document */) => { const file = doc.files?.[0]; - if (!file || !file?.uid) return; + if (!file) return; - return Files.getInstance() - .download(file.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.fileBlob.data], { type: file.fileBlob.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 onDownloadFileNotary = useCallback((doc: DocumentNotary) => { diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx index d599b1b0..b060b849 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/index.tsx @@ -7,14 +7,15 @@ import Customer from "le-coffre-resources/dist/Customer"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import Link from "next/link"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; import { AnchorStatus } from ".."; import classes from "./classes.module.scss"; import ClientBox from "./ClientBox"; import DocumentTables from "./DocumentTables"; import EmailReminder from "./EmailReminder"; -import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary"; + +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; type IProps = { folder: OfficeFolder; @@ -59,26 +60,21 @@ export default function ClientView(props: IProps) { ); const handleClientDelete = useCallback( - async (customerUid: string) => { + (customerUid: string) => { if (!folder.uid) return; - const documentsNotary = await DocumentsNotary.getInstance().get({ - where: { customer: { uid: customerUid }, folder: { uid: folder.uid } }, + + FolderService.getFolderByUid(folder.uid, false, false).then((process: any) => { + if (process) { + const folder: any = process.processData; + + // FilterBy customerUid + const customers = folder.customers.filter((uid: string) => uid !== customerUid); + + FolderService.updateFolder(process, { customers: customers }).then(() => { + window.location.reload(); + }); + } }); - - if (documentsNotary.length > 0) { - documentsNotary.forEach(async (doc) => { - await DocumentsNotary.getInstance().delete(doc.uid!); - }); - } - - Folders.getInstance().put( - folder.uid, - OfficeFolder.hydrate({ - ...folder, - customers: folder.customers?.filter((customer: any) => customer.uid !== customerUid), - }), - ); - window.location.reload(); }, [folder], ); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx index 2f60367f..00fcab8d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx @@ -1,4 +1,3 @@ -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; import Modal from "@Front/Components/DesignSystem/Modal"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Module from "@Front/Config/Module"; @@ -6,7 +5,7 @@ import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { useRouter } from "next/router"; import React, { useCallback } from "react"; -import MessageBus from "src/sdk/MessageBus"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; type IProps = { isOpen: boolean; @@ -23,16 +22,16 @@ export default function DeleteFolderModal(props: IProps) { if ((folder?.customers?.length ?? 0) > 0 || (folder?.documents?.length ?? 0) > 0) return console.warn("Cannot delete folder with customers or documents"); - /* TODO: review - return Folders.getInstance() - .delete(folder.uid) + return new Promise( + (resolve: () => void) => { + FolderService.getFolderByUid(folder.uid!).then((process: any) => { + if (process) { + FolderService.updateFolder(process, { isDeleted: 'true' }).then(() => resolve()); + } + }); + }) .then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)) .then(onClose); - */ - - MessageBus.getInstance().isReady().then(() => { - //MessageBus.getInstance().deleteFolder(folder.uid).then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)).then(onClose); - }); }, [folder, router, onClose]); return ( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 17730f3b..d08183bc 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -22,6 +22,7 @@ import NoClientView from "./NoClientView"; import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; +import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService"; export enum AnchorStatus { "VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN", @@ -109,7 +110,22 @@ export default function FolderInformation(props: IProps) { return FolderService.getFolderByUid(folderUid).then((process: any) => { if (process) { const folder: any = process.processData; - setFolder(folder); + + NoteService.getNotes().then((processes: any) => { + if (processes.length > 0) { + let notes: any[] = processes.map((process: any) => process.processData); + + // FilterBy folder.uid + notes = notes.filter((note: any) => note.folder.uid === folderUid); + + if (notes.length > 0) { + folder.notes = notes; + } + } + + setFolder(folder); + }); + } }); }, [folderUid]); diff --git a/src/front/Components/Layouts/Folder/UpdateCustomerNote/index.tsx b/src/front/Components/Layouts/Folder/UpdateCustomerNote/index.tsx index e3cd46c1..1ea2323e 100644 --- a/src/front/Components/Layouts/Folder/UpdateCustomerNote/index.tsx +++ b/src/front/Components/Layouts/Folder/UpdateCustomerNote/index.tsx @@ -11,7 +11,8 @@ import { NextRouter, useRouter } from "next/router"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; import Note from "le-coffre-resources/dist/Customer/Note"; -import Notes from "@Front/Api/LeCoffreApi/Customer/Notes/Notes"; + +import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService"; type IProps = {}; @@ -66,35 +67,33 @@ class UpdateCustomerNoteClass extends BasePage { } public override async componentDidMount() { - const query = { - q: { - customer: "true", - folder: "true", - }, - }; - const note = await Notes.getInstance().getByUid(this.props.noteUid, query); - // const folder = await Folders.getInstance().getByUid(this.props.folderUid, { note: true }); - //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); - this.setState({ - note, - backwardPath: Module.getInstance() - .get() - .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", note.folder?.uid!), + NoteService.getNoteByUid(this.props.noteUid).then((process: any) => { + if (process) { + const note: any = process.processData; + + // const folder = await Folders.getInstance().getByUid(this.props.folderUid, { note: true }); + //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); + this.setState({ + note, + backwardPath: Module.getInstance() + .get() + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", note.folder?.uid!), + }); + } }); } private async onFormSubmit(e: React.FormEvent | null, values: { [key: string]: string }) { try { - const note = { - content: values["content"], - }; + NoteService.getNoteByUid(this.props.noteUid).then((process: any) => { + if (process) { - await Notes.getInstance().put(this.props.noteUid, note); - this.props.router.push(this.state.backwardPath); - - // await Folders.getInstance().put(this.props.folderUid, values); - // this.props.router.push(this.backwardPath); + NoteService.updateNote(process, { content: values["content"] }).then(() => { + this.props.router.push(this.state.backwardPath); + }); + } + }); } catch (error) { console.error(error); } diff --git a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx index 09e7955a..6b661a2b 100644 --- a/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/ViewDocuments/index.tsx @@ -1,6 +1,5 @@ import LeftArrowIcon from "@Assets/Icons/left-arrow.svg"; import RightArrowIcon from "@Assets/Icons/right-arrow.svg"; -import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; import FilePreview from "@Front/Components/DesignSystem/FilePreview"; import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; @@ -15,12 +14,11 @@ import React from "react"; import BasePage from "../../Base"; import classes from "./classes.module.scss"; -import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files"; import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; 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 MessageBus from "src/sdk/MessageBus"; type IProps = {}; @@ -145,7 +143,7 @@ class ViewDocumentsClass extends BasePage { )} {this.state.document?.document_status === "VALIDATED" && this.state.fileBlob && ( - + )} @@ -217,16 +215,12 @@ class ViewDocumentsClass extends BasePage { 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 ps: any[] = await MessageBus.getInstance().getFiles(); + const p: any = ps.find((p: any) => p.processData.document.get('uid') === document.uid); + if (p) { - /* - const files: any[] = (await FileService.getFiles()) - .map((p: any) => p.processData) - .filter((file: any) => file.isDeleted === 'false'); - */ - - document.files = [process1.processData]; + document.files = [p.processData]; + } resolve(document); } @@ -282,24 +276,8 @@ class ViewDocumentsClass extends BasePage { 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); - const a = document.createElement("a"); - a.style.display = "none"; - a.href = url; - // the filename you want - a.download = this.state.selectedFile?.file_name as string; - document.body.appendChild(a); - a.click(); - window.URL.revokeObjectURL(url); - } - */ - private getRandomPercentageForOcr() { // find diff let difference = 100 - 90; @@ -360,15 +338,19 @@ class ViewDocumentsClass extends BasePage { private async refuseDocument() { try { - await Documents.getInstance().refuse(this.props.documentUid, this.state.refuseText); - - this.props.router.push( - Module.getInstance() - .get() - .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + - "?customerUid=" + - this.state.document?.depositor?.uid, - ); + DocumentService.getDocumentByUid(this.props.documentUid).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentStatus.REFUSED, refused_reason: this.state.refuseText }).then(() => { + this.props.router.push( + Module.getInstance() + .get() + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + + "?customerUid=" + + this.state.document?.depositor?.uid, + ); + }); + } + }); } catch (e) { console.error(e); } @@ -376,17 +358,19 @@ class ViewDocumentsClass extends BasePage { private async validateDocument() { try { - await Documents.getInstance().put(this.props.documentUid, { - document_status: EDocumentStatus.VALIDATED, + DocumentService.getDocumentByUid(this.props.documentUid).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentStatus.VALIDATED }).then(() => { + this.props.router.push( + Module.getInstance() + .get() + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + + "?customerUid=" + + this.state.document?.depositor?.uid, + ); + }); + } }); - - this.props.router.push( - Module.getInstance() - .get() - .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) + - "?customerUid=" + - this.state.document?.depositor?.uid, - ); } catch (e) { console.error(e); } diff --git a/src/sdk/MessageBus.ts b/src/sdk/MessageBus.ts index c2300889..fa491596 100644 --- a/src/sdk/MessageBus.ts +++ b/src/sdk/MessageBus.ts @@ -100,89 +100,6 @@ export default class MessageBus { }); } - public createFile(fileData: any, stakeholdersId: string[], customersId: string[]): Promise { - return new Promise((resolve: (processCreated: any) => void, reject: (error: string) => void) => { - this.checkToken().then(() => { - const messageId = `CREATE_FILE_${uuidv4()}`; - - const unsubscribe = EventBus.getInstance().on('PROCESS_CREATED', (responseId: string, processCreated: any) => { - if (responseId !== messageId) { - return; - } - unsubscribe(); - resolve(processCreated); - }); - - const unsubscribeError = EventBus.getInstance().on('ERROR_PROCESS_CREATED', (responseId: string, error: string) => { - if (responseId !== messageId) { - return; - } - unsubscribeError(); - reject(error); - }); - - const user = User.getInstance(); - const accessToken = user.getAccessToken()!; - - const ownerId = user.getPairingId()!; - const fileDataFields: string[] = Object.keys(fileData); - - this.sendMessage({ - type: 'CREATE_PROCESS', - processData: fileData, - privateFields: fileDataFields, - roles: { - demiurge: { - members: [ownerId], - validation_rules: [], - storages: [] - }, - owner: { - members: [ownerId], - validation_rules: [ - { - quorum: 0.5, - fields: [...fileDataFields, 'roles'], - min_sig_member: 1, - }, - ], - storages: [] - }, - stakeholders: { - members: stakeholdersId, - validation_rules: [ - { - quorum: 0.5, - fields: ['documents', 'motes'], - min_sig_member: 1, - }, - ], - storages: [] - }, - customers: { - members: customersId, - validation_rules: [ - { - quorum: 0.0, - fields: fileDataFields, - min_sig_member: 0.0, - }, - ], - storages: [] - }, - apophis: { - members: [ownerId], - validation_rules: [], - storages: [] - } - }, - accessToken, - messageId - }); - }).catch(console.error); - }); - } - public getFiles(): Promise { return new Promise((resolve: (files: any[]) => void, reject: (error: string) => void) => { this.getProcesses().then(async (processes: any) => {