From a979438a5fff4a899f56e9a3afc6acbfaab74509 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Tue, 2 May 2023 09:57:59 +0200 Subject: [PATCH] :sparkles: Handling default files --- .../DesignSystem/DepositDocument/index.tsx | 30 +++++++++++++++---- .../Layouts/ClientDashboard/index.tsx | 12 +++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/front/Components/DesignSystem/DepositDocument/index.tsx b/src/front/Components/DesignSystem/DepositDocument/index.tsx index a9632b22..909cf124 100644 --- a/src/front/Components/DesignSystem/DepositDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositDocument/index.tsx @@ -9,12 +9,12 @@ import Button, { EButtonVariant } from "../Button"; import Tooltip from "../ToolTip"; import Typography, { ITypo, ITypoColor } from "../Typography"; import classes from "./classes.module.scss"; -import { Document } from "le-coffre-resources/dist/Customer"; +import { File as FileCustomer } from "le-coffre-resources/dist/Customer"; type IProps = { title: string; dateAsked: Date; - defaultDocuments?: Document[]; + defaultFiles?: FileCustomer[]; onChange?: (files: File[]) => void; }; @@ -80,7 +80,7 @@ export default class DepositDocument extends React.Component {
Document check - {fileObj.name} + {this.shortName(fileObj.name)}
{ ); } + public override componentDidMount(): void { + console.log(this.props.defaultFiles); + if (this.props.defaultFiles) { + this.setState({ + files: this.props.defaultFiles.map((file) => ({ + index: this.index++, + file: new File([""], file.file_path, {}), + })), + }); + } + } + + private shortName(name: string): string { + const maxLength = 20; + if (name.length > maxLength) { + return name.substring(0, maxLength / 2) + "..." + name.substring(name.length - maxLength / 2, name.length); + } + return name; + } + private onDragOver(event: React.DragEvent) { if (!this.state.isDragOver) { this.setState({ @@ -143,7 +163,7 @@ export default class DepositDocument extends React.Component { ], }); - if (this.props.onChange) this.props.onChange(this.state.files.map((file) => file.file)); + if (this.props.onChange) this.props.onChange(this.state.files.map((file) => file.file)); } private removeFile(e: any) { @@ -154,7 +174,7 @@ export default class DepositDocument extends React.Component { files: this.state.files.filter((file) => file.index !== parseInt(indexToRemove)), }); - if (this.props.onChange) this.props.onChange(this.state.files.map((file) => file.file)); + if (this.props.onChange) this.props.onChange(this.state.files.map((file) => file.file)); } private async onFileChange() { diff --git a/src/front/Components/Layouts/ClientDashboard/index.tsx b/src/front/Components/Layouts/ClientDashboard/index.tsx index cbfd4649..1f147b94 100644 --- a/src/front/Components/Layouts/ClientDashboard/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/index.tsx @@ -6,7 +6,7 @@ import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import Base from "@Front/Components/Layouts/Base"; import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate"; import React from "react"; - +import { documentDeposited } from "../DesignSystem/dummyData"; import classes from "./classes.module.scss"; type IProps = {}; @@ -31,7 +31,11 @@ export default class ClientDashboard extends Base { {this.renderHeader()}
- + @@ -40,10 +44,10 @@ export default class ClientDashboard extends Base {
Documents supplémentaires (facultatif) - Vous souhaitez envoyer d’autres documents à votre notaire ? + Vous souhaitez envoyer d'autres documents à votre notaire ?