Fix some bugs - continue

This commit is contained in:
Anthony Janin 2025-06-27 01:26:39 +02:00
parent f9abdd31cd
commit 39c14ff490
21 changed files with 335 additions and 486 deletions

View File

@ -25,6 +25,7 @@ export default class CustomerService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -78,12 +79,12 @@ export default class CustomerService {
} }
public static getCustomers(): Promise<any[]> { public static getCustomers(): Promise<any[]> {
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<any> { public static getCustomerByUid(uid: string): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -96,7 +97,7 @@ export default class CustomerService {
public static updateCustomer(process: any, newData: any): Promise<void> { public static updateCustomer(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -27,6 +27,7 @@ export default class DeedTypeService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -80,12 +81,12 @@ export default class DeedTypeService {
} }
public static getDeedTypes(): Promise<any[]> { public static getDeedTypes(): Promise<any[]> {
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<any> { public static getDeedTypeByUid(uid: string, includeDocumentTypes: boolean = true): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -112,7 +113,7 @@ export default class DeedTypeService {
public static updateDeedType(process: any, newData: any): Promise<void> { public static updateDeedType(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -25,6 +25,7 @@ export default class DocumentService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -78,12 +79,12 @@ export default class DocumentService {
} }
public static getDocuments(): Promise<any[]> { public static getDocuments(): Promise<any[]> {
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<any> { public static getDocumentByUid(uid: string): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -96,7 +97,7 @@ export default class DocumentService {
public static updateDocument(process: any, newData: any): Promise<void> { public static updateDocument(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -25,6 +25,7 @@ export default class DocumentTypeService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -78,12 +79,12 @@ export default class DocumentTypeService {
} }
public static getDocumentTypes(): Promise<any[]> { public static getDocumentTypes(): Promise<any[]> {
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<any> { public static getDocumentTypeByUid(uid: string): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -96,7 +97,7 @@ export default class DocumentTypeService {
public static updateDocumentType(process: any, newData: any): Promise<void> { public static updateDocumentType(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -25,6 +25,7 @@ export default class FileService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -78,12 +79,12 @@ export default class FileService {
} }
public static getFiles(): Promise<any[]> { public static getFiles(): Promise<any[]> {
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<any> { public static getFileByUid(uid: string): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -96,7 +97,7 @@ export default class FileService {
public static updateFile(process: any, newData: any): Promise<void> { public static updateFile(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -28,6 +28,7 @@ export default class FolderService {
const privateFields: string[] = Object.keys(processData); const privateFields: string[] = Object.keys(processData);
privateFields.splice(privateFields.indexOf('uid'), 1); privateFields.splice(privateFields.indexOf('uid'), 1);
privateFields.splice(privateFields.indexOf('utype'), 1); privateFields.splice(privateFields.indexOf('utype'), 1);
privateFields.splice(privateFields.indexOf('isDeleted'), 1);
const roles: any = { const roles: any = {
demiurge: { demiurge: {
@ -87,12 +88,12 @@ export default class FolderService {
} }
public static getFolders(): Promise<any[]> { public static getFolders(): Promise<any[]> {
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<any> { public static getFolderByUid(uid: string, includeCustomers: boolean = true, includeDeedType: boolean = true): Promise<any> {
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => { return new Promise<any>((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) { if (processes.length === 0) {
resolve(null); resolve(null);
} else { } else {
@ -124,7 +125,7 @@ export default class FolderService {
public static updateFolder(process: any, newData: any): Promise<void> { public static updateFolder(process: any, newData: any): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (error: string) => void) => { return new Promise<void>((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; const newStateId: string = processUpdated.diffs[0]?.state_id;
this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { this.messageBus.notifyUpdate(process.processId, newStateId).then(() => {
this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => {

View File

@ -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<any> {
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<any>((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<any[]> {
return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'note' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false');
}
public static getNoteByUid(uid: string): Promise<any> {
return new Promise<any>((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<void> {
return new Promise<void>((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);
});
}
}

View File

@ -4,7 +4,6 @@ import { Document } from "le-coffre-resources/dist/Customer";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useMemo, useState } from "react";
import classes from "./classes.module.scss"; 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 { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
@ -93,21 +92,19 @@ export default function DepositDocumentComponent(props: IProps) {
(resolve: () => void) => { (resolve: () => void) => {
FileService.getFileByUid(filedUid).then((process: any) => { FileService.getFileByUid(filedUid).then((process: any) => {
if (process) { 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(onChange)
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" })) .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier supprimé avec succès!" }))
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message })); .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], [onChange],
); );

View File

@ -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<File | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!isOpen) {
setSelectedFile(null);
if (fileInputRef.current) {
fileInputRef.current.value = '';
}
}
}, [isOpen]);
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
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 (
<Modal
isOpen={isOpen}
onClose={onClose}
title='Ajouter un document'
>
<div style={{ padding: '20px 0' }}>
<div style={{ marginBottom: '20px' }}>
<Typography typo={ETypo.TEXT_MD_SEMIBOLD} className="mb-2">
Document
</Typography>
<div style={{ display: 'flex', alignItems: 'center' }}>
<input
ref={fileInputRef}
type="file"
accept="application/pdf"
onChange={handleFileChange}
style={{ display: 'none' }}
/>
<Button
variant={EButtonVariant.SECONDARY}
styletype={EButtonstyletype.OUTLINED}
onClick={handleButtonClick}
>
Sélectionner un fichier PDF
</Button>
{selectedFile && (
<div className="ml-3">
<Typography typo={ETypo.TEXT_MD_REGULAR}>
{selectedFile.name}
</Typography>
</div>
)}
</div>
</div>
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: '12px', marginTop: '20px' }}>
<Button
variant={EButtonVariant.SECONDARY}
styletype={EButtonstyletype.OUTLINED}
onClick={onClose}
>
Annuler
</Button>
<Button
variant={EButtonVariant.PRIMARY}
styletype={EButtonstyletype.CONTAINED}
onClick={() => selectedFile && onSubmit(selectedFile)}
disabled={!selectedFile}
>
Enregistrer
</Button>
</div>
</div>
</Modal>
);
}

View File

@ -26,7 +26,6 @@ import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentN
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument"; import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
import AuthModal from "src/sdk/AuthModal"; import AuthModal from "src/sdk/AuthModal";
//import FormModal from "./FormModal";
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
@ -47,11 +46,15 @@ export default function ClientDashboard(props: IProps) {
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false); const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
//const [isFormModalOpen, setIsFormModalOpen] = useState(false);
const fetchFolderAndCustomer = useCallback(async () => { const fetchFolderAndCustomer = useCallback(async () => {
let jwt: ICustomerJwtPayload | undefined;
if (typeof document !== "undefined") {
jwt = JwtService.getInstance().decodeCustomerJwt();
}
// TODO: review // TODO: review
const { folder, customer, file } = await new Promise<any>((resolve) => { const { folder, customer } = await new Promise<any>((resolve) => {
FolderService.getFolderByUid(folderUid as string).then((process: any) => { FolderService.getFolderByUid(folderUid as string).then((process: any) => {
if (process) { if (process) {
const folder: any = process.processData; 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<any>((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); setCustomer(customer);
@ -101,11 +76,6 @@ export default function ClientDashboard(props: IProps) {
return { folder, customer }; return { folder, customer };
/* /*
let jwt: ICustomerJwtPayload | undefined;
if (typeof document !== "undefined") {
jwt = JwtService.getInstance().decodeCustomerJwt();
}
const folder = await Folders.getInstance().getByUid(folderUid as string, { const folder = await Folders.getInstance().getByUid(folderUid as string, {
q: { q: {
office: true, office: true,
@ -140,7 +110,7 @@ export default function ClientDashboard(props: IProps) {
}, [folderUid]); }, [folderUid]);
const fetchDocuments = useCallback( const fetchDocuments = useCallback(
(customerUid: string | undefined) => { async (customerUid: string | undefined) => {
/* /*
const query: IGetDocumentsparams = { const query: IGetDocumentsparams = {
where: { depositor: { uid: customerUid }, folder_uid: folderUid as string }, where: { depositor: { uid: customerUid }, folder_uid: folderUid as string },
@ -166,15 +136,14 @@ export default function ClientDashboard(props: IProps) {
.then((documents) => setDocuments(documents)); .then((documents) => setDocuments(documents));
*/ */
const files: any[] = (await FileService.getFiles()).map((p: any) => p.processData);
return DocumentService.getDocuments().then(async (processes: any[]) => { return DocumentService.getDocuments().then(async (processes: any[]) => {
if (processes.length > 0) { 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()) // FilterBy folder_uid
.map((p: any) => p.processData) documents = documents.filter((document: any) => document.folder.uid === folderUid);
.filter((file: any) => file.isDeleted === 'false');
// TODO: review - customerUid
for (const document of documents) { for (const document of documents) {
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid); const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
@ -222,23 +191,6 @@ export default function ClientDashboard(props: IProps) {
setIsAddDocumentModalVisible(true); 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(() => { const renderBox = useCallback(() => {
return ( return (
<DepositOtherDocument <DepositOtherDocument
@ -267,19 +219,6 @@ export default function ClientDashboard(props: IProps) {
<Typography typo={ETypo.TITLE_H4} color={ETypoColor.TEXT_PRIMARY}> <Typography typo={ETypo.TITLE_H4} color={ETypoColor.TEXT_PRIMARY}>
Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)} Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)}
</Typography> </Typography>
{/*
{file && (
<Button
variant={EButtonVariant.SECONDARY}
styletype={EButtonstyletype.OUTLINED}
onClick={() => onDownloadFile()}
>
Télécharger le document
</Button>
)}
*/}
<Tag color={ETagColor.INFO} label={folder?.deed?.deed_type?.name ?? ""} /> <Tag color={ETagColor.INFO} label={folder?.deed?.deed_type?.name ?? ""} />
<div className={classes["office-container"]}> <div className={classes["office-container"]}>
<Typography typo={ETypo.TEXT_MD_REGULAR} color={ETypoColor.TEXT_SECONDARY}> <Typography typo={ETypo.TEXT_MD_REGULAR} color={ETypoColor.TEXT_SECONDARY}>
@ -372,57 +311,8 @@ export default function ClientDashboard(props: IProps) {
isOpen={isAuthModalOpen} isOpen={isAuthModalOpen}
onClose={() => { onClose={() => {
setIsAuthModalOpen(false); setIsAuthModalOpen(false);
/*
setTimeout(() => {
setIsFormModalOpen(true);
}, 500);
*/
}} }}
/>} />}
{/*
<FormModal
isOpen={isFormModalOpen}
onClose={() => 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);
}
}}
/>
*/}
</div> </div>
</DefaultCustomerDashboard> </DefaultCustomerDashboard>
); );

View File

@ -1,6 +1,5 @@
import ChevronIcon from "@Assets/Icons/chevron.svg"; import ChevronIcon from "@Assets/Icons/chevron.svg";
import PenICon from "@Assets/Icons/pen.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 Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/DropdownOption"; import { IOption } from "@Front/Components/DesignSystem/Dropdown/DropdownMenu/DropdownOption";
import Form from "@Front/Components/DesignSystem/Form"; import Form from "@Front/Components/DesignSystem/Form";
@ -51,14 +50,13 @@ export default function DeedTypesInformations(props: IProps) {
}, []); }, []);
const deleteDeedType = useCallback(async () => { const deleteDeedType = useCallback(async () => {
await DeedTypes.getInstance().put( DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => {
deedTypeUid as string, if (process) {
DeedType.hydrate<DeedType>({ DeedTypeService.updateDeedType(process, { archived_at: new Date().toISOString() }).then(() => {
uid: deedTypeUid as string,
archived_at: new Date(),
}),
);
router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path); router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path);
});
}
});
}, [deedTypeUid, router]); }, [deedTypeUid, router]);
useEffect(() => { useEffect(() => {
@ -119,7 +117,6 @@ export default function DeedTypesInformations(props: IProps) {
DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => { DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => {
closeSaveModal(); closeSaveModal();
}); });
} }
}); });
}, [closeSaveModal, deedTypeUid, selectedDocuments]); }, [closeSaveModal, deedTypeUid, selectedDocuments]);

View File

@ -13,10 +13,10 @@ import BasePage from "../../Base";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import Customer from "le-coffre-resources/dist/Customer"; import Customer from "le-coffre-resources/dist/Customer";
import Note from "le-coffre-resources/dist/Customer/Note"; 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 FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService"; import CustomerService from "src/common/Api/LeCoffreApi/sdk/CustomerService";
import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService";
type IProps = {}; type IProps = {};
@ -108,14 +108,22 @@ class CreateCustomerNoteClass extends BasePage<IPropsClass, IState> {
if (!this.state.folder || !this.state.customer) { if (!this.state.folder || !this.state.customer) {
throw new Error("Folder or customer not found"); 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); // 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); this.props.router.push(this.backwardPath);
});
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }

View File

@ -12,7 +12,8 @@ import { useCallback } from "react";
import { AnchorStatus } from "../.."; import { AnchorStatus } from "../..";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import DeleteCustomerModal from "./DeleteCustomerModal"; import DeleteCustomerModal from "./DeleteCustomerModal";
import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
type IProps = { type IProps = {
customer: Customer; customer: Customer;
@ -35,17 +36,25 @@ export default function ClientBox(props: IProps) {
}, [customer.uid, folderUid]); }, [customer.uid, folderUid]);
const handleDelete = useCallback( const handleDelete = useCallback(
async (customerUid: string) => { (customerUid: string) => {
console.log(customer); DocumentService.getDocuments().then((processes: any[]) => {
const documents = await Documents.getInstance().get({ where: { depositor_uid: customerUid, folder_uid: folderUid } }); if (processes.length > 0) {
console.log(documents); let documents: any[] = processes.map((process: any) => process.processData);
// FilterBy depositor_uid & folder_uid
documents = documents.filter((document: any) => document.depositor.uid === customerUid && document.folder.uid === folderUid);
if (documents && documents.length > 0) { if (documents && documents.length > 0) {
closeDeleteModal(); closeDeleteModal();
openErrorModal(); openErrorModal();
return; return;
} }
props.onDelete(customerUid); props.onDelete(customerUid);
} else {
props.onDelete(customerUid);
}
});
}, },
[closeDeleteModal, customer.documents, openErrorModal, props, customer, folderUid], [closeDeleteModal, customer.documents, openErrorModal, props, customer, folderUid],
); );

View File

@ -1,9 +1,10 @@
import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents";
import Modal from "@Front/Components/DesignSystem/Modal"; import Modal from "@Front/Components/DesignSystem/Modal";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster"; import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
import React, { useCallback } from "react"; import React, { useCallback } from "react";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
type IProps = { type IProps = {
documentUid: string; documentUid: string;
isOpen: boolean; isOpen: boolean;
@ -16,8 +17,14 @@ export default function DeleteAskedDocumentModal(props: IProps) {
const onDelete = useCallback( const onDelete = useCallback(
() => () =>
Documents.getInstance() new Promise<void>(
.delete(documentUid) (resolve: () => void) => {
DocumentService.getDocumentByUid(documentUid).then((process: any) => {
if (process) {
DocumentService.updateDocument(process, { isDeleted: 'true' }).then(() => resolve());
}
});
})
.then(() => onDeleteSuccess(documentUid)) .then(() => onDeleteSuccess(documentUid))
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." })) .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." }))
.then(onClose) .then(onClose)

View File

@ -25,6 +25,8 @@ import DeleteSentDocumentModal from "./DeleteSentDocumentModal";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
import MessageBus from "src/sdk/MessageBus";
type IProps = { type IProps = {
customerUid: string; customerUid: string;
folderUid: string; folderUid: string;
@ -54,7 +56,9 @@ export default function DocumentTables(props: IProps) {
const deleteSentDocumentModal = useOpenable(); const deleteSentDocumentModal = useOpenable();
const fetchDocuments = useCallback( const fetchDocuments = useCallback(
() => () => {
setDocuments([]);
DocumentService.getDocuments().then(async (processes: any[]) => { DocumentService.getDocuments().then(async (processes: any[]) => {
if (processes.length > 0) { if (processes.length > 0) {
let documents: any[] = processes.map((process: any) => process.processData); let documents: any[] = processes.map((process: any) => process.processData);
@ -62,24 +66,26 @@ export default function DocumentTables(props: IProps) {
// FilterBy folder.uid & depositor.uid // FilterBy folder.uid & depositor.uid
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor.uid === customerUid); 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) { for (const document of documents) {
const documentTypeUid: string = document.document_type.uid; const documentTypeUid: string = document.document_type.uid;
const p: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid); const p1: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid);
document.document_type = p.processData; 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); 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], [customerUid, folderUid],
); );
@ -116,21 +122,23 @@ export default function DocumentTables(props: IProps) {
[deleteSentDocumentModal], [deleteSentDocumentModal],
); );
const onDownload = useCallback((doc: Document) => { const onDownload = useCallback((doc: any /* Document */) => {
const file = doc.files?.[0]; const file = doc.files?.[0];
if (!file || !file?.uid) return; if (!file) return;
return Files.getInstance() return new Promise<void>((resolve: () => void) => {
.download(file.uid) const blob = new Blob([file.fileBlob.data], { type: file.fileBlob.type });
.then((blob) => {
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const a = document.createElement("a"); const a = document.createElement('a');
a.href = url; a.href = url;
a.download = file.file_name ?? "file"; a.download = file.file_name;
document.body.appendChild(a);
a.click(); a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
})
.catch((e) => console.warn(e)); resolve();
}).catch((e) => console.warn(e));
}, []); }, []);
const onDownloadFileNotary = useCallback((doc: DocumentNotary) => { const onDownloadFileNotary = useCallback((doc: DocumentNotary) => {

View File

@ -7,14 +7,15 @@ import Customer from "le-coffre-resources/dist/Customer";
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { OfficeFolder } from "le-coffre-resources/dist/Notary";
import Link from "next/link"; import Link from "next/link";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useMemo, useState } from "react";
import { AnchorStatus } from ".."; import { AnchorStatus } from "..";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import ClientBox from "./ClientBox"; import ClientBox from "./ClientBox";
import DocumentTables from "./DocumentTables"; import DocumentTables from "./DocumentTables";
import EmailReminder from "./EmailReminder"; import EmailReminder from "./EmailReminder";
import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary";
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
type IProps = { type IProps = {
folder: OfficeFolder; folder: OfficeFolder;
@ -59,26 +60,21 @@ export default function ClientView(props: IProps) {
); );
const handleClientDelete = useCallback( const handleClientDelete = useCallback(
async (customerUid: string) => { (customerUid: string) => {
if (!folder.uid) return; if (!folder.uid) return;
const documentsNotary = await DocumentsNotary.getInstance().get({
where: { customer: { uid: customerUid }, folder: { uid: folder.uid } },
});
if (documentsNotary.length > 0) { FolderService.getFolderByUid(folder.uid, false, false).then((process: any) => {
documentsNotary.forEach(async (doc) => { if (process) {
await DocumentsNotary.getInstance().delete(doc.uid!); 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();
}); });
} }
});
Folders.getInstance().put(
folder.uid,
OfficeFolder.hydrate<OfficeFolder>({
...folder,
customers: folder.customers?.filter((customer: any) => customer.uid !== customerUid),
}),
);
window.location.reload();
}, },
[folder], [folder],
); );

View File

@ -1,4 +1,3 @@
import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders";
import Modal from "@Front/Components/DesignSystem/Modal"; import Modal from "@Front/Components/DesignSystem/Modal";
import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography";
import Module from "@Front/Config/Module"; import Module from "@Front/Config/Module";
@ -6,7 +5,7 @@ import { OfficeFolder } from "le-coffre-resources/dist/Notary";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import React, { useCallback } from "react"; import React, { useCallback } from "react";
import MessageBus from "src/sdk/MessageBus"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
type IProps = { type IProps = {
isOpen: boolean; isOpen: boolean;
@ -23,16 +22,16 @@ export default function DeleteFolderModal(props: IProps) {
if ((folder?.customers?.length ?? 0) > 0 || (folder?.documents?.length ?? 0) > 0) if ((folder?.customers?.length ?? 0) > 0 || (folder?.documents?.length ?? 0) > 0)
return console.warn("Cannot delete folder with customers or documents"); return console.warn("Cannot delete folder with customers or documents");
/* TODO: review return new Promise<void>(
return Folders.getInstance() (resolve: () => void) => {
.delete(folder.uid) 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(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path))
.then(onClose); .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]); }, [folder, router, onClose]);
return ( return (

View File

@ -22,6 +22,7 @@ import NoClientView from "./NoClientView";
import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo"; import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService";
export enum AnchorStatus { export enum AnchorStatus {
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN", "VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
@ -109,7 +110,22 @@ export default function FolderInformation(props: IProps) {
return FolderService.getFolderByUid(folderUid).then((process: any) => { return FolderService.getFolderByUid(folderUid).then((process: any) => {
if (process) { if (process) {
const folder: any = process.processData; const folder: any = process.processData;
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); setFolder(folder);
});
} }
}); });
}, [folderUid]); }, [folderUid]);

View File

@ -11,7 +11,8 @@ import { NextRouter, useRouter } from "next/router";
import BasePage from "../../Base"; import BasePage from "../../Base";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import Note from "le-coffre-resources/dist/Customer/Note"; 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 = {}; type IProps = {};
@ -66,13 +67,10 @@ class UpdateCustomerNoteClass extends BasePage<IPropsClass, IState> {
} }
public override async componentDidMount() { public override async componentDidMount() {
const query = { NoteService.getNoteByUid(this.props.noteUid).then((process: any) => {
q: { if (process) {
customer: "true", const note: any = process.processData;
folder: "true",
},
};
const note = await Notes.getInstance().getByUid(this.props.noteUid, query);
// const folder = await Folders.getInstance().getByUid(this.props.folderUid, { note: true }); // 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 //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); // const folderNote = folder.notes?.find((note) => note.customer?.uid === this.props.customerUid);
@ -83,18 +81,19 @@ class UpdateCustomerNoteClass extends BasePage<IPropsClass, IState> {
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", note.folder?.uid!), .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", note.folder?.uid!),
}); });
} }
});
}
private async onFormSubmit(e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) { private async onFormSubmit(e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) {
try { try {
const note = { NoteService.getNoteByUid(this.props.noteUid).then((process: any) => {
content: values["content"], if (process) {
};
await Notes.getInstance().put(this.props.noteUid, note); NoteService.updateNote(process, { content: values["content"] }).then(() => {
this.props.router.push(this.state.backwardPath); this.props.router.push(this.state.backwardPath);
});
// await Folders.getInstance().put(this.props.folderUid, values); }
// this.props.router.push(this.backwardPath); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }

View File

@ -1,6 +1,5 @@
import LeftArrowIcon from "@Assets/Icons/left-arrow.svg"; import LeftArrowIcon from "@Assets/Icons/left-arrow.svg";
import RightArrowIcon from "@Assets/Icons/right-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 Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button";
import FilePreview from "@Front/Components/DesignSystem/FilePreview"; import FilePreview from "@Front/Components/DesignSystem/FilePreview";
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm"; import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
@ -15,12 +14,11 @@ import React from "react";
import BasePage from "../../Base"; import BasePage from "../../Base";
import classes from "./classes.module.scss"; import classes from "./classes.module.scss";
import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
import MessageBox from "@Front/Components/Elements/MessageBox"; import MessageBox from "@Front/Components/Elements/MessageBox";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
import MessageBus from "src/sdk/MessageBus"; import MessageBus from "src/sdk/MessageBus";
type IProps = {}; type IProps = {};
@ -217,16 +215,12 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
if (process) { if (process) {
const document: any = process.processData; const document: any = process.processData;
const processes: any[] = await MessageBus.getInstance().getFiles(); const ps: any[] = await MessageBus.getInstance().getFiles();
const process1: any = processes.find((process: any) => process.processData.document.get('uid') === document.uid); const p: any = ps.find((p: any) => p.processData.document.get('uid') === document.uid);
if (p) {
/* document.files = [p.processData];
const files: any[] = (await FileService.getFiles()) }
.map((p: any) => p.processData)
.filter((file: any) => file.isDeleted === 'false');
*/
document.files = [process1.processData];
resolve(document); resolve(document);
} }
@ -282,24 +276,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
a.click(); a.click();
document.body.removeChild(a); document.body.removeChild(a);
URL.revokeObjectURL(url); 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() { private getRandomPercentageForOcr() {
// find diff // find diff
let difference = 100 - 90; let difference = 100 - 90;
@ -360,8 +338,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
private async refuseDocument() { private async refuseDocument() {
try { try {
await Documents.getInstance().refuse(this.props.documentUid, this.state.refuseText); 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( this.props.router.push(
Module.getInstance() Module.getInstance()
.get() .get()
@ -369,6 +348,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
"?customerUid=" + "?customerUid=" +
this.state.document?.depositor?.uid, this.state.document?.depositor?.uid,
); );
});
}
});
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@ -376,10 +358,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
private async validateDocument() { private async validateDocument() {
try { try {
await Documents.getInstance().put(this.props.documentUid, { DocumentService.getDocumentByUid(this.props.documentUid).then((process: any) => {
document_status: EDocumentStatus.VALIDATED, if (process) {
}); DocumentService.updateDocument(process, { document_status: EDocumentStatus.VALIDATED }).then(() => {
this.props.router.push( this.props.router.push(
Module.getInstance() Module.getInstance()
.get() .get()
@ -387,6 +368,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
"?customerUid=" + "?customerUid=" +
this.state.document?.depositor?.uid, this.state.document?.depositor?.uid,
); );
});
}
});
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -100,89 +100,6 @@ export default class MessageBus {
}); });
} }
public createFile(fileData: any, stakeholdersId: string[], customersId: string[]): Promise<any> {
return new Promise<any>((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<any> { public getFiles(): Promise<any> {
return new Promise<any>((resolve: (files: any[]) => void, reject: (error: string) => void) => { return new Promise<any>((resolve: (files: any[]) => void, reject: (error: string) => void) => {
this.getProcesses().then(async (processes: any) => { this.getProcesses().then(async (processes: any) => {