Fix some bugs - continue

This commit is contained in:
Anthony Janin 2025-06-26 16:18:00 +02:00
parent d7e27bbb9a
commit f9abdd31cd
4 changed files with 98 additions and 22 deletions

View File

@ -5,10 +5,12 @@ import { useCallback, useMemo, useState } from "react";
import classes from "./classes.module.scss";
import Files from "@Front/Api/LeCoffreApi/Customer/Files/Files";
import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document";
import { ToasterService } from "@Front/Components/DesignSystem/Toaster";
import Confirm from "@Front/Components/DesignSystem/OldModal/Confirm";
import FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService";
type IProps = {
document: Document;
@ -59,15 +61,21 @@ export default function DepositDocumentComponent(props: IProps) {
const fileData = {
document: {
uid: document.uid
uid: document.uid!
},
file: fileBlob,
fileBlob: fileBlob,
file_name: file.name,
mimetype: file.type
}
const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0';
FileService.createFile(fileData, validatorId).then(() => resolve());
FileService.createFile(fileData, validatorId).then(() => {
DocumentService.getDocumentByUid(document.uid!).then((process: any) => {
if (process) {
DocumentService.updateDocument(process, { document_status: EDocumentStatus.DEPOSITED }).then(() => resolve());
}
});
});
}
};
reader.readAsArrayBuffer(file);

View File

@ -42,7 +42,6 @@ export default function ClientDashboard(props: IProps) {
const [customer, setCustomer] = useState<Customer | null>(null);
const [folder, setFolder] = useState<OfficeFolderNotary | null>(null);
const [file, setFile] = useState<any | null>(null);
const [documentsNotary, setDocumentsNotary] = useState<DocumentNotary[]>([]);
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
@ -96,11 +95,8 @@ export default function ClientDashboard(props: IProps) {
setCustomer(customer);
setFolder(folder);
setFile(file);
if (!file) {
setIsAuthModalOpen(true);
}
setIsAuthModalOpen(true);
return { folder, customer };
@ -178,6 +174,8 @@ export default function ClientDashboard(props: IProps) {
.map((p: any) => p.processData)
.filter((file: any) => file.isDeleted === 'false');
// TODO: review - customerUid
for (const document of documents) {
const p: any = await DocumentTypeService.getDocumentTypeByUid(document.document_type.uid);
document.document_type = p.processData;
@ -224,6 +222,7 @@ export default function ClientDashboard(props: IProps) {
setIsAddDocumentModalVisible(true);
}, []);
/*
const onDownloadFile = useCallback(() => {
if (!file) {
return;
@ -238,6 +237,7 @@ export default function ClientDashboard(props: IProps) {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, [file]);
*/
const renderBox = useCallback(() => {
return (
@ -267,6 +267,8 @@ export default function ClientDashboard(props: IProps) {
<Typography typo={ETypo.TITLE_H4} color={ETypoColor.TEXT_PRIMARY}>
Bonjour {customer?.contact?.first_name.concat(" ", customer?.contact?.last_name)}
</Typography>
{/*
{file && (
<Button
variant={EButtonVariant.SECONDARY}
@ -276,6 +278,7 @@ export default function ClientDashboard(props: IProps) {
Télécharger le document
</Button>
)}
*/}
<Tag color={ETagColor.INFO} label={folder?.deed?.deed_type?.name ?? ""} />
<div className={classes["office-container"]}>

View File

@ -19,6 +19,10 @@ import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
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 FileService from "src/common/Api/LeCoffreApi/sdk/FileService";
import MessageBus from "src/sdk/MessageBus";
type IProps = {};
type IPropsClass = {
documentUid: string;
@ -31,7 +35,7 @@ type IState = {
isValidateModalVisible: boolean;
refuseText: string;
selectedFileIndex: number;
selectedFile: File | null;
selectedFile: any; // File | null; TODO: review
validatedPercentage: number;
document: Document | null;
fileBlob: Blob | null;
@ -90,9 +94,9 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
)}
<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.mimetype === "image/jpeg" ||
this.state.selectedFile.mimetype === "image/png" ||
this.state.selectedFile.mimetype === "image/jpg" ? (
<FilePreview
href={this.state.fileBlob ? URL.createObjectURL(this.state.fileBlob) : ""}
fileName={this.state.selectedFile.file_name}
@ -141,7 +145,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
</>
)}
{this.state.document?.document_status === "VALIDATED" && this.state.fileBlob && (
<Button onClick={this.downloadFile}>Télécharger</Button>
<Button onClick={this.downloadFile}>Télécharger</Button>
)}
</div>
</div>
@ -197,6 +201,7 @@ 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 },
@ -205,6 +210,29 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
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 processes: any[] = await MessageBus.getInstance().getFiles();
const process1: any = processes.find((process: any) => process.processData.document.get('uid') === document.uid);
/*
const files: any[] = (await FileService.getFiles())
.map((p: any) => p.processData)
.filter((file: any) => file.isDeleted === 'false');
*/
document.files = [process1.processData];
resolve(document);
}
});
});
this.setState(
{
document,
@ -226,7 +254,11 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
private async getFilePreview(): Promise<void> {
try {
const fileBlob: Blob = await Files.getInstance().download(this.state.selectedFile?.uid as string);
// 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);
this.setState({
fileBlob,
@ -236,6 +268,24 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
}
}
private downloadFile() {
// TODO: review
//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(blob);
const a = document.createElement('a');
a.href = url;
a.download = this.state.selectedFile.file_name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
/* TODO: review
private downloadFile() {
if (!this.state.fileBlob) return;
const url = window.URL.createObjectURL(this.state.fileBlob);
@ -248,6 +298,7 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
a.click();
window.URL.revokeObjectURL(url);
}
*/
private getRandomPercentageForOcr() {
// find diff
@ -315,8 +366,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
Module.getInstance()
.get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) +
"?customerUid=" +
this.state.document?.depositor?.uid,
"?customerUid=" +
this.state.document?.depositor?.uid,
);
} catch (e) {
console.error(e);
@ -333,8 +384,8 @@ class ViewDocumentsClass extends BasePage<IPropsClass, IState> {
Module.getInstance()
.get()
.modules.pages.Folder.pages.FolderInformation.props.path.replace("[folderUid]", this.props.folderUid) +
"?customerUid=" +
this.state.document?.depositor?.uid,
"?customerUid=" +
this.state.document?.depositor?.uid,
);
} catch (e) {
console.error(e);

View File

@ -194,11 +194,25 @@ export default class MessageBus {
continue;
}
const isFile: boolean = process.states
.map((state: any) => state.keys)
.filter((keys: any) => keys['uid'] && keys['utype_ff']).length > 0;
const publicDataDecoded: { [key: string]: any } = {};
if (!isFile) {
for (let stateId = 0; stateId < process.states.length - 1; stateId++) {
const state = process.states[stateId];
if (!state) {
continue;
}
const publicDataEncoded = state.public_data;
if (!publicDataEncoded) {
continue;
}
for (const key of Object.keys(publicDataEncoded)) {
publicDataDecoded[key] = await this.getPublicData(publicDataEncoded[key]);
}
}
if (publicDataDecoded['utype'] !== 'file') {
continue;
}