From b011d2e41eed3bb72f366f98601164034403e0db Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Thu, 26 Oct 2023 13:23:48 +0200 Subject: [PATCH] add alert modal for wrong file types --- .../DesignSystem/DepositDocument/index.tsx | 28 ++- .../DepositOtherDocument/index.tsx | 190 ++++++++++-------- .../Modal/Alert/classes.module.scss | 26 ++- 3 files changed, 154 insertions(+), 90 deletions(-) diff --git a/src/front/Components/DesignSystem/DepositDocument/index.tsx b/src/front/Components/DesignSystem/DepositDocument/index.tsx index be75b1ac..c72738a6 100644 --- a/src/front/Components/DesignSystem/DepositDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositDocument/index.tsx @@ -14,6 +14,7 @@ import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; import classNames from "classnames"; import Confirm from "../Modal/Confirm"; +import Alert from "../Modal/Alert"; import GreenCheckIcon from "@Assets/Icons/green-check.svg"; import Loader from "../Loader"; import TextAreaField from "../Form/TextareaField"; @@ -38,6 +39,7 @@ type IState = { currentFiles?: FileCustomer[]; refusedReason?: string; isShowRefusedReasonModalVisible: boolean; + showFailedUploaded: string | null; loading: boolean; }; @@ -78,6 +80,7 @@ export default class DepositDocument extends React.Component { currentFiles: this.props.defaultFiles, refusedReason: "", isShowRefusedReasonModalVisible: false, + showFailedUploaded: null, loading: false, }; @@ -90,6 +93,7 @@ export default class DepositDocument extends React.Component { this.onCloseModalShowRefusedReason = this.onCloseModalShowRefusedReason.bind(this); this.onOpenModalShowRefusedReason = this.onOpenModalShowRefusedReason.bind(this); this.showRefusedReason = this.showRefusedReason.bind(this); + this.onCloseAlertUpload = this.onCloseAlertUpload.bind(this); } public override render(): JSX.Element { @@ -210,6 +214,17 @@ export default class DepositDocument extends React.Component { Ce document n'est pas conforme. Veuillez le déposer à nouveau. )} + {this.state.showFailedUploaded && ( + +
+ + {this.state.showFailedUploaded} + +
+
+ )} ); } @@ -339,7 +354,14 @@ export default class DepositDocument extends React.Component { const query = JSON.stringify({ document: { uid: this.props.document.uid } }); formData.append("q", query); - const newFile = await Files.getInstance().post(formData); + let newFile: FileCustomer; + try { + newFile = await Files.getInstance().post(formData); + } catch (e) { + + this.setState({ showFailedUploaded: "Le fichier ne correspond pas aux critères demandés", loading: false, }); + return false; + } const files = this.state.currentFiles ? [...this.state.currentFiles, newFile] : [newFile]; const newFileList = [ @@ -396,6 +418,10 @@ export default class DepositDocument extends React.Component { } } + private onCloseAlertUpload() { + this.setState({ showFailedUploaded: null }); + } + private addDocument() { if (!this.inputRef.current) return; this.inputRef.current.value = ""; diff --git a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx index d2192944..467be008 100644 --- a/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx +++ b/src/front/Components/DesignSystem/DepositOtherDocument/index.tsx @@ -16,6 +16,7 @@ import Button, { EButtonVariant } from "../Button"; import Confirm from "../Modal/Confirm"; import Documents from "@Front/Api/LeCoffreApi/Customer/Documents/Documents"; import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files"; +import Alert from "../Modal/Alert"; type IProps = { onChange?: (files: File[]) => void; @@ -38,6 +39,7 @@ type IState = { currentFiles?: IFile[]; refusedReason?: string; isShowRefusedReasonModalVisible: boolean; + showFailedUploaded: string | null; isAddDocumentModalVisible: boolean; isLoading: boolean; }; @@ -55,6 +57,7 @@ export default class DepositOtherDocument extends React.Component -
-
- - Vous souhaitez envoyer un autre document à votre notaire ? - - - Glissez / Déposez votre document dans la zone prévue à cet effet ou cliquez sur la zone puis sélectionnez le - document correspondant. - -
- -
-
- Deposit document -
-
-
- -
- {this.props.document.document_type?.name} -
-
- - Sélectionnez des documents .jpg, .pdf ou .png - -
-
- {this.state.currentFiles && this.state.currentFiles.length > 0 && ( -
- {this.state.currentFiles.map((file) => { - - const fileObj = file.file; - - return ( -
-
- Document check - - {this.shortName(fileObj.name)} - -
- Cross icon +
+ +
+
+ + Vous souhaitez envoyer un autre document à votre notaire ? + + + Glissez / Déposez votre document dans la zone prévue à cet effet ou cliquez sur la zone puis sélectionnez le + document correspondant. + +
+ +
+
+ Deposit document +
+
+
+ +
+ {this.props.document.document_type?.name}
- ); - })} +
+ + Sélectionnez des documents .jpg, .pdf ou .png + +
+
+ {this.state.currentFiles && this.state.currentFiles.length > 0 && ( +
+ {this.state.currentFiles.map((file) => { + const fileObj = file.file; + + return ( +
+
+ Document check + + {this.shortName(fileObj.name)} + +
+ Cross icon +
+ ); + })} +
+ )} +
+
- )} -
-
-
- + + {this.state.showFailedUploaded && ( + +
+ + {this.state.showFailedUploaded} + +
+
+ )} +
); } public override componentDidMount(): void {} + private onCloseAlertUpload() { + this.setState({ showFailedUploaded: null }); + } + private async onAccept() { this.setState({ isLoading: true, @@ -182,7 +203,12 @@ export default class DepositOtherDocument extends React.Component