Fix some bugs - continue
This commit is contained in:
parent
39c14ff490
commit
6ed6682824
@ -78,21 +78,8 @@ export default class FileService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getFiles(): Promise<any[]> {
|
|
||||||
return this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['utype'] && publicValues['utype'] === 'file' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getFileByUid(uid: string): Promise<any> {
|
public static getFileByUid(uid: string): Promise<any> {
|
||||||
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
return this.messageBus.getFileByUid(uid);
|
||||||
this.messageBus.getProcessesDecoded((publicValues: any) => publicValues['uid'] && publicValues['uid'] === uid && publicValues['utype'] && publicValues['utype'] === 'file' && publicValues['isDeleted'] && publicValues['isDeleted'] === 'false').then(async (processes: any[]) => {
|
|
||||||
if (processes.length === 0) {
|
|
||||||
resolve(null);
|
|
||||||
} else {
|
|
||||||
const process: any = processes[0];
|
|
||||||
resolve(process);
|
|
||||||
}
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static updateFile(process: any, newData: any): Promise<void> {
|
public static updateFile(process: any, newData: any): Promise<void> {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import DragAndDrop, { IDocumentFileWithUid } from "@Front/Components/DesignSystem/DragAndDrop";
|
import DragAndDrop, { IDocumentFileWithUid } from "@Front/Components/DesignSystem/DragAndDrop";
|
||||||
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||||
import { Document } from "le-coffre-resources/dist/Customer";
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
@ -12,7 +11,7 @@ import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
|||||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
document: Document;
|
document: any;
|
||||||
onChange: () => void;
|
onChange: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,29 +21,16 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
const [refused_reason, setRefusedReason] = useState<string | null>(null);
|
const [refused_reason, setRefusedReason] = useState<string | null>(null);
|
||||||
|
|
||||||
const defaultFiles: IDocumentFileWithUid[] = useMemo(() => {
|
const defaultFiles: IDocumentFileWithUid[] = useMemo(() => {
|
||||||
const filesNotArchived = document.files?.filter((file) => !file.archived_at) ?? [];
|
const filesNotArchived = document.files?.filter((file: any) => !file.archived_at) ?? [];
|
||||||
return filesNotArchived.map((file) => ({
|
return filesNotArchived.map((file: any) => ({
|
||||||
id: file.uid!,
|
id: file.uid!,
|
||||||
file: new File([""], file.file_name!, { type: file.mimetype }),
|
file: new File([""], file.file_name!, { type: file.file_blob.type }),
|
||||||
uid: file.uid!,
|
uid: file.uid!,
|
||||||
}));
|
}));
|
||||||
}, [document.files]);
|
}, [document.files]);
|
||||||
|
|
||||||
const addFile = useCallback(
|
const addFile = useCallback(
|
||||||
(file: File) => {
|
(file: File) => {
|
||||||
/* TODO: review
|
|
||||||
const formData = new FormData();
|
|
||||||
const safeFileName = file.name.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
||||||
formData.append("file", file, safeFileName);
|
|
||||||
const query = JSON.stringify({ document: { uid: document.uid } });
|
|
||||||
formData.append("q", query);
|
|
||||||
return Files.getInstance()
|
|
||||||
.post(formData)
|
|
||||||
.then(onChange)
|
|
||||||
.then(() => ToasterService.getInstance().success({ title: "Succès !", description: "Fichier uploadé avec succès!" }))
|
|
||||||
.catch((error) => ToasterService.getInstance().error({ title: "Erreur !", description: error.message }));
|
|
||||||
*/
|
|
||||||
|
|
||||||
return new Promise<void>(
|
return new Promise<void>(
|
||||||
(resolve: () => void) => {
|
(resolve: () => void) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
@ -53,25 +39,31 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
const arrayBuffer = event.target.result as ArrayBuffer;
|
const arrayBuffer = event.target.result as ArrayBuffer;
|
||||||
const uint8Array = new Uint8Array(arrayBuffer);
|
const uint8Array = new Uint8Array(arrayBuffer);
|
||||||
|
|
||||||
const fileBlob = {
|
const fileBlob: any = {
|
||||||
type: file.type,
|
type: file.type,
|
||||||
data: uint8Array
|
data: uint8Array
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileData = {
|
const fileData: any = {
|
||||||
document: {
|
file_blob: fileBlob,
|
||||||
uid: document.uid!
|
file_name: file.name
|
||||||
},
|
};
|
||||||
fileBlob: fileBlob,
|
|
||||||
file_name: file.name,
|
|
||||||
mimetype: file.type
|
|
||||||
}
|
|
||||||
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
|
||||||
|
|
||||||
FileService.createFile(fileData, validatorId).then(() => {
|
FileService.createFile(fileData, validatorId).then((processCreated: any) => {
|
||||||
|
const fileUid: string = processCreated.processData.uid;
|
||||||
|
|
||||||
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
|
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DocumentService.updateDocument(process, { document_status: EDocumentStatus.DEPOSITED }).then(() => resolve());
|
const document: any = process.processData;
|
||||||
|
|
||||||
|
let files: any[] = document.files;
|
||||||
|
if (!files) {
|
||||||
|
files = [];
|
||||||
|
}
|
||||||
|
files.push({ uid: fileUid });
|
||||||
|
|
||||||
|
DocumentService.updateDocument(process, { files: files, document_status: EDocumentStatus.DEPOSITED }).then(() => resolve());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -87,15 +79,23 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const deleteFile = useCallback(
|
const deleteFile = useCallback(
|
||||||
(filedUid: string) => {
|
(fileUid: string) => {
|
||||||
return new Promise<void>(
|
return new Promise<void>(
|
||||||
(resolve: () => void) => {
|
(resolve: () => void) => {
|
||||||
FileService.getFileByUid(filedUid).then((process: any) => {
|
FileService.getFileByUid(fileUid).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
FileService.updateFile(process, { isDeleted: 'true' }).then(() => {
|
FileService.updateFile(process, { isDeleted: 'true' }).then(() => {
|
||||||
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
|
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
DocumentService.updateDocument(process, { document_status: EDocumentStatus.ASKED }).then(() => resolve());
|
const document: any = process.processData;
|
||||||
|
|
||||||
|
let files: any[] = document.files;
|
||||||
|
if (!files) {
|
||||||
|
files = [];
|
||||||
|
}
|
||||||
|
files = files.filter((file: any) => file.uid !== fileUid);
|
||||||
|
|
||||||
|
DocumentService.updateDocument(process, { files: files, document_status: EDocumentStatus.ASKED }).then(() => resolve());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -110,7 +110,7 @@ export default function DepositDocumentComponent(props: IProps) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onOpenModal = useCallback(async () => {
|
const onOpenModal = useCallback(async () => {
|
||||||
const refused_reason = document.document_history?.find((history) => history.document_status === "REFUSED")?.refused_reason;
|
const refused_reason = document.document_history?.find((history: any) => history.document_status === "REFUSED")?.refused_reason;
|
||||||
if (!refused_reason) return;
|
if (!refused_reason) return;
|
||||||
setRefusedReason(refused_reason);
|
setRefusedReason(refused_reason);
|
||||||
setIsModalOpen(true);
|
setIsModalOpen(true);
|
||||||
|
@ -3,7 +3,7 @@ import RightArrowIcon from "@Assets/Icons/right-arrow.svg";
|
|||||||
import Button from "@Front/Components/DesignSystem/Button";
|
import Button from "@Front/Components/DesignSystem/Button";
|
||||||
import FilePreview from "@Front/Components/DesignSystem/FilePreview";
|
import FilePreview from "@Front/Components/DesignSystem/FilePreview";
|
||||||
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||||
import { DocumentNotary, File } from "le-coffre-resources/dist/Notary";
|
import { DocumentNotary } from "le-coffre-resources/dist/Notary";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { NextRouter, useRouter } from "next/router";
|
import { NextRouter, useRouter } from "next/router";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@ -25,7 +25,7 @@ type IState = {
|
|||||||
isValidateModalVisible: boolean;
|
isValidateModalVisible: boolean;
|
||||||
refuseText: string;
|
refuseText: string;
|
||||||
selectedFileIndex: number;
|
selectedFileIndex: number;
|
||||||
selectedFile: File | null;
|
selectedFile: any;
|
||||||
documentNotary: DocumentNotary | null;
|
documentNotary: DocumentNotary | null;
|
||||||
fileBlob: Blob | null;
|
fileBlob: Blob | null;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
@ -71,10 +71,10 @@ class ViewDocumentsNotaryClass extends BasePage<IPropsClass, IState> {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className={classes["file-container"]}>
|
<div className={classes["file-container"]}>
|
||||||
{this.state.selectedFile.mimetype === "application/pdf" ||
|
{this.state.selectedFile.file_blob.type === "application/pdf" ||
|
||||||
this.state.selectedFile.mimetype === "image/jpeg" ||
|
this.state.selectedFile.file_blob.type === "image/jpeg" ||
|
||||||
this.state.selectedFile.mimetype === "image/png" ||
|
this.state.selectedFile.file_blob.type === "image/png" ||
|
||||||
this.state.selectedFile.mimetype === "image/jpg" ? (
|
this.state.selectedFile.file_blob.type === "image/jpg" ? (
|
||||||
<FilePreview
|
<FilePreview
|
||||||
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
||||||
fileName={this.state.selectedFile.file_name}
|
fileName={this.state.selectedFile.file_name}
|
||||||
|
@ -111,7 +111,7 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
|
|
||||||
const fetchDocuments = useCallback(
|
const fetchDocuments = useCallback(
|
||||||
async (customerUid: string | undefined) => {
|
async (customerUid: string | undefined) => {
|
||||||
/*
|
/* TODO: review
|
||||||
const query: IGetDocumentsparams = {
|
const query: IGetDocumentsparams = {
|
||||||
where: { depositor: { uid: customerUid }, folder_uid: folderUid as string },
|
where: { depositor: { uid: customerUid }, folder_uid: folderUid as string },
|
||||||
include: {
|
include: {
|
||||||
@ -136,8 +136,6 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
.then((documents) => setDocuments(documents));
|
.then((documents) => setDocuments(documents));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const files: any[] = (await FileService.getFiles()).map((p: any) => p.processData);
|
|
||||||
|
|
||||||
return DocumentService.getDocuments().then(async (processes: any[]) => {
|
return DocumentService.getDocuments().then(async (processes: any[]) => {
|
||||||
if (processes.length > 0) {
|
if (processes.length > 0) {
|
||||||
let documents: any[] = processes.map((process: any) => process.processData);
|
let documents: any[] = processes.map((process: any) => process.processData);
|
||||||
@ -146,11 +144,14 @@ export default function ClientDashboard(props: IProps) {
|
|||||||
documents = documents.filter((document: any) => document.folder.uid === folderUid);
|
documents = documents.filter((document: any) => document.folder.uid === folderUid);
|
||||||
|
|
||||||
for (const document of documents) {
|
for (const document of documents) {
|
||||||
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
|
document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData;
|
||||||
document.document_type = p.processData;
|
|
||||||
|
|
||||||
if (files.length > 0) {
|
if (document.files && document.files.length > 0) {
|
||||||
document.files = files.filter((file: any) => file.document.uid === document.uid);
|
const files: any[] = [];
|
||||||
|
for (const file of document.files) {
|
||||||
|
files.push((await FileService.getFileByUid(file.uid)).processData);
|
||||||
|
}
|
||||||
|
document.files = files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import Modal from "@Front/Components/DesignSystem/Modal";
|
import Modal from "@Front/Components/DesignSystem/Modal";
|
||||||
import { File } from "le-coffre-resources/dist/Customer";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
file: File;
|
file: any;
|
||||||
url: string;
|
url: string;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
@ -14,7 +13,7 @@ export default function FilePreviewModal(props: IProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal key={file.uid} isOpen={isOpen} onClose={onClose} fullscreen>
|
<Modal key={file.uid} isOpen={isOpen} onClose={onClose} fullscreen>
|
||||||
<object data={url} type={file.mimetype} width="100%" height="800px" />
|
<object data={url} type={file.file_blob.type} width="100%" height="800px" />
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary";
|
import DocumentsNotary from "@Front/Api/LeCoffreApi/Notary/DocumentsNotary/DocumentsNotary";
|
||||||
import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
|
|
||||||
import FilesNotary from "@Front/Api/LeCoffreApi/Notary/FilesNotary/Files";
|
import FilesNotary from "@Front/Api/LeCoffreApi/Notary/FilesNotary/Files";
|
||||||
import CircleProgress from "@Front/Components/DesignSystem/CircleProgress";
|
import CircleProgress from "@Front/Components/DesignSystem/CircleProgress";
|
||||||
import IconButton from "@Front/Components/DesignSystem/IconButton";
|
import IconButton from "@Front/Components/DesignSystem/IconButton";
|
||||||
@ -24,8 +23,7 @@ import DeleteSentDocumentModal from "./DeleteSentDocumentModal";
|
|||||||
|
|
||||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||||
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
import DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
||||||
|
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||||
import MessageBus from "src/sdk/MessageBus";
|
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
customerUid: string;
|
customerUid: string;
|
||||||
@ -66,17 +64,15 @@ export default function DocumentTables(props: IProps) {
|
|||||||
// FilterBy folder.uid & depositor.uid
|
// FilterBy folder.uid & depositor.uid
|
||||||
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor.uid === customerUid);
|
documents = documents.filter((document: any) => document.folder.uid === folderUid && document.depositor.uid === customerUid);
|
||||||
|
|
||||||
const ps: any[] = await MessageBus.getInstance().getFiles();
|
|
||||||
|
|
||||||
for (const document of documents) {
|
for (const document of documents) {
|
||||||
const documentTypeUid: string = document.document_type.uid;
|
document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData;
|
||||||
|
|
||||||
const p1: any = await DocumentTypeService.getDocumentTypeByUid(documentTypeUid);
|
if (document.files && document.files.length > 0) {
|
||||||
document.document_type = p1.processData;
|
const files: any[] = [];
|
||||||
|
for (const file of document.files) {
|
||||||
const p2: any = ps.find((p2: any) => p2.processData.document.get('uid') === document.uid);
|
files.push((await FileService.getFileByUid(file.uid)).processData);
|
||||||
if (p2) {
|
}
|
||||||
document.files = [p2.processData];
|
document.files = files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +118,12 @@ export default function DocumentTables(props: IProps) {
|
|||||||
[deleteSentDocumentModal],
|
[deleteSentDocumentModal],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onDownload = useCallback((doc: any /* Document */) => {
|
const onDownload = useCallback((doc: any) => {
|
||||||
const file = doc.files?.[0];
|
const file = doc.files?.[0];
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
return new Promise<void>((resolve: () => void) => {
|
return new Promise<void>((resolve: () => void) => {
|
||||||
const blob = new Blob([file.fileBlob.data], { type: file.fileBlob.type });
|
const blob = new Blob([file.file_blob.data], { type: file.file_blob.type });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
|
@ -23,6 +23,7 @@ import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
|
|||||||
|
|
||||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||||
import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService";
|
import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService";
|
||||||
|
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||||
|
|
||||||
export enum AnchorStatus {
|
export enum AnchorStatus {
|
||||||
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
|
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
|
||||||
@ -107,25 +108,39 @@ export default function FolderInformation(props: IProps) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: review
|
// TODO: review
|
||||||
return FolderService.getFolderByUid(folderUid).then((process: any) => {
|
return FolderService.getFolderByUid(folderUid).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const folder: any = process.processData;
|
const folder: any = process.processData;
|
||||||
|
|
||||||
NoteService.getNotes().then((processes: any) => {
|
await new Promise<void>((resolve: () => void) => {
|
||||||
if (processes.length > 0) {
|
NoteService.getNotes().then((processes: any) => {
|
||||||
let notes: any[] = processes.map((process: any) => process.processData);
|
if (processes.length > 0) {
|
||||||
|
let notes: any[] = processes.map((process: any) => process.processData);
|
||||||
|
|
||||||
// FilterBy folder.uid
|
// FilterBy folder.uid
|
||||||
notes = notes.filter((note: any) => note.folder.uid === folderUid);
|
notes = notes.filter((note: any) => note.folder.uid === folderUid);
|
||||||
|
|
||||||
if (notes.length > 0) {
|
if (notes.length > 0) {
|
||||||
folder.notes = notes;
|
folder.notes = notes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
resolve();
|
||||||
|
});
|
||||||
setFolder(folder);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await new Promise<void>((resolve: () => void) => {
|
||||||
|
DocumentService.getDocuments().then((processes: any[]) => {
|
||||||
|
if (processes.length > 0) {
|
||||||
|
const documents: any[] = processes.map((process: any) => process.processData);
|
||||||
|
for (const customer of folder.customers) {
|
||||||
|
customer.documents = documents.filter((document: any) => document.depositor.uid === customer.uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
setFolder(folder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [folderUid]);
|
}, [folderUid]);
|
||||||
|
@ -18,8 +18,7 @@ import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
|||||||
import MessageBox from "@Front/Components/Elements/MessageBox";
|
import MessageBox from "@Front/Components/Elements/MessageBox";
|
||||||
|
|
||||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||||
|
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||||
import MessageBus from "src/sdk/MessageBus";
|
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
type IPropsClass = {
|
type IPropsClass = {
|
||||||
@ -91,10 +90,10 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className={classes["file-container"]}>
|
<div className={classes["file-container"]}>
|
||||||
{this.state.selectedFile.mimetype === "application/pdf" ||
|
{this.state.selectedFile.file_blob.type === "application/pdf" ||
|
||||||
this.state.selectedFile.mimetype === "image/jpeg" ||
|
this.state.selectedFile.file_blob.type === "image/jpeg" ||
|
||||||
this.state.selectedFile.mimetype === "image/png" ||
|
this.state.selectedFile.file_blob.type === "image/png" ||
|
||||||
this.state.selectedFile.mimetype === "image/jpg" ? (
|
this.state.selectedFile.file_blob.type === "image/jpg" ? (
|
||||||
<FilePreview
|
<FilePreview
|
||||||
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
||||||
fileName={this.state.selectedFile.file_name}
|
fileName={this.state.selectedFile.file_name}
|
||||||
@ -199,27 +198,17 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
|
|
||||||
override async componentDidMount() {
|
override async componentDidMount() {
|
||||||
try {
|
try {
|
||||||
/* TODO: review
|
|
||||||
const document = await Documents.getInstance().getByUid(this.props.documentUid, {
|
|
||||||
files: {
|
|
||||||
where: { archived_at: null },
|
|
||||||
},
|
|
||||||
document_type: true,
|
|
||||||
folder: true,
|
|
||||||
depositor: true,
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
const document: any = await new Promise((resolve: (document: any) => void) => {
|
const document: any = await new Promise((resolve: (document: any) => void) => {
|
||||||
DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => {
|
DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => {
|
||||||
if (process) {
|
if (process) {
|
||||||
const document: any = process.processData;
|
const document: any = process.processData;
|
||||||
|
|
||||||
const ps: any[] = await MessageBus.getInstance().getFiles();
|
if (document.files && document.files.length > 0) {
|
||||||
const p: any = ps.find((p: any) => p.processData.document.get('uid') === document.uid);
|
const files: any[] = [];
|
||||||
if (p) {
|
for (const file of document.files) {
|
||||||
|
files.push((await FileService.getFileByUid(file.uid)).processData);
|
||||||
document.files = [p.processData];
|
}
|
||||||
|
document.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(document);
|
resolve(document);
|
||||||
@ -248,12 +237,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
|
|
||||||
private async getFilePreview(): Promise<void> {
|
private async getFilePreview(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// TODO: review
|
const fileBlob: Blob = new Blob([this.state.selectedFile.file_blob.data], { type: this.state.selectedFile.file_blob.type });
|
||||||
const file: any = this.state.selectedFile.fileBlob;
|
|
||||||
|
|
||||||
const fileBlob: Blob = new Blob([file.data], { type: file.type });
|
|
||||||
//const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
fileBlob,
|
fileBlob,
|
||||||
});
|
});
|
||||||
@ -263,12 +247,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private downloadFile() {
|
private downloadFile() {
|
||||||
// TODO: review
|
if (!this.state.fileBlob) return;
|
||||||
//if (!this.state.fileBlob) return;
|
|
||||||
const file: any = this.state.selectedFile.fileBlob;
|
|
||||||
|
|
||||||
const blob = new Blob([file.data], { type: file.type });
|
const url = URL.createObjectURL(this.state.fileBlob);
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = this.state.selectedFile.file_name;
|
a.download = this.state.selectedFile.file_name;
|
||||||
|
@ -100,7 +100,7 @@ export default class MessageBus {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFiles(): Promise<any> {
|
public getFileByUid(uid: string): Promise<any> {
|
||||||
return new Promise<any>((resolve: (files: any[]) => void, reject: (error: string) => void) => {
|
return new Promise<any>((resolve: (files: any[]) => void, reject: (error: string) => void) => {
|
||||||
this.getProcesses().then(async (processes: any) => {
|
this.getProcesses().then(async (processes: any) => {
|
||||||
const files: any[] = [];
|
const files: any[] = [];
|
||||||
@ -129,7 +129,7 @@ export default class MessageBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (publicDataDecoded['utype'] !== 'file') {
|
if (!(publicDataDecoded['uid'] && publicDataDecoded['uid'] === uid && publicDataDecoded['utype'] && publicDataDecoded['utype'] === 'file')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +171,10 @@ export default class MessageBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
files.push(file);
|
files.push(file);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(files);
|
resolve(files[0]);
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user