From d4f51cec5ff2fa104ac4319cd00d89260be3a344 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Thu, 31 Jul 2025 11:39:34 +0200 Subject: [PATCH] Fix some issues --- .../Api/LeCoffreApi/sdk/AbstractService.ts | 2 +- .../LeCoffreApi/sdk/CollaboratorService.ts | 136 +++++++++++++++--- .../Api/LeCoffreApi/sdk/CustomerService.ts | 2 +- .../Api/LeCoffreApi/sdk/DeedTypeService.ts | 101 +++++++++---- .../Api/LeCoffreApi/sdk/DocumentService.ts | 6 +- .../LeCoffreApi/sdk/DocumentTypeService.ts | 2 +- src/common/Api/LeCoffreApi/sdk/FileService.ts | 4 +- .../Api/LeCoffreApi/sdk/FolderService.ts | 112 +++++++++++++-- src/common/Api/LeCoffreApi/sdk/NoteService.ts | 2 +- .../Api/LeCoffreApi/sdk/OfficeRibService.ts | 2 +- .../Api/LeCoffreApi/sdk/OfficeRoleService.ts | 2 +- .../Api/LeCoffreApi/sdk/OfficeService.ts | 2 +- src/common/Api/LeCoffreApi/sdk/RoleService.ts | 2 +- .../Api/LeCoffreApi/sdk/RuleGroupService.ts | 2 +- src/common/Api/LeCoffreApi/sdk/RuleService.ts | 2 +- .../DesignSystem/LogOutButton/index.tsx | 1 - .../DefaultCollaboratorDashboard/index.tsx | 2 +- .../DefaultCustomerDashboard/index.tsx | 8 +- .../DefaultDeedTypeDashboard/index.tsx | 19 +-- .../DefaultNotaryDashboard/index.tsx | 2 +- .../DefaultOfficeDashboard/index.tsx | 29 ++-- .../DefaultUserDashboard/index.tsx | 40 +++--- .../DepositDocumentComponent/index.tsx | 6 +- .../Layouts/ClientDashboard/index.tsx | 75 +--------- .../DeedTypes/DeedTypesInformations/index.tsx | 2 +- .../Layouts/Folder/CreateFolder/index.tsx | 4 +- .../DeleteAskedDocumentModal/index.tsx | 6 +- .../DeleteSentDocumentModal/index.tsx | 5 +- .../ClientView/DocumentTables/index.tsx | 7 +- .../NoClientView/DeleteFolderModal/index.tsx | 2 +- .../elements/AnchoringAlertInfo/index.tsx | 6 +- .../elements/ArchiveAlertWarning/index.tsx | 20 ++- .../elements/ArchiveModal/index.tsx | 23 +-- .../Folder/FolderInformation/index.tsx | 13 +- .../Layouts/Folder/SendDocuments/index.tsx | 2 +- src/front/Components/Layouts/Folder/index.tsx | 6 +- .../Layouts/LoginCallback/index.tsx | 28 ++-- .../Offices/OfficeInformations/index.tsx | 33 +++-- .../Components/Layouts/SelectFolder/index.tsx | 2 +- .../Layouts/Users/UserInformations/index.tsx | 40 ++++-- 40 files changed, 484 insertions(+), 276 deletions(-) diff --git a/src/common/Api/LeCoffreApi/sdk/AbstractService.ts b/src/common/Api/LeCoffreApi/sdk/AbstractService.ts index c8224c89..a045da9d 100644 --- a/src/common/Api/LeCoffreApi/sdk/AbstractService.ts +++ b/src/common/Api/LeCoffreApi/sdk/AbstractService.ts @@ -6,7 +6,7 @@ export default abstract class AbstractService { protected static readonly messageBus: MessageBus = MessageBus.getInstance(); - private static readonly CACHE_TTL = 45 * 60 * 1000; // 45 minutes cache TTL + private static readonly CACHE_TTL = 60 * 60 * 1000; // 60 minutes cache TTL protected constructor() { } diff --git a/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts index 76fed7b9..809fde98 100644 --- a/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts +++ b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts @@ -23,7 +23,7 @@ export default class CollaboratorService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...collaboratorData, + ...collaboratorData }; const privateFields: string[] = Object.keys(processData); @@ -82,11 +82,14 @@ export default class CollaboratorService extends AbstractService { }); } - public static getCollaborators(): Promise { + public static getCollaborators(callback: (processes: any[]) => void, waitForAll: boolean = false): void { // Check if we have valid cache const items: any[] = this.getItems('_collaborators_'); + if (items.length > 0 && !waitForAll) { + setTimeout(() => callback([...items]), 0); + } - return this.messageBus.getProcessesDecoded((publicValues: any) => + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'collaborator' && @@ -95,18 +98,101 @@ export default class CollaboratorService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { - return items; - } else { - for (let process of processes) { - process = await this.completeCollaborator(process); - - // Update cache - this.setItem('_collaborators_', process); - - items.push(process); - } - return items; + return; } + + const updatedItems: any[] = [...items]; + + for (let processIndex = 0; processIndex < processes.length; processIndex++) { + let process = processes[processIndex]; + + if (!waitForAll) { + process = await this.completeCollaborator(process, (processInProgress: any) => { + const currentItems: any[] = [...updatedItems]; + + const existingIndex: number = currentItems.findIndex(item => item.processData?.uid === processInProgress.processData?.uid); + if (existingIndex >= 0) { + currentItems[existingIndex] = processInProgress; + } else { + currentItems.push(processInProgress); + } + + callback(currentItems); + }); + } else { + process = await this.completeCollaborator(process); + } + + // Update cache + this.setItem('_collaborators_', process); + + const existingIndex: number = updatedItems.findIndex(item => item.processData?.uid === process.processData?.uid); + if (existingIndex >= 0) { + updatedItems[existingIndex] = process; + } else { + updatedItems.push(process); + } + + if (!waitForAll) { + callback([...updatedItems]); + } + } + + if (waitForAll) { + callback([...updatedItems]); + } + }); + } + + public static getCollaboratorsBy(whereClause: { [path: string]: any }): Promise { + return new Promise((resolve: (collaborators: any[]) => void) => { + this.getCollaborators((processes: any[]) => { + resolve(processes.length > 0 ? processes.map((process: any) => process.processData).filter((collaborator: any) => { + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = collaborator; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; + } + } + return true; + }) : []); + }, true); + }); + } + + public static getCollaboratorBy(whereClause: { [path: string]: any }): Promise { + return new Promise((resolve: (collaborator: any | null) => void) => { + this.getCollaborators((processes: any[]) => { + resolve(processes.length > 0 ? processes.map((process: any) => process.processData).find((collaborator: any) => { + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = collaborator; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; + } + } + return true; + }) : null); + }, true); }); } @@ -157,15 +243,23 @@ export default class CollaboratorService extends AbstractService { }); } - private static async completeCollaborator(process: any): Promise { + private static async completeCollaborator(process: any, progressCallback?: (processInProgress: any) => void): Promise { + const progressiveProcess: any = JSON.parse(JSON.stringify(process)); + if (process.processData.office) { const office: any = (await OfficeService.getOfficeByUid(process.processData.office.uid)).processData; process.processData.office = { uid: office.uid, idNot: office.idNot, crpcen: office.crpcen, + name: office.name, office_status: office.office_status }; + + if (progressCallback) { + progressiveProcess.processData.office = process.processData.office; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } if (process.processData.role) { @@ -174,6 +268,11 @@ export default class CollaboratorService extends AbstractService { uid: role.uid, name: role.name }; + + if (progressCallback) { + progressiveProcess.processData.role = process.processData.role; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } if (process.processData.office_role) { @@ -181,13 +280,18 @@ export default class CollaboratorService extends AbstractService { process.processData.office_role = { uid: officeRole.uid, name: officeRole.name, - rules: officeRole.rules.map((rule: any) => { + rules: officeRole.rules?.map((rule: any) => { return { uid: rule.uid, name: rule.name }; }) }; + + if (progressCallback) { + progressiveProcess.processData.office_role = process.processData.office_role; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } return process; diff --git a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts index 5fecb25f..601cab38 100644 --- a/src/common/Api/LeCoffreApi/sdk/CustomerService.ts +++ b/src/common/Api/LeCoffreApi/sdk/CustomerService.ts @@ -19,7 +19,7 @@ export default class CustomerService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...customerData, + ...customerData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts index 722bb126..12cd9d71 100644 --- a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts @@ -3,6 +3,7 @@ import { v4 as uuidv4 } from 'uuid'; import User from 'src/sdk/User'; import AbstractService from './AbstractService'; + import DocumentTypeService from './DocumentTypeService'; export default class DeedTypeService extends AbstractService { @@ -20,7 +21,7 @@ export default class DeedTypeService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...deedTypeData, + ...deedTypeData }; const privateFields: string[] = Object.keys(processData); @@ -79,11 +80,14 @@ export default class DeedTypeService extends AbstractService { }); } - public static getDeedTypes(): Promise { + public static getDeedTypes(callback: (processes: any[]) => void, waitForAll: boolean = false): void { // Check if we have valid cache const items: any[] = this.getItems('_deed_types_'); + if (items.length > 0 && !waitForAll) { + setTimeout(() => callback([...items]), 0); + } - return this.messageBus.getProcessesDecoded((publicValues: any) => + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'deedType' && @@ -91,22 +95,53 @@ export default class DeedTypeService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { - return items; - } else { - for (let process of processes) { + return; + } + + const updatedItems: any[] = [...items]; + + for (let processIndex = 0; processIndex < processes.length; processIndex++) { + let process = processes[processIndex]; + + if (!waitForAll) { + process = await this.completeDeedType(process, (processInProgress: any) => { + const currentItems: any[] = [...updatedItems]; + + const existingIndex: number = currentItems.findIndex(item => item.processData?.uid === processInProgress.processData?.uid); + if (existingIndex >= 0) { + currentItems[existingIndex] = processInProgress; + } else { + currentItems.push(processInProgress); + } + + callback(currentItems); + }); + } else { process = await this.completeDeedType(process); - - // Update cache - this.setItem('_deed_types_', process); - - items.push(process); } - return items; + + // Update cache + this.setItem('_deed_types_', process); + + const existingIndex: number = updatedItems.findIndex(item => item.processData?.uid === process.processData?.uid); + if (existingIndex >= 0) { + updatedItems[existingIndex] = process; + } else { + updatedItems.push(process); + } + + if (!waitForAll) { + callback([...updatedItems]); + } + } + + if (waitForAll) { + callback([...updatedItems]); } }); } - public static getDeedTypeByUid(uid: string, includeDocumentTypes: boolean = true): Promise { + public static getDeedTypeByUid(uid: string): Promise { // Check if we have valid cache const item: any = this.getItem('_deed_types_', uid); if (item) { @@ -114,7 +149,14 @@ export default class DeedTypeService extends AbstractService { } 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' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').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 { @@ -146,20 +188,31 @@ export default class DeedTypeService extends AbstractService { }); } - private static async completeDeedType(process: any): Promise { + private static async completeDeedType(process: any, progressCallback?: (processInProgress: any) => void): Promise { + const progressiveProcess: any = JSON.parse(JSON.stringify(process)); + if (process.processData.document_types && process.processData.document_types.length > 0) { - process.processData.document_types = await new Promise(async (resolve: (document_types: any[]) => void) => { - let document_types: any[] = []; - for (const document_type of process.processData.document_types) { - document_types.push((await DocumentTypeService.getDocumentTypeByUid(document_type.uid)).processData); - } + progressiveProcess.processData.document_types = []; + if (progressCallback) { + progressCallback(progressiveProcess); + } + + for (const document_type of process.processData.document_types) { + const documentTypeData = (await DocumentTypeService.getDocumentTypeByUid(document_type.uid)).processData; + progressiveProcess.processData.document_types.push(documentTypeData); // Remove duplicates - document_types = document_types.filter((item: any, index: number) => document_types.findIndex((t: any) => t.uid === item.uid) === index); - resolve(document_types); - }); + progressiveProcess.processData.document_types = progressiveProcess.processData.document_types + .filter((item: any, index: number) => progressiveProcess.processData.document_types.findIndex((t: any) => t.uid === item.uid) === index); + + if (progressCallback) { + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } + } + + process.processData.document_types = progressiveProcess.processData.document_types; } - return process + return process; } } diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts index 7660f38d..f43b9be0 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts @@ -19,7 +19,7 @@ export default class DocumentService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...documentData, + ...documentData }; const privateFields: string[] = Object.keys(processData); @@ -80,7 +80,7 @@ export default class DocumentService extends AbstractService { public static getDocuments(): Promise { // Check if we have valid cache - const items: any[] = [];//this.getItems('_documents_'); + const items: any[] = this.getItems('_documents_'); return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && @@ -108,7 +108,7 @@ export default class DocumentService extends AbstractService { // Check if we have valid cache const item: any = this.getItem('_documents_', uid); if (item) { - //return Promise.resolve(item); + return Promise.resolve(item); } return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts index 65eb32d6..ef829988 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts @@ -19,7 +19,7 @@ export default class DocumentTypeService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...documentTypeData, + ...documentTypeData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/FileService.ts b/src/common/Api/LeCoffreApi/sdk/FileService.ts index 448f2522..2212ed12 100644 --- a/src/common/Api/LeCoffreApi/sdk/FileService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FileService.ts @@ -20,7 +20,7 @@ export default class FileService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...fileData, + ...fileData }; const privateFields: string[] = Object.keys(processData); @@ -83,7 +83,7 @@ export default class FileService { return this.messageBus.getFileByUid(uid); } - public static updateFile(process: any, newData: Partial & { isDeleted?: string }): Promise { + public static updateFile(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; diff --git a/src/common/Api/LeCoffreApi/sdk/FolderService.ts b/src/common/Api/LeCoffreApi/sdk/FolderService.ts index e5a21fbd..58566cce 100644 --- a/src/common/Api/LeCoffreApi/sdk/FolderService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FolderService.ts @@ -26,7 +26,7 @@ export default class FolderService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...folderData, + ...folderData }; const privateFields: string[] = Object.keys(processData); @@ -91,11 +91,14 @@ export default class FolderService extends AbstractService { }); } - public static getFolders(): Promise { + public static getFolders(callback: (processes: any[]) => void, waitForAll: boolean = false): void { // Check if we have valid cache const items: any[] = this.getItems('_folders_'); + if (items.length > 0 && !waitForAll) { + setTimeout(() => callback([...items]), 0); + } - return this.messageBus.getProcessesDecoded((publicValues: any) => + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'folder' && @@ -104,18 +107,75 @@ export default class FolderService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { - return items; - } else { - for (let process of processes) { - process = await this.completeFolder(process); - - // Update cache - this.setItem('_folders_', process); - - items.push(process); - } - return items; + return; } + + const updatedItems: any[] = [...items]; + + for (let processIndex = 0; processIndex < processes.length; processIndex++) { + let process = processes[processIndex]; + + if (!waitForAll) { + process = await this.completeFolder(process, (processInProgress: any) => { + const currentItems: any[] = [...updatedItems]; + + const existingIndex: number = currentItems.findIndex(item => item.processData?.uid === processInProgress.processData?.uid); + if (existingIndex >= 0) { + currentItems[existingIndex] = processInProgress; + } else { + currentItems.push(processInProgress); + } + + callback(currentItems); + }); + } else { + process = await this.completeFolder(process); + } + + // Update cache + this.setItem('_folders_', process); + + const existingIndex: number = updatedItems.findIndex(item => item.processData?.uid === process.processData?.uid); + if (existingIndex >= 0) { + updatedItems[existingIndex] = process; + } else { + updatedItems.push(process); + } + + if (!waitForAll) { + callback([...updatedItems]); + } + } + + if (waitForAll) { + callback([...updatedItems]); + } + }); + } + + public static getFoldersBy(whereClause: { [path: string]: any }): Promise { + return new Promise((resolve: (folders: any[]) => void) => { + this.getFolders((processes: any[]) => { + resolve(processes.length > 0 ? processes.map((process: any) => process.processData).filter((folder: any) => { + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = folder; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; + } + } + return true; + }) : []); + }, true); }); } @@ -174,7 +234,9 @@ export default class FolderService extends AbstractService { }); } - private static async completeFolder(process: any): Promise { + private static async completeFolder(process: any, progressCallback?: (processInProgress: any) => void): Promise { + const progressiveProcess: any = JSON.parse(JSON.stringify(process)); + if (process.processData.customers && process.processData.customers.length > 0) { process.processData.customers = await new Promise(async (resolve: (customers: any[]) => void) => { const customers: any[] = []; @@ -204,6 +266,11 @@ export default class FolderService extends AbstractService { } } } + + if (progressCallback) { + progressiveProcess.processData.customers = process.processData.customers; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } if (process.processData.stakeholders && process.processData.stakeholders.length > 0) { @@ -214,6 +281,11 @@ export default class FolderService extends AbstractService { } resolve(stakeholders); }); + + if (progressCallback) { + progressiveProcess.processData.stakeholders = process.processData.stakeholders; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } if (process.processData.deed && process.processData.deed.deed_type) { @@ -224,11 +296,21 @@ export default class FolderService extends AbstractService { // Remove duplicates process.processData.deed.document_types = deed_type.document_types.filter((item: any, index: number) => deed_type.document_types.findIndex((t: any) => t.uid === item.uid) === index); } + + if (progressCallback) { + progressiveProcess.processData.deed = process.processData.deed; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } const notes: any[] = (await NoteService.getNotes()).map((process: any) => process.processData); if (notes.length > 0) { process.processData.notes = notes.filter((note: any) => note.folder.uid === process.processData.uid); + + if (progressCallback) { + progressiveProcess.processData.notes = process.processData.notes; + progressCallback(JSON.parse(JSON.stringify(progressiveProcess))); + } } return process; diff --git a/src/common/Api/LeCoffreApi/sdk/NoteService.ts b/src/common/Api/LeCoffreApi/sdk/NoteService.ts index b80fec38..afb1b7e7 100644 --- a/src/common/Api/LeCoffreApi/sdk/NoteService.ts +++ b/src/common/Api/LeCoffreApi/sdk/NoteService.ts @@ -18,7 +18,7 @@ export default class NoteService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...noteData, + ...noteData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/OfficeRibService.ts b/src/common/Api/LeCoffreApi/sdk/OfficeRibService.ts index b5475c68..e5b488ef 100644 --- a/src/common/Api/LeCoffreApi/sdk/OfficeRibService.ts +++ b/src/common/Api/LeCoffreApi/sdk/OfficeRibService.ts @@ -20,7 +20,7 @@ export default class OfficeRibService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...fileData, + ...fileData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/OfficeRoleService.ts b/src/common/Api/LeCoffreApi/sdk/OfficeRoleService.ts index d34a5bd1..ef3c0bd9 100644 --- a/src/common/Api/LeCoffreApi/sdk/OfficeRoleService.ts +++ b/src/common/Api/LeCoffreApi/sdk/OfficeRoleService.ts @@ -22,7 +22,7 @@ export default class OfficeRoleService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...roleData, + ...roleData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/OfficeService.ts b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts index eeed8a9e..a207d3bb 100644 --- a/src/common/Api/LeCoffreApi/sdk/OfficeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/OfficeService.ts @@ -19,7 +19,7 @@ export default class OfficeService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...officeData, + ...officeData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/RoleService.ts b/src/common/Api/LeCoffreApi/sdk/RoleService.ts index 4593f383..3604ecf1 100644 --- a/src/common/Api/LeCoffreApi/sdk/RoleService.ts +++ b/src/common/Api/LeCoffreApi/sdk/RoleService.ts @@ -21,7 +21,7 @@ export default class RoleService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...roleData, + ...roleData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/RuleGroupService.ts b/src/common/Api/LeCoffreApi/sdk/RuleGroupService.ts index aeb47afe..0619b95c 100644 --- a/src/common/Api/LeCoffreApi/sdk/RuleGroupService.ts +++ b/src/common/Api/LeCoffreApi/sdk/RuleGroupService.ts @@ -21,7 +21,7 @@ export default class RuleGroupService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...ruleGroupData, + ...ruleGroupData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/common/Api/LeCoffreApi/sdk/RuleService.ts b/src/common/Api/LeCoffreApi/sdk/RuleService.ts index d7f1cf97..a7d1cc1c 100644 --- a/src/common/Api/LeCoffreApi/sdk/RuleService.ts +++ b/src/common/Api/LeCoffreApi/sdk/RuleService.ts @@ -19,7 +19,7 @@ export default class RuleService extends AbstractService { isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), - ...ruleData, + ...ruleData }; const privateFields: string[] = Object.keys(processData); diff --git a/src/front/Components/DesignSystem/LogOutButton/index.tsx b/src/front/Components/DesignSystem/LogOutButton/index.tsx index 24f6a88a..197a0634 100644 --- a/src/front/Components/DesignSystem/LogOutButton/index.tsx +++ b/src/front/Components/DesignSystem/LogOutButton/index.tsx @@ -16,7 +16,6 @@ export default function LogOut(props: { isCustomer?: boolean }) { .disconnect() .then(() => router.push(`https://qual-connexion.idnot.fr/user/auth/logout?sourceURL=${variables.FRONT_APP_HOST}`)); } else { - sessionStorage.setItem("customerIsConnected", "false"); router.push("/"); } }, [router, variables.FRONT_APP_HOST]); diff --git a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx index e1b286b4..ae7e6524 100644 --- a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/index.tsx @@ -38,7 +38,7 @@ export default function DefaultCollaboratorDashboard(props: IProps) { const user: any = UserStore.instance.getUser(); const officeId: string = user.office.uid; - CollaboratorService.getCollaborators().then((processes: any[]) => { + CollaboratorService.getCollaborators((processes: any[]) => { if (processes.length > 0) { let collaborators: any[] = processes.map((process: any) => process.processData); diff --git a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx index 1c8a8f2d..8400f1f8 100644 --- a/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCustomerDashboard/index.tsx @@ -19,8 +19,8 @@ export default function DefaultCustomerDashboard(props: IProps) { const [folders, setFolders] = useState([]); useEffect(() => { - const jwt = JwtService.getInstance().decodeCustomerJwt(); - if (!jwt) return; + //const jwt = JwtService.getInstance().decodeCustomerJwt(); + //if (!jwt) return; /* Folders.getInstance() @@ -49,10 +49,10 @@ export default function DefaultCustomerDashboard(props: IProps) { */ if (props.isReady) { - FolderService.getFolders().then((processes: any[]) => { + FolderService.getFolders((processes: any[]) => { if (processes.length > 0) { let folders: any[] = processes.map((process: any) => process.processData); - + // Filter By customer.uid folders = folders.filter((folder: any) => folder.customers.some((customer: any) => customer.uid === profileUid)); diff --git a/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx index 877408b1..018c4f63 100644 --- a/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDeedTypeDashboard/index.tsx @@ -11,21 +11,24 @@ import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService"; type IProps = IPropsDashboardWithList; export default function DefaultDeedTypeDashboard(props: IProps) { - const [deedTypes, setDeedTypes] = React.useState(null); const router = useRouter(); + const { deedTypeUid } = router.query; + const [deedTypes, setDeedTypes] = React.useState(null); useEffect(() => { - DeedTypeService.getDeedTypes().then((processes: any) => { - let deedTypes = processes.map((process: any) => process.processData); + DeedTypeService.getDeedTypes((processes: any[]) => { + if (processes.length > 0) { + let deedTypes = processes.map((process: any) => process.processData); - // FilterBy archived_at = null or not defined - deedTypes = deedTypes.filter((deedType: any) => !deedType.archived_at); + // FilterBy archived_at = null or not defined + deedTypes = deedTypes.filter((deedType: any) => !deedType.archived_at); - // OrderBy name asc - deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name)); + // OrderBy name asc + deedTypes.sort((a: any, b: any) => a.name.localeCompare(b.name)); - setDeedTypes(deedTypes); + setDeedTypes(deedTypes); + } }); }, []); diff --git a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx index b4d3d506..f7161440 100644 --- a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx @@ -115,7 +115,7 @@ export default function DefaultNotaryDashboard(props: IProps) { .then((folders) => setFolders(folders)); */ - FolderService.getFolders().then((processes: any[]) => { + FolderService.getFolders((processes: any[]) => { if (processes.length > 0) { let folders: any[] = processes.map((process: any) => process.processData); diff --git a/src/front/Components/LayoutTemplates/DefaultOfficeDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultOfficeDashboard/index.tsx index d8e0fa6c..f3ed0714 100644 --- a/src/front/Components/LayoutTemplates/DefaultOfficeDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultOfficeDashboard/index.tsx @@ -1,25 +1,26 @@ -import { Office } from "le-coffre-resources/dist/SuperAdmin"; import React, { useEffect } from "react"; import { useRouter } from "next/router"; import Module from "@Front/Config/Module"; import { IBlock } from "@Front/Components/DesignSystem/SearchBlockList/BlockList/Block"; import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList"; -// import Offices from "@Front/Api/LeCoffreApi/SuperAdmin/Offices/Offices"; + +import OfficeService from "src/common/Api/LeCoffreApi/sdk/OfficeService"; type IProps = IPropsDashboardWithList; export default function DefaultOfficeDashboard(props: IProps) { - const [offices, setOffices] = React.useState(null); + const [offices, setOffices] = React.useState(null); const router = useRouter(); const { officeUid } = router.query; + useEffect(() => { - /* TODO: review - Offices.getInstance() - .get() - .then((offices) => setOffices(offices)); - */ - setOffices([]); + OfficeService.getOffices().then((processes: any[]) => { + if (processes.length > 0) { + const offices: any[] = processes.map((process: any) => process.processData); + setOffices(offices); + } + }); }, []); const onSelectedBlock = (block: IBlock) => { @@ -33,11 +34,11 @@ export default function DefaultOfficeDashboard(props: IProps) { blocks={ offices ? offices.map((office) => ({ - id: office.uid!, - primaryText: office.name, - isActive: office.uid === officeUid, - secondaryText: office.crpcen, - })) + id: office.uid!, + primaryText: office.name, + isActive: office.uid === officeUid, + secondaryText: office.crpcen, + })) : [] } /> diff --git a/src/front/Components/LayoutTemplates/DefaultUserDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultUserDashboard/index.tsx index c690ebe9..070ffc0a 100644 --- a/src/front/Components/LayoutTemplates/DefaultUserDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultUserDashboard/index.tsx @@ -1,28 +1,34 @@ -// import Users, { IGetUsersparams } from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; -import User from "le-coffre-resources/dist/SuperAdmin"; import React, { useEffect } from "react"; import { useRouter } from "next/router"; import Module from "@Front/Config/Module"; import { IBlock } from "@Front/Components/DesignSystem/SearchBlockList/BlockList/Block"; import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDashboardWithList"; +import UserStore from "@Front/Stores/UserStore"; + +import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService"; type IProps = IPropsDashboardWithList; export default function DefaultUserDashboard(props: IProps) { - const [users, setUsers] = React.useState(null); + const [users, setUsers] = React.useState(null); const router = useRouter(); const { userUid } = router.query; useEffect(() => { - /* TODO: review - const query: IGetUsersparams = { - include: { contact: true, office_membership: true }, - }; - Users.getInstance() - .get(query) - .then((users) => setUsers(users)); - */ - setUsers([]); + const user: any = UserStore.instance.getUser(); + if (!user) return; + const officeId: string = user.office.uid; + + CollaboratorService.getCollaborators((processes: any[]) => { + if (processes.length > 0) { + let collaborators: any[] = processes.map((process: any) => process.processData); + + // FilterBy office.uid + collaborators = collaborators.filter((collaborator: any) => collaborator.office.uid === officeId); + + setUsers(collaborators); + } + }); }, []); const onSelectedBlock = (block: IBlock) => { @@ -36,11 +42,11 @@ export default function DefaultUserDashboard(props: IProps) { blocks={ users ? users.map((user) => ({ - id: user.uid!, - primaryText: user.contact?.first_name + " " + user.contact?.last_name, - isActive: user.uid === userUid, - secondaryText: user.office_membership?.crpcen + " - " + user.office_membership?.name, - })) + id: user.uid!, + primaryText: user.contact?.first_name + " " + user.contact?.last_name, + isActive: user.uid === userUid, + secondaryText: user.office?.crpcen + " - " + user.office?.name, + })) : [] } /> diff --git a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx index 3cc24447..4cc67148 100644 --- a/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/DepositDocumentComponent/index.tsx @@ -154,7 +154,7 @@ export default function DepositDocumentComponent(props: IProps) { (resolve: () => void) => { FileService.getFileByUid(fileUid).then((res: any) => { if (res) { - FileService.updateFile(res.processId, { isDeleted: 'true' }).then(() => { + FileService.updateFile(res.processId, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => { DocumentService.getDocumentByUid(document.uid!).then((process: any) => { if (process) { const document: any = process.processData; @@ -165,7 +165,9 @@ export default function DepositDocumentComponent(props: IProps) { } files = files.filter((file: any) => file.uid !== fileUid); - DocumentService.updateDocument(process, { files: files, document_status: EDocumentStatus.ASKED }).then(() => resolve()); + DocumentService.updateDocument(process, { files: files, document_status: EDocumentStatus.ASKED }).then(() => { + FolderService.refreshFolderByUid(document.folder.uid).then(() => resolve()); + }); } }); }); diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index 61acd009..d9b948fd 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -22,9 +22,6 @@ import ContactBox from "./ContactBox"; import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary"; import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument"; -import Modal from "@Front/Components/DesignSystem/Modal"; -import TextField from "@Front/Components/DesignSystem/Form/TextField"; - import AuthModal from "src/sdk/AuthModal"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; @@ -47,32 +44,7 @@ export default function ClientDashboard(props: IProps) { const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState(false); const [isReady, setIsReady] = useState(false); - const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); - const [isSmsModalOpen, setIsSmsModalOpen] = useState(true); - const [smsCode, setSmsCode] = useState(""); - const [smsError, setSmsError] = useState(""); - - const verifySmsCode = useCallback(() => { - if (smsCode === "1234") { - setIsSmsModalOpen(false); - setIsAuthModalOpen(true); - } else { - setSmsError("Code incorrect. Le code valide est 1234."); - } - }, [smsCode]); - - useEffect(() => { - const handleKeyPress = (e: KeyboardEvent) => { - if (e.key === "Enter" && isSmsModalOpen) { - verifySmsCode(); - } - }; - - window.addEventListener("keypress", handleKeyPress); - return () => { - window.removeEventListener("keypress", handleKeyPress); - }; - }, [isSmsModalOpen, smsCode, verifySmsCode]); + const [isAuthModalOpen, setIsAuthModalOpen] = useState(true); const fetchFolderAndCustomer = useCallback(async () => { let jwt: ICustomerJwtPayload | undefined; @@ -345,53 +317,8 @@ export default function ClientDashboard(props: IProps) { setIsReady(true); setIsAuthModalOpen(false); fetchFolderAndCustomer().then(({ customer }) => fetchDocuments(customer.uid)); - - sessionStorage.setItem("customerIsConnected", "true"); }} />} - - {isSmsModalOpen && ( - setIsSmsModalOpen(false)} - title="Vérification SMS" - > -
- - Veuillez saisir le code à 4 chiffres que vous avez reçu par SMS - - - { - const value = e.target.value; - // Only allow digits - if (value === "" || /^\d+$/.test(value)) { - setSmsCode(value); - setSmsError(""); - } - }} - /> - - {smsError && ( - - {smsError} - - )} - -
- -
-
-
- )} ); } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index f7cc77f0..94d28a49 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -107,7 +107,7 @@ export default function DeedTypesInformations(props: IProps) { const saveDocumentTypes = useCallback(() => { LoaderService.getInstance().show(); - DeedTypeService.getDeedTypeByUid(deedTypeUid as string, false).then((process: any) => { + DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => { if (process) { const deedType: any = process.processData; diff --git a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx index 0df0fa45..2d0f696e 100644 --- a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx @@ -131,14 +131,14 @@ export default function CreateFolder(): JSX.Element { * UseEffect */ useEffect(() => { - DeedTypeService.getDeedTypes().then((processes: any[]) => { + DeedTypeService.getDeedTypes((processes: any[]) => { if (processes.length > 0) { const deedTypes: any[] = processes.map((process: any) => process.processData); setAvailableDeedTypes(deedTypes); } }); - CollaboratorService.getCollaborators().then((processes: any[]) => { + CollaboratorService.getCollaborators((processes: any[]) => { if (processes.length > 0) { const collaborators: any[] = processes.map((process: any) => process.processData); setAvailableCollaborators(collaborators); 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 95983ee9..e9c5c552 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 @@ -4,6 +4,7 @@ import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import React, { useCallback } from "react"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; type IProps = { @@ -23,7 +24,10 @@ export default function DeleteAskedDocumentModal(props: IProps) { (resolve: () => void) => { DocumentService.getDocumentByUid(documentUid).then((process: any) => { if (process) { - DocumentService.updateDocument(process, { isDeleted: 'true' }).then(() => resolve()); + const document: any = process.processData; + DocumentService.updateDocument(process, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => { + FolderService.refreshFolderByUid(document.folder.uid).then(() => resolve()); + }); } }); }) diff --git a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx index 233c9566..5cd03ef2 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/DeleteSentDocumentModal/index.tsx @@ -4,6 +4,7 @@ import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; import React, { useCallback } from "react"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; type IProps = { @@ -21,8 +22,10 @@ export default function DeleteSentDocumentModal(props: IProps) { LoaderService.getInstance().show(); DocumentService.getDocumentByUid(documentUid).then((process: any) => { if (process) { - DocumentService.updateDocument(process, { isDeleted: 'true' }) + const document: any = process.processData; + DocumentService.updateDocument(process, { isDeleted: 'true', archived_at: new Date().toISOString() }) .then(() => onDeleteSuccess(documentUid)) + .then(() => FolderService.refreshFolderByUid(document.folder.uid)) .then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Le document a été supprimé avec succès." })) .then(() => LoaderService.getInstance().hide()) .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 afe5eff6..ec02f8f2 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -150,7 +150,12 @@ export default function DocumentTables(props: IProps) { const file = doc.files?.[0]; if (!file) return; - return new Promise((resolve: () => void) => { + return new Promise(async (resolve: () => void) => { + if (!file.file_blob) { + LoaderService.getInstance().show(); + file.file_blob = (await FileService.getFileByUid(file.uid)).processData.file_blob; + LoaderService.getInstance().hide(); + } const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); 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 197325c0..070eb714 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/NoClientView/DeleteFolderModal/index.tsx @@ -28,7 +28,7 @@ export default function DeleteFolderModal(props: IProps) { LoaderService.getInstance().show(); FolderService.getFolderByUid(folder.uid!).then((process: any) => { if (process) { - FolderService.updateFolder(process, { isDeleted: 'true' }).then(() => { + FolderService.updateFolder(process, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => { LoaderService.getInstance().hide(); resolve(); }); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx index bbdf1378..62a2e588 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx @@ -1,6 +1,6 @@ import Alert, { EAlertVariant } from "@Front/Components/DesignSystem/Alert"; import { EButtonstyletype } from "@Front/Components/DesignSystem/Button"; -import { LockClosedIcon } from "@heroicons/react/24/outline"; +import { ArchiveBoxIcon } from "@heroicons/react/24/outline"; type IProps = { onAnchor: () => void; @@ -13,9 +13,9 @@ export default function AnchoringAlertInfo(props: IProps) { title="Validation et Certification du Dossier" description="Votre dossier est désormais complet à 100%. Vous pouvez maintenant procéder à la validation et à l'ancrage des documents dans la blockchain. Cette étape garantit la sécurité et l'authenticité de vos documents." firstButton={{ - children: "Ancrer et certifier", + children: "Archiver", styletype: EButtonstyletype.CONTAINED, - rightIcon: , + rightIcon: , onClick: onAnchor, }} variant={EAlertVariant.INFO} diff --git a/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveAlertWarning/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveAlertWarning/index.tsx index 89828c08..d094d00d 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveAlertWarning/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveAlertWarning/index.tsx @@ -1,11 +1,14 @@ -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; import Alert, { EAlertVariant } from "@Front/Components/DesignSystem/Alert"; import { EButtonstyletype } from "@Front/Components/DesignSystem/Button"; import Module from "@Front/Config/Module"; import { ArchiveBoxArrowDownIcon, ArchiveBoxIcon, ArrowDownOnSquareIcon } from "@heroicons/react/24/outline"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; import { useRouter } from "next/router"; import { useCallback } from "react"; +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; + type IProps = { onDownloadAnchoringProof: () => void; folderUid: string; @@ -17,12 +20,15 @@ export default function ArchiveAlertWarning(props: IProps) { const router = useRouter(); const restoreArchive = useCallback(() => { - Folders.getInstance() - .restore(folderUid) - .then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)) - .catch((e) => { - console.warn(e); - }); + LoaderService.getInstance().show(); + FolderService.getFolderByUid(folderUid).then((process: any) => { + if (process) { + FolderService.updateFolder(process, { archived_at: null, archived_description: null, status: EFolderStatus.LIVE }) + .then(() => LoaderService.getInstance().hide()) + .then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)) + .catch((e) => console.error(e)); + } + }); }, [folderUid, router]); return ( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx index ff1c6621..9acdbc38 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/ArchiveModal/index.tsx @@ -1,4 +1,3 @@ -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField"; import Modal from "@Front/Components/DesignSystem/Modal"; import Typography, { ETypo } from "@Front/Components/DesignSystem/Typography"; @@ -6,6 +5,10 @@ import Module from "@Front/Config/Module"; import { useRouter } from "next/router"; import React, { useCallback } from "react"; import classes from "./classes.module.scss"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; + +import LoaderService from "src/common/Api/LeCoffreApi/sdk/Loader/LoaderService"; +import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; type IProps = { isOpen: boolean; @@ -19,14 +22,16 @@ export default function ArchiveModal(props: IProps) { const archive = useCallback(() => { const description = (document.querySelector("textarea[name='archived_description']") as HTMLTextAreaElement).value ?? ""; - - Folders.getInstance() - .archive(folderUid, description) - .then(onClose) - .then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)) - .catch((e) => { - console.warn(e); - }); + LoaderService.getInstance().show(); + FolderService.getFolderByUid(folderUid).then((process: any) => { + if (process) { + FolderService.updateFolder(process, { archived_at: new Date().toISOString(), archived_description: description, status: EFolderStatus.ARCHIVED }) + .then(() => LoaderService.getInstance().hide()) + .then(onClose) + .then(() => router.push(Module.getInstance().get().modules.pages.Folder.props.path)) + .catch((e) => console.error(e)); + } + }); }, [folderUid, onClose, router]); return ( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index a10f69ff..90749ed8 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -21,6 +21,7 @@ import NoClientView from "./NoClientView"; import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; export enum AnchorStatus { "VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN", @@ -34,7 +35,7 @@ export default function FolderInformation(props: IProps) { const { isArchived = false } = props; const [anchorStatus, setAnchorStatus] = useState(AnchorStatus.NOT_ANCHORED); const [isLoading, setIsLoading] = useState(true); - const [folder, setFolder] = useState(null); + const [folder, setFolder] = useState(null); const anchoringModal = useOpenable(); const downloadAnchoringProofModal = useOpenable(); const requireAnchoringModal = useOpenable(); @@ -46,10 +47,10 @@ export default function FolderInformation(props: IProps) { const progress = useMemo(() => { let total = 0; let validatedDocuments = 0; - folder?.customers?.forEach((customer) => { - const documents = customer.documents; + folder?.customers?.forEach((customer: any) => { + const documents = customer.documents.filter((document: any) => document.depositor); total += documents?.length ?? 0; - validatedDocuments += documents?.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0; + validatedDocuments += documents?.filter((document: any) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0; }); if (total === 0) return 0; const percentage = (validatedDocuments / total) * 100; @@ -138,7 +139,7 @@ export default function FolderInformation(props: IProps) { }, [fetchData]); const onArchive = useCallback(() => { - if (anchorStatus === AnchorStatus.NOT_ANCHORED) return requireAnchoringModal.open(); + //if (anchorStatus === AnchorStatus.NOT_ANCHORED) return requireAnchoringModal.open(); archiveModal.open(); }, [anchorStatus, archiveModal, requireAnchoringModal]); @@ -153,7 +154,7 @@ export default function FolderInformation(props: IProps) { anchorStatus={anchorStatus} isArchived={isArchived} /> - {progress === 100 && anchorStatus === AnchorStatus.NOT_ANCHORED && ( + {progress === 100 && /*anchorStatus === AnchorStatus.NOT_ANCHORED*/ folder.status !== EFolderStatus.ARCHIVED && ( )} {!isArchived && anchorStatus === AnchorStatus.VERIFIED_ON_CHAIN && ( diff --git a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx index 2a2f27e4..74a00bd5 100644 --- a/src/front/Components/Layouts/Folder/SendDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/SendDocuments/index.tsx @@ -83,7 +83,7 @@ export default function SendDocuments() { const date: Date = new Date(); const strDate: string = `${date.getDate().toString().padStart(2, '0')}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getFullYear()}`; - const fileName: string = `${customer.contact.last_name}_${strDate}.${file.name.split('.').pop()}`; + const fileName: string = `aplc_${customer.contact.last_name}_${strDate}.${file.name.split('.').pop()}`; const arrayBuffer: ArrayBuffer = event.target.result as ArrayBuffer; const uint8Array: Uint8Array = new Uint8Array(arrayBuffer); diff --git a/src/front/Components/Layouts/Folder/index.tsx b/src/front/Components/Layouts/Folder/index.tsx index d9615e4f..4bf850c6 100644 --- a/src/front/Components/Layouts/Folder/index.tsx +++ b/src/front/Components/Layouts/Folder/index.tsx @@ -25,12 +25,12 @@ export default function Folder() { useEffect(() => { // TODO: review - FolderService.getFolders().then((processes: any[]) => { + FolderService.getFoldersBy({ status: EFolderStatus.LIVE }).then((processes: any[]) => { if (processes.length > 0) { let folders: any[] = processes.map((process: any) => process.processData); - // FilterBy status - folders = folders.filter((folder: any) => folder.status === EFolderStatus.LIVE); + // OrderBy created_at desc + folders = folders.sort((a: any, b: any) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); if (folders.length > 0) { router.push( diff --git a/src/front/Components/Layouts/LoginCallback/index.tsx b/src/front/Components/Layouts/LoginCallback/index.tsx index e3bd56be..eaf959aa 100644 --- a/src/front/Components/Layouts/LoginCallback/index.tsx +++ b/src/front/Components/Layouts/LoginCallback/index.tsx @@ -275,21 +275,19 @@ export default function LoginCallBack() { }; const getCollaborator = async (collaboratorData: any) => { - return await new Promise((resolve: (role: any) => void) => { - CollaboratorService.getCollaborators().then((processes: any[]) => { - const collaboratorFound: any = processes.length > 0 ? processes.map((process: any) => process.processData).find((collaborator: any) => collaborator.idNot === idNotUser.idNot) : null; - if (collaboratorFound) { - resolve(collaboratorFound); - } else { - const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; - CollaboratorService.createCollaborator(collaboratorData, validatorId).then((process: any) => { - if (process) { - const collaborator: any = process.processData; - resolve(collaborator); - } - }); - } - }); + return await new Promise(async (resolve: (role: any) => void) => { + const collaboratorFound: any | null = await CollaboratorService.getCollaboratorBy({ idNot: idNotUser.idNot }); + if (collaboratorFound) { + resolve(collaboratorFound); + } else { + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + CollaboratorService.createCollaborator(collaboratorData, validatorId).then((process: any) => { + if (process) { + const collaborator: any = process.processData; + resolve(collaborator); + } + }); + } }); }; diff --git a/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx b/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx index 2a761172..0fd36ef6 100644 --- a/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx +++ b/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx @@ -1,4 +1,3 @@ -import Offices from "@Front/Api/LeCoffreApi/SuperAdmin/Offices/Offices"; import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography"; import DefaultOfficeDashboard from "@Front/Components/LayoutTemplates/DefaultOfficeDashboard"; import User, { Office } from "le-coffre-resources/dist/SuperAdmin"; @@ -7,6 +6,9 @@ import { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; +import OfficeService from "src/common/Api/LeCoffreApi/sdk/OfficeService"; +import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService"; + type IProps = {}; export default function OfficeInformations(props: IProps) { const router = useRouter(); @@ -19,22 +21,20 @@ export default function OfficeInformations(props: IProps) { useEffect(() => { async function getOffice() { if (!officeUid) return; - const office = await Offices.getInstance().getByUid(officeUid as string, { - q: { - address: true, - users: { - include: { - role: true, - office_role: true, - contact: true, - }, - }, - }, + const office: any = await new Promise((resolve: (office: any) => void) => { + OfficeService.getOfficeByUid(officeUid as string).then((process: any) => { + if (process) { + const office: any = process.processData; + resolve(office); + } + }); }); if (!office) return; setOfficeSelected(office); - const adminUsers = office.users?.filter((user) => { + const users: any[] = await CollaboratorService.getCollaboratorsBy({ 'office.uid': office.uid }); + + const adminUsers = users.filter((user) => { if (user.office_role && user.office_role.name === "admin") { return true; } @@ -46,8 +46,9 @@ export default function OfficeInformations(props: IProps) { } return false; }); + setAdminUsers(adminUsers); - const collaboratorUsers = office.users?.filter((user) => { + const collaboratorUsers = users.filter((user) => { if (user.office_role && user.office_role.name === "admin") { return false; } @@ -59,9 +60,7 @@ export default function OfficeInformations(props: IProps) { } return true; }); - - setAdminUsers(adminUsers!); - setCollaboratorUsers(collaboratorUsers!); + setCollaboratorUsers(collaboratorUsers); } getOffice(); diff --git a/src/front/Components/Layouts/SelectFolder/index.tsx b/src/front/Components/Layouts/SelectFolder/index.tsx index 323cd6f4..5032186a 100644 --- a/src/front/Components/Layouts/SelectFolder/index.tsx +++ b/src/front/Components/Layouts/SelectFolder/index.tsx @@ -27,7 +27,7 @@ export default function SelectFolder() { return; } LoaderService.getInstance().show(); - FolderService.getFolders().then((processes: any[]) => { + FolderService.getFolders((processes: any[]) => { if (processes.length > 0) { let folders: any[] = processes.map((process: any) => process.processData); diff --git a/src/front/Components/Layouts/Users/UserInformations/index.tsx b/src/front/Components/Layouts/Users/UserInformations/index.tsx index 2a723553..b4d54f2d 100644 --- a/src/front/Components/Layouts/Users/UserInformations/index.tsx +++ b/src/front/Components/Layouts/Users/UserInformations/index.tsx @@ -20,6 +20,8 @@ import classes from "./classes.module.scss"; import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles"; import Loader from "@Front/Components/DesignSystem/Loader"; +import CollaboratorService from "src/common/Api/LeCoffreApi/sdk/CollaboratorService"; + type IProps = {}; export default function UserInformations(props: IProps) { const router = useRouter(); @@ -43,6 +45,8 @@ export default function UserInformations(props: IProps) { const getUser = useCallback(async () => { if (!userUid) return; setIsLoading(true); + + /* const user = await Users.getInstance().getByUid(userUid as string, { q: { contact: true, @@ -61,7 +65,17 @@ export default function UserInformations(props: IProps) { votes: true, }, }); + */ + const user: any = await new Promise((resolve: (collaborator: any) => void) => { + CollaboratorService.getCollaboratorByUid(userUid as string).then((process: any) => { + if (process) { + const collaborator: any = process.processData; + resolve(collaborator); + } + }); + }); if (!user) return; + /* const roles = await OfficeRoles.getInstance().get({ where: { office: { uid: user.office_membership?.uid }, @@ -69,6 +83,7 @@ export default function UserInformations(props: IProps) { }, }); if (!roles) return; + */ setIsLoading(false); setUserSelected(user); }, [userUid]); @@ -286,12 +301,10 @@ export default function UserInformations(props: IProps) {
{currentAppointment.choice === EVote.NOMINATE - ? `Un ou des collaborateurs souhaitent attribuer le titre de Super Admin à ce collaborateur. Il manque ${ - 3 - currentAppointment.votes?.length! - } vote(s) pour que le collaborateur se voit attribuer le titre.` - : `Un ou des collaborateurs souhaitent retirer le titre de Super Admin à ce collaborateur. Il manque ${ - 3 - currentAppointment.votes?.length! - } vote(s) pour que le collaborateur se voit retirer le titre.`} + ? `Un ou des collaborateurs souhaitent attribuer le titre de Super Admin à ce collaborateur. Il manque ${3 - currentAppointment.votes?.length! + } vote(s) pour que le collaborateur se voit attribuer le titre.` + : `Un ou des collaborateurs souhaitent retirer le titre de Super Admin à ce collaborateur. Il manque ${3 - currentAppointment.votes?.length! + } vote(s) pour que le collaborateur se voit retirer le titre.`}
{userHasVoted() && ( @@ -312,9 +325,8 @@ export default function UserInformations(props: IProps) { onClose={closeSuperAdminModal} onAccept={handleSuperAdminModalAccepted} closeBtn - header={`Souhaitez-vous attribuer un vote à ${ - userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name - } pour ${superAdminModalType === "add" ? "devenir" : "retirer son rôle de"} Super Administrateur ?`} + header={`Souhaitez-vous attribuer un vote à ${userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name + } pour ${superAdminModalType === "add" ? "devenir" : "retirer son rôle de"} Super Administrateur ?`} confirmText={"Attribuer un vote"} cancelText={"Annuler"}>
@@ -331,12 +343,10 @@ export default function UserInformations(props: IProps) { closeBtn header={ adminModalType === "add" - ? `Souhaitez-vous nommer ${ - userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name - } administrateur de son office ?` - : `Souhaitez-vous retirer le rôle administrateur de son office à ${ - userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name - } ?` + ? `Souhaitez-vous nommer ${userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name + } administrateur de son office ?` + : `Souhaitez-vous retirer le rôle administrateur de son office à ${userSelected?.contact?.first_name + " " + userSelected?.contact?.last_name + } ?` } confirmText={adminModalType === "add" ? "Ajouter" : "Retirer"} cancelText={"Annuler"}>