diff --git a/src/front/Components/DesignSystem/FolderListContainer/index.tsx b/src/front/Components/DesignSystem/FolderListContainer/index.tsx index 0ac30339..4c3f0a39 100644 --- a/src/front/Components/DesignSystem/FolderListContainer/index.tsx +++ b/src/front/Components/DesignSystem/FolderListContainer/index.tsx @@ -2,8 +2,8 @@ import Module from "@Front/Config/Module"; import { OfficeFolder } from "le-coffre-resources/dist/Notary"; import { EDocumentStatus } from "le-coffre-resources/dist/Notary/Document"; import Link from "next/link"; -import { NextRouter, useRouter } from "next/router"; -import React from "react"; +import { useRouter } from "next/router"; +import React, { useCallback, useEffect } from "react"; import BlockList, { IBlock } from "../BlockList"; import Button from "../Button"; @@ -19,110 +19,17 @@ type IProps = { onCloseLeftSide?: () => void; }; -type IPropsClass = IProps & { - router: NextRouter; - selectedFolder: string; -}; +export default function FolderListContainer(props: IProps) { + const router = useRouter(); + const { folderUid } = router.query; + const { folders, isArchived } = props; -type IState = { - filteredFolders: OfficeFolder[]; - blocks: IBlock[]; -}; - -class FolderListContainerClass extends React.Component { - private redirectPath: string = this.props.isArchived + const redirectPath: string = 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, - blocks: this.getBlocks(this.props.folders), - }; - this.filterFolders = this.filterFolders.bind(this); - this.onSelectedFolder = this.onSelectedFolder.bind(this); - } - public override render(): JSX.Element { - const navigatePath = Module.getInstance().get().modules.pages.Folder.pages.CreateFolder.props.path; - return ( -
-
-
- -
-
- -
-
- {!this.props.isArchived && ( -
- - - - - -
- )} -
- ); - } - - public override componentDidUpdate(prevProps: Readonly, prevState: Readonly, snapshot?: any): void { - if (prevProps.selectedFolder !== this.props.selectedFolder) { - this.setState({ filteredFolders: this.props.folders, blocks: this.getBlocks(this.props.folders) }); - } - } - private getBlocks(folders: OfficeFolder[]): IBlock[] { - const pendingFolders = 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 = 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!, - selected: this.props.selectedFolder === folder.uid, - hasFlag: folder.documents?.some((document) => document.document_status === EDocumentStatus.DEPOSITED), - }; - }); - } - - 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: OfficeFolder[] = this.props.folders.filter((folder) => { + const filterFolders = (value: string): void => { + const filteredFolders: OfficeFolder[] = folders.filter((folder) => { const name = folder.name.toLowerCase(); const number = folder.folder_number.toLowerCase(); value = value.toLowerCase(); @@ -139,12 +46,86 @@ class FolderListContainerClass extends React.Component { return name.includes(value) || number.includes(value); }); - this.setState({ filteredFolders, blocks: this.getBlocks(filteredFolders) }); - } -} + setBlocks(getBlocks(filteredFolders)); + }; -export default function FolderListContainer(props: IProps) { - const router = useRouter(); - const { folderUid } = router.query; - return ; + const getBlocks = useCallback( + (folders: OfficeFolder[]): IBlock[] => { + const pendingFolders = 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 = 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!, + selected: folderUid === folder.uid, + hasFlag: folder.documents?.some((document) => document.document_status === EDocumentStatus.DEPOSITED), + }; + }); + }, + [folderUid], + ); + + const [blocks, setBlocks] = React.useState(getBlocks(folders)); + + const onSelectedFolder = (block: IBlock) => { + const folder = folders.find((folder) => folder.uid === block.id); + if (!folder) return; + props.onSelectedFolder && props.onSelectedFolder(folder); + const path = redirectPath.replace("[folderUid]", folder.uid ?? ""); + router.push(path); + }; + + useEffect(() => { + setBlocks(getBlocks(folders)); + }, [folders, getBlocks]); + + const navigatePath = Module.getInstance().get().modules.pages.Folder.pages.CreateFolder.props.path; + return ( +
+
+
+ +
+
+ +
+
+ {!isArchived && ( +
+ + + + + +
+ )} +
+ ); } diff --git a/src/front/Components/DesignSystem/SearchBar/classes.module.scss b/src/front/Components/DesignSystem/SearchBar/classes.module.scss index 326e7950..e4350b4e 100644 --- a/src/front/Components/DesignSystem/SearchBar/classes.module.scss +++ b/src/front/Components/DesignSystem/SearchBar/classes.module.scss @@ -2,30 +2,66 @@ .root { display: flex; - align-items: center; - padding-left: 24px; - background-color: var(--color-generic-white); - border: 1px solid var(--color-neutral-200); - position: relative; + padding: var(--spacing-2, 16px) var(--spacing-sm, 8px); + align-items: flex-start; + gap: var(--spacing-2, 16px); - .fake-placeholder { - position: absolute; - left: 47px; - top: 24px; - color: var(--color-neutral-500); - pointer-events: none; + border-radius: var(--input-radius, 0px); + border: 1px solid var(--input-main-border-default, #d7dce0); + background: var(--input-background, #fff); + + &:hover { + border-radius: var(--input-radius, 0px); + border: 1px solid var(--input-main-border-hovered, #b4bec5); + background: var(--input-background, #fff); } - .input { - border: 0; - margin-left: 8px; - padding: 24px 0; - width: 100%; - font-family: "Inter", sans-serif; - font-style: normal; - font-weight: 400; - font-size: 18px; - line-height: 22px; - color: var(--color-neutral-500); + &[data-has-value="true"] { + border-radius: var(--input-radius, 0px); + border: 1px solid var(--input-main-border-filled, #6d7e8a); + background: var(--input-background, #fff); + } + + &[data-is-focused="true"] { + border-radius: var(--input-radius, 0px); + border: 1px solid var(--input-main-border-focused, #005bcb); + background: var(--input-background, #fff); + } + + .input-container { + display: flex; + flex: 1; + gap: 8px; + padding: 0px var(--spacing-2, 16px); + + .input { + flex: 1; + border: none; + + color: var(--input-placeholder-filled, #24282e); + + /* text/md/semibold */ + font-family: var(--font-text-family, Poppins); + font-size: 16px; + font-style: normal; + font-weight: var(--font-text-weight-semibold, 600); + line-height: normal; + letter-spacing: 0.08px; + + &::placeholder { + color: var(--input-placeholder-empty, #6d7e8a); + /* text/md/regular */ + font-family: var(--font-text-family, Poppins); + font-size: 16px; + font-style: normal; + font-weight: var(--font-text-weight-regular, 400); + line-height: normal; + letter-spacing: 0.08px; + } + } + + .cross { + cursor: pointer; + } } } diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 8c16ee0c..9289a034 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -1,54 +1,53 @@ -import LoopIcon from "@Assets/Icons/loop.svg"; -import Image from "next/image"; -import React from "react"; +import React, { useCallback } from "react"; -import Typography, { ETypo, ETypoColor } from "../Typography"; import classes from "./classes.module.scss"; +import { MagnifyingGlassIcon, XMarkIcon } from "@heroicons/react/24/outline"; type IProps = { onChange?: (input: string) => void; placeholder?: string; }; -type IState = { - hasValue: boolean; -}; +export default function SearchBar({ onChange, placeholder = "Rechercher" }: IProps) { + const [isFocused, setIsFocused] = React.useState(false); + const [value, setValue] = React.useState(""); -export default class SearchBar extends React.Component { - static defaultProps = { - placeholder: "Search", - }; + const handleOnChange = useCallback( + (event: React.ChangeEvent) => { + setValue(event.target.value); + onChange && onChange(event.target.value); + }, + [onChange], + ); - public constructor(props: IProps) { - super(props); - this.state = { - hasValue: false, - }; - this.doesInputHaveValue = this.doesInputHaveValue.bind(this); - this.onChange = this.onChange.bind(this); - } - public override render(): JSX.Element { - return ( -
- Loop icon - {!this.state.hasValue && ( - -
{this.props.placeholder}
-
- )} - + const handleFocus = useCallback(() => { + setIsFocused(true); + }, []); + + const handleBlur = useCallback(() => { + setIsFocused(false); + }, []); + + const clearValue = useCallback(() => { + setValue(""); + onChange && onChange(""); + }, [onChange]); + + return ( + + ); }