import ChevronIcon from "@Assets/Icons/chevron.svg"; import PlusIcon from "@Assets/Icons/plus.svg"; import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; import Module from "@Front/Config/Module"; import classNames from "classnames"; import Customer, { Document } from "le-coffre-resources/dist/Customer"; import Image from "next/image"; import Link from "next/link"; import React from "react"; import Button, { EButtonVariant } from "../Button"; import Confirm from "../Modal/Confirm"; import QuantityProgressBar from "../QuantityProgressBar"; import classes from "./classes.module.scss"; import DocumentList from "./DocumentList"; import UserFolderHeader from "./UserFolderHeader"; type IProps = { customer: Customer; animationDelay?: number; folder: IDashBoardFolder; isArchived?: boolean; }; type IState = { isOpen: boolean; isOpenDeletionModal: boolean; willClose: boolean; }; export default class UserFolder extends React.Component { static defaultProps = { animationDelay: 300, isArchived: false, }; public rootRefElement = React.createRef(); constructor(props: IProps) { super(props); this.state = { isOpen: false, isOpenDeletionModal: false, willClose: false, }; this.toggleOpen = this.toggleOpen.bind(this); this.closeDeletionModal = this.closeDeletionModal.bind(this); this.openDeletionModal = this.openDeletionModal.bind(this); this.openComponent = this.openComponent.bind(this); this.closeComponent = this.closeComponent.bind(this); } public override render(): JSX.Element { const documentsAsked: Document[] | null = this.getDocumentsByStatus("ASKED"); const otherDocuments: Document[] | null = this.getValidatedAndPendindDocuments(); const redirectPath = Module.getInstance() .get() .modules.pages.Folder.pages.AskDocument.props.path.replace("[folderUid]", this.props.folder.uid); return (
Êtes-vous vous de vouloir supprimer la demande de document ?
chevron open close
{this.state.isOpen && (
0 ? "Vous avez des documents à valider." : "Vous n'avez aucun document à valider" } openDeletionModal={this.openDeletionModal} />
{!this.props.isArchived && (
{}
)}
)}
); } public override componentDidUpdate(): void { this.rootRefElement.current?.style.setProperty("--animation-delay", this.props.animationDelay!.toString().concat("ms")); } private calculateDocumentsPercentageProgress(): number { if (!this.props.customer.documents) return 0; const totalDocuments: number = this.props.customer.documents.length; const numberDocumentsAsked: number = this.getDocumentsByStatus("ASKED")?.length || 0; return Math.round(((totalDocuments - numberDocumentsAsked) / totalDocuments) * 100); } private getDocumentsByStatus(status: string): Document[] | null { if (!this.props.customer.documents) return null; const filteredDocuments = this.props.customer.documents.filter( (document) => document.document_status === status && document.folder.uid === this.props.folder.uid, ); return filteredDocuments; } // Get all documents Validated, pending private getValidatedAndPendindDocuments(): Document[] | null { const pendingDocuments = this.getDocumentsByStatus("PENDING"); const validatedDocuments = this.getDocumentsByStatus("VALIDATED"); if (!pendingDocuments && !validatedDocuments) return null; pendingDocuments?.push(...validatedDocuments!); return pendingDocuments; } // TODO: REFACTO this because the other documents should only be correspond to other documents of the props folders // private getOtherDocuments(documentToExclude: Document[] | null): Document[] | null { // if (!this.props.customer.documents) return null; // if (!documentToExclude) return this.props.customer.documents; // return this.props.customer.documents.filter((document) => !documentToExclude.includes(document)); // } private toggleOpen(): void { if (this.state.isOpen) { this.closeComponent(); } else { this.openComponent(); } } private openComponent(): void { this.setState({ isOpen: true, }); } private closeComponent(): void { if (this.state.willClose) return; this.setState({ willClose: true }); window.setTimeout(() => { this.setState({ isOpen: false, willClose: false, }); }, this.props.animationDelay); } private openDeletionModal(uid: string): void { // TODO: call API to delete document this.setState({ isOpenDeletionModal: true, }); } private closeDeletionModal(): void { this.setState({ isOpenDeletionModal: false, }); } }