From f5729af068b94a8d5dc9037f79a6861a3aa83d1f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 3 May 2023 13:52:21 +0200 Subject: [PATCH] :sparkles: Filter now include clients --- .../DesignSystem/SearchBar/index.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 1bef9e75..7d4ccd32 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -1,9 +1,10 @@ -import React from "react"; -import classes from "./classes.module.scss"; import LoopIcon from "@Assets/Icons/loop.svg"; -import Image from "next/image"; -import Typography, { ITypo } from "../Typography"; import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import Image from "next/image"; +import React from "react"; + +import Typography, { ITypo } from "../Typography"; +import classes from "./classes.module.scss"; type IProps = { folders: IDashBoardFolder[]; @@ -53,10 +54,24 @@ export default class SearchBar extends React.Component { } private filterFolders(event: React.ChangeEvent) { - const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) =>{ + const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) => { const name = folder.name.toLowerCase(); const number = folder.folder_number.toLowerCase(); const value = event.target.value.toLowerCase(); + + if (folder.office_folder_has_customers) { + const customersNames = folder.office_folder_has_customers?.reduce((acc: string[], customer) => { + return acc.concat( + `${customer.customer.contact.first_name.toLowerCase()} ${customer.customer.contact.last_name.toLowerCase()}`, + ); + }, []); + let namesIncludesValue = false; + customersNames.forEach((name) => { + if (name.includes(value)) namesIncludesValue = true; + }); + return name.includes(value) || number.includes(value) || namesIncludesValue; + } + return name.includes(value) || number.includes(value); }); return filteredFolders;