From 5ad6465b74f62686f046e222d9fe27f5180a2343 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Thu, 26 Jun 2025 11:35:12 +0200 Subject: [PATCH] Fix some bugs --- .../Api/LeCoffreApi/sdk/DeedTypeService.ts | 9 +- .../Api/LeCoffreApi/sdk/DocumentService.ts | 13 +++ .../LeCoffreApi/sdk/DocumentTypeService.ts | 108 ++++++++++++++++++ .../Api/LeCoffreApi/sdk/FolderService.ts | 2 +- .../DefaultDocumentTypesDashboard/index.tsx | 4 +- .../DefaultNotaryDashboard/index.tsx | 14 ++- .../DeedTypes/DeedTypesInformations/index.tsx | 6 +- .../DocumentTypesCreate/index.tsx | 4 +- .../DocumentTypesInformations/index.tsx | 4 +- .../AskDocuments/ParameterDocuments/index.tsx | 4 +- .../Layouts/Folder/AskDocuments/index.tsx | 44 ++----- .../Layouts/Folder/CreateFolder/index.tsx | 4 +- .../ClientView/DocumentTables/index.tsx | 29 ++++- .../Folder/FolderInformation/index.tsx | 15 +-- src/front/Components/Layouts/Folder/index.tsx | 10 +- 15 files changed, 198 insertions(+), 72 deletions(-) create mode 100644 src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts diff --git a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts index 23f9970a..96ceb87b 100644 --- a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts @@ -3,7 +3,8 @@ import { v4 as uuidv4 } from 'uuid'; import MessageBus from 'src/sdk/MessageBus'; import User from 'src/sdk/User'; -import DocumentService from './DocumentService'; + +import DocumentTypeService from './DocumentTypeService'; export default class DeedTypeService { @@ -92,11 +93,13 @@ export default class DeedTypeService { if (includeDocumentTypes && process.processData.document_types && process.processData.document_types.length > 0) { process.processData.document_types = await new Promise(async (resolve: (document_types: any[]) => void) => { - const document_types: any[] = []; + let document_types: any[] = []; for (const document_type of process.processData.document_types) { - const p: any = await DocumentService.getDocumentByUid(document_type.uid); + const p: any = await DocumentTypeService.getDocumentTypeByUid(document_type.uid); document_types.push(p.processData); } + // Remove duplicates + document_types = document_types.filter((item: any, index: number) => document_types.findIndex((t: any) => t.uid === item.uid) === index); resolve(document_types); }); } diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts index 77104d67..35e47aa4 100644 --- a/src/common/Api/LeCoffreApi/sdk/DocumentService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DocumentService.ts @@ -92,4 +92,17 @@ export default class DocumentService { }).catch(reject); }); } + + public static updateDocument(process: any, newData: any): Promise { + return new Promise((resolve: () => void, reject: (error: string) => void) => { + this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + const newStateId: string = processUpdated.diffs[0]?.state_id; + this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { + this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { + resolve(); + }).catch(reject); + }).catch(reject); + }).catch(reject); + }); + } } diff --git a/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts new file mode 100644 index 00000000..bab7577a --- /dev/null +++ b/src/common/Api/LeCoffreApi/sdk/DocumentTypeService.ts @@ -0,0 +1,108 @@ + +import { v4 as uuidv4 } from 'uuid'; + +import MessageBus from 'src/sdk/MessageBus'; +import User from 'src/sdk/User'; + +export default class DocumentTypeService { + + private static readonly messageBus: MessageBus = MessageBus.getInstance(); + + private constructor() { } + + public static createDocumentType(documentData: any, validatorId: string): Promise { + const ownerId = User.getInstance().getPairingId()!; + + const processData: any = { + uid: uuidv4(), + utype: 'documentType', + isDeleted: 'false', + created_at: new Date().toISOString(), + updated_at: new Date().toISOString(), + ...documentData, + }; + + const privateFields: string[] = Object.keys(processData); + privateFields.splice(privateFields.indexOf('uid'), 1); + privateFields.splice(privateFields.indexOf('utype'), 1); + + const roles: any = { + demiurge: { + members: [...[ownerId], validatorId], + validation_rules: [], + storages: [] + }, + owner: { + members: [ownerId], + validation_rules: [ + { + quorum: 0.5, + fields: [...privateFields, 'roles', 'uid', 'utype'], + min_sig_member: 1, + }, + ], + storages: [] + }, + validator: { + members: [validatorId], + validation_rules: [ + { + quorum: 0.5, + fields: ['idCertified', 'roles'], + min_sig_member: 1, + }, + { + quorum: 0.0, + fields: [...privateFields], + min_sig_member: 0, + }, + ], + storages: [] + }, + apophis: { + members: [ownerId], + validation_rules: [], + storages: [] + } + }; + + return new Promise((resolve: (processCreated: any) => void, reject: (error: string) => void) => { + this.messageBus.createProcess(processData, privateFields, roles).then((processCreated: any) => { + this.messageBus.notifyUpdate(processCreated.processId, processCreated.process.states[0].state_id).then(() => { + this.messageBus.validateState(processCreated.processId, processCreated.process.states[0].state_id).then((_stateValidated: any) => { + resolve(processCreated); + }).catch(reject); + }).catch(reject); + }).catch(reject); + }); + } + + public static getDocumentTypes(): Promise { + return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'documentType'); + } + + public static getDocumentTypeByUid(uid: string): Promise { + return new Promise((resolve: (process: any) => void, reject: (error: string) => void) => { + this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'documentType').then((processes: any[]) => { + if (processes.length === 0) { + resolve(null); + } else { + resolve(processes[0]); + } + }).catch(reject); + }); + } + + public static updateDocumentType(process: any, newData: any): Promise { + return new Promise((resolve: () => void, reject: (error: string) => void) => { + this.messageBus.updateProcess(process.processId, newData, [], null).then((processUpdated: any) => { + const newStateId: string = processUpdated.diffs[0]?.state_id; + this.messageBus.notifyUpdate(process.processId, newStateId).then(() => { + this.messageBus.validateState(process.processId, newStateId).then((_stateValidated) => { + resolve(); + }).catch(reject); + }).catch(reject); + }).catch(reject); + }); + } +} diff --git a/src/common/Api/LeCoffreApi/sdk/FolderService.ts b/src/common/Api/LeCoffreApi/sdk/FolderService.ts index 6e8f39eb..bdedd1f5 100644 --- a/src/common/Api/LeCoffreApi/sdk/FolderService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FolderService.ts @@ -19,7 +19,6 @@ export default class FolderService { const processData: any = { uid: uuidv4(), utype: 'folder', - isArchived: 'false', isDeleted: 'false', created_at: new Date().toISOString(), updated_at: new Date().toISOString(), @@ -113,6 +112,7 @@ export default class FolderService { if (includeDeedType && process.processData.deed && process.processData.deed.deed_type) { const p: any = await DeedTypeService.getDeedTypeByUid(process.processData.deed.deed_type.uid); process.processData.deed.deed_type = p.processData; + // Remove duplicates process.processData.deed.document_types = p.processData.document_types.filter((item: any, index: number) => p.processData.document_types.findIndex((t: any) => t.uid === item.uid) === index); } diff --git a/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/index.tsx index 1eb6528a..de28f865 100644 --- a/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultDocumentTypesDashboard/index.tsx @@ -6,7 +6,7 @@ import DefaultDashboardWithList, { IPropsDashboardWithList } from "../DefaultDas import JwtService from "@Front/Services/JwtService/JwtService"; import { DocumentType } from "le-coffre-resources/dist/Notary"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; type IProps = IPropsDashboardWithList; @@ -21,7 +21,7 @@ export default function DefaultDocumentTypeDashboard(props: IProps) { // TODO: review const officeId = 'demo_notary_office_id'; // jwt.office_Id; - DocumentService.getDocuments().then((processes: any[]) => { + DocumentTypeService.getDocumentTypes().then((processes: any[]) => { if (processes.length > 0) { let documents: any[] = processes.map((process: any) => process.processData); diff --git a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx index 31ca4d88..b4d3d506 100644 --- a/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultNotaryDashboard/index.tsx @@ -1,7 +1,6 @@ -import Folders, { IGetFoldersParams } from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; import { OfficeFolder } from "le-coffre-resources/dist/Notary"; -import React, { useCallback, useEffect, useState } from "react"; +import React, { useCallback, useEffect } from "react"; import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; import Module from "@Front/Config/Module"; @@ -76,9 +75,10 @@ export default function DefaultNotaryDashboard(props: IProps) { }, [folders, getBlocks]); useEffect(() => { - /* TODO: review let targetedStatus: EFolderStatus = EFolderStatus["LIVE" as keyof typeof EFolderStatus]; if (isArchived) targetedStatus = EFolderStatus.ARCHIVED; + + /* TODO: review const query: IGetFoldersParams = { q: { where: { status: targetedStatus }, @@ -117,8 +117,12 @@ export default function DefaultNotaryDashboard(props: IProps) { FolderService.getFolders().then((processes: any[]) => { if (processes.length > 0) { - const folders: any[] = processes.map((process: any) => process.processData); - setFolders(folders.filter((folder: any) => folder.isArchived && folder.isArchived === (isArchived ? 'true' : 'false'))); + let folders: any[] = processes.map((process: any) => process.processData); + + // FilterBy status + folders = folders.filter((folder: any) => folder.status === targetedStatus); + + setFolders(folders); } }); }, [isArchived]); diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index d07a4d32..457f6d8f 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -20,7 +20,7 @@ import { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; import DeedTypeService from "src/common/Api/LeCoffreApi/sdk/DeedTypeService"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; type IProps = {}; export default function DeedTypesInformations(props: IProps) { @@ -85,7 +85,7 @@ export default function DeedTypesInformations(props: IProps) { } async function getDocuments() { - DocumentService.getDocuments().then((processes: any[]) => { + DocumentTypeService.getDocumentTypes().then((processes: any[]) => { if (processes.length) { const documents: any[] = processes.map((process: any) => process.processData); setAvailableDocuments(documents); @@ -119,7 +119,7 @@ export default function DeedTypesInformations(props: IProps) { DeedTypeService.updateDeedType(process, { document_types: document_types }).then(() => { closeSaveModal(); }); - + } }); }, [closeSaveModal, deedTypeUid, selectedDocuments]); diff --git a/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx b/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx index 8f3328e8..91906073 100644 --- a/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx +++ b/src/front/Components/Layouts/DocumentTypes/DocumentTypesCreate/index.tsx @@ -13,7 +13,7 @@ import { useCallback, useState } from "react"; import classes from "./classes.module.scss"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; type IProps = {}; export default function DocumentTypesCreate(props: IProps) { @@ -45,7 +45,7 @@ export default function DocumentTypesCreate(props: IProps) { }; const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; - DocumentService.createDocument(documentData, validatorId).then((processCreated: any) => { + DocumentTypeService.createDocumentType(documentData, validatorId).then((processCreated: any) => { router.push( Module.getInstance() .get() diff --git a/src/front/Components/Layouts/DocumentTypes/DocumentTypesInformations/index.tsx b/src/front/Components/Layouts/DocumentTypes/DocumentTypesInformations/index.tsx index 89a87e2c..892ee1c0 100644 --- a/src/front/Components/Layouts/DocumentTypes/DocumentTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DocumentTypes/DocumentTypesInformations/index.tsx @@ -12,7 +12,7 @@ import { useEffect, useState } from "react"; import classes from "./classes.module.scss"; import Button, { EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; export default function DocumentTypesInformations() { const router = useRouter(); @@ -24,7 +24,7 @@ export default function DocumentTypesInformations() { async function getDocument() { if (!documentTypeUid) return; - DocumentService.getDocumentByUid(documentTypeUid as string).then((process: any) => { + DocumentTypeService.getDocumentTypeByUid(documentTypeUid as string).then((process: any) => { if (process) { const document: any = process.processData; setDocumentSelected(document); diff --git a/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx index 6fe966de..3ab37262 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/ParameterDocuments/index.tsx @@ -12,7 +12,7 @@ import { ChangeEvent, useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; -import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; type IProps = { isCreateDocumentModalVisible: boolean; @@ -31,7 +31,7 @@ export default function ParameterDocuments(props: IProps) { const [formattedOptions, setFormattedOptions] = useState([]); const getAvailableDocuments = useCallback(async () => { - DocumentService.getDocuments().then((processes: any[]) => { + DocumentTypeService.getDocumentTypes().then((processes: any[]) => { if (processes.length > 0) { const documents: any[] = processes.map((process: any) => process.processData); diff --git a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx index 700444ad..9897aed5 100644 --- a/src/front/Components/Layouts/Folder/AskDocuments/index.tsx +++ b/src/front/Components/Layouts/Folder/AskDocuments/index.tsx @@ -1,5 +1,3 @@ -import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; -import Folders from "@Front/Api/LeCoffreApi/Notary/Folders/Folders"; import Button, { EButtonSize, EButtonstyletype, EButtonVariant } from "@Front/Components/DesignSystem/Button"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Form from "@Front/Components/DesignSystem/Form"; @@ -8,6 +6,7 @@ import BackArrow from "@Front/Components/Elements/BackArrow"; import Module from "@Front/Config/Module"; import { PlusIcon } from "@heroicons/react/24/outline"; import { OfficeFolder } from "le-coffre-resources/dist/Notary"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import { useRouter } from "next/router"; import React, { useCallback, useEffect, useState, useRef } from "react"; import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; @@ -15,7 +14,9 @@ import classes from "./classes.module.scss"; import ParameterDocuments from "./ParameterDocuments"; import { IOption } from "@Front/Components/DesignSystem/Form/SelectFieldOld"; import backgroundImage from "@Assets/images/background_refonte.svg"; + import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; export default function AskDocuments() { const router = useRouter(); @@ -58,10 +59,9 @@ export default function AskDocuments() { try { // TODO: review const documentAsked: [] = values["document_types"] as []; - - /* + for (let i = 0; i < documentAsked.length; i++) { - await Documents.getInstance().post({ + const documentData: any = { folder: { uid: folderUid, }, @@ -69,9 +69,13 @@ export default function AskDocuments() { uid: customerUid, }, document_type: { - uid: documentAsked[i], + uid: documentAsked[i] }, - }); + document_status: EDocumentStatus.ASKED + }; + const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; + + await DocumentService.createDocument(documentData, validatorId); } router.push( @@ -79,7 +83,6 @@ export default function AskDocuments() { .get() .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folderUid as string), ); - */ } catch (e) { console.error(e); } @@ -124,25 +127,6 @@ export default function AskDocuments() { const loadData = useCallback(async () => { try { - /* - const folder = await Folders.getInstance().getByUid(folderUid as string, { - q: { - deed: { - include: { - document_types: true, - }, - }, - office: true, - documents: { - include: { - depositor: true, - document_type: true, - }, - }, - }, - }); - */ - FolderService.getFolderByUid(folderUid as string).then(async (process: any) => { if (process) { const folder: any = process.processData; @@ -150,12 +134,6 @@ export default function AskDocuments() { setDocumentTypes(await getAvailableDocuments(folder)); } }); - - /* - if (!folder) return; - setFolder(folder); - setDocumentTypes(await getAvailableDocuments(folder)); - */ } catch (e) { console.error(e); } diff --git a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx index d095a776..7063f195 100644 --- a/src/front/Components/Layouts/Folder/CreateFolder/index.tsx +++ b/src/front/Components/Layouts/Folder/CreateFolder/index.tsx @@ -14,6 +14,7 @@ import JwtService from "@Front/Services/JwtService/JwtService"; import { ValidationError } from "class-validator/types/validation/ValidationError"; import { Deed, Office, OfficeFolder } from "le-coffre-resources/dist/Notary"; import User from "le-coffre-resources/dist/Notary"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; import { DeedType } from "le-coffre-resources/dist/Notary"; import { useRouter } from "next/router"; import React, { useCallback, useEffect, useState } from "react"; @@ -90,7 +91,8 @@ export default function CreateFolder(): JSX.Element { customers: [], documents: [], notes: [], - stakeholders: folderAccessType === "whole_office" ? availableCollaborators : selectedCollaborators + stakeholders: folderAccessType === "whole_office" ? availableCollaborators : selectedCollaborators, + status: EFolderStatus.LIVE }; FolderService.createFolder(folderData, [], []).then((processCreated: any) => { 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 2d5893bd..26dd236c 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/ClientView/DocumentTables/index.tsx @@ -1,4 +1,3 @@ -import Documents from "@Front/Api/LeCoffreApi/Notary/Documents/Documents"; import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary"; import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files"; import FilesNotary from "@Front/Api/LeCoffreApi/Notary/FilesNotary/Files"; @@ -23,6 +22,9 @@ import classes from "./classes.module.scss"; import DeleteAskedDocumentModal from "./DeleteAskedDocumentModal"; import DeleteSentDocumentModal from "./DeleteSentDocumentModal"; +import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; +import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService"; + type IProps = { customerUid: string; folderUid: string; @@ -53,13 +55,31 @@ export default function DocumentTables(props: IProps) { const fetchDocuments = useCallback( () => + DocumentService.getDocuments().then(async (processes: any[]) => { + if (processes.length > 0) { + let documents: any[] = processes.map((process: any) => process.processData); + + // FilterBy folder.uid & depositor.uid + documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor.uid === customerUid); + + for (const document of documents) { + const documentTypeUid: string = document.document_type.uid; + + const p: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid); + document.document_type = p.processData; + } + + setDocuments(documents); + } + }) + /* Documents.getInstance() .get({ where: { folder: { uid: folderUid }, depositor: { uid: customerUid } }, include: { files: true, document_type: true }, }) .then(setDocuments) - .catch(console.warn), + .catch(console.warn)*/, [customerUid, folderUid], ); @@ -73,10 +93,9 @@ export default function DocumentTables(props: IProps) { ); useEffect(() => { - /* TODO: review + // TODO: review fetchDocuments(); - fetchDocumentsNotary(); - */ + //fetchDocumentsNotary(); }, [fetchDocuments, fetchDocumentsNotary]); const openDeleteAskedDocumentModal = useCallback( diff --git a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx index 44eb3574..17730f3b 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/index.tsx @@ -106,14 +106,11 @@ export default function FolderInformation(props: IProps) { */ // TODO: review - return new Promise((resolve: (value: any) => void) => { - FolderService.getFolderByUid(folderUid).then((process: any) => { - if (process) { - const folder: any = process.processData; - setFolder(folder); - resolve(folder); - } - }); + return FolderService.getFolderByUid(folderUid).then((process: any) => { + if (process) { + const folder: any = process.processData; + setFolder(folder); + } }); }, [folderUid]); @@ -129,7 +126,7 @@ export default function FolderInformation(props: IProps) { const fetchData = useCallback(() => { setIsLoading(true); return fetchFolder() - .then((folder) => { + .then(() => { // TODO: review //return fetchAnchorStatus() }) diff --git a/src/front/Components/Layouts/Folder/index.tsx b/src/front/Components/Layouts/Folder/index.tsx index de83f825..d9615e4f 100644 --- a/src/front/Components/Layouts/Folder/index.tsx +++ b/src/front/Components/Layouts/Folder/index.tsx @@ -27,14 +27,16 @@ export default function Folder() { // TODO: review FolderService.getFolders().then((processes: any[]) => { if (processes.length > 0) { - const folders: any[] = processes.map((process: any) => process.processData); + let folders: any[] = processes.map((process: any) => process.processData); - const foldersLive = folders.filter((folder: any) => folder.isArchived === 'false'); - if (foldersLive.length !== 0) { + // FilterBy status + folders = folders.filter((folder: any) => folder.status === EFolderStatus.LIVE); + + if (folders.length > 0) { router.push( Module.getInstance() .get() - .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", foldersLive[foldersLive.length - 1].uid) + .modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", folders[0].uid) ); } }