From 7e3849a2e4f10e51f7c01126cf1d5614d7ba0ada Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 11 Jul 2023 17:10:16 +0200 Subject: [PATCH] :sparkles: Fixing folders --- .../FolderListContainer/index.tsx | 86 ++++++++++++++++--- .../DesignSystem/SearchBar/index.tsx | 2 - .../CollaboratorListContainer/index.tsx | 11 +-- .../classes.module.scss | 1 + 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/front/Components/DesignSystem/FolderListContainer/index.tsx b/src/front/Components/DesignSystem/FolderListContainer/index.tsx index 2063cba5..ebecaaa0 100644 --- a/src/front/Components/DesignSystem/FolderListContainer/index.tsx +++ b/src/front/Components/DesignSystem/FolderListContainer/index.tsx @@ -4,9 +4,11 @@ import Link from "next/link"; import React from "react"; import Button from "../Button"; -import FolderList from "../FolderList"; import SearchBar from "../SearchBar"; import classes from "./classes.module.scss"; +import BlockList, { IBlock } from "../BlockList"; +import { NextRouter, useRouter } from "next/router"; +import { EDocumentStatus } from "le-coffre-resources/dist/SuperAdmin/Document"; type IProps = { folders: IDashBoardFolder[]; @@ -14,17 +16,26 @@ type IProps = { onSelectedFolder?: (folder: IDashBoardFolder) => void; onCloseLeftSide?: () => void; }; + +type IPropsClass = IProps & { + router: NextRouter; +}; + type IState = { filteredFolders: IDashBoardFolder[]; }; -export default class FolderListContainer extends React.Component { - public constructor(props: IProps) { +class FolderListContainerClass 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 constructor(props: IPropsClass) { super(props); this.state = { filteredFolders: this.props.folders, }; this.filterFolders = this.filterFolders.bind(this); + this.onSelectedFolder = this.onSelectedFolder.bind(this); } public override render(): JSX.Element { @@ -33,15 +44,10 @@ export default class FolderListContainer extends React.Component
- +
- +
{!this.props.isArchived && ( @@ -55,8 +61,62 @@ export default class FolderListContainer extends React.Component ); } - private filterFolders(folders: IDashBoardFolder[]): IDashBoardFolder[] { - this.setState({ filteredFolders: folders }); - return folders; + private getBlocks(): IBlock[] { + 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 { id: folder.uid!, name: folder.folder_number! + " - " + folder.name! }; + }); + } + private onSelectedFolder(block: IBlock) { + const folder = this.props.folders.find((folder) => folder.uid === block.id); + if (!folder) return; + this.props.onSelectedFolder && this.props.onSelectedFolder(folder); + const path = this.redirectPath.replace("[folderUid]", folder.uid ?? ""); + this.props.router.push(path); + } + + private filterFolders(value: string): void { + const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) => { + const name = folder.name.toLowerCase(); + const number = folder.folder_number.toLowerCase(); + + if (folder.customers) { + const customerNames = folder.customers + .map((customer) => { + return `${customer.contact?.first_name.toLowerCase()} ${customer.contact?.last_name.toLowerCase()}`; + }) + .join(", "); + return name.includes(value) || number.includes(value) || customerNames.includes(value); + } + + return name.includes(value) || number.includes(value); + }); + this.setState({ filteredFolders }); } } + +export default function FolderListContainer(props: IProps) { + const router = useRouter(); + return ; +} diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index d2b8f05f..cf1bf6c8 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -4,10 +4,8 @@ import React from "react"; import Typography, { ITypo } from "../Typography"; import classes from "./classes.module.scss"; -import { IBlock } from "../BlockList"; type IProps = { - blocks: IBlock[]; onChange?: (input: string) => void; placeholder?: string; }; diff --git a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/CollaboratorListContainer/index.tsx b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/CollaboratorListContainer/index.tsx index b2744692..2b18e1b3 100644 --- a/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/CollaboratorListContainer/index.tsx +++ b/src/front/Components/LayoutTemplates/DefaultCollaboratorDashboard/CollaboratorListContainer/index.tsx @@ -43,16 +43,7 @@ export default function CollaboratorListContainer(props: IProps) {
- { - return { - name: collaborator.contact?.first_name + " " + collaborator.contact?.last_name, - id: collaborator.uid!, - }; - })} - onChange={filterUsers} - placeholder="Chercher un collaborateur" - /> +