From 6029a217605ccfcd41960ceb72b135ee70175f87 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 10 May 2023 18:59:00 +0200 Subject: [PATCH] :bug: Fixing folders order --- .../DesignSystem/FolderList/index.tsx | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/src/front/Components/DesignSystem/FolderList/index.tsx b/src/front/Components/DesignSystem/FolderList/index.tsx index 359ca97f..d98d432c 100644 --- a/src/front/Components/DesignSystem/FolderList/index.tsx +++ b/src/front/Components/DesignSystem/FolderList/index.tsx @@ -1,12 +1,12 @@ import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import Module from "@Front/Config/Module"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import Link from "next/link"; import { useRouter } from "next/router"; import React from "react"; import FolderContainer from "../FolderContainer"; import classes from "./classes.module.scss"; -import Module from "@Front/Config/Module"; -import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; type IProps = { folders: IDashBoardFolder[]; @@ -22,41 +22,53 @@ type IPropsClass = IProps & { type IState = {}; class FolderListClass extends React.Component { + private redirectPath: string = this.props.isArchived + ? Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.pages.FolderInformation.props.path + : Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path; public override render(): JSX.Element { - const redirectPath: string = this.props.isArchived - ? Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.pages.FolderInformation.props.path - : Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path; return (
- {this.props.folders - .sort((folder) => { - const pendingDocuments = (folder.documents ?? []).filter( - (document) => document.document_status === EDocumentStatus.DEPOSITED, - ); - return pendingDocuments.length >= 1 ? -1 : 1; - }) - .sort((folder1, folder2) => { - return folder1.created_at! < folder2.created_at! ? -1 : 1; - }) - .sort((folder1, folder2) => { - return folder1.folder_number! < folder2.folder_number! ? -1 : 1; - }) - .map((folder) => { - return ( -
- - ; - -
- ); - })} - ; + {this.renderFolders()}
); } + + private renderFolders(): JSX.Element[] { + const pendingFolders = this.props.folders + .filter((folder) => { + const pendingDocuments = (folder.documents ?? []).filter( + (document) => document.document_status === EDocumentStatus.DEPOSITED, + ); + return pendingDocuments.length >= 1; + }) + .sort((folder1, folder2) => { + return folder1.created_at! > folder2.created_at! ? -1 : 1; + }); + + const otherFolders = this.props.folders + .filter((folder) => { + const pendingDocuments = (folder.documents ?? []).filter( + (document) => document.document_status === EDocumentStatus.DEPOSITED, + ); + return pendingDocuments.length === 0; + }) + .sort((folder1, folder2) => { + return folder1.created_at! > folder2.created_at! ? -1 : 1; + }); + + return [...pendingFolders, ...otherFolders].map((folder) => { + return ( +
+ + ; + +
+ ); + }); + } } export default function FolderList(props: IProps) {