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> {
|
||||
return new Promise<any>((resolve: (process: any) => void, reject: (error: string) => void) => {
|
||||
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);
|
||||
});
|
||||
return this.messageBus.getFileByUid(uid);
|
||||
}
|
||||
|
||||
public static updateFile(process: any, newData: any): Promise<void> {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import DragAndDrop, { IDocumentFileWithUid } from "@Front/Components/DesignSystem/DragAndDrop";
|
||||
import Typography, { ETypo, ETypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
|
||||
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";
|
||||
|
||||
type IProps = {
|
||||
document: Document;
|
||||
document: any;
|
||||
onChange: () => void;
|
||||
};
|
||||
|
||||
@ -22,29 +21,16 @@ export default function DepositDocumentComponent(props: IProps) {
|
||||
const [refused_reason, setRefusedReason] = useState<string | null>(null);
|
||||
|
||||
const defaultFiles: IDocumentFileWithUid[] = useMemo(() => {
|
||||
const filesNotArchived = document.files?.filter((file) => !file.archived_at) ?? [];
|
||||
return filesNotArchived.map((file) => ({
|
||||
const filesNotArchived = document.files?.filter((file: any) => !file.archived_at) ?? [];
|
||||
return filesNotArchived.map((file: any) => ({
|
||||
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!,
|
||||
}));
|
||||
}, [document.files]);
|
||||
|
||||
const addFile = useCallback(
|
||||
(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>(
|
||||
(resolve: () => void) => {
|
||||
const reader = new FileReader();
|
||||
@ -53,25 +39,31 @@ export default function DepositDocumentComponent(props: IProps) {
|
||||
const arrayBuffer = event.target.result as ArrayBuffer;
|
||||
const uint8Array = new Uint8Array(arrayBuffer);
|
||||
|
||||
const fileBlob = {
|
||||
const fileBlob: any = {
|
||||
type: file.type,
|
||||
data: uint8Array
|
||||
};
|
||||
|
||||
const fileData = {
|
||||
document: {
|
||||
uid: document.uid!
|
||||
},
|
||||
fileBlob: fileBlob,
|
||||
file_name: file.name,
|
||||
mimetype: file.type
|
||||
}
|
||||
const fileData: any = {
|
||||
file_blob: fileBlob,
|
||||
file_name: file.name
|
||||
};
|
||||
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) => {
|
||||
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(
|
||||
(filedUid: string) => {
|
||||
(fileUid: string) => {
|
||||
return new Promise<void>(
|
||||
(resolve: () => void) => {
|
||||
FileService.getFileByUid(filedUid).then((process: any) => {
|
||||
FileService.getFileByUid(fileUid).then((process: any) => {
|
||||
if (process) {
|
||||
FileService.updateFile(process, { isDeleted: 'true' }).then(() => {
|
||||
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
|
||||
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 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;
|
||||
setRefusedReason(refused_reason);
|
||||
setIsModalOpen(true);
|
||||
|
@ -3,7 +3,7 @@ import RightArrowIcon from "@Assets/Icons/right-arrow.svg";
|
||||
import Button from "@Front/Components/DesignSystem/Button";
|
||||
import FilePreview from "@Front/Components/DesignSystem/FilePreview";
|
||||
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 { NextRouter, useRouter } from "next/router";
|
||||
import React from "react";
|
||||
@ -25,7 +25,7 @@ type IState = {
|
||||
isValidateModalVisible: boolean;
|
||||
refuseText: string;
|
||||
selectedFileIndex: number;
|
||||
selectedFile: File | null;
|
||||
selectedFile: any;
|
||||
documentNotary: DocumentNotary | null;
|
||||
fileBlob: Blob | null;
|
||||
isLoading: boolean;
|
||||
@ -71,10 +71,10 @@ class ViewDocumentsNotaryClass extends BasePage<IPropsClass, IState> {
|
||||
</div>
|
||||
)}
|
||||
<div className={classes["file-container"]}>
|
||||
{this.state.selectedFile.mimetype === "application/pdf" ||
|
||||
this.state.selectedFile.mimetype === "image/jpeg" ||
|
||||
this.state.selectedFile.mimetype === "image/png" ||
|
||||
this.state.selectedFile.mimetype === "image/jpg" ? (
|
||||
{this.state.selectedFile.file_blob.type === "application/pdf" ||
|
||||
this.state.selectedFile.file_blob.type === "image/jpeg" ||
|
||||
this.state.selectedFile.file_blob.type === "image/png" ||
|
||||
this.state.selectedFile.file_blob.type === "image/jpg" ? (
|
||||
<FilePreview
|
||||
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
||||
fileName={this.state.selectedFile.file_name}
|
||||
|
@ -111,7 +111,7 @@ export default function ClientDashboard(props: IProps) {
|
||||
|
||||
const fetchDocuments = useCallback(
|
||||
async (customerUid: string | undefined) => {
|
||||
/*
|
||||
/* TODO: review
|
||||
const query: IGetDocumentsparams = {
|
||||
where: { depositor: { uid: customerUid }, folder_uid: folderUid as string },
|
||||
include: {
|
||||
@ -136,8 +136,6 @@ export default function ClientDashboard(props: IProps) {
|
||||
.then((documents) => setDocuments(documents));
|
||||
*/
|
||||
|
||||
const files: any[] = (await FileService.getFiles()).map((p: any) => p.processData);
|
||||
|
||||
return DocumentService.getDocuments().then(async (processes: any[]) => {
|
||||
if (processes.length > 0) {
|
||||
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);
|
||||
|
||||
for (const document of documents) {
|
||||
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
|
||||
document.document_type = p.processData;
|
||||
document.document_type = (await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid)).processData;
|
||||
|
||||
if (files.length > 0) {
|
||||
document.files = files.filter((file: any) => file.document.uid === document.uid);
|
||||
if (document.files && document.files.length > 0) {
|
||||
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 { File } from "le-coffre-resources/dist/Customer";
|
||||
import React from "react";
|
||||
|
||||
type IProps = {
|
||||
file: File;
|
||||
file: any;
|
||||
url: string;
|
||||
isOpen: boolean;
|
||||
onClose?: () => void;
|
||||
@ -14,7 +13,7 @@ export default function FilePreviewModal(props: IProps) {
|
||||
|
||||
return (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
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 CircleProgress from "@Front/Components/DesignSystem/CircleProgress";
|
||||
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 DocumentTypeService from "src/common/Api/LeCoffreApi/sdk/DocumentTypeService";
|
||||
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||
|
||||
type IProps = {
|
||||
customerUid: string;
|
||||
@ -66,17 +64,15 @@ export default function DocumentTables(props: IProps) {
|
||||
// FilterBy folder.uid & depositor.uid
|
||||
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) {
|
||||
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);
|
||||
document.document_type = p1.processData;
|
||||
|
||||
const p2: any = ps.find((p2: any) => p2.processData.document.get('uid') === document.uid);
|
||||
if (p2) {
|
||||
document.files = [p2.processData];
|
||||
if (document.files && document.files.length > 0) {
|
||||
const files: any[] = [];
|
||||
for (const file of document.files) {
|
||||
files.push((await FileService.getFileByUid(file.uid)).processData);
|
||||
}
|
||||
document.files = files;
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,12 +118,12 @@ export default function DocumentTables(props: IProps) {
|
||||
[deleteSentDocumentModal],
|
||||
);
|
||||
|
||||
const onDownload = useCallback((doc: any /* Document */) => {
|
||||
const onDownload = useCallback((doc: any) => {
|
||||
const file = doc.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
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 a = document.createElement('a');
|
||||
a.href = url;
|
||||
|
@ -23,6 +23,7 @@ import AnchoringProcessingInfo from "./elements/AnchoringProcessingInfo";
|
||||
|
||||
import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService";
|
||||
import NoteService from "src/common/Api/LeCoffreApi/sdk/NoteService";
|
||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||
|
||||
export enum AnchorStatus {
|
||||
"VERIFIED_ON_CHAIN" = "VERIFIED_ON_CHAIN",
|
||||
@ -107,10 +108,11 @@ export default function FolderInformation(props: IProps) {
|
||||
*/
|
||||
|
||||
// TODO: review
|
||||
return FolderService.getFolderByUid(folderUid).then((process: any) => {
|
||||
return FolderService.getFolderByUid(folderUid).then(async (process: any) => {
|
||||
if (process) {
|
||||
const folder: any = process.processData;
|
||||
|
||||
await new Promise<void>((resolve: () => void) => {
|
||||
NoteService.getNotes().then((processes: any) => {
|
||||
if (processes.length > 0) {
|
||||
let notes: any[] = processes.map((process: any) => process.processData);
|
||||
@ -122,10 +124,23 @@ export default function FolderInformation(props: IProps) {
|
||||
folder.notes = notes;
|
||||
}
|
||||
}
|
||||
|
||||
setFolder(folder);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
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]);
|
||||
|
@ -18,8 +18,7 @@ import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
||||
import MessageBox from "@Front/Components/Elements/MessageBox";
|
||||
|
||||
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
|
||||
|
||||
import MessageBus from "src/sdk/MessageBus";
|
||||
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
|
||||
|
||||
type IProps = {};
|
||||
type IPropsClass = {
|
||||
@ -91,10 +90,10 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
</div>
|
||||
)}
|
||||
<div className={classes["file-container"]}>
|
||||
{this.state.selectedFile.mimetype === "application/pdf" ||
|
||||
this.state.selectedFile.mimetype === "image/jpeg" ||
|
||||
this.state.selectedFile.mimetype === "image/png" ||
|
||||
this.state.selectedFile.mimetype === "image/jpg" ? (
|
||||
{this.state.selectedFile.file_blob.type === "application/pdf" ||
|
||||
this.state.selectedFile.file_blob.type === "image/jpeg" ||
|
||||
this.state.selectedFile.file_blob.type === "image/png" ||
|
||||
this.state.selectedFile.file_blob.type === "image/jpg" ? (
|
||||
<FilePreview
|
||||
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
|
||||
fileName={this.state.selectedFile.file_name}
|
||||
@ -199,27 +198,17 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
|
||||
override async componentDidMount() {
|
||||
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) => {
|
||||
DocumentService.getDocumentByUid(this.props.documentUid).then(async (process: any) => {
|
||||
if (process) {
|
||||
const document: any = process.processData;
|
||||
|
||||
const ps: any[] = await MessageBus.getInstance().getFiles();
|
||||
const p: any = ps.find((p: any) => p.processData.document.get('uid') === document.uid);
|
||||
if (p) {
|
||||
|
||||
document.files = [p.processData];
|
||||
if (document.files && document.files.length > 0) {
|
||||
const files: any[] = [];
|
||||
for (const file of document.files) {
|
||||
files.push((await FileService.getFileByUid(file.uid)).processData);
|
||||
}
|
||||
document.files = files;
|
||||
}
|
||||
|
||||
resolve(document);
|
||||
@ -248,12 +237,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
|
||||
private async getFilePreview(): Promise<void> {
|
||||
try {
|
||||
// TODO: review
|
||||
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);
|
||||
|
||||
const fileBlob: Blob = new Blob([this.state.selectedFile.file_blob.data], { type: this.state.selectedFile.file_blob.type });
|
||||
this.setState({
|
||||
fileBlob,
|
||||
});
|
||||
@ -263,12 +247,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
|
||||
}
|
||||
|
||||
private downloadFile() {
|
||||
// TODO: review
|
||||
//if (!this.state.fileBlob) return;
|
||||
const file: any = this.state.selectedFile.fileBlob;
|
||||
if (!this.state.fileBlob) return;
|
||||
|
||||
const blob = new Blob([file.data], { type: file.type });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const url = URL.createObjectURL(this.state.fileBlob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
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) => {
|
||||
this.getProcesses().then(async (processes: 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;
|
||||
}
|
||||
|
||||
@ -171,9 +171,10 @@ export default class MessageBus {
|
||||
}
|
||||
|
||||
files.push(file);
|
||||
break;
|
||||
}
|
||||
|
||||
resolve(files);
|
||||
resolve(files[0]);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user