diff --git a/src/front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary.ts b/src/front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary.ts index 508ffd71..00036c2d 100644 --- a/src/front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary.ts +++ b/src/front/Api/LeCoffreApi/Customer/DocumentsNotary/DocumentsNotary.ts @@ -35,4 +35,16 @@ export default class DocumentsNotary extends BaseCustomer { return Promise.reject(err); } } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Api/LeCoffreApi/Customer/Files/Files.ts b/src/front/Api/LeCoffreApi/Customer/Files/Files.ts index 6ae12cf0..75aebd53 100644 --- a/src/front/Api/LeCoffreApi/Customer/Files/Files.ts +++ b/src/front/Api/LeCoffreApi/Customer/Files/Files.ts @@ -90,4 +90,14 @@ export default class Files extends BaseCustomer { return Promise.reject(err); } } + + public async download(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/download/${uid}`)); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } } diff --git a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx index 7c7f49fd..014498a4 100644 --- a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx @@ -9,7 +9,7 @@ import BackArrow from "@Front/Components/Elements/BackArrow"; import DefaultTemplate from "@Front/Components/LayoutTemplates/DefaultTemplate"; import Module from "@Front/Config/Module"; import JwtService from "@Front/Services/JwtService/JwtService"; -import { ArrowDownTrayIcon } from "@heroicons/react/24/outline"; +import { ArrowDownTrayIcon, EyeIcon } from "@heroicons/react/24/outline"; import { saveAs } from "file-saver"; import JSZip from "jszip"; import DocumentNotary from "le-coffre-resources/dist/Notary/DocumentNotary"; @@ -17,6 +17,7 @@ import { useRouter } from "next/router"; import React, { useCallback, useEffect, useState } from "react"; import classes from "./classes.module.scss"; +import Link from "next/link"; const header: readonly IHead[] = [ { @@ -100,7 +101,7 @@ export default function ReceivedDocuments() { Un document vous a été envoyé - +
+ + + + )} + {(!this.state.selectedFile || !this.state.documentNotary) && !this.state.isLoading && ( +
+ + Document non trouvé + +
+ )} + + ); + } + + override async componentDidMount() { + try { + const documentNotary = await DocumentsNotary.getInstance().getByUid(this.props.documentUid, { + files: true, + folder: true, + depositor: true, + }); + console.log(documentNotary); + + this.setState( + { + documentNotary, + selectedFileIndex: 0, + selectedFile: documentNotary.files![0]!, + isLoading: false, + }, + () => { + this.getFilePreview(); + }, + ); + } catch (e) { + this.setState({ + isLoading: false, + }); + console.error(e); + } + } + + private async getFilePreview(): Promise { + try { + const fileBlob: Blob = await FilesNotary.getInstance().download(this.state.selectedFile?.uid as string, this.props.documentUid); + + this.setState({ + fileBlob, + }); + } catch (e) { + console.error(e); + } + } + + private downloadFile() { + if (!this.state.fileBlob) return; + const url = window.URL.createObjectURL(this.state.fileBlob); + const a = document.createElement("a"); + a.style.display = "none"; + a.href = url; + // the filename you want + a.download = this.state.selectedFile?.file_name as string; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + } + + private goToPrevious() { + const index = this.state.selectedFileIndex - 1; + if (this.hasPrevious()) { + this.setState( + { + selectedFile: this.state.documentNotary!.files![index]!, + selectedFileIndex: index, + fileBlob: null, + }, + () => { + this.getFilePreview(); + }, + ); + } + } + + private goToNext() { + if (this.hasNext()) { + const index = this.state.selectedFileIndex + 1; + this.setState( + { + selectedFile: this.state.documentNotary!.files![index]!, + selectedFileIndex: index, + fileBlob: null, + }, + () => { + this.getFilePreview(); + }, + ); + } + } + + private hasPrevious() { + const index = this.state.selectedFileIndex - 1; + return index >= 0; + } + + private hasNext() { + const index = this.state.selectedFileIndex + 1; + return index < this.state.documentNotary!.files!.length; + } +} + +export default function ViewDocumentsNotary(props: IProps) { + const router = useRouter(); + let { folderUid, documentUid } = router.query; + documentUid = documentUid as string; + folderUid = folderUid as string; + return ; +} diff --git a/src/front/Config/Module/development.json b/src/front/Config/Module/development.json index e6628aad..12e7eb49 100644 --- a/src/front/Config/Module/development.json +++ b/src/front/Config/Module/development.json @@ -38,6 +38,13 @@ "labelKey": "client-dashboard" }, "pages": { + "ViewDocuments": { + "enabled": true, + "props": { + "path": "/client-dashboard/[folderUid]/documentNotary/[documentUid]", + "labelKey": "view_documents" + } + }, "ReceiveDocuments": { "enabled": true, "props": { diff --git a/src/front/Config/Module/preprod.json b/src/front/Config/Module/preprod.json index e6628aad..12e7eb49 100644 --- a/src/front/Config/Module/preprod.json +++ b/src/front/Config/Module/preprod.json @@ -38,6 +38,13 @@ "labelKey": "client-dashboard" }, "pages": { + "ViewDocuments": { + "enabled": true, + "props": { + "path": "/client-dashboard/[folderUid]/documentNotary/[documentUid]", + "labelKey": "view_documents" + } + }, "ReceiveDocuments": { "enabled": true, "props": { diff --git a/src/front/Config/Module/production.json b/src/front/Config/Module/production.json index e6628aad..12e7eb49 100644 --- a/src/front/Config/Module/production.json +++ b/src/front/Config/Module/production.json @@ -38,6 +38,13 @@ "labelKey": "client-dashboard" }, "pages": { + "ViewDocuments": { + "enabled": true, + "props": { + "path": "/client-dashboard/[folderUid]/documentNotary/[documentUid]", + "labelKey": "view_documents" + } + }, "ReceiveDocuments": { "enabled": true, "props": { diff --git a/src/front/Config/Module/staging.json b/src/front/Config/Module/staging.json index e6628aad..12e7eb49 100644 --- a/src/front/Config/Module/staging.json +++ b/src/front/Config/Module/staging.json @@ -38,6 +38,13 @@ "labelKey": "client-dashboard" }, "pages": { + "ViewDocuments": { + "enabled": true, + "props": { + "path": "/client-dashboard/[folderUid]/documentNotary/[documentUid]", + "labelKey": "view_documents" + } + }, "ReceiveDocuments": { "enabled": true, "props": { diff --git a/src/pages/client-dashboard/[folderUid]/documentNotary/[documentUid]/index.tsx b/src/pages/client-dashboard/[folderUid]/documentNotary/[documentUid]/index.tsx new file mode 100644 index 00000000..904ab317 --- /dev/null +++ b/src/pages/client-dashboard/[folderUid]/documentNotary/[documentUid]/index.tsx @@ -0,0 +1,5 @@ +import ViewDocumentsNotary from "@Front/Components/Layouts/ClientDashboard/ViewDocumentsNotary"; + +export default function Route() { + return ; +}